summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/defs.js2
-rw-r--r--src/lapi.js4
-rw-r--r--src/lauxlib.js9
-rw-r--r--src/lbaselib.js17
-rw-r--r--src/lcode.js34
-rw-r--r--src/ldblib.js19
-rw-r--r--src/ldo.js6
-rw-r--r--src/ldump.js24
-rw-r--r--src/linit.js2
-rw-r--r--src/liolib.js4
-rw-r--r--src/llex.js2
-rw-r--r--src/lmathlib.js2
-rw-r--r--src/loadlib.js10
-rw-r--r--src/lobject.js16
-rw-r--r--src/loslib.js4
-rw-r--r--src/lparser.js16
-rw-r--r--src/lstrlib.js10
-rw-r--r--src/ltable.js101
-rw-r--r--src/ltm.js8
-rw-r--r--src/lualib.js2
-rw-r--r--src/lundump.js36
-rw-r--r--src/lvm.js10
22 files changed, 171 insertions, 167 deletions
diff --git a/src/defs.js b/src/defs.js
index 3ebb747..268e76e 100644
--- a/src/defs.js
+++ b/src/defs.js
@@ -291,7 +291,7 @@ module.exports.LUA_EXEC_DIR = LUA_EXEC_DIR;
const LUA_VDIR = LUA_VERSION_MAJOR + "." + LUA_VERSION_MINOR;
module.exports.LUA_VDIR = LUA_VDIR;
-if (WEB) {
+if (typeof process === "undefined") {
const LUA_DIRSEP = "/";
module.exports.LUA_DIRSEP = LUA_DIRSEP;
diff --git a/src/lapi.js b/src/lapi.js
index be80672..2ae5b3c 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -128,8 +128,8 @@ const lua_xmove = function(from, to, n) {
*/
const lua_absindex = function(L, idx) {
return (idx > 0 || idx <= defs.LUA_REGISTRYINDEX)
- ? idx
- : (L.top - L.ci.funcOff) + idx;
+ ? idx
+ : (L.top - L.ci.funcOff) + idx;
};
const lua_gettop = function(L) {
diff --git a/src/lauxlib.js b/src/lauxlib.js
index d976cee..0c42a05 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -493,13 +493,14 @@ const luaL_tolstring = function(L, idx) {
case lua.LUA_TNIL:
lua.lua_pushliteral(L, "nil");
break;
- default:
+ default: {
let tt = luaL_getmetafield(L, idx, lua.to_luastring("__name", true));
let kind = tt === lua.LUA_TSTRING ? lua.lua_tostring(L, -1) : luaL_typename(L, idx);
lua.lua_pushfstring(L, lua.to_luastring("%s: %p"), kind, lua.lua_topointer(L, idx));
if (tt !== lua.LUA_TNIL)
lua.lua_remove(L, -2);
break;
+ }
}
}
@@ -708,13 +709,13 @@ class LoadF {
constructor() {
this.n = NaN; /* number of pre-read characters */
this.f = null; /* file being read */
- this.buff = WEB ? new Array(1024) : new Buffer(1024); /* area for reading file */
+ this.buff = typeof process === "undefined" ? new Array(1024) : new Buffer(1024); /* area for reading file */
this.pos = 0; /* current position in file */
this.err = void 0;
}
}
-if (WEB) {
+if (typeof process === "undefined") {
const getF = function(L, ud) {
let lf = ud;
@@ -858,7 +859,7 @@ const luaL_dofile = function(L, filename) {
const lua_writestringerror = function() {
for (let i=0; i<arguments.length; i++) {
let a = arguments[i];
- if (WEB) {
+ if (typeof process === "undefined") {
if (typeof a !== "string")
a = lua.to_jsstring(a);
console.error(a);
diff --git a/src/lbaselib.js b/src/lbaselib.js
index c598474..54e73b1 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -5,7 +5,7 @@ const lauxlib = require('./lauxlib.js');
let lua_writestring;
let lua_writeline;
-if (WEB) {
+if (typeof process === "undefined") {
let buff = [];
lua_writestring = function(s) {
buff = buff.concat(s);
@@ -99,9 +99,11 @@ const luaB_rawset = function(L) {
return 1;
};
-const opts = ["stop", "restart", "collect",
-"count", "step", "setpause", "setstepmul",
-"isrunning"].map((e) => lua.to_luastring(e));
+const opts = [
+ "stop", "restart", "collect",
+ "count", "step", "setpause", "setstepmul",
+ "isrunning"
+].map((e) => lua.to_luastring(e));
const luaB_collectgarbage = function(L) {
lauxlib.luaL_checkoption(L, 1, lua.to_luastring("collect"), opts);
lauxlib.luaL_optinteger(L, 2, 0);
@@ -174,14 +176,15 @@ const b_str2int = function(s, base) {
} catch (e) {
return null;
}
- let r = /^[\t\v\f \n\r]*([\+\-]?)0*([0-9A-Za-z]+)[\t\v\f \n\r]*$/.exec(s);
+ let r = /^[\t\v\f \n\r]*([+-]?)0*([0-9A-Za-z]+)[\t\v\f \n\r]*$/.exec(s);
if (!r) return null;
let neg = r[1] === "-";
let digits = r[2];
let n = 0;
for (let si=0; si<digits.length; si++) {
- let digit = /\d/.test(digits[si]) ? (digits.charCodeAt(si) - '0'.charCodeAt(0))
- : (digits[si].toUpperCase().charCodeAt(0) - 'A'.charCodeAt(0) + 10);
+ let digit = /\d/.test(digits[si])
+ ? (digits.charCodeAt(si) - '0'.charCodeAt(0))
+ : (digits[si].toUpperCase().charCodeAt(0) - 'A'.charCodeAt(0) + 10);
if (digit >= base) return null; /* invalid numeral */
n = ((n * base)|0) + digit;
}
diff --git a/src/lcode.js b/src/lcode.js
index 60b7452..e7259f2 100644
--- a/src/lcode.js
+++ b/src/lcode.js
@@ -189,8 +189,8 @@ const luaK_ret = function(fs, first, nret) {
** followed by a jump. Return jump position.
*/
const condjump = function(fs, op, A, B, C) {
- luaK_codeABC(fs, op, A, B, C);
- return luaK_jump(fs);
+ luaK_codeABC(fs, op, A, B, C);
+ return luaK_jump(fs);
};
/*
@@ -389,8 +389,8 @@ const luaK_checkstack = function(fs, n) {
** Reserve 'n' registers in register stack
*/
const luaK_reserveregs = function(fs, n) {
- luaK_checkstack(fs, n);
- fs.freereg += n;
+ luaK_checkstack(fs, n);
+ fs.freereg += n;
};
/*
@@ -785,7 +785,7 @@ const luaK_storevar = function(fs, vr, ex) {
case ek.VUPVAL: {
let e = luaK_exp2anyreg(fs, ex);
luaK_codeABC(fs, OpCodesI.OP_SETUPVAL, e, vr.u.info, 0);
- break;
+ break;
}
case ek.VINDEXED: {
let op = (vr.u.ind.vt === ek.VLOCAL) ? OpCodesI.OP_SETTABLE : OpCodesI.OP_SETTABUP;
@@ -850,17 +850,17 @@ const luaK_goiftrue = function(fs, e) {
luaK_dischargevars(fs, e);
switch (e.k) {
case ek.VJMP: { /* condition? */
- negatecondition(fs, e); /* jump when it is false */
- pc = e.u.info; /* save jump position */
- break;
+ negatecondition(fs, e); /* jump when it is false */
+ pc = e.u.info; /* save jump position */
+ break;
}
case ek.VK: case ek.VKFLT: case ek.VKINT: case ek.VTRUE: {
- pc = NO_JUMP; /* always true; do nothing */
- break;
+ pc = NO_JUMP; /* always true; do nothing */
+ break;
}
default: {
- pc = jumponcond(fs, e, 0); /* jump when false */
- break;
+ pc = jumponcond(fs, e, 0); /* jump when false */
+ break;
}
}
e.f = luaK_concat(fs, e.f, pc); /* insert new jump in false list */
@@ -989,11 +989,11 @@ const constfolding = function(op, e1, e2) {
** Expression to produce final result will be encoded in 'e'.
*/
const codeunexpval = function(fs, op, e, line) {
- let r = luaK_exp2anyreg(fs, e); /* opcodes operate only on registers */
- freeexp(fs, e);
- e.u.info = luaK_codeABC(fs, op, 0, r, 0); /* generate opcode */
- e.k = lparser.expkind.VRELOCABLE; /* all those operations are relocatable */
- luaK_fixline(fs, line);
+ let r = luaK_exp2anyreg(fs, e); /* opcodes operate only on registers */
+ freeexp(fs, e);
+ e.u.info = luaK_codeABC(fs, op, 0, r, 0); /* generate opcode */
+ e.k = lparser.expkind.VRELOCABLE; /* all those operations are relocatable */
+ luaK_fixline(fs, line);
};
/*
diff --git a/src/ldblib.js b/src/ldblib.js
index 2faa9f0..96db3c7 100644
--- a/src/ldblib.js
+++ b/src/ldblib.js
@@ -46,11 +46,11 @@ const db_getuservalue = function(L) {
const db_setuservalue = function(L) {
- lauxlib.luaL_checktype(L, 1, lua.LUA_TUSERDATA);
- lauxlib.luaL_checkany(L, 2);
- lua.lua_settop(L, 2);
- lua.lua_setuservalue(L, 1);
- return 1;
+ lauxlib.luaL_checktype(L, 1, lua.LUA_TUSERDATA);
+ lauxlib.luaL_checkany(L, 2);
+ lua.lua_settop(L, 2);
+ lua.lua_setuservalue(L, 1);
+ return 1;
};
/*
@@ -247,9 +247,9 @@ const checkupval = function(L, argf, argnup) {
};
const db_upvalueid = function(L) {
- let n = checkupval(L, 1, 2);
- lua.lua_pushlightuserdata(L, lua.lua_upvalueid(L, 1, n));
- return 1;
+ let n = checkupval(L, 1, 2);
+ lua.lua_pushlightuserdata(L, lua.lua_upvalueid(L, 1, n));
+ return 1;
};
const db_upvaluejoin = function(L) {
@@ -395,8 +395,7 @@ const dblib = {
"upvaluejoin": db_upvaluejoin
};
-// Only with Node
-if (!WEB) {
+if (typeof process !== "undefined") { // Only with Node
const readlineSync = require('readline-sync');
readlineSync.setDefaultOptions({
prompt: 'lua_debug> '
diff --git a/src/ldo.js b/src/ldo.js
index f381ca4..3adedd4 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -656,9 +656,9 @@ const luaD_pcall = function(L, func, u, old_top, ef) {
** Similar to 'luaD_call', but does not allow yields during the call
*/
const luaD_callnoyield = function(L, off, nResults) {
- L.nny++;
- luaD_call(L, off, nResults);
- L.nny--;
+ L.nny++;
+ luaD_call(L, off, nResults);
+ L.nny--;
};
/*
diff --git a/src/ldump.js b/src/ldump.js
index 3ab0e47..8b9b1ff 100644
--- a/src/ldump.js
+++ b/src/ldump.js
@@ -164,18 +164,18 @@ const DumpFunction = function(f, psource, D) {
};
const DumpHeader = function(D) {
- DumpLiteral(defs.LUA_SIGNATURE, D);
- DumpByte(LUAC_VERSION, D);
- DumpByte(LUAC_FORMAT, D);
- let cdata = LUAC_DATA.split('').map(e => e.charCodeAt(0));
- DumpBlock(cdata, cdata.length, D);
- DumpByte(4, D); // intSize
- DumpByte(4, D); // size_tSize
- DumpByte(4, D); // instructionSize
- DumpByte(4, D); // integerSize
- DumpByte(8, D); // numberSize
- DumpInteger(LUAC_INT, D);
- DumpNumber(LUAC_NUM, D);
+ DumpLiteral(defs.LUA_SIGNATURE, D);
+ DumpByte(LUAC_VERSION, D);
+ DumpByte(LUAC_FORMAT, D);
+ let cdata = LUAC_DATA.split('').map(e => e.charCodeAt(0));
+ DumpBlock(cdata, cdata.length, D);
+ DumpByte(4, D); // intSize
+ DumpByte(4, D); // size_tSize
+ DumpByte(4, D); // instructionSize
+ DumpByte(4, D); // integerSize
+ DumpByte(8, D); // numberSize
+ DumpInteger(LUAC_INT, D);
+ DumpNumber(LUAC_NUM, D);
};
/*
diff --git a/src/linit.js b/src/linit.js
index 90ad978..97cbfc9 100644
--- a/src/linit.js
+++ b/src/linit.js
@@ -26,7 +26,7 @@ const luaL_openlibs = function(L) {
"_G": lbaselib.luaopen_base
};
- if (!WEB) loadedlibs[lualib.LUA_IOLIBNAME] = require('./liolib.js').luaopen_io;
+ if (typeof process !== "undefined") loadedlibs[lualib.LUA_IOLIBNAME] = require('./liolib.js').luaopen_io;
/* "require" functions from 'loadedlibs' and set results to global table */
for (let lib in loadedlibs) {
diff --git a/src/liolib.js b/src/liolib.js
index a87309a..3241011 100644
--- a/src/liolib.js
+++ b/src/liolib.js
@@ -95,11 +95,11 @@ const g_iofile = function(L, f, mode) {
};
const io_input = function(L) {
- return g_iofile(L, IO_INPUT, "r");
+ return g_iofile(L, IO_INPUT, "r");
};
const io_output = function(L) {
- return g_iofile(L, IO_OUTPUT, "w");
+ return g_iofile(L, IO_OUTPUT, "w");
};
const g_write = function(L, f, arg) {
diff --git a/src/llex.js b/src/llex.js
index cc3d0ef..9e27d02 100644
--- a/src/llex.js
+++ b/src/llex.js
@@ -415,7 +415,7 @@ const read_string = function(ls, del, seminfo) {
case char['u']: utf8esc(ls); will = 'no_save'; break;
case char['\n']: case char['\r']:
inclinenumber(ls); c = char['\n']; will = 'only_save'; break;
- case char['\\']: case char['\"']: case char['\'']:
+ case char['\\']: case char['"']: case char['\'']:
c = ls.current; will = 'read_save'; break;
case lzio.EOZ: will = 'no_save'; break; /* will raise an error next loop */
case char['z']: { /* zap following span of spaces */
diff --git a/src/lmathlib.js b/src/lmathlib.js
index f2354ca..e056fd8 100644
--- a/src/lmathlib.js
+++ b/src/lmathlib.js
@@ -27,7 +27,7 @@ const math_random = function(L) {
/* random integer in the interval [low, up] */
lauxlib.luaL_argcheck(L, low <= up, 1, lua.to_luastring("interval is empty", true));
lauxlib.luaL_argcheck(L, low >= 0 || up <= luaconf.LUA_MAXINTEGER + low, 1,
- lua.to_luastring("interval too large", true));
+ lua.to_luastring("interval too large", true));
r *= (up - low) + 1;
lua.lua_pushinteger(L, Math.floor(r) + low);
diff --git a/src/loadlib.js b/src/loadlib.js
index dbd5c3c..cae377f 100644
--- a/src/loadlib.js
+++ b/src/loadlib.js
@@ -36,7 +36,7 @@ const AUXMARK = [1];
** error string in the stack.
*/
let lsys_load;
-if (WEB) {
+if (typeof process === "undefined") {
lsys_load = function(L, path, seeglb) {
path = lua.to_uristring(path);
let xhr = new XMLHttpRequest();
@@ -111,9 +111,7 @@ const noenv = function(L) {
};
let readable;
-// Only with Node
-if (!WEB) {
-
+if (typeof process !== "undefined") { // Only with Node
const fs = require('fs');
readable = function(filename) {
@@ -189,7 +187,7 @@ const ll_loadlib = function(L) {
};
let env;
-if (WEB) {
+if (typeof process === "undefined") {
env = window;
} else {
env = process.env;
@@ -304,7 +302,7 @@ const checkload = function(L, stat, filename) {
return 2; /* return open function and file name */
} else
return lauxlib.luaL_error(L, lua.to_luastring("error loading module '%s' from file '%s':\n\t%s"),
- lua.lua_tostring(L, 1), filename, lua.lua_tostring(L, -1));
+ lua.lua_tostring(L, 1), filename, lua.lua_tostring(L, -1));
};
const searcher_Lua = function(L) {
diff --git a/src/lobject.js b/src/lobject.js
index bc0909d..becec17 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -417,7 +417,7 @@ const lua_str2number = function(s) {
return null;
}
/* parseFloat ignores trailing junk, validate with regex first */
- if (!/^[\t\v\f \n\r]*[\+\-]?([0-9]+\.?[0-9]*|\.[0-9]*)([eE][\+\-]?[0-9]+)?[\t\v\f \n\r]*$/.test(s))
+ if (!/^[\t\v\f \n\r]*[+-]?([0-9]+\.?[0-9]*|\.[0-9]*)([eE][+-]?[0-9]+)?[\t\v\f \n\r]*$/.test(s))
return null;
let flt = parseFloat(s);
return !isNaN(flt) ? flt : null;
@@ -539,23 +539,25 @@ const luaO_pushvfstring = function(L, fmt, argp) {
let i = 0;
let a = 0;
let e;
- while (1) {
+ for (;;) {
e = fmt.indexOf(char['%'], i);
if (e == -1) break;
pushstr(L, fmt.slice(i, e));
switch(fmt[e+1]) {
- case char['s']:
+ case char['s']: {
let s = argp[a++];
if (s === null) s = defs.to_luastring("(null)", true);
pushstr(L, s);
break;
- case char['c']:
+ }
+ case char['c']: {
let buff = argp[a++];
if (ljstype.lisprint(buff))
pushstr(L, [buff]);
else
luaO_pushfstring(L, defs.to_luastring("<\\%d>", true), buff);
break;
+ }
case char['d']:
case char['I']:
ldo.luaD_inctop(L);
@@ -567,7 +569,7 @@ const luaO_pushvfstring = function(L, fmt, argp) {
L.stack[L.top-1].setfltvalue(argp[a++]);
luaO_tostring(L, L.stack[L.top-1]);
break;
- case char['p']:
+ case char['p']: {
let v = argp[a++];
if (v instanceof lstate.lua_State ||
v instanceof ltable.Table ||
@@ -598,15 +600,15 @@ const luaO_pushvfstring = function(L, fmt, argp) {
pushstr(L, defs.to_luastring("<id NYI>"));
}
break;
+ }
case char['U']:
pushstr(L, defs.to_luastring(String.fromCodePoint(argp[a++])));
break;
case char['%']:
pushstr(L, [char['%']]);
break;
- default: {
+ default:
ldebug.luaG_runerror(L, defs.to_luastring("invalid option '%%%c' to 'lua_pushfstring'"), fmt[e + 1]);
- }
}
n += 2;
i = e + 2;
diff --git a/src/loslib.js b/src/loslib.js
index 4b147cf..19dfd02 100644
--- a/src/loslib.js
+++ b/src/loslib.js
@@ -82,7 +82,7 @@ const checkoption = function(L, conv, i, buff) {
};
/* maximum size for an individual 'strftime' item */
-const SIZETIMEFMT = 250;
+// const SIZETIMEFMT = 250;
const os_date = function(L) {
@@ -157,7 +157,7 @@ const syslib = {
"time": os_time
};
-if (WEB) {
+if (typeof process === "undefined") {
syslib.clock = function(L) {
lua.lua_pushnumber(L, performance.now()/1000);
return 1;
diff --git a/src/lparser.js b/src/lparser.js
index ddd514e..d183d25 100644
--- a/src/lparser.js
+++ b/src/lparser.js
@@ -118,7 +118,7 @@ class FuncState {
}
}
- /* description of active local variable */
+/* description of active local variable */
class Vardesc {
constructor() {
this.idx = NaN; /* variable index in stack */
@@ -214,7 +214,7 @@ const check_match = function(ls, what, who, where) {
else
llex.luaX_syntaxerror(ls, lobject.luaO_pushfstring(ls.L,
defs.to_luastring("%s expected (to close %s at line %d)"),
- llex.luaX_token2str(ls, what), llex.luaX_token2str(ls, who), where));
+ llex.luaX_token2str(ls, what), llex.luaX_token2str(ls, who), where));
}
};
@@ -351,7 +351,7 @@ const singlevar = function(ls, vr) {
let varname = str_checkname(ls);
let fs = ls.fs;
singlevaraux(fs, varname, vr, 1);
- if (vr.k === expkind.VVOID) { /* global name? */
+ if (vr.k === expkind.VVOID) { /* is global name? */
let key = new expdesc();
singlevaraux(fs, ls.envn, vr, 1); /* get environment variable */
assert(vr.k !== expkind.VVOID); /* this one must exist */
@@ -504,8 +504,8 @@ const breaklabel = function(ls) {
*/
const undefgoto = function(ls, gt) {
let msg = llex.isreserved(gt.name)
- ? "<%s> at line %d not inside a loop"
- : "no visible label '%s' for <goto> at line %d";
+ ? "<%s> at line %d not inside a loop"
+ : "no visible label '%s' for <goto> at line %d";
msg = lobject.luaO_pushfstring(ls.L, defs.to_luastring(msg), gt.name.getstr(), gt.line);
semerror(ls, msg);
};
@@ -1166,8 +1166,8 @@ const checkrepeated = function(fs, ll, label) {
for (let i = fs.bl.firstlabel; i < ll.n; i++) {
if (eqstr(label, ll.arr[i].name)) {
let msg = lobject.luaO_pushfstring(fs.ls.L,
- defs.to_luastring("label '%s' already defined on line %d", true),
- label.getstr(), ll.arr[i].line);
+ defs.to_luastring("label '%s' already defined on line %d", true),
+ label.getstr(), ll.arr[i].line);
semerror(fs.ls, msg);
}
}
@@ -1340,7 +1340,7 @@ const test_then_block = function(ls, escapelist) {
lcode.luaK_goiffalse(ls.fs, v); /* will jump to label if condition is true */
enterblock(fs, bl, false); /* must enter block before 'goto' */
gotostat(ls, v.t); /* handle goto/break */
- while (testnext(ls, char[';'])) {} /* skip colons */
+ while (testnext(ls, char[';'])); /* skip colons */
if (block_follow(ls, 0)) { /* 'goto' is the entire block? */
leaveblock(fs);
return escapelist; /* and that is it */
diff --git a/src/lstrlib.js b/src/lstrlib.js
index 80a5f55..cfd1c28 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -148,7 +148,7 @@ const lua_number2strx = function(L, fmt, x) {
** is maximum exponent + 1). (99+3+1 then rounded to 120 for "extra
** expenses", such as locale-dependent stuff)
*/
-const MAX_ITEM = 120;// TODO: + l_mathlim(MAX_10_EXP);
+// const MAX_ITEM = 120;// TODO: + l_mathlim(MAX_10_EXP);
/* valid flags in a format specification */
@@ -157,7 +157,7 @@ const FLAGS = ["-".charCodeAt(0), "+".charCodeAt(0), " ".charCodeAt(0), "#"
/*
** maximum size of each format specification (such as "%-099.99d")
*/
-const MAX_FORMAT = 32;
+// const MAX_FORMAT = 32;
// TODO: locale ? and do it better
const isalpha = e => ('a'.charCodeAt(0) <= e && e <= 'z'.charCodeAt(0)) || (e >= 'A'.charCodeAt(0) && e <= 'Z'.charCodeAt(0));
@@ -607,8 +607,8 @@ const str_pack = function(L) {
case KOption.Kstring: { /* strings with length count */
let s = lauxlib.luaL_checkstring(L, arg);
let len = s.length;
- lauxlib.luaL_argcheck(L, size >= 4 /* sizeof(size_t) */ ||
- len < (1 << (size * NB)),
+ lauxlib.luaL_argcheck(L,
+ size >= 4 /* sizeof(size_t) */ || len < (1 << (size * NB)),
arg, lua.to_luastring("string length does not fit in given size", true));
packint(b, len, h.islittle, size, 0); /* pack length */
b.push(...s);
@@ -1331,7 +1331,7 @@ const add_value = function(ms, b, s, e, tr) {
lua.lua_pushlstring(L, ms.src.slice(s, e), e - s); /* keep original text */
} else if (!lua.lua_isstring(L, -1))
lauxlib.luaL_error(L, lua.to_luastring("invalid replacement value (a %s)"), lauxlib.luaL_typename(L, -1));
- lauxlib.luaL_addvalue(b); /* add result to accumulator */
+ lauxlib.luaL_addvalue(b); /* add result to accumulator */
};
const str_gsub = function(L) {
diff --git a/src/ltable.js b/src/ltable.js
index f7b1167..cf8b1da 100644
--- a/src/ltable.js
+++ b/src/ltable.js
@@ -24,58 +24,59 @@ const get_lightuserdata_hash = function(v) {
const table_hash = function(L, key) {
switch(key.type) {
- case CT.LUA_TNIL:
- return ldebug.luaG_runerror(L, defs.to_luastring("table index is nil", true));
- case CT.LUA_TNUMFLT:
- if (isNaN(key.value))
- return ldebug.luaG_runerror(L, defs.to_luastring("table index is NaN", true));
- /* fall through */
- case CT.LUA_TNUMINT: /* takes advantage of floats and integers being same in JS */
- case CT.LUA_TBOOLEAN:
- case CT.LUA_TTABLE:
- case CT.LUA_TLCL:
- case CT.LUA_TLCF:
- case CT.LUA_TCCL:
- case CT.LUA_TUSERDATA:
- case CT.LUA_TTHREAD:
- return key.value;
- case CT.LUA_TSHRSTR:
- case CT.LUA_TLNGSTR:
- return lstring.luaS_hashlongstr(key.tsvalue());
- case CT.LUA_TLIGHTUSERDATA:
- let v = key.value;
- switch(typeof v) {
- case "string":
- /* possible conflict with LUA_TSTRING.
- prefix this string with "*" so they don't clash */
- return "*" + v;
- case "number":
- /* possible conflict with LUA_TNUMBER.
- turn into string and prefix with "#" to avoid clash with other strings */
- return "#" + v;
- case "boolean":
- /* possible conflict with LUA_TBOOLEAN. use strings ?true and ?false instead */
- return v?"?true":"?false";
- case "function":
- /* possible conflict with LUA_TLCF.
- indirect via a weakmap */
- return get_lightuserdata_hash(v);
- case "object":
- /* v could be a lua_State, CClosure, LClosure, Table or Userdata from this state as returned by lua_topointer */
- if ((v instanceof lstate.lua_State && v.l_G === L.l_G) ||
- v instanceof Table ||
- v instanceof lobject.Udata ||
- v instanceof lobject.LClosure ||
- v instanceof lobject.CClosure) {
- /* indirect via a weakmap */
- return get_lightuserdata_hash(v);
- }
+ case CT.LUA_TNIL:
+ return ldebug.luaG_runerror(L, defs.to_luastring("table index is nil", true));
+ case CT.LUA_TNUMFLT:
+ if (isNaN(key.value))
+ return ldebug.luaG_runerror(L, defs.to_luastring("table index is NaN", true));
/* fall through */
- default:
- return v;
+ case CT.LUA_TNUMINT: /* takes advantage of floats and integers being same in JS */
+ case CT.LUA_TBOOLEAN:
+ case CT.LUA_TTABLE:
+ case CT.LUA_TLCL:
+ case CT.LUA_TLCF:
+ case CT.LUA_TCCL:
+ case CT.LUA_TUSERDATA:
+ case CT.LUA_TTHREAD:
+ return key.value;
+ case CT.LUA_TSHRSTR:
+ case CT.LUA_TLNGSTR:
+ return lstring.luaS_hashlongstr(key.tsvalue());
+ case CT.LUA_TLIGHTUSERDATA: {
+ let v = key.value;
+ switch(typeof v) {
+ case "string":
+ /* possible conflict with LUA_TSTRING.
+ prefix this string with "*" so they don't clash */
+ return "*" + v;
+ case "number":
+ /* possible conflict with LUA_TNUMBER.
+ turn into string and prefix with "#" to avoid clash with other strings */
+ return "#" + v;
+ case "boolean":
+ /* possible conflict with LUA_TBOOLEAN. use strings ?true and ?false instead */
+ return v?"?true":"?false";
+ case "function":
+ /* possible conflict with LUA_TLCF.
+ indirect via a weakmap */
+ return get_lightuserdata_hash(v);
+ case "object":
+ /* v could be a lua_State, CClosure, LClosure, Table or Userdata from this state as returned by lua_topointer */
+ if ((v instanceof lstate.lua_State && v.l_G === L.l_G) ||
+ v instanceof Table ||
+ v instanceof lobject.Udata ||
+ v instanceof lobject.LClosure ||
+ v instanceof lobject.CClosure) {
+ /* indirect via a weakmap */
+ return get_lightuserdata_hash(v);
+ }
+ /* fall through */
+ default:
+ return v;
+ }
}
- default:
- throw new Error("unknown key type: " + key.type);
+ default:
+ throw new Error("unknown key type: " + key.type);
}
};
diff --git a/src/ltm.js b/src/ltm.js
index 632efe7..79a483e 100644
--- a/src/ltm.js
+++ b/src/ltm.js
@@ -141,18 +141,18 @@ const luaT_trybinTM = function(L, p1, p2, res, event) {
if (!luaT_callbinTM(L, p1, p2, res, event)) {
switch (event) {
case TMS.TM_CONCAT:
- ldebug.luaG_concaterror(L, p1, p2);
+ return ldebug.luaG_concaterror(L, p1, p2);
case TMS.TM_BAND: case TMS.TM_BOR: case TMS.TM_BXOR:
case TMS.TM_SHL: case TMS.TM_SHR: case TMS.TM_BNOT: {
let n1 = lvm.tonumber(p1);
let n2 = lvm.tonumber(p2);
if (n1 !== false && n2 !== false)
- ldebug.luaG_tointerror(L, p1, p2);
+ return ldebug.luaG_tointerror(L, p1, p2);
else
- ldebug.luaG_opinterror(L, p1, p2, defs.to_luastring("perform bitwise operation on", true));
+ return ldebug.luaG_opinterror(L, p1, p2, defs.to_luastring("perform bitwise operation on", true));
}
default:
- ldebug.luaG_opinterror(L, p1, p2, defs.to_luastring("perform arithmetic on", true));
+ return ldebug.luaG_opinterror(L, p1, p2, defs.to_luastring("perform arithmetic on", true));
}
}
};
diff --git a/src/lualib.js b/src/lualib.js
index 50ca433..4fbae44 100644
--- a/src/lualib.js
+++ b/src/lualib.js
@@ -14,7 +14,7 @@ const LUA_TABLIBNAME = "table";
module.exports.LUA_TABLIBNAME = LUA_TABLIBNAME;
module.exports.luaopen_table = require("./ltablib.js").luaopen_table;
-if (!WEB) {
+if (typeof process !== "undefined") {
const LUA_IOLIBNAME = "io";
module.exports.LUA_IOLIBNAME = LUA_IOLIBNAME;
module.exports.luaopen_io = require("./liolib.js").luaopen_io;
diff --git a/src/lundump.js b/src/lundump.js
index b25a955..ff87903 100644
--- a/src/lundump.js
+++ b/src/lundump.js
@@ -145,24 +145,24 @@ class BytecodeParser {
let t = this.readByte();
switch (t) {
- case defs.CT.LUA_TNIL:
- f.k.push(new lobject.TValue(defs.CT.LUA_TNIL, null));
- break;
- case defs.CT.LUA_TBOOLEAN:
- f.k.push(new lobject.TValue(defs.CT.LUA_TBOOLEAN, this.readByte() !== 0));
- break;
- case defs.CT.LUA_TNUMFLT:
- f.k.push(new lobject.TValue(defs.CT.LUA_TNUMFLT, this.readNumber()));
- break;
- case defs.CT.LUA_TNUMINT:
- f.k.push(new lobject.TValue(defs.CT.LUA_TNUMINT, this.readInteger()));
- break;
- case defs.CT.LUA_TSHRSTR:
- case defs.CT.LUA_TLNGSTR:
- f.k.push(new lobject.TValue(defs.CT.LUA_TLNGSTR, this.readString()));
- break;
- default:
- this.error(`unrecognized constant '${t}'`);
+ case defs.CT.LUA_TNIL:
+ f.k.push(new lobject.TValue(defs.CT.LUA_TNIL, null));
+ break;
+ case defs.CT.LUA_TBOOLEAN:
+ f.k.push(new lobject.TValue(defs.CT.LUA_TBOOLEAN, this.readByte() !== 0));
+ break;
+ case defs.CT.LUA_TNUMFLT:
+ f.k.push(new lobject.TValue(defs.CT.LUA_TNUMFLT, this.readNumber()));
+ break;
+ case defs.CT.LUA_TNUMINT:
+ f.k.push(new lobject.TValue(defs.CT.LUA_TNUMINT, this.readInteger()));
+ break;
+ case defs.CT.LUA_TSHRSTR:
+ case defs.CT.LUA_TLNGSTR:
+ f.k.push(new lobject.TValue(defs.CT.LUA_TLNGSTR, this.readString()));
+ break;
+ default:
+ this.error(`unrecognized constant '${t}'`);
}
}
}
diff --git a/src/lvm.js b/src/lvm.js
index ffc1d74..8cc95b3 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -78,16 +78,16 @@ const luaV_finishOp = function(L) {
};
const RA = function(L, base, i) {
- return base + i.A;
+ return base + i.A;
};
const RB = function(L, base, i) {
- return base + i.B;
+ return base + i.B;
};
-const RC = function(L, base, i) {
- return base + i.C;
-};
+// const RC = function(L, base, i) {
+// return base + i.C;
+// };
const RKB = function(L, base, k, i) {
return lopcodes.ISK(i.B) ? k[lopcodes.INDEXK(i.B)] : L.stack[base + i.B];