New function 'table.create'

Creates a table preallocating memory. (It just exports to Lua the API
function 'lua_createtable'.)
This commit is contained in:
Roberto Ierusalimschy
2024-01-18 15:16:26 -03:00
parent 4a8e480864
commit 3e9dbe143d
3 changed files with 45 additions and 2 deletions

View File

@@ -3234,11 +3234,11 @@ Values at other positions are not affected.
}
@APIEntry{void lua_createtable (lua_State *L, int narr, int nrec);|
@APIEntry{void lua_createtable (lua_State *L, int nseq, int nrec);|
@apii{0,1,m}
Creates a new empty table and pushes it onto the stack.
Parameter @id{narr} is a hint for how many elements the table
Parameter @id{nseq} is a hint for how many elements the table
will have as a sequence;
parameter @id{nrec} is a hint for how many other elements
the table will have.
@@ -7969,6 +7969,19 @@ If @id{i} is greater than @id{j}, returns the empty string.
}
@LibEntry{table.create (nseq [, nrec])|
Creates a new empty table, preallocating memory.
This preallocation may help performance and save memory
when you know in advance how many elements the table will have.
Parameter @id{nseq} is a hint for how many elements the table
will have as a sequence.
Optional parameter @id{nrec} is a hint for how many other elements
the table will have; its default is zero.
}
@LibEntry{table.insert (list, [pos,] value)|
Inserts element @id{value} at position @id{pos} in @id{list},