diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-24 08:13:38 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-24 08:13:38 +0100 |
commit | bd3ffd7282de8236cd4eb2ff2e21bbc10791bfeb (patch) | |
tree | 2de6c6153d1cce350402053e364236cecb1c9725 /src/ltablib.js | |
parent | 8b9545c6b2a158d44e18dcaa1147cc1206eabfd3 (diff) | |
download | fengari-bd3ffd7282de8236cd4eb2ff2e21bbc10791bfeb.tar.gz fengari-bd3ffd7282de8236cd4eb2ff2e21bbc10791bfeb.tar.bz2 fengari-bd3ffd7282de8236cd4eb2ff2e21bbc10791bfeb.zip |
table.pack
Diffstat (limited to 'src/ltablib.js')
-rw-r--r-- | src/ltablib.js | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/ltablib.js b/src/ltablib.js index 8e1f758..ec7c578 100644 --- a/src/ltablib.js +++ b/src/ltablib.js @@ -80,8 +80,20 @@ const tconcat = function(L) { return 1; }; +const pack = function(L) { + let n = lapi.lua_gettop(L); /* number of elements to pack */ + lapi.lua_createtable(L, n, 1); /* create result table */ + lapi.lua_insert(L, 1); /* put it at index 1 */ + for (let i = n; i >= 1; i--) /* assign elements */ + lapi.lua_seti(L, 1, i); + lapi.lua_pushinteger(L, n); + lapi.lua_setfield(L, 1, "n"); /* t.n = number of elements */ + return 1; /* return table */ +}; + const tab_funcs = { - "concat": tconcat + "concat": tconcat, + "pack": pack }; const luaopen_table = function(L) { |