summaryrefslogtreecommitdiff
path: root/src/lapi.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-24 11:38:23 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-24 11:40:35 +0100
commit2f9fe378bc341921e1ae259a2fec049663100738 (patch)
tree64f5f5a5cbc40630c894f5700502d3f757eef1f1 /src/lapi.js
parent2ccf4ee80dbbf3e9af8ff006fcc18798e668a413 (diff)
downloadfengari-2f9fe378bc341921e1ae259a2fec049663100738.tar.gz
fengari-2f9fe378bc341921e1ae259a2fec049663100738.tar.bz2
fengari-2f9fe378bc341921e1ae259a2fec049663100738.zip
table.move
Diffstat (limited to 'src/lapi.js')
-rw-r--r--src/lapi.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lapi.js b/src/lapi.js
index f34216b..488fb58 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -538,6 +538,23 @@ const lua_topointer = function(L, idx) {
}
};
+const lua_compare = function(L, index1, index2, op) {
+ let i = 0;
+ let o1 = index2addr(L, index1);
+ let o2 = index2addr(L, index1);
+
+ if (!o1.ttisnil() && !o2.ttisnil()) {
+ switch (op) {
+ case lua.LUA_OPEQ: i = lvm.luaV_equalobj(L, o1, o2); break;
+ case lua.LUA_OPLT: i = lvm.luaV_lessthan(L, o1, o2); break;
+ case lua.LUA_OPLE: i = lvm.luaV_lessequal(L, o1, o2); break;
+ default: assert(false, "invalid option");
+ }
+ }
+
+ return i;
+};
+
const lua_stringtonumber = function(L, s) {
let number = parseFloat(s);
L.stack[L.top++] = new TValue(number % 1 !== 0 ? CT.LUA_TNUMFLT : CT.LUA_TNUMINT, number);
@@ -568,6 +585,10 @@ const lua_typename = function(L, t) {
return ltm.ttypename(t);
};
+const lua_isnoneornil = function(L, n) {
+ return lua_type(L, n) <= 0;
+}
+
const lua_istable = function(L, idx) {
return index2addr(L, idx).ttistable();
};
@@ -741,6 +762,7 @@ module.exports.lua_atpanic = lua_atpanic;
module.exports.lua_call = lua_call;
module.exports.lua_callk = lua_callk;
module.exports.lua_checkstack = lua_checkstack;
+module.exports.lua_compare = lua_compare;
module.exports.lua_concat = lua_concat;
module.exports.lua_copy = lua_copy;
module.exports.lua_createtable = lua_createtable;
@@ -755,6 +777,7 @@ module.exports.lua_getmetatable = lua_getmetatable;
module.exports.lua_gettable = lua_gettable;
module.exports.lua_gettop = lua_gettop;
module.exports.lua_insert = lua_insert;
+module.exports.lua_isnoneornil = lua_isnoneornil;
module.exports.lua_isstring = lua_isstring;
module.exports.lua_istable = lua_istable;
module.exports.lua_len = lua_len;