aboutsummaryrefslogtreecommitdiff
path: root/ltablib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-01-18 15:16:26 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-01-18 15:16:26 -0300
commit3e9dbe143d3338f5f13a5e421ea593adff482da0 (patch)
treece070c600970d216f3a68c78ae9e55d8048ec4ff /ltablib.c
parent4a8e48086433ad12f2991c07f3064278714fd0f1 (diff)
downloadlua-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.c9
1 files changed, 9 insertions, 0 deletions
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) {
58} 58}
59 59
60 60
61static 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
61static int tinsert (lua_State *L) { 69static 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
391static const luaL_Reg tab_funcs[] = { 399static 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},