aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-24 11:14:25 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-24 11:14:25 +0100
commit2ccf4ee80dbbf3e9af8ff006fcc18798e668a413 (patch)
tree1e56eed9cf006b12af8449ea20a28b1909cd4681 /src
parentcc578361f82c892fc5cce7d2ce9757ca237e87bf (diff)
downloadfengari-2ccf4ee80dbbf3e9af8ff006fcc18798e668a413.tar.gz
fengari-2ccf4ee80dbbf3e9af8ff006fcc18798e668a413.tar.bz2
fengari-2ccf4ee80dbbf3e9af8ff006fcc18798e668a413.zip
table.remove
Diffstat (limited to 'src')
-rw-r--r--src/ltablib.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/ltablib.js b/src/ltablib.js
index 8ea6f08..6255761 100644
--- a/src/ltablib.js
+++ b/src/ltablib.js
@@ -83,6 +83,21 @@ const tinsert = function(L) {
return 0;
};
+const tremove = function(L) {
+ let size = aux_getn(L, 1, TAB_RW);
+ let pos = lauxlib.luaL_optinteger(L, 2, size);
+ if (pos !== size) /* validate 'pos' if given */
+ lauxlib.luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, "position out of bounds");
+ lapi.lua_geti(L, 1, pos); /* result = t[pos] */
+ for (; pos < size; pos++) {
+ lapi.lua_geti(L, 1, pos + 1);
+ lapi.lua_seti(L, 1, pos); /* t[pos] = t[pos + 1] */
+ }
+ lapi.lua_pushnil(L);
+ lapi.lua_seti(L, 1, pos); /* t[pos] = nil */
+ return 1;
+};
+
const tconcat = function(L) {
let last = aux_getn(L, 1, TAB_R);
let sep = lauxlib.luaL_optlstring(L, 2, "");
@@ -133,6 +148,7 @@ const tab_funcs = {
"concat": tconcat,
"insert": tinsert,
"pack": pack,
+ "remove": tremove,
"unpack": unpack
};