aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lapi.js4
-rw-r--r--src/lauxlib.js4
-rw-r--r--src/lmathlib.js6
-rw-r--r--src/lobject.js28
-rw-r--r--src/lstrlib.js14
-rw-r--r--src/luaconf.js4
-rw-r--r--src/lvm.js44
7 files changed, 52 insertions, 52 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 991e982..5064c30 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -209,7 +209,7 @@ const lua_pushnumber = function(L, n) {
const lua_pushinteger = function(L, n) {
assert(typeof n === "number");
- L.stack[L.top++] = new TValue(CT.LUA_TNUMINT, n|0);
+ L.stack[L.top++] = new TValue(CT.LUA_TNUMINT, n);
assert(L.top <= L.ci.top, "stack overflow");
};
@@ -959,4 +959,4 @@ module.exports.lua_touserdata = lua_touserdata;
module.exports.lua_type = lua_type;
module.exports.lua_typename = lua_typename;
module.exports.lua_version = lua_version;
-module.exports.lua_xmove = lua_xmove; \ No newline at end of file
+module.exports.lua_xmove = lua_xmove;
diff --git a/src/lauxlib.js b/src/lauxlib.js
index f175fde..c2852ac 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -165,7 +165,7 @@ const luaL_checkstring = function(L, n) {
const luaL_checklstring = function(L, arg) {
let s = lapi.lua_tolstring(L, arg);
- if (!s) tag_error(L, arg, CT.LUA_TSTRING);
+ if (typeof s !== "string") tag_error(L, arg, CT.LUA_TSTRING);
return s;
};
@@ -577,4 +577,4 @@ module.exports.luaL_requiref = luaL_requiref;
module.exports.luaL_setfuncs = luaL_setfuncs;
module.exports.luaL_tolstring = luaL_tolstring;
module.exports.luaL_typename = luaL_typename;
-module.exports.luaL_where = luaL_where; \ No newline at end of file
+module.exports.luaL_where = luaL_where;
diff --git a/src/lmathlib.js b/src/lmathlib.js
index 55f8416..724ad75 100644
--- a/src/lmathlib.js
+++ b/src/lmathlib.js
@@ -268,11 +268,11 @@ const luaopen_math = function(L) {
lapi.lua_setfield(L, -2, "pi");
lapi.lua_pushnumber(L, Number.MAX_VALUE);
lapi.lua_setfield(L, -2, "huge");
- lapi.lua_pushnumber(L, Number.MAX_SAFE_INTEGER);
+ lapi.lua_pushinteger(L, Number.MAX_SAFE_INTEGER);
lapi.lua_setfield(L, -2, "maxinteger");
- lapi.lua_pushnumber(L, Number.MIN_SAFE_INTEGER);
+ lapi.lua_pushinteger(L, Number.MIN_SAFE_INTEGER);
lapi.lua_setfield(L, -2, "mininteger");
return 1;
};
-module.exports.luaopen_math = luaopen_math; \ No newline at end of file
+module.exports.luaopen_math = luaopen_math;
diff --git a/src/lobject.js b/src/lobject.js
index 8fc587d..c2950b6 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -424,18 +424,18 @@ const luaO_int2fb = function(x) {
const intarith = function(L, op, v1, v2) {
switch (op) {
- case lua.LUA_OPADD: return (v1 + v2)|0;
- case lua.LUA_OPSUB: return (v1 - v2)|0;
- case lua.LUA_OPMUL: return (v1 * v2)|0;
- case lua.LUA_OPMOD: return (v1 % v2)|0;
- case lua.LUA_OPIDIV: return (v1 / v2)|0;
- case lua.LUA_OPBAND: return (v1 & v2)|0;
- case lua.LUA_OPBOR: return (v1 | v2)|0;
- case lua.LUA_OPBXOR: return (v1 ^ v2)|0;
- case lua.LUA_OPSHL: return (v1 << v2)|0;
- case lua.LUA_OPSHR: return (v1 >> v2)|0;
- case lua.LUA_OPUNM: return (-v1)|0;
- case lua.LUA_OPBNOT: return (~v1)|0;
+ case lua.LUA_OPADD: return (v1 + v2);
+ case lua.LUA_OPSUB: return (v1 - v2);
+ case lua.LUA_OPMUL: return (v1 * v2);
+ case lua.LUA_OPMOD: return (v1 % v2);
+ case lua.LUA_OPIDIV: return (v1 / v2);
+ case lua.LUA_OPBAND: return (v1 & v2);
+ case lua.LUA_OPBOR: return (v1 | v2);
+ case lua.LUA_OPBXOR: return (v1 ^ v2);
+ case lua.LUA_OPSHL: return (v1 << v2);
+ case lua.LUA_OPSHR: return (v1 >> v2);
+ case lua.LUA_OPUNM: return (-v1);
+ case lua.LUA_OPBNOT: return (~v1);
}
};
@@ -447,7 +447,7 @@ const numarith = function(L, op, v1, v2) {
case lua.LUA_OPMUL: return v1 * v2;
case lua.LUA_OPDIV: return v1 / v2;
case lua.LUA_OPPOW: return Math.pow(v1, v2);
- case lua.LUA_OPIDIV: return (v1 / v2)|0;
+ case lua.LUA_OPIDIV: return (v1 / v2);
case lua.LUA_OPUNM: return -v1;
case lua.LUA_OPMOD: return v1 % v2;
}
@@ -465,4 +465,4 @@ module.exports.luaO_hexavalue = luaO_hexavalue;
module.exports.luaO_int2fb = luaO_int2fb;
module.exports.luaO_str2num = luaO_str2num;
module.exports.luaO_utf8desc = luaO_utf8desc;
-module.exports.numarith = numarith; \ No newline at end of file
+module.exports.numarith = numarith;
diff --git a/src/lstrlib.js b/src/lstrlib.js
index 95fb375..c6c0dc3 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -109,7 +109,7 @@ const ldexp = function(mantissa, exponent) {
** Add integer part of 'x' to buffer and return new 'x'
*/
const adddigit = function(buff, n, x) {
- let d = Math.floor(x)|0; /* get integer part from 'x' */
+ let d = Math.floor(x); /* get integer part from 'x' */
buff[n] = d < 10 ? d + '0'.charCodeAt(0) : d - 10 + 'a'.charCodeAt(0); /* add to buffer */
return x - d; /* return what is left */
};
@@ -233,7 +233,7 @@ const addliteral = function(L, b, arg) {
} else { /* integers */
let n = lapi.lua_tointeger(L, arg);
let format = (n === Number.MIN_SAFE_INTEGER) ? `0x%${luaconf.LUA_INTEGER_FRMLEN}x` : luaconf.LUA_INTEGER_FMT;
- buff.b += sprintf(format, n|0);
+ buff.b += sprintf(format, n);
}
break;
}
@@ -319,7 +319,7 @@ const str_format = function(L) {
strfrmt = strfrmt.slice(1);
let n = lauxlib.luaL_checkinteger(L, arg);
form = addlenmod(form, luaconf.LUA_INTEGER_FRMLEN.split('').map(e => e.charCodeAt(0)));
- buff.b += sprintf(String.fromCharCode(...form), n|0);
+ buff.b += sprintf(String.fromCharCode(...form), n);
break;
}
case 'a': case 'A': {
@@ -1177,16 +1177,16 @@ const str_find_aux = function(L, find) {
let init = posrelat(lauxlib.luaL_optinteger(L, 3, 1), ls);
if (init < 1) init = 1;
else if (init > ls + 1) { /* start after string's end? */
- lauxlib.lua_pushnil(L); /* cannot find anything */
+ lapi.lua_pushnil(L); /* cannot find anything */
return 1;
}
/* explicit request or no special characters? */
if (find && (lapi.lua_toboolean(L, 4) || nospecials(p, lp))) {
/* do a plain search */
- let f = s.indexOf(p);
+ let f = s.slice(init - 1).indexOf(p);
if (f > -1) {
- lapi.lua_pushinteger(L, f + 1);
- lapi.lua_pushinteger(L, f + lp);
+ lapi.lua_pushinteger(L, init + f);
+ lapi.lua_pushinteger(L, init + f + lp - 1);
return 2;
}
} else {
diff --git a/src/luaconf.js b/src/luaconf.js
index fc96224..a965954 100644
--- a/src/luaconf.js
+++ b/src/luaconf.js
@@ -17,7 +17,7 @@ const LUAI_MAXSTACK = 1000000;
const LUA_IDSIZE = 60;
const lua_numbertointeger = function(n) {
- return n|0;
+ return n;
};
const LUA_INTEGER_FRMLEN = "";
@@ -37,4 +37,4 @@ module.exports.LUA_INTEGER_FRMLEN = LUA_INTEGER_FRMLEN;
module.exports.LUA_NUMBER_FMT = LUA_NUMBER_FMT;
module.exports.LUA_NUMBER_FRMLEN = LUA_NUMBER_FRMLEN;
module.exports.lua_getlocaledecpoint = lua_getlocaledecpoint;
-module.exports.lua_numbertointeger = lua_numbertointeger; \ No newline at end of file
+module.exports.lua_numbertointeger = lua_numbertointeger;
diff --git a/src/lvm.js b/src/lvm.js
index 873cd20..b48d5b6 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -222,7 +222,7 @@ const luaV_execute = function(L) {
let numberop2 = tonumber(op2);
if (op1.ttisinteger() && op2.ttisinteger()) {
- L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value + op2.value)|0);
+ L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value + op2.value));
} else if (numberop1 !== false && numberop2 !== false) {
L.stack[ra] = new TValue(CT.LUA_TNUMFLT, op1.value + op2.value);
} else {
@@ -238,7 +238,7 @@ const luaV_execute = function(L) {
let numberop2 = tonumber(op2);
if (op1.ttisinteger() && op2.ttisinteger()) {
- L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value - op2.value)|0);
+ L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value - op2.value));
} else if (numberop1 !== false && numberop2 !== false) {
L.stack[ra] = new TValue(CT.LUA_TNUMFLT, op1.value - op2.value);
} else {
@@ -254,7 +254,7 @@ const luaV_execute = function(L) {
let numberop2 = tonumber(op2);
if (op1.ttisinteger() && op2.ttisinteger()) {
- L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value * op2.value)|0);
+ L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value * op2.value));
} else if (numberop1 !== false && numberop2 !== false) {
L.stack[ra] = new TValue(CT.LUA_TNUMFLT, k[i.B].value * op2.value);
} else {
@@ -270,7 +270,7 @@ const luaV_execute = function(L) {
let numberop2 = tonumber(op2);
if (op1.ttisinteger() && op2.ttisinteger()) {
- L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value % op2.value)|0);
+ L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value % op2.value));
} else if (numberop1 !== false && numberop2 !== false) {
L.stack[ra] = new TValue(CT.LUA_TNUMFLT, k[i.B].value % op2.value);
} else {
@@ -314,9 +314,9 @@ const luaV_execute = function(L) {
let numberop2 = tonumber(op2);
if (op1.ttisinteger() && op2.ttisinteger()) {
- L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value / op2.value)|0);
+ L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value / op2.value));
} else if (numberop1 !== false && numberop2 !== false) {
- L.stack[ra] = new TValue(CT.LUA_TNUMFLT, (op1.value / op2.value)|0);
+ L.stack[ra] = new TValue(CT.LUA_TNUMFLT, (op1.value / op2.value));
} else {
ltm.luaT_trybinTM(L, op1, op2, ra, ltm.TMS.TM_IDIV);
base = ci.u.l.base;
@@ -330,7 +330,7 @@ const luaV_execute = function(L) {
let numberop2 = tonumber(op2);
if (op1.ttisinteger() && op2.ttisinteger()) {
- L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value & op2.value)|0);
+ L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value & op2.value));
} else {
ltm.luaT_trybinTM(L, op1, op2, ra, ltm.TMS.TM_BAND);
base = ci.u.l.base;
@@ -344,7 +344,7 @@ const luaV_execute = function(L) {
let numberop2 = tonumber(op2);
if (op1.ttisinteger() && op2.ttisinteger()) {
- L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value | op2.value)|0);
+ L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value | op2.value));
} else {
ltm.luaT_trybinTM(L, op1, op2, ra, ltm.TMS.TM_BOR);
base = ci.u.l.base;
@@ -358,7 +358,7 @@ const luaV_execute = function(L) {
let numberop2 = tonumber(op2);
if (op1.ttisinteger() && op2.ttisinteger()) {
- L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value ^ op2.value)|0);
+ L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value ^ op2.value));
} else {
ltm.luaT_trybinTM(L, op1, op2, ra, ltm.TMS.TM_BXOR);
base = ci.u.l.base;
@@ -372,7 +372,7 @@ const luaV_execute = function(L) {
let numberop2 = tonumber(op2);
if (op1.ttisinteger() && op2.ttisinteger()) {
- L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value << op2.value)|0);
+ L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value << op2.value));
} else {
ltm.luaT_trybinTM(L, op1, op2, ra, ltm.TMS.TM_SHL);
base = ci.u.l.base;
@@ -386,7 +386,7 @@ const luaV_execute = function(L) {
let numberop2 = tonumber(op2);
if (op1.ttisinteger() && op2.ttisinteger()) {
- L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value >> op2.value)|0);
+ L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value >> op2.value));
} else {
ltm.luaT_trybinTM(L, op1, op2, ra, ltm.TMS.TM_SHR);
base = ci.u.l.base;
@@ -716,14 +716,14 @@ const donextjump = function(L, ci) {
const luaV_lessthan = function(L, l, r) {
if (l.ttisnumber() && r.ttisnumber())
- return LTnum(l, r);
+ return LTnum(l, r) ? 1 : 0;
else if (l.ttisstring() && r.ttisstring())
- return l_strcmp(l, r) < 0;
+ return l_strcmp(l, r) < 0 ? 1 : 0;
else {
let res = ltm.luaT_callorderTM(L, l, r, ltm.TMS.TM_LT);
if (res < 0)
ldebug.luaG_ordererror(L, l, r);
- return res;
+ return res ? 1 : 0;
}
};
@@ -731,13 +731,13 @@ const luaV_lessequal = function(L, l, r) {
let res;
if (l.ttisnumber() && r.ttisnumber())
- return LEnum(l, r);
+ return LEnum(l, r) ? 1 : 0;
else if (l.ttisstring() && r.ttisstring())
- return l_strcmp(l, r) <= 0;
+ return l_strcmp(l, r) <= 0 ? 1 : 0;
else {
res = ltm.luaT_callorderTM(L, l, r, ltm.TMS.TM_LE);
if (res >= 0)
- return res;
+ return res ? 1 : 0;
}
L.ci.callstatus |= lstate.CIST_LEQ; /* mark it is doing 'lt' for 'le' */
@@ -843,7 +843,7 @@ const forlimit = function(obj, step) {
const luaV_tointeger = function(obj, mode) {
if (obj.ttisfloat()) {
let n = obj.value;
- let f = n|0;
+ let f = n;
if (n !== f) { /* not an integral value? */
if (mode === 0)
@@ -852,9 +852,9 @@ const luaV_tointeger = function(obj, mode) {
f += 1; /* convert floor to ceil (remember: n !== f) */
}
- return f|0;
+ return f;
} else if (obj.ttisinteger()) {
- return obj.value|0;
+ return obj.value;
} else if (obj.ttisstring()) {
return luaV_tointeger(new TValue(CT.LUA_TNUMFLT, parseFloat(obj.jsstring())), mode); // TODO: luaO_str2num
}
@@ -863,7 +863,7 @@ const luaV_tointeger = function(obj, mode) {
};
const tointeger = function(o) {
- return o.ttisinteger() ? o.value|0 : luaV_tointeger(o, 0);
+ return o.ttisinteger() ? o.value : luaV_tointeger(o, 0);
};
const tonumber = function(v) {
@@ -1117,4 +1117,4 @@ module.exports.luaV_rawequalobj = luaV_rawequalobj;
module.exports.luaV_tointeger = luaV_tointeger;
module.exports.settable = settable;
module.exports.tointeger = tointeger;
-module.exports.tonumber = tonumber; \ No newline at end of file
+module.exports.tonumber = tonumber;