Skip to content

Commit 88a3cd6

Browse files
committed
Implement support for LuaJIT's table.new and table.clear
1 parent e069d28 commit 88a3cd6

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

locale/en-us/meta.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,19 @@ table.foreachi =
726726
'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.'
727727
table.getn =
728728
'Returns the number of elements in the table. This function is equivalent to `#list`.'
729+
table.new =
730+
[[This creates a pre-sized table, just like the C API equivalent `lua_createtable()`. This is useful for big tables if the final table size is known and automatic table resizing is too expensive. `narray` parameter specifies the number of array-like items, and `nhash` parameter specifies the number of hash-like items. The function needs to be required before use.
731+
```lua
732+
require("table.new")
733+
```
734+
]]
735+
table.clear =
736+
[[This clears all keys and values from a table, but preserves the allocated array/hash sizes. This is useful when a table, which is linked from multiple places, needs to be cleared and/or when recycling a table for use by the same context. This avoids managing backlinks, saves an allocation and the overhead of incremental array/hash part growth. The function needs to be required before use.
737+
```lua
738+
require("table.clear").
739+
```
740+
Please note this function is meant for very specific situations. In most cases it's better to replace the (usually single) link with a new table and let the GC do its work.
741+
]]
729742

730743
utf8 =
731744
''

locale/pt-br/meta.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ debug.getuservalue['<5.3'] =
293293
debug.getuservalue['>5.4'] =
294294
[[
295295
Retorna o `n`-ésimo valor de usuário associado
296-
aos dados do usuário `u` e um booleano,
296+
aos dados do usuário `u` e um booleano,
297297
`false`, se nos dados do usuário não existir esse valor.
298298
]]
299299
debug.setcstacklimit =
@@ -726,6 +726,19 @@ table.foreachi = -- TODO: need translate!
726726
'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.'
727727
table.getn = -- TODO: need translate!
728728
'Returns the number of elements in the table. This function is equivalent to `#list`.'
729+
table.new = -- TODO: need translate!
730+
[[This creates a pre-sized table, just like the C API equivalent `lua_createtable()`. This is useful for big tables if the final table size is known and automatic table resizing is too expensive. `narray` parameter specifies the number of array-like items, and `nhash` parameter specifies the number of hash-like items. The function needs to be required before use.
731+
```lua
732+
require("table.new")
733+
```
734+
]]
735+
table.clear = -- TODO: need translate!
736+
[[This clears all keys and values from a table, but preserves the allocated array/hash sizes. This is useful when a table, which is linked from multiple places, needs to be cleared and/or when recycling a table for use by the same context. This avoids managing backlinks, saves an allocation and the overhead of incremental array/hash part growth. The function needs to be required before use.
737+
```lua
738+
require("table.clear").
739+
```
740+
Please note this function is meant for very specific situations. In most cases it's better to replace the (usually single) link with a new table and let the GC do its work.
741+
]]
729742

730743
utf8 =
731744
''

locale/zh-cn/meta.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,19 @@ table.foreachi =
734734
'遍历数组中的每一个元素,并以索引号index和value执行回调函数。如果回调函数返回一个非nil值则循环终止,并且返回这个值。该函数等同ipair(list),比ipair(list)更慢。不推荐使用'
735735
table.getn =
736736
'返回表的长度。该函数等价于#list。'
737+
table.new = -- TODO: need translate!
738+
[[This creates a pre-sized table, just like the C API equivalent `lua_createtable()`. This is useful for big tables if the final table size is known and automatic table resizing is too expensive. `narray` parameter specifies the number of array-like items, and `nhash` parameter specifies the number of hash-like items. The function needs to be required before use.
739+
```lua
740+
require("table.new")
741+
```
742+
]]
743+
table.clear = -- TODO: need translate!
744+
[[This clears all keys and values from a table, but preserves the allocated array/hash sizes. This is useful when a table, which is linked from multiple places, needs to be cleared and/or when recycling a table for use by the same context. This avoids managing backlinks, saves an allocation and the overhead of incremental array/hash part growth. The function needs to be required before use.
745+
```lua
746+
require("table.clear").
747+
```
748+
Please note this function is meant for very specific situations. In most cases it's better to replace the (usually single) link with a new table and let the GC do its work.
749+
]]
737750

738751
utf8 =
739752
''

locale/zh-tw/meta.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,19 @@ table.foreachi =
734734
'走訪表中的每一個元素,並以索引號index和value執行回呼函式。如果回呼函式回傳一個非nil值則循環終止,並且回傳這個值。該函式等同ipair(list),比ipair(list)更慢。不推薦使用'
735735
table.getn =
736736
'回傳表的長度。該函式等價於#list。'
737+
table.new = -- TODO: need translate!
738+
[[This creates a pre-sized table, just like the C API equivalent `lua_createtable()`. This is useful for big tables if the final table size is known and automatic table resizing is too expensive. `narray` parameter specifies the number of array-like items, and `nhash` parameter specifies the number of hash-like items. The function needs to be required before use.
739+
```lua
740+
require("table.new")
741+
```
742+
]]
743+
table.clear = -- TODO: need translate!
744+
[[This clears all keys and values from a table, but preserves the allocated array/hash sizes. This is useful when a table, which is linked from multiple places, needs to be cleared and/or when recycling a table for use by the same context. This avoids managing backlinks, saves an allocation and the overhead of incremental array/hash part growth. The function needs to be required before use.
745+
```lua
746+
require("table.clear").
747+
```
748+
Please note this function is meant for very specific situations. In most cases it's better to replace the (usually single) link with a new table and let the GC do its work.
749+
]]
737750

738751
utf8 =
739752
''

meta/template/table.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,16 @@ function table.foreachi(list, callback) end
9292
---@deprecated
9393
function table.getn(list) end
9494

95+
---@version JIT
96+
---#DES 'table.new'
97+
---@param narray integer
98+
---@param nhash integer
99+
---@return table
100+
function table.new(narray, nhash) end
101+
102+
---@version JIT
103+
---#DES 'table.clear'
104+
---@param tab table
105+
function table.clear(tab) end
106+
95107
return table

0 commit comments

Comments
 (0)