diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-01-18 15:16:26 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-01-18 15:16:26 -0300 |
commit | 3e9dbe143d3338f5f13a5e421ea593adff482da0 (patch) | |
tree | ce070c600970d216f3a68c78ae9e55d8048ec4ff /ltablib.c | |
parent | 4a8e48086433ad12f2991c07f3064278714fd0f1 (diff) | |
download | lua-3e9dbe143d3338f5f13a5e421ea593adff482da0.tar.gz lua-3e9dbe143d3338f5f13a5e421ea593adff482da0.tar.bz2 lua-3e9dbe143d3338f5f13a5e421ea593adff482da0.zip |
New function 'table.create'
Creates a table preallocating memory. (It just exports to Lua the API
function 'lua_createtable'.)
Diffstat (limited to 'ltablib.c')
-rw-r--r-- | ltablib.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -58,6 +58,14 @@ static void checktab (lua_State *L, int arg, int what) { | |||
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
61 | static int tcreate (lua_State *L) { | ||
62 | int sizeseq = (int)luaL_checkinteger(L, 1); | ||
63 | int sizerest = (int)luaL_optinteger(L, 2, 0); | ||
64 | lua_createtable(L, sizeseq, sizerest); | ||
65 | return 1; | ||
66 | } | ||
67 | |||
68 | |||
61 | static int tinsert (lua_State *L) { | 69 | static int tinsert (lua_State *L) { |
62 | lua_Integer pos; /* where to insert new element */ | 70 | lua_Integer pos; /* where to insert new element */ |
63 | lua_Integer e = aux_getn(L, 1, TAB_RW); | 71 | lua_Integer e = aux_getn(L, 1, TAB_RW); |
@@ -390,6 +398,7 @@ static int sort (lua_State *L) { | |||
390 | 398 | ||
391 | static const luaL_Reg tab_funcs[] = { | 399 | static const luaL_Reg tab_funcs[] = { |
392 | {"concat", tconcat}, | 400 | {"concat", tconcat}, |
401 | {"create", tcreate}, | ||
393 | {"insert", tinsert}, | 402 | {"insert", tinsert}, |
394 | {"pack", tpack}, | 403 | {"pack", tpack}, |
395 | {"unpack", tunpack}, | 404 | {"unpack", tunpack}, |