summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--locale/en-us/meta.lua6
-rw-r--r--locale/zh-cn/meta.lua6
-rw-r--r--meta/template/table.lua27
3 files changed, 39 insertions, 0 deletions
diff --git a/locale/en-us/meta.lua b/locale/en-us/meta.lua
index 858cde13..839dc27a 100644
--- a/locale/en-us/meta.lua
+++ b/locale/en-us/meta.lua
@@ -677,6 +677,12 @@ Returns the elements from the given list. This function is equivalent to
```
By default, `i` is `1` and `j` is `#list`.
]]
+table.foreach =
+'Executes the given f over all elements of table. For each element, f is called with the index and respective value as arguments. If f returns a non-nil value, then the loop is broken, and this value is returned as the final value of foreach.'
+table.foreachi =
+'Executes the given f over the numerical indices of table. For each index, f is called with the index and respective value as arguments. Indices are visited in sequential order, from 1 to n, where n is the size of the table. If f returns a non-nil value, then the loop is broken and this value is returned as the result of foreachi.'
+table.getn =
+'Returns the number of elements in the table. This function is equivalent to `#list`.'
utf8 =
''
diff --git a/locale/zh-cn/meta.lua b/locale/zh-cn/meta.lua
index 8e7c37e8..61ba6c9b 100644
--- a/locale/zh-cn/meta.lua
+++ b/locale/zh-cn/meta.lua
@@ -655,6 +655,12 @@ table.unpack =
```
i 默认为 1 ,j 默认为 #list。
]]
+table.foreach =
+'遍历表中的每一个元素,并以key和value执行回调函数。如果回调函数返回一个非nil值则循环终止,并且返回这个值。该函数等同pair(list),比pair(list)更慢。不推荐使用'
+table.foreachi =
+'遍历数组中的每一个元素,并以索引号index和value执行回调函数。如果回调函数返回一个非nil值则循环终止,并且返回这个值。该函数等同ipair(list),比ipair(list)更慢。不推荐使用'
+table.getn =
+'返回表的长度。该函数等价于#list。'
utf8 =
''
diff --git a/meta/template/table.lua b/meta/template/table.lua
index 3ec92ce8..21c8b619 100644
--- a/meta/template/table.lua
+++ b/meta/template/table.lua
@@ -64,4 +64,31 @@ function table.sort(list, comp) end
---@nodiscard
function table.unpack(list, i, j) end
+---@version <5.1, JIT
+---#DES 'table.foreach'
+---@generic T
+---@param list any
+---@param callback fun(key: string, value: any):T|nil
+---@return T|nil
+---@deprecated
+function table.foreach(list, callback) end
+
+---@version <5.1, JIT
+---#DES 'table.foreachi'
+---@generic T
+---@param list any
+---@param callback fun(key: string, value: any):T|nil
+---@return T|nil
+---@deprecated
+function table.foreachi(list, callback) end
+
+---@version <5.1, JIT
+---#DES 'table.getn'
+---@generic T
+---@param list T[]
+---@return integer
+---@nodiscard
+---@deprecated
+function table.getn(list) end
+
return table