From 3e9dbe143d3338f5f13a5e421ea593adff482da0 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 18 Jan 2024 15:16:26 -0300 Subject: New function 'table.create' Creates a table preallocating memory. (It just exports to Lua the API function 'lua_createtable'.) --- ltablib.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ltablib.c') diff --git a/ltablib.c b/ltablib.c index 44d55ef5..c8838963 100644 --- a/ltablib.c +++ b/ltablib.c @@ -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}, -- cgit v1.2.3-55-g6feb