Skip to content

Commit 66504f8

Browse files
fesilysumneko
authored andcommitted
add table meta:foreach,foreachi,getn
1 parent 23f9c21 commit 66504f8

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

locale/en-us/meta.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,12 @@ Returns the elements from the given list. This function is equivalent to
677677
```
678678
By default, `i` is `1` and `j` is `#list`.
679679
]]
680+
table.foreach =
681+
'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.'
682+
table.foreachi =
683+
'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.'
684+
table.getn =
685+
'Returns the number of elements in the table. This function is equivalent to `#list`.'
680686

681687
utf8 =
682688
''

locale/zh-cn/meta.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,12 @@ table.unpack =
655655
```
656656
i 默认为 1 ,j 默认为 #list。
657657
]]
658+
table.foreach =
659+
'遍历表中的每一个元素,并以key和value执行回调函数。如果回调函数返回一个非nil值则循环终止,并且返回这个值。该函数等同pair(list),比pair(list)更慢。不推荐使用'
660+
table.foreachi =
661+
'遍历数组中的每一个元素,并以索引号index和value执行回调函数。如果回调函数返回一个非nil值则循环终止,并且返回这个值。该函数等同ipair(list),比ipair(list)更慢。不推荐使用'
662+
table.getn =
663+
'返回表的长度。该函数等价于#list。'
658664

659665
utf8 =
660666
''

meta/template/table.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,31 @@ function table.sort(list, comp) end
6464
---@nodiscard
6565
function table.unpack(list, i, j) end
6666

67+
---@version <5.1, JIT
68+
---#DES 'table.foreach'
69+
---@generic T
70+
---@param list any
71+
---@param callback fun(key: string, value: any):T|nil
72+
---@return T|nil
73+
---@deprecated
74+
function table.foreach(list, callback) end
75+
76+
---@version <5.1, JIT
77+
---#DES 'table.foreachi'
78+
---@generic T
79+
---@param list any
80+
---@param callback fun(key: string, value: any):T|nil
81+
---@return T|nil
82+
---@deprecated
83+
function table.foreachi(list, callback) end
84+
85+
---@version <5.1, JIT
86+
---#DES 'table.getn'
87+
---@generic T
88+
---@param list T[]
89+
---@return integer
90+
---@nodiscard
91+
---@deprecated
92+
function table.getn(list) end
93+
6794
return table

0 commit comments

Comments
 (0)