diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-05-14 00:09:23 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-05-14 00:09:23 +0200 |
commit | 4cc641ef7394d4aa07889d633068350eb26f893a (patch) | |
tree | dbe2b6e266f96a0fee5bba5bc1aeb2d4c7df07ee /src/lapi.js | |
parent | 00026860d3fe14b12cd539ee76ee791b0d46f7a4 (diff) | |
download | fengari-4cc641ef7394d4aa07889d633068350eb26f893a.tar.gz fengari-4cc641ef7394d4aa07889d633068350eb26f893a.tar.bz2 fengari-4cc641ef7394d4aa07889d633068350eb26f893a.zip |
lua_arith, moved luaO_arith to lobject.js
Diffstat (limited to 'src/lapi.js')
-rw-r--r-- | src/lapi.js | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/lapi.js b/src/lapi.js index 9fc1cc7..4d2f288 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -857,6 +857,18 @@ const lua_rawequal = function(L, index1, index2) { return isvalid(o1) && isvalid(o2) ? lvm.luaV_equalobj(null, o1, o2) : 0; // TODO: isvalid ? }; +const lua_arith = function(L, op) { + if (op !== defs.LUA_OPUNM && op !== defs.LUA_OPBNOT) + assert(2 < L.top - L.ci.funcOff, "not enough elements in the stack"); /* all other operations expect two operands */ + else { /* for unary operations, add fake 2nd operand */ + assert(1 < L.top - L.ci.funcOff, "not enough elements in the stack"); + L.stack[L.top++] = L.stack[L.top - 1]; + } + /* first operand at top - 2, second at top - 1; result go to top - 2 */ + lobject.luaO_arith(L, op, L.stack[L.top - 2], L.stack[L.top - 1], L.stack[L.top - 2]); + L.op--; /* remove second operand */ +}; + /* ** 'load' and 'call' functions (run Lua code) */ @@ -1069,6 +1081,7 @@ const lua_getextraspace = function () { module.exports.index2addr = index2addr; module.exports.index2addr_ = index2addr_; module.exports.lua_absindex = lua_absindex; +module.exports.lua_arith = lua_arith; module.exports.lua_atpanic = lua_atpanic; module.exports.lua_call = lua_call; module.exports.lua_callk = lua_callk; @@ -1115,6 +1128,7 @@ module.exports.lua_pop = lua_pop; module.exports.lua_pushboolean = lua_pushboolean; module.exports.lua_pushcclosure = lua_pushcclosure; module.exports.lua_pushcfunction = lua_pushcfunction; +module.exports.lua_pushfstring = lua_pushfstring; module.exports.lua_pushglobaltable = lua_pushglobaltable; module.exports.lua_pushinteger = lua_pushinteger; module.exports.lua_pushjsclosure = lua_pushjsclosure; @@ -1125,10 +1139,9 @@ module.exports.lua_pushlstring = lua_pushlstring; module.exports.lua_pushnil = lua_pushnil; module.exports.lua_pushnumber = lua_pushnumber; module.exports.lua_pushstring = lua_pushstring; -module.exports.lua_pushfstring = lua_pushfstring; -module.exports.lua_pushvfstring = lua_pushvfstring; module.exports.lua_pushthread = lua_pushthread; module.exports.lua_pushvalue = lua_pushvalue; +module.exports.lua_pushvfstring = lua_pushvfstring; module.exports.lua_rawequal = lua_rawequal; module.exports.lua_rawget = lua_rawget; module.exports.lua_rawgeti = lua_rawgeti; |