Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions locale/en-us/meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,19 @@ 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`.'
table.new =
[[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.
```lua
require("table.new")
```
]]
table.clear =
[[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.
```lua
require("table.clear").
```
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.
]]

utf8 =
''
Expand Down
15 changes: 14 additions & 1 deletion locale/pt-br/meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ debug.getuservalue['<5.3'] =
debug.getuservalue['>5.4'] =
[[
Retorna o `n`-ésimo valor de usuário associado
aos dados do usuário `u` e um booleano,
aos dados do usuário `u` e um booleano,
`false`, se nos dados do usuário não existir esse valor.
]]
debug.setcstacklimit =
Expand Down Expand Up @@ -726,6 +726,19 @@ table.foreachi = -- TODO: need translate!
'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 = -- TODO: need translate!
'Returns the number of elements in the table. This function is equivalent to `#list`.'
table.new = -- TODO: need translate!
[[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.
```lua
require("table.new")
```
]]
table.clear = -- TODO: need translate!
[[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.
```lua
require("table.clear").
```
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.
]]

utf8 =
''
Expand Down
13 changes: 13 additions & 0 deletions locale/zh-cn/meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,19 @@ table.foreachi =
'遍历数组中的每一个元素,并以索引号index和value执行回调函数。如果回调函数返回一个非nil值则循环终止,并且返回这个值。该函数等同ipair(list),比ipair(list)更慢。不推荐使用'
table.getn =
'返回表的长度。该函数等价于#list。'
table.new = -- TODO: need translate!
[[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.
```lua
require("table.new")
```
]]
table.clear = -- TODO: need translate!
[[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.
```lua
require("table.clear").
```
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.
]]

utf8 =
''
Expand Down
13 changes: 13 additions & 0 deletions locale/zh-tw/meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,19 @@ table.foreachi =
'走訪表中的每一個元素,並以索引號index和value執行回呼函式。如果回呼函式回傳一個非nil值則循環終止,並且回傳這個值。該函式等同ipair(list),比ipair(list)更慢。不推薦使用'
table.getn =
'回傳表的長度。該函式等價於#list。'
table.new = -- TODO: need translate!
[[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.
```lua
require("table.new")
```
]]
table.clear = -- TODO: need translate!
[[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.
```lua
require("table.clear").
```
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.
]]

utf8 =
''
Expand Down
7 changes: 0 additions & 7 deletions meta/3rd/OpenResty/library/table.clear.lua

This file was deleted.

10 changes: 0 additions & 10 deletions meta/3rd/OpenResty/library/table.new.lua

This file was deleted.

12 changes: 12 additions & 0 deletions meta/template/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,16 @@ function table.foreachi(list, callback) end
---@deprecated
function table.getn(list) end

---@version JIT
Copy link
Contributor

@flrgh flrgh May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question. So, in OpenResty libraries, it's very common to see code that does this:

-- require the `table.new` function and stash it in a local 
local new_table = require "table.new"

-- ...now use the local function to create a table 
local my_table = new_table(0, 5)

Examples:

Whether or not this is common elsewhere, in OpenResty it's considered idiomatic, largely because one is not relying on the side effect of modifying _G.table. This is why I originally created table.new/table.clear as standalone modules that return a function.

So my question is: with this change, will the type of new_table in the code snippet above still be detected correctly? Ideally I'd like this use-case to not be broken.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the described behavior is what I had in mind. Unfortunately, I don't have the build system set up to try this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please open a separate issue, I have no time to deal with this recently.

---#DES 'table.new'
---@param narray integer
---@param nhash integer
---@return table
function table.new(narray, nhash) end

---@version JIT
---#DES 'table.clear'
---@param tab table
function table.clear(tab) end

return table