summaryrefslogtreecommitdiff
path: root/src/lbaselib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-22 09:00:12 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-22 09:00:12 +0100
commita40719dc74b8dbb0d6c8fc0272c0d79ad8a7a9ea (patch)
treea87cbfa7d3e7620b64681f3f738320c58be0f469 /src/lbaselib.js
parentdbe2a3bf2ef8c053e6c596c99e29eb27b6118f1b (diff)
downloadfengari-a40719dc74b8dbb0d6c8fc0272c0d79ad8a7a9ea.tar.gz
fengari-a40719dc74b8dbb0d6c8fc0272c0d79ad8a7a9ea.tar.bz2
fengari-a40719dc74b8dbb0d6c8fc0272c0d79ad8a7a9ea.zip
select
Diffstat (limited to 'src/lbaselib.js')
-rw-r--r--src/lbaselib.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/lbaselib.js b/src/lbaselib.js
index d0e094f..19a990e 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -138,6 +138,20 @@ const luaB_error = function(L) {
return lapi.lua_error(L);
};
+const luaB_select = function(L) {
+ let n = lapi.lua_gettop(L);
+ if (lapi.lua_type(L, 1) === CT.LUA_TSTRING && lapi.lua_tostring(L, 1) === "#") {
+ lapi.lua_pushinteger(L, n - 1);
+ return 1;
+ } else {
+ let i = lauxlib.luaL_checkinteger(L, 1);
+ if (i < 0) i = n + i;
+ else if (i > n) i = n;
+ lauxlib.luaL_argcheck(L, 1 <= i, 1, "index out of range");
+ return n - i;
+ }
+};
+
/*
** Continuation function for 'pcall' and 'xpcall'. Both functions
** already pushed a 'true' before doing the call, so in case of success
@@ -183,6 +197,7 @@ const base_funcs = {
"tostring": luaB_tostring,
"getmetatable": luaB_getmetatable,
"ipairs": luaB_ipairs,
+ "select": luaB_select,
"setmetatable": luaB_setmetatable,
"rawequal": luaB_rawequal,
"rawset": luaB_rawset,