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

@@ -58,6 +58,14 @@ static void checktab (lua_State *L, int arg, int what) {
}
static int tcreate (lua_State *L) {
int sizeseq = (int)luaL_checkinteger(L, 1);
int sizerest = (int)luaL_optinteger(L, 2, 0);
lua_createtable(L, sizeseq, sizerest);
return 1;
}
static int tinsert (lua_State *L) {
lua_Integer pos; /* where to insert new element */
lua_Integer e = aux_getn(L, 1, TAB_RW);
@@ -390,6 +398,7 @@ static int sort (lua_State *L) {
static const luaL_Reg tab_funcs[] = {
{"concat", tconcat},
{"create", tcreate},
{"insert", tinsert},
{"pack", tpack},
{"unpack", tunpack},