summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-03-29 14:39:57 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-03-30 09:57:53 +0200
commit456ab7b69f88859683c60cc2261e70d6dbadd8e8 (patch)
tree12baf4ae489e7afd4819ec94bc413c1c2a1db05d
parent2e5b595a2e04fe72555a565af4aae43560946473 (diff)
downloadfengari-456ab7b69f88859683c60cc2261e70d6dbadd8e8.tar.gz
fengari-456ab7b69f88859683c60cc2261e70d6dbadd8e8.tar.bz2
fengari-456ab7b69f88859683c60cc2261e70d6dbadd8e8.zip
8-bit string internally tests
Lexing/Parsing is done on byte rather than js strings
-rw-r--r--src/lapi.js4
-rw-r--r--src/lauxlib.js11
-rw-r--r--src/lbaselib.js4
-rw-r--r--src/lcode.js2
-rw-r--r--src/ldebug.js4
-rw-r--r--src/ldo.js10
-rw-r--r--src/linit.js5
-rw-r--r--src/llex.js113
-rw-r--r--src/lobject.js6
-rw-r--r--src/lparser.js124
-rw-r--r--src/lstrlib.js2
-rw-r--r--src/ltablib.js2
-rw-r--r--src/ltm.js2
-rw-r--r--src/lua.js2
-rw-r--r--src/lundump.js30
-rw-r--r--src/lutf8lib.js63
-rw-r--r--src/lvm.js16
-rw-r--r--tests/lapi.js90
-rw-r--r--tests/lbaselib.js68
-rw-r--r--tests/lcorolib.js16
-rw-r--r--tests/ldebug.js30
-rw-r--r--tests/lexparse.js127
-rw-r--r--tests/lmathlib.js32
-rw-r--r--tests/load.js12
-rw-r--r--tests/lstrlib.js71
-rw-r--r--tests/ltablib.js20
-rw-r--r--tests/ltm.js55
-rw-r--r--tests/lutf8lib.js6
-rw-r--r--tests/lvm.js20
29 files changed, 476 insertions, 471 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 6e1471d..e7fbf4f 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -678,7 +678,7 @@ const lua_compare_ = function(L, o1, o2, op) {
};
const lua_stringtonumber = function(L, s) {
- let number = parseFloat(s);
+ let number = parseFloat(lobject.jsstring(s));
L.stack[L.top++] = new TValue(number % 1 !== 0 ? CT.LUA_TNUMFLT : CT.LUA_TNUMINT, number);
assert(L.top <= L.ci.top, "stack overflow");
return s.length;
@@ -980,6 +980,8 @@ module.exports.lua_toboolean = lua_toboolean;
module.exports.lua_todataview = lua_todataview;
module.exports.lua_tointeger = lua_tointeger;
module.exports.lua_tointegerx = lua_tointegerx;
+module.exports.lua_tojsstring = lua_tojsstring;
+module.exports.lua_toljsstring = lua_toljsstring;
module.exports.lua_tolstring = lua_tolstring;
module.exports.lua_tonumber = lua_tonumber;
module.exports.lua_topointer = lua_topointer;
diff --git a/src/lauxlib.js b/src/lauxlib.js
index f60bd8c..9813095 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -55,7 +55,7 @@ const findfield = function(L, objidx, level) {
const pushglobalfuncname = function(L, ar) {
let top = lapi.lua_gettop(L);
ldebug.lua_getinfo(L, 'f', ar); /* push function */
- lapi.lua_getfield(L, lua.LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
+ lapi.lua_getfield(L, lua.LUA_REGISTRYINDEX, lua.to_luastring(LUA_LOADED_TABLE));
if (findfield(L, top + 1, 2)) {
let name = lapi.lua_tostring(L, -1);
if (name.jsstring().startsWith("_G.")) {
@@ -333,7 +333,7 @@ const luaL_tolstring = function(L, idx) {
** Leaves resulting module on the top.
*/
const luaL_requiref = function(L, modname, openf, glb) {
- luaL_getsubtable(L, lua.LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
+ luaL_getsubtable(L, lua.LUA_REGISTRYINDEX, lua.to_luastring(LUA_LOADED_TABLE));
lapi.lua_getfield(L, -1, modname); /* LOADED[modname] */
if (!lapi.lua_toboolean(L, -1)) { /* package not already loaded? */
lapi.lua_pop(L, 1); /* remove field */
@@ -441,7 +441,7 @@ if (typeof require === "function") {
lf.pos += bytes;
}
if (bytes > 0)
- return lf.binary ? toDataView(lf.buff) : lf.buff;
+ return lf.binary ? toDataView(lf.buff) : lf.buff.slice(0, bytes);
else return null;
};
@@ -502,15 +502,16 @@ if (typeof require === "function") {
};
const luaL_loadfilex = function(L, filename, mode) {
+ let jsfilename = lobject.jsstring(filename);
let lf = new LoadF();
let fnameindex = lapi.lua_gettop(L) + 1; /* index of filename on the stack */
if (filename === null) {
lapi.lua_pushliteral(L, "=stdin");
lf.f = process.stdin.fd;
} else {
- lapi.lua_pushliteral(L, `@${filename}`);
+ lapi.lua_pushliteral(L, `@${jsfilename}`);
try {
- lf.f = fs.openSync(filename, "r");
+ lf.f = fs.openSync(jsfilename, "r");
} catch (e) {
return errfile(L, lua.to_luastring("open"), fnameindex, e);
}
diff --git a/src/lbaselib.js b/src/lbaselib.js
index 8420672..4d0fb9c 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -11,7 +11,7 @@ const TS = lua.thread_status;
const luaB_print = function(L) {
let n = lapi.lua_gettop(L); /* number of arguments */
- let str = "";
+ let str = [];
lapi.lua_getglobal(L, lua.to_luastring("tostring"));
for (let i = 1; i <= n; i++) {
@@ -201,7 +201,7 @@ const luaB_assert = function(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) === "#") {
+ if (lapi.lua_type(L, 1) === CT.LUA_TSTRING && lapi.lua_tostring(L, 1)[0] === "#".charCodeAt(0)) {
lapi.lua_pushinteger(L, n - 1);
return 1;
} else {
diff --git a/src/lcode.js b/src/lcode.js
index 8b4a57c..752eedf 100644
--- a/src/lcode.js
+++ b/src/lcode.js
@@ -1231,7 +1231,7 @@ const luaK_setlist = function(fs, base, nelems, tostore) {
codeextraarg(fs, c);
}
else
- llex.luaX_syntaxerror(fs.ls, "constructor too long");
+ llex.luaX_syntaxerror(fs.ls, lua.to_luastring("constructor too long"));
fs.freereg = base + 1; /* free registers with list values */
};
diff --git a/src/ldebug.js b/src/ldebug.js
index 507e764..0fba4cb 100644
--- a/src/ldebug.js
+++ b/src/ldebug.js
@@ -431,7 +431,7 @@ const varinfo = function(L, o) {
kind = getobjname(ci.func.p, ci.pcOff, stkid - ci.u.l.base);
}
- return lua.to_luastring(kind ? ` (${lobject.jsstring(kind.funcname)} '${lobject.jsstring(kind.name)}')` : ``);
+ return lua.to_luastring(kind ? ` (${lobject.jsstring(kind.funcname)} '${kind.name.jsstring()}')` : ``);
};
const luaG_typeerror = function(L, o, op) {
@@ -457,7 +457,7 @@ const luaG_opinterror = function(L, p1, p2, msg) {
const luaG_ordererror = function(L, p1, p2) {
let t1 = ltm.luaT_objtypename(L, p1);
let t2 = ltm.luaT_objtypename(L, p2);
- if (t1 === t2)
+ if (t1.join() === t2.join())
luaG_runerror(L, lua.to_luastring(`attempt to compare two ${lobject.jsstring(t1)} values`));
else
luaG_runerror(L, lua.to_luastring(`attempt to compare ${lobject.jsstring(t1)} with ${lobject.jsstring(t2)}`));
diff --git a/src/ldo.js b/src/ldo.js
index 54d1ac0..6a74cad 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -519,8 +519,8 @@ class SParser {
}
const checkmode = function(L, mode, x) {
- if (mode && mode.indexOf(x.charCodeAt(0)) === -1) {
- lapi.lua_pushstring(L, lua.to_luastring(`attempt to load a ${lobject.jsstring(x)} chunk (mode is '${mode}')`));
+ if (mode && mode.indexOf(x[0]) === -1) {
+ lapi.lua_pushstring(L, lua.to_luastring(`attempt to load a ${lobject.jsstring(x)} chunk (mode is '${lobject.jsstring(mode)}')`));
luaD_throw(L, TS.LUA_ERRSYNTAX);
}
};
@@ -528,11 +528,11 @@ const checkmode = function(L, mode, x) {
const f_parser = function(L, p) {
let cl;
let c = p.z.getc(); /* read first character */
- if (String.fromCharCode(c) === lua.LUA_SIGNATURE.charAt(0)) {
- checkmode(L, p.mode, "binary");
+ if (c === lua.LUA_SIGNATURE.charCodeAt(0)) {
+ checkmode(L, p.mode, lua.to_luastring("binary"));
cl = new BytecodeParser(L, p.z.buffer).luaU_undump();
} else {
- checkmode(L, p.mode, "text");
+ checkmode(L, p.mode, lua.to_luastring("text"));
cl = lparser.luaY_parser(L, p.z, p.buff, p.dyd, p.name, c);
}
diff --git a/src/linit.js b/src/linit.js
index 4d50f8b..3e9b1af 100644
--- a/src/linit.js
+++ b/src/linit.js
@@ -2,6 +2,7 @@
const assert = require('assert');
+const lua = require('./lua.js');
const lapi = require('./lapi.js');
const lauxlib = require('./lauxlib.js');
const lbaselib = require('./lbaselib.js');
@@ -24,9 +25,9 @@ const loadedlibs = {
const luaL_openlibs = function(L) {
/* "require" functions from 'loadedlibs' and set results to global table */
for (let lib in loadedlibs) {
- lauxlib.luaL_requiref(L, lib, loadedlibs[lib], 1);
+ lauxlib.luaL_requiref(L, lua.to_luastring(lib), loadedlibs[lib], 1);
lapi.lua_pop(L, 1); /* remove lib */
}
};
-module.exports.luaL_openlibs = luaL_openlibs; \ No newline at end of file
+module.exports.luaL_openlibs = luaL_openlibs;
diff --git a/src/llex.js b/src/llex.js
index 9b81cd7..e043c17 100644
--- a/src/llex.js
+++ b/src/llex.js
@@ -15,6 +15,12 @@ const TS = lua.thread_status;
const FIRST_RESERVED = 257;
+// To avoid charCodeAt everywhere
+const char = [];
+for (let i = 0; i < 127; i++)
+ char[String.fromCharCode(i)] = i;
+module.exports.char = char;
+
const RESERVED = {
/* terminal symbols denoted by reserved words */
TK_AND: FIRST_RESERVED,
@@ -157,7 +163,7 @@ const save = function(ls, c) {
const luaX_token2str = function(ls, token) {
if (typeof token === "string" || token < FIRST_RESERVED) { /* single-byte symbols? */
- return lua.to_luastring(`'${typeof token === "string" ? token : lobject.jsstring(token)}'`);
+ return lua.to_luastring(`'${typeof token === "string" ? token : lobject.jsstring([token])}'`);
} else {
let s = luaX_tokens[token - FIRST_RESERVED];
if (token < R.TK_EOS) /* fixed format (symbols and reserved words)? */
@@ -168,7 +174,7 @@ const luaX_token2str = function(ls, token) {
};
const currIsNewline = function(ls) {
- return ls.current === '\n'.charCodeAt(0) || ls.current === '\r'.charCodeAt(0);
+ return ls.current === char['\n'] || ls.current === char['\r'];
};
const next = function(ls) {
@@ -235,7 +241,7 @@ const check_next1 = function(ls, c) {
** saves it
*/
const check_next2 = function(ls, set) {
- if (ls.current === set.charAt(0).charCodeAt(0) || ls.current === set.charAt(1).charCodeAt(0)) {
+ if (ls.current === set[0].charCodeAt(0) || ls.current === set[1].charCodeAt(0)) {
save_and_next(ls);
return true;
}
@@ -248,7 +254,7 @@ const read_numeral = function(ls, seminfo) {
let first = ls.current;
assert(ljstype.lisdigit(ls.current));
save_and_next(ls);
- if (first === '0' && check_next2(ls, "xX")) /* hexadecimal? */
+ if (first === char['0'] && check_next2(ls, "xX")) /* hexadecimal? */
expo = "Pp";
for (;;) {
@@ -256,7 +262,7 @@ const read_numeral = function(ls, seminfo) {
check_next2(ls, "-+"); /* optional exponent sign */
if (ljstype.lisxdigit(ls.current))
save_and_next(ls);
- else if (ls.current === '.')
+ else if (ls.current === char['.'])
save_and_next(ls);
else break;
}
@@ -295,7 +301,6 @@ const lexerror = function(ls, msg, token) {
};
const luaX_syntaxerror = function(ls, msg) {
- msg = msg instanceof TValue ? msg.value : lua.to_luastring(msg);
lexerror(ls, msg, ls.t.token);
};
@@ -307,9 +312,9 @@ const luaX_syntaxerror = function(ls, msg) {
const skip_sep = function(ls) {
let count = 0;
let s = ls.current;
- assert(s === '['.charCodeAt(0) || s === ']'.charCodeAt(0));
+ assert(s === char['['] || s === char[']']);
save_and_next(ls);
- while (ls.current === '='.charCodeAt(0)) {
+ while (ls.current === char['=']) {
save_and_next(ls);
count++;
}
@@ -332,15 +337,15 @@ const read_long_string = function(ls, seminfo, sep) {
lexerror(ls, lua.to_luastring(msg), R.TK_EOS);
break;
}
- case ']'.charCodeAt(0): {
+ case char[']']: {
if (skip_sep(ls) === sep) {
save_and_next(ls); /* skip 2nd ']' */
skip = true;
}
break;
}
- case '\n'.charCodeAt(0): case '\r'.charCodeAt(0): {
- save(ls, '\n'.charCodeAt(0));
+ case char['\n']: case char['\r']: {
+ save(ls, char['\n']);
inclinenumber(ls);
if (!seminfo) {
ls.buff.n = 0;
@@ -386,7 +391,7 @@ const readhexaesc = function(ls) {
const readutf8desc = function(ls) {
let i = 4; /* chars to be removed: '\', 'u', '{', and first digit */
save_and_next(ls); /* skip 'u' */
- esccheck(ls, ls.current === '{'.charCodeAt(0), lua.to_luastring("missing '{'"));
+ esccheck(ls, ls.current === char['{'], lua.to_luastring("missing '{'"));
let r = gethexa(ls); /* must have at least one digit */
save_and_next(ls);
@@ -396,7 +401,7 @@ const readutf8desc = function(ls) {
esccheck(ls, r <= 0x10FFFF, lua.to_luastring("UTF-8 value too large"));
save_and_next(ls);
}
- esccheck(ls, ls.current === '}'.charCodeAt(0), lua.to_luastring("missing '}'"));
+ esccheck(ls, ls.current === char['}'], lua.to_luastring("missing '}'"));
next(ls); /* skip '}' */
ls.buff.n -= i; /* remove saved chars from buffer */
return r;
@@ -429,30 +434,30 @@ const read_string = function(ls, del, seminfo) {
case -1:
lexerror(ls, lua.to_luastring("unfinished string"), R.TK_EOS);
break;
- case '\n'.charCodeAt(0):
- case '\r'.charCodeAt(0):
+ case char['\n']:
+ case char['\r']:
lexerror(ls, lua.to_luastring("unfinished string"), R.TK_STRING);
break;
- case '\\'.charCodeAt(0): { /* escape sequences */
+ case char['\\']: { /* escape sequences */
save_and_next(ls); /* keep '\\' for error messages */
let will;
let c;
switch(ls.current) {
- case 'a': c = '\a'.charCodeAt(0); will = 'read_save'; break;
- case 'b': c = '\b'.charCodeAt(0); will = 'read_save'; break;
- case 'f': c = '\f'.charCodeAt(0); will = 'read_save'; break;
- case 'n': c = '\n'.charCodeAt(0); will = 'read_save'; break;
- case 'r': c = '\r'.charCodeAt(0); will = 'read_save'; break;
- case 't': c = '\t'.charCodeAt(0); will = 'read_save'; break;
- case 'v': c = '\v'.charCodeAt(0); will = 'read_save'; break;
- case 'x': c = readhexaesc(ls); will = 'read_save'; break;
- case 'u': utf8esc(ls); will = 'no_save'; break;
- case '\n'.charCodeAt(0): case '\r'.charCodeAt(0):
- inclinenumber(ls); c = '\n'; will = 'only_save'; break;
- case '\\'.charCodeAt(0): case '\"'.charCodeAt(0): case '\''.charCodeAt(0):
+ case char['a']: c = char['\a']; will = 'read_save'; break;
+ case char['b']: c = char['\b']; will = 'read_save'; break;
+ case char['f']: c = char['\f']; will = 'read_save'; break;
+ case char['n']: c = char['\n']; will = 'read_save'; break;
+ case char['r']: c = char['\r']; will = 'read_save'; break;
+ case char['t']: c = char['\t']; will = 'read_save'; break;
+ case char['v']: c = char['\v']; will = 'read_save'; break;
+ case char['x']: c = readhexaesc(ls); will = 'read_save'; break;
+ 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['\'']:
c = ls.current; will = 'read_save'; break;
case -1: will = 'no_save'; break; /* will raise an error next loop */
- case 'z': { /* zap following span of spaces */
+ case char['z']: { /* zap following span of spaces */
ls.buff.n -= 1; /* remove '\\' */
next(ls); /* skip the 'z' */
while (ljstype.lisspace(ls.current)) {
@@ -500,20 +505,20 @@ const llex = function(ls, seminfo) {
for (;;) {
switch (ls.current) {
- case '\n'.charCodeAt(0): case '\r'.charCodeAt(0): { /* line breaks */
+ case char['\n']: case char['\r']: { /* line breaks */
inclinenumber(ls);
break;
}
- case ' '.charCodeAt(0): case '\f'.charCodeAt(0): case '\t'.charCodeAt(0): case '\v'.charCodeAt(0): { /* spaces */
+ case char[' ']: case char['\f']: case char['\t']: case char['\v']: { /* spaces */
next(ls);
break;
}
- case '-'.charCodeAt(0): { /* '-' or '--' (comment) */
+ case char['-']: { /* '-' or '--' (comment) */
next(ls);
- if (ls.current !== '-'.charCodeAt(0)) return '-';
+ if (ls.current !== char['-']) return char['-'];
/* else is a comment */
next(ls);
- if (ls.current === '['.charCodeAt(0)) { /* long comment? */
+ if (ls.current === char['[']) { /* long comment? */
let sep = skip_sep(ls);
ls.buff.n = 0; /* 'skip_sep' may dirty the buffer */
ls.buff.buffer = [];
@@ -530,63 +535,63 @@ const llex = function(ls, seminfo) {
next(ls); /* skip until end of line (or end of file) */
break;
}
- case '['.charCodeAt(0): { /* long string or simply '[' */
+ case char['[']: { /* long string or simply '[' */
let sep = skip_sep(ls);
if (sep >= 0) {
read_long_string(ls, seminfo, sep);
return R.TK_STRING;
} else if (sep !== -1) /* '[=...' missing second bracket */
lexerror(ls, lua.to_luastring("invalid long string delimiter"), R.TK_STRING);
- return '[';
+ return char['['];
}
- case '='.charCodeAt(0): {
+ case char['=']: {
next(ls);
if (check_next1(ls, '=')) return R.TK_EQ;
- else return '=';
+ else return char['='];
}
- case '<'.charCodeAt(0): {
+ case char['<']: {
next(ls);
if (check_next1(ls, '=')) return R.TK_LE;
else if (check_next1(ls, '<')) return R.TK_SHL;
- else return '<';
+ else return char['<'];
}
- case '>'.charCodeAt(0): {
+ case char['>']: {
next(ls);
if (check_next1(ls, '=')) return R.TK_GE;
else if (check_next1(ls, '>')) return R.TK_SHR;
- else return '>';
+ else return char['>'];
}
- case '/'.charCodeAt(0): {
+ case char['/']: {
next(ls);
if (check_next1(ls, '/')) return R.TK_IDIV;
- else return '/';
+ else return char['/'];
}
- case '~'.charCodeAt(0): {
+ case char['~']: {
next(ls);
if (check_next1(ls, '=')) return R.TK_NE;
- else return '~';
+ else return char['~'];
}
- case ':'.charCodeAt(0): {
+ case char[':']: {
next(ls);
if (check_next1(ls, ':')) return R.TK_DBCOLON;
- else return ':';
+ else return char[':'];
}
- case '"'.charCodeAt(0): case '\''.charCodeAt(0): { /* short literal strings */
+ case char['"']: case char['\'']: { /* short literal strings */
read_string(ls, ls.current, seminfo);
return R.TK_STRING;
}
- case '.'.charCodeAt(0): { /* '.', '..', '...', or number */
+ case char['.']: { /* '.', '..', '...', or number */
save_and_next(ls);
if (check_next1(ls, '.')) {
if (check_next1(ls, '.'))
return R.TK_DOTS; /* '...' */
else return R.TK_CONCAT; /* '..' */
}
- else if (!ljstype.lisdigit(ls.current)) return '.';
+ else if (!ljstype.lisdigit(ls.current)) return char['.'];
else return read_numeral(ls, seminfo);
}
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9': {
+ case char['0']: case char['1']: case char['2']: case char['3']: case char['4']:
+ case char['5']: case char['6']: case char['7']: case char['8']: case char['9']: {
return read_numeral(ls, seminfo);
}
case -1: {
@@ -598,7 +603,7 @@ const llex = function(ls, seminfo) {
save_and_next(ls);
} while (ljstype.lislalnum(ls.current));
- let ts = new TValue(CT.LUA_TLNGSTR, lua.to_luastring(ls.buff.buffer.join('')));
+ let ts = new TValue(CT.LUA_TLNGSTR, ls.buff.buffer);
seminfo.ts = ts;
let kidx = luaX_tokens.slice(0, 22).indexOf(ts.jsstring());
if (kidx >= 0) /* reserved word? */
diff --git a/src/lobject.js b/src/lobject.js
index 812ac6a..e958975 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -132,6 +132,8 @@ const luaO_nilobject = new TValue(CT.LUA_TNIL, null);
module.exports.luaO_nilobject = luaO_nilobject;
const jsstring = function(value, from, to) {
+ assert(Array.isArray(value), "jsstring expect a array of bytes");
+
let u0, u1, u2, u3, u4, u5;
let idx = 0;
value = value.slice(from ? from : 0, to);
@@ -194,6 +196,8 @@ class Table extends TValue {
}
} else if (typeof key === "string") { // To avoid
key = lua.to_luastring(key).map(e => `${e}|`).join('');
+ } else if (Array.isArray(key)) {
+ key = key.map(e => `${e}|`).join('');
}
return key;
@@ -293,7 +297,7 @@ const luaO_chunkid = function(source, bufflen) {
else { /* truncate it */
out = out.concat(source.slice(1, bufflen));
}
- } else if (source.charAt(0) === '@') { /* file name */
+ } else if (source[0] === '@'.charCodeAt(0)) { /* file name */
if (l <= bufflen) /* small enough? */
out = source.slice(1);
else { /* add '...' before rest of name */
diff --git a/src/lparser.js b/src/lparser.js
index 01b9a08..249d51f 100644
--- a/src/lparser.js
+++ b/src/lparser.js
@@ -18,6 +18,8 @@ const Table = lobject.Table;
const UnOpr = lcode.UnOpr;
const UpVal = lfunc.UpVal;
+const char = llex.char;
+
const MAXVARS = 200;
const hasmultret = function(k) {
@@ -248,7 +250,7 @@ const new_localvar = function(ls, name) {
};
const new_localvarliteral = function(ls, name) {
- new_localvar(ls, new TValue(lua.CT.LUA_TLNGSTR, lua.to_luastring(name)));
+ new_localvar(ls, new TValue(lua.CT.LUA_TLNGSTR, name));
};
const getlocvar = function(fs, i) {
@@ -273,7 +275,7 @@ const removevars = function(fs, tolevel) {
const searchupvalue = function(fs, name) {
let up = fs.f.upvalues;
for (let i = 0; i < fs.nups; i++) {
- if (up[i].name.join() === name.join())
+ if (up[i].name.value.join() === name.value.join())
return i;
}
return -1; /* not found */
@@ -291,7 +293,7 @@ const newupvalue = function(fs, name, v) {
const searchvar = function(fs, n) {
for (let i = fs.nactvar - 1; i >= 0; i--) {
- if (n.join() === getlocvar(fs, i).varname.join())
+ if (n.value.join() === getlocvar(fs, i).varname.value.join())
return i;
}
@@ -611,7 +613,7 @@ const yindex = function(ls, v) {
llex.luaX_next(ls); /* skip the '[' */
expr(ls, v);
lcode.luaK_exp2val(ls.fs, v);
- checknext(ls, ']');
+ checknext(ls, char[']']);
};
/*
@@ -643,7 +645,7 @@ const recfield = function(ls, cc) {
} else /* ls->t.token === '[' */
yindex(ls, key);
cc.nh++;
- checknext(ls, '=');
+ checknext(ls, char['=']);
let rkkey = lcode.luaK_exp2RK(fs, key);
expr(ls, val);
lcode.luaK_codeABC(fs, OpCodesI.OP_SETTABLE, cc.t.u.info, rkkey, lcode.luaK_exp2RK(fs, val));
@@ -685,13 +687,13 @@ const field = function(ls, cc) {
/* field -> listfield | recfield */
switch (ls.t.token) {
case R.TK_NAME: { /* may be 'listfield' or 'recfield' */
- if (llex.luaX_lookahead(ls) !== '=') /* expression? */
+ if (llex.luaX_lookahead(ls) !== char['=']) /* expression? */
listfield(ls, cc);
else
recfield(ls, cc);
break;
}
- case '[': {
+ case char['[']: {
recfield(ls, cc);
break;
}
@@ -714,14 +716,14 @@ const constructor = function(ls, t) {
init_exp(t, expkind.VRELOCABLE, pc);
init_exp(cc.v, expkind.VVOID, 0); /* no value (yet) */
lcode.luaK_exp2nextreg(ls.fs, t); /* fix it at stack top */
- checknext(ls, '{');
+ checknext(ls, char['{']);
do {
assert(cc.v.k === expkind.VVOID || cc.tostore > 0);
- if (ls.t.token === '}') break;
+ if (ls.t.token === char['}']) break;
closelistfield(fs, cc);
field(ls, cc);
- } while (testnext(ls, ',') || testnext(ls, ';'));
- check_match(ls, '}', '{', line);
+ } while (testnext(ls, char[',']) || testnext(ls, char[';']));
+ check_match(ls, char['}'], char['{'], line);
lastlistfield(fs, cc);
lopcode.SETARG_B(fs.f.code[pc], lobject.luaO_int2fb(cc.na)); /* set initial array size */
lopcode.SETARG_C(fs.f.code[pc], lobject.luaO_int2fb(cc.nh)); /* set initial table size */
@@ -735,7 +737,7 @@ const parlist = function(ls) {
let f = fs.f;
let nparams = 0;
f.is_vararg = 0;
- if (ls.t.token !== ')') { /* is 'parlist' not empty? */
+ if (ls.t.token !== char[')']) { /* is 'parlist' not empty? */
do {
switch (ls.t.token) {
case R.TK_NAME: { /* param -> NAME */
@@ -750,7 +752,7 @@ const parlist = function(ls) {
}
default: llex.luaX_syntaxerror(ls, lua.to_luastring("<name> or '...' expected"));
}
- } while(!f.is_vararg && testnext(ls, ','));
+ } while(!f.is_vararg && testnext(ls, char[',']));
}
adjustlocalvars(ls, nparams);
f.numparams = fs.nactvar;
@@ -764,13 +766,13 @@ const body = function(ls, e, ismethod, line) {
new_fs.f = addprototype(ls);
new_fs.f.linedefined = line;
open_func(ls, new_fs, bl);
- checknext(ls, '(');
+ checknext(ls, char['(']);
if (ismethod) {
new_localvarliteral(ls, lua.to_luastring("self")); /* create 'self' parameter */
adjustlocalvars(ls, 1);
}
parlist(ls);
- checknext(ls, ')');
+ checknext(ls, char[')']);
statlist(ls);
new_fs.f.lastlinedefined = ls.linenumber;
check_match(ls, R.TK_END, R.TK_FUNCTION, line);
@@ -782,7 +784,7 @@ const explist = function(ls, v) {
/* explist -> expr { ',' expr } */
let n = 1; /* at least one expression */
expr(ls, v);
- while (testnext(ls, ',')) {
+ while (testnext(ls, char[','])) {
lcode.luaK_exp2nextreg(ls.fs, v);
expr(ls, v);
n++;
@@ -794,18 +796,18 @@ const funcargs = function(ls, f, line) {
let fs = ls.fs;
let args = new expdesc();
switch (ls.t.token) {
- case '(': { /* funcargs -> '(' [ explist ] ')' */
+ case char['(']: { /* funcargs -> '(' [ explist ] ')' */
llex.luaX_next(ls);
- if (ls.t.token === ')') /* arg list is empty? */
+ if (ls.t.token === char[')']) /* arg list is empty? */
args.k = expkind.VVOID;
else {
explist(ls, args);
lcode.luaK_setmultret(fs, args);
}
- check_match(ls, ')', '(', line);
+ check_match(ls, char[')'], char['('], line);
break;
}
- case '{': { /* funcargs -> constructor */
+ case char['{']: { /* funcargs -> constructor */
constructor(ls, args);
break;
}
@@ -842,11 +844,11 @@ const funcargs = function(ls, f, line) {
const primaryexp = function(ls, v) {
/* primaryexp -> NAME | '(' expr ')' */
switch (ls.t.token) {
- case '(': {
+ case char['(']: {
let line = ls.linenumber;
llex.luaX_next(ls);
expr(ls, v);
- check_match(ls, ')', '(', line);
+ check_match(ls, char[')'], char['('], line);
lcode.luaK_dischargevars(ls.fs, v);
return;
}
@@ -868,18 +870,18 @@ const suffixedexp = function(ls, v) {
primaryexp(ls, v);
for (;;) {
switch (ls.t.token) {
- case '.': { /* fieldsel */
+ case char['.']: { /* fieldsel */
fieldsel(ls, v);
break;
}
- case '[': { /* '[' exp1 ']' */
+ case char['[']: { /* '[' exp1 ']' */
let key = new expdesc();
lcode.luaK_exp2anyregup(fs, v);
yindex(ls, key);
lcode.luaK_indexed(fs, v, key);
break;
}
- case ':': { /* ':' NAME funcargs */
+ case char[':']: { /* ':' NAME funcargs */
let key = new expdesc();
llex.luaX_next(ls);
checkname(ls, key);
@@ -887,7 +889,7 @@ const suffixedexp = function(ls, v) {
funcargs(ls, v, line);
break;
}
- case '(': case R.TK_STRING: case '{': { /* funcargs */
+ case char['(']: case R.TK_STRING: case char['{']: { /* funcargs */
lcode.luaK_exp2nextreg(fs, v);
funcargs(ls, v, line);
break;
@@ -933,7 +935,7 @@ const simpleexp = function(ls, v) {
init_exp(v, expkind.VVARARG, lcode.luaK_codeABC(fs, OpCodesI.OP_VARARG, 0, 1, 0));
break;
}
- case '{': { /* constructor */
+ case char['{']: { /* constructor */
constructor(ls, v);
return;
}
@@ -952,34 +954,34 @@ const simpleexp = function(ls, v) {
const getunopr = function(op) {
switch (op) {
- case R.TK_NOT: return UnOpr.OPR_NOT;
- case '-': return UnOpr.OPR_MINUS;
- case '~': return UnOpr.OPR_BNOT;
- case '#': return UnOpr.OPR_LEN;
- default: return UnOpr.OPR_NOUNOPR;
+ case R.TK_NOT: return UnOpr.OPR_NOT;
+ case char['-']: return UnOpr.OPR_MINUS;
+ case char['~']: return UnOpr.OPR_BNOT;
+ case char['#']: return UnOpr.OPR_LEN;
+ default: return UnOpr.OPR_NOUNOPR;
}
};
const getbinopr = function(op) {
switch (op) {
- case '+': return BinOpr.OPR_ADD;
- case '-': return BinOpr.OPR_SUB;
- case '*': return BinOpr.OPR_MUL;
- case '%': return BinOpr.OPR_MOD;
- case '^': return BinOpr.OPR_POW;
- case '/': return BinOpr.OPR_DIV;
+ case char['+']: return BinOpr.OPR_ADD;
+ case char['-']: return BinOpr.OPR_SUB;
+ case char['*']: return BinOpr.OPR_MUL;
+ case char['%']: return BinOpr.OPR_MOD;
+ case char['^']: return BinOpr.OPR_POW;
+ case char['/']: return BinOpr.OPR_DIV;
case R.TK_IDIV: return BinOpr.OPR_IDIV;
- case '&': return BinOpr.OPR_BAND;
- case '|': return BinOpr.OPR_BOR;
- case '~': return BinOpr.OPR_BXOR;
+ case char['&']: return BinOpr.OPR_BAND;
+ case char['|']: return BinOpr.OPR_BOR;
+ case char['~']: return BinOpr.OPR_BXOR;
case R.TK_SHL: return BinOpr.OPR_SHL;
case R.TK_SHR: return BinOpr.OPR_SHR;
case R.TK_CONCAT: return BinOpr.OPR_CONCAT;
case R.TK_NE: return BinOpr.OPR_NE;
case R.TK_EQ: return BinOpr.OPR_EQ;
- case '<': return BinOpr.OPR_LT;
+ case char['<']: return BinOpr.OPR_LT;
case R.TK_LE: return BinOpr.OPR_LE;
- case '>': return BinOpr.OPR_GT;
+ case char['>']: return BinOpr.OPR_GT;
case R.TK_GE: return BinOpr.OPR_GE;
case R.TK_AND: return BinOpr.OPR_AND;
case R.TK_OR: return BinOpr.OPR_OR;
@@ -1102,7 +1104,7 @@ const check_conflict = function(ls, lh, v) {
const assignment = function(ls, lh, nvars) {
let e = new expdesc();
check_condition(ls, vkisvar(lh.v.k), lua.to_luastring("syntax error"));
- if (testnext(ls, ',')) { /* assignment -> ',' suffixedexp assignment */
+ if (testnext(ls, char[','])) { /* assignment -> ',' suffixedexp assignment */
let nv = new LHS_assign();
nv.prev = lh;
suffixedexp(ls, nv.v);
@@ -1111,7 +1113,7 @@ const assignment = function(ls, lh, nvars) {
checklimit(ls.fs, nvars + ls.L.nCcalls, llimit.LUAI_MAXCCALLS, lua.to_luastring("JS levels"));
assignment(ls, nv, nvars + 1);
} else { /* assignment -> '=' explist */
- checknext(ls, '=');
+ checknext(ls, char['=']);
let nexps = explist(ls, e);
if (nexps !== nvars)
adjust_assign(ls, nvars, nexps, e);
@@ -1158,7 +1160,7 @@ const checkrepeated = function(fs, ll, label) {
/* skip no-op statements */
const skipnoopstat = function(ls) {
- while (ls.t.token === ';' || ls.t.token === R.TK_DBCOLON)
+ while (ls.t.token === char[';'] || ls.t.token === R.TK_DBCOLON)
statement(ls);
};
@@ -1256,11 +1258,11 @@ const fornum = function(ls, varname, line) {
new_localvarliteral(ls, lua.to_luastring("(for limit)"));
new_localvarliteral(ls, lua.to_luastring("(for step)"));
new_localvar(ls, varname);
- checknext(ls, '=');
+ checknext(ls, char['=']);
exp1(ls); /* initial value */
- checknext(ls, ',');
+ checknext(ls, char[',']);
exp1(ls); /* limit */
- if (testnext(ls, ','))
+ if (testnext(ls, char[',']))
exp1(ls); /* optional step */
else { /* default step = 1 */
lcode.luaK_codek(fs, fs.freereg, lcode.luaK_intK(fs, 1));
@@ -1281,7 +1283,7 @@ const forlist = function(ls, indexname) {
new_localvarliteral(ls, lua.to_luastring("(for control)"));
/* create declared variables */
new_localvar(ls, indexname);
- while (testnext(ls, ',')) {
+ while (testnext(ls, char[','])) {
new_localvar(ls, str_checkname(ls));
nvars++;
}
@@ -1300,8 +1302,8 @@ const forstat = function(ls, line) {
llex.luaX_next(ls); /* skip 'for' */
let varname = str_checkname(ls); /* first variable name */
switch (ls.t.token) {
- case '=': fornum(ls, varname, line); break;
- case ',': case R.TK_IN: forlist(ls, varname); break;
+ case char['=']: fornum(ls, varname, line); break;
+ case char[',']: case R.TK_IN: forlist(ls, varname); break;
default: llex.luaX_syntaxerror(ls, lua.to_luastring("'=' or 'in' expected"));
}
check_match(ls, R.TK_END, R.TK_FOR, line);
@@ -1373,8 +1375,8 @@ const localstat = function(ls) {
do {
new_localvar(ls, str_checkname(ls));
nvars++;
- } while (testnext(ls, ','));
- if (testnext(ls, '='))
+ } while (testnext(ls, char[',']));
+ if (testnext(ls, char['=']))
nexps = explist(ls, e);
else {
e.k = expkind.VVOID;
@@ -1388,9 +1390,9 @@ const funcname = function(ls, v) {
/* funcname -> NAME {fieldsel} [':' NAME] */
let ismethod = 0;
singlevar(ls, v);
- while (ls.t.token === '.')
+ while (ls.t.token === char['.'])
fieldsel(ls, v);
- if (ls.t.token === ':') {
+ if (ls.t.token === char[':']) {
ismethod = 1;
fieldsel(ls, v);
}
@@ -1413,7 +1415,7 @@ const exprstat= function(ls) {
let fs = ls.fs;
let v = new LHS_assign();
suffixedexp(ls, v.v);
- if (ls.t.token === '=' || ls.t.token === ',') { /* stat . assignment ? */
+ if (ls.t.token === char['='] || ls.t.token === char[',']) { /* stat . assignment ? */
v.prev = null;
assignment(ls, v, 1);
}
@@ -1428,7 +1430,7 @@ const retstat = function(ls) {
let fs = ls.fs;
let e = new expdesc();
let first, nret; /* registers with returned values */
- if (block_follow(ls, 1) || ls.t.token === ';')
+ if (block_follow(ls, 1) || ls.t.token === char[';'])
first = nret = 0; /* return no values */
else {
nret = explist(ls, e); /* optional return values */
@@ -1451,14 +1453,14 @@ const retstat = function(ls) {
}
}
lcode.luaK_ret(fs, first, nret);
- testnext(ls, ';'); /* skip optional semicolon */
+ testnext(ls, char[';']); /* skip optional semicolon */
};
const statement = function(ls) {
let line = ls.linenumber; /* may be needed for error messages */
enterlevel(ls);
switch(ls.t.token) {
- case ';': { /* stat -> ';' (empty statement) */
+ case char[';']: { /* stat -> ';' (empty statement) */
llex.luaX_next(ls); /* skip ';' */
break;
}
@@ -1547,7 +1549,7 @@ const luaY_parser = function(L, z, buff, dyd, name, firstchar) {
lexstate.h = new Table(); /* create table for scanner */
L.stack[L.top++] = lexstate.h;
funcstate.f = cl.p = new Proto(L);
- funcstate.f.source = new TValue(lua.CT.LUA_TLNGSTR, lua.to_luastring(name));
+ funcstate.f.source = new TValue(lua.CT.LUA_TLNGSTR, name);
lexstate.buff = buff;
lexstate.dyd = dyd;
dyd.actvar.n = dyd.gt.n = dyd.label.n = 0;
diff --git a/src/lstrlib.js b/src/lstrlib.js
index 471187b..e163485 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -1372,7 +1372,7 @@ const createmetatable = function(L) {
lapi.lua_setmetatable(L, -2); /* set table as metatable for strings */
lapi.lua_pop(L, 1); /* pop dummy string */
lapi.lua_pushvalue(L, -2); /* get string library */
- lapi.lua_setfield(L, -2, "__index"); /* metatable.__index = string */
+ lapi.lua_setfield(L, -2, lua.to_luastring("__index")); /* metatable.__index = string */
lapi.lua_pop(L, 1); /* pop metatable */
};
diff --git a/src/ltablib.js b/src/ltablib.js
index c45f7e5..eaaf24d 100644
--- a/src/ltablib.js
+++ b/src/ltablib.js
@@ -163,7 +163,7 @@ const pack = function(L) {
for (let i = n; i >= 1; i--) /* assign elements */
lapi.lua_seti(L, 1, i);
lapi.lua_pushinteger(L, n);
- lapi.lua_setfield(L, 1, "n"); /* t.n = number of elements */
+ lapi.lua_setfield(L, 1, ["n".charCodeAt(0)]); /* t.n = number of elements */
return 1; /* return table */
};
diff --git a/src/ltm.js b/src/ltm.js
index d2df961..4a90f6d 100644
--- a/src/ltm.js
+++ b/src/ltm.js
@@ -53,7 +53,7 @@ const luaT_typenames_ = [
"userdata",
"thread",
"proto" /* this last case is used for tests only */
-];
+].map(e => lua.to_luastring(e));
const ttypename = function(t) {
return luaT_typenames_[t + 1];
diff --git a/src/lua.js b/src/lua.js
index 4710ded..85d4b64 100644
--- a/src/lua.js
+++ b/src/lua.js
@@ -135,6 +135,8 @@ class lua_Debug {
}
const to_luastring = function(str, maxBytesToWrite) {
+ assert(typeof str === "string", "to_luastring expect a js string");
+
maxBytesToWrite = maxBytesToWrite !== undefined ? maxBytesToWrite : Number.MAX_SAFE_INTEGER;
let outU8Array = [];
diff --git a/src/lundump.js b/src/lundump.js
index 7452c43..36fd674 100644
--- a/src/lundump.js
+++ b/src/lundump.js
@@ -5,10 +5,8 @@ const fs = require('fs');
const assert = require('assert');
const lua = require('./lua.js');
-const LClosure = require('./lobject.js').LClosure;
-const TValue = require('./lobject.js').TValue;
+const lobject = require('./lobject.js');
const Proto = require('./lfunc.js').Proto;
-const constant_types = require('./lua.js').constant_types;
const OpCodes = require('./lopcodes.js');
const LUAI_MAXSHORTLEN = 40;
@@ -167,20 +165,20 @@ class BytecodeParser {
let t = this.readByte();
switch (t) {
- case constant_types.LUA_TNIL:
- f.k.push(new TValue(constant_types.LUA_TNIL, null));
+ case lua.CT.LUA_TNIL:
+ f.k.push(new lobject.TValue(lua.CT.LUA_TNIL, null));
break;
- case constant_types.LUA_TBOOLEAN:
- f.k.push(new TValue(constant_types.LUA_TBOOLEAN, this.readByte()));
+ case lua.CT.LUA_TBOOLEAN:
+ f.k.push(new lobject.TValue(lua.CT.LUA_TBOOLEAN, this.readByte()));
break;
- case constant_types.LUA_TNUMFLT:
- f.k.push(new TValue(constant_types.LUA_TNUMFLT, this.readNumber()));
+ case lua.CT.LUA_TNUMFLT:
+ f.k.push(new lobject.TValue(lua.CT.LUA_TNUMFLT, this.readNumber()));
break;
- case constant_types.LUA_TNUMINT:
- f.k.push(new TValue(constant_types.LUA_TNUMINT, this.readInteger()));
+ case lua.CT.LUA_TNUMINT:
+ f.k.push(new lobject.TValue(lua.CT.LUA_TNUMINT, this.readInteger()));
break;
- case constant_types.LUA_TSHRSTR:
- case constant_types.LUA_TLNGSTR:
+ case lua.CT.LUA_TSHRSTR:
+ case lua.CT.LUA_TLNGSTR:
f.k.push(this.L.l_G.intern(this.read8bitString()));
break;
default:
@@ -206,7 +204,7 @@ class BytecodeParser {
n = this.readInt();
for (let i = 0; i < n; i++) {
f.locvars[i] = {
- varname: this.readString(),
+ varname: new lobject.TValue(lua.CT.LUA_TLNGSTR, lua.to_luastring(this.readString())),
startpc: this.readInt(),
endpc: this.readInt()
};
@@ -264,7 +262,7 @@ class BytecodeParser {
luaU_undump() {
this.checkHeader();
- let cl = new LClosure(this.L, this.readByte());
+ let cl = new lobject.LClosure(this.L, this.readByte());
this.L.stack[this.L.top] = cl;
this.L.top++;
@@ -280,4 +278,4 @@ class BytecodeParser {
}
-module.exports = BytecodeParser; \ No newline at end of file
+module.exports = BytecodeParser;
diff --git a/src/lutf8lib.js b/src/lutf8lib.js
index 1df6096..ef9739f 100644
--- a/src/lutf8lib.js
+++ b/src/lutf8lib.js
@@ -58,50 +58,37 @@ const utf8_decode = function(s, val) {
** range [i,j], or nil + current position if 's' is not well formed in
** that interval
*/
-// const utflen = function(L) {
-// let n = 0;
-// let s = lauxlib.luaL_checkstring(L, 1);
-// s = L.stack[lapi.index2addr_(L, 1)].value;
-// let len = s.length;
-// let posi = u_posrelat(lauxlib.luaL_optinteger(L, 2, 1), len);
-// let posj = u_posrelat(lauxlib.luaL_optinteger(L, 3, -1), len);
-//
-// lauxlib.luaL_argcheck(L, 1 <= posi && --posi <= len, 2, "initial position out of string");
-// lauxlib.luaL_argcheck(L, --posj < len, 3, "final position out of string");
-//
-// while (posi <= posj) {
-// let dec = utf8_decode(s[posi]);
-// let s1 = dec ? dec.string : null;
-// if (s1 === null) {
-// /* conversion error? */
-// lapi.lua_pushnil(L); /* return nil ... */
-// lapi.lua_pushinteger(L, posi + 1); /* ... and current position */
-// return 2;
-// }
-// posi = dec.pos;
-// n++;
-// }
-// lapi.lua_pushinteger(L, n);
-// return 1;
-// };
-
-// Shorter JSesque solution but doesn't take invalid UTF-8 sequence (but how can we get one ?)
const utflen = function(L) {
+ let n = 0;
let s = lauxlib.luaL_checkstring(L, 1);
- let posi = u_posrelat(lauxlib.luaL_optinteger(L, 2, 1), s.length);
- let posj = u_posrelat(lauxlib.luaL_optinteger(L, 3, -1), s.length);
-
- lauxlib.luaL_argcheck(L, 1 <= posi && --posi <= s.length, 2, lua.to_luastring("initial position out of string"));
- lauxlib.luaL_argcheck(L, --posj < s.length, 3, lua.to_luastring("final position out of string"));
-
- lapi.lua_pushinteger(L, s.slice(posi, posj + 1).length);
+ s = L.stack[lapi.index2addr_(L, 1)].value;
+ let len = s.length;
+ let posi = u_posrelat(lauxlib.luaL_optinteger(L, 2, 1), len);
+ let posj = u_posrelat(lauxlib.luaL_optinteger(L, 3, -1), len);
+
+ lauxlib.luaL_argcheck(L, 1 <= posi && --posi <= len, 2, "initial position out of string");
+ lauxlib.luaL_argcheck(L, --posj < len, 3, "final position out of string");
+
+ while (posi <= posj) {
+ let dec = utf8_decode(s.slice(posi));
+ let s1 = dec ? dec.string : null;
+ if (s1 === null) {
+ /* conversion error? */
+ lapi.lua_pushnil(L); /* return nil ... */
+ lapi.lua_pushinteger(L, posi + 1); /* ... and current position */
+ return 2;
+ }
+ posi = s.length - s1.length;
+ n++;
+ }
+ lapi.lua_pushinteger(L, n);
return 1;
};
const pushutfchar = function(L, arg) {
let code = lauxlib.luaL_checkinteger(L, arg);
lauxlib.luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, lua.to_luastring("value out of range"));
- lapi.lua_pushstring(L, `${String.fromCharCode(code)}`);
+ lapi.lua_pushstring(L, lua.to_luastring(String.fromCharCode(code)));
};
/*
@@ -248,8 +235,8 @@ const UTF8PATT = "[\0-\x7F\xC2-\xF4][\x80-\xBF]*";
const luaopen_utf8 = function(L) {
lauxlib.luaL_newlib(L, funcs);
- lapi.lua_pushstring(L, UTF8PATT);
- lapi.lua_setfield(L, -2, "charpattern");
+ lapi.lua_pushstring(L, lua.to_luastring(UTF8PATT));
+ lapi.lua_setfield(L, -2, lua.to_luastring("charpattern"));
return 1;
};
diff --git a/src/lvm.js b/src/lvm.js
index 53e1584..6f49ad3 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -592,19 +592,19 @@ const luaV_execute = function(L) {
let nstep = tonumber(pstep);
if (nlimit === false)
- ldebug.luaG_runerror(L, "'for' limit must be a number");
+ ldebug.luaG_runerror(L, lua.to_luastring("'for' limit must be a number"));
plimit.type = CT.LUA_TNUMFLT;
plimit.value = nlimit;
if (nstep === false)
- ldebug.luaG_runerror(L, "'for' step must be a number");
+ ldebug.luaG_runerror(L, lua.to_luastring("'for' step must be a number"));
pstep.type = CT.LUA_TNUMFLT;
pstep.value = nstep;
if (ninit === false)
- ldebug.luaG_runerror(L, "'for' initial value must be a number");
+ ldebug.luaG_runerror(L, lua.to_luastring("'for' initial value must be a number"));
init.type = CT.LUA_TNUMFLT;
init.value = ninit - nstep;
@@ -977,7 +977,7 @@ const luaV_objlen = function(L, ra, rb) {
default: {
tm = ltm.luaT_gettmbyobj(L, rb, ltm.TMS.TM_LEN);
if (tm.ttisnil())
- ldebug.luaG_typeerror(L, rb, "get length of");
+ ldebug.luaG_typeerror(L, rb, lua.to_luastring("get length of"));
break;
}
}
@@ -1042,7 +1042,7 @@ const gettable = function(L, table, key, ra, recur) {
recur = recur ? recur : 0;
if (recur >= MAXTAGRECUR)
- ldebug.luaG_runerror(L, "'__index' chain too long; possible loop");
+ ldebug.luaG_runerror(L, lua.to_luastring("'__index' chain too long; possible loop"));
if (table.ttistable()) {
let element = table.__index(table, key);
@@ -1063,7 +1063,7 @@ const luaV_finishget = function(L, t, key, val, slot, recur) {
assert(!t.ttistable());
tm = ltm.luaT_gettmbyobj(L, t, ltm.TMS.TM_INDEX);
if (tm.ttisnil())
- ldebug.luaG_typeerror(L, t, 'index');
+ ldebug.luaG_typeerror(L, t, lua.to_luastring('index'));
} else { /* 't' is a table */
assert(slot.ttisnil());
tm = ltm.luaT_gettmbyobj(L, t, ltm.TMS.TM_INDEX); // TODO: fasttm
@@ -1085,7 +1085,7 @@ const settable = function(L, table, key, v, recur) {
recur = recur ? recur : 0;
if (recur >= MAXTAGRECUR)
- ldebug.luaG_runerror(L, "'__newindex' chain too long; possible loop");
+ ldebug.luaG_runerror(L, lua.to_luastring("'__newindex' chain too long; possible loop"));
if (table.ttistable()) {
let element = table.__index(table, key);
@@ -1112,7 +1112,7 @@ const luaV_finishset = function(L, t, key, val, slot, recur) {
} else { /* not a table; check metamethod */
tm = ltm.luaT_gettmbyobj(L, t, ltm.TMS.TM_NEWINDEX);
if (tm.ttisnil())
- ldebug.luaG_typeerror(L, t, 'index');
+ ldebug.luaG_typeerror(L, t, lua.to_luastring('index'));
}
if (tm.ttisfunction()) {
diff --git a/tests/lapi.js b/tests/lapi.js
index c422ada..c6e9c53 100644
--- a/tests/lapi.js
+++ b/tests/lapi.js
@@ -28,9 +28,9 @@ test('luaL_newstate, lua_pushnil, luaL_typename', function (t) {
}, "JS Lua program ran without error");
- t.strictEqual(
+ t.deepEqual(
lauxlib.luaL_typename(L, -1),
- "nil",
+ "nil".split('').map(e => e.charCodeAt(0)),
"Correct element(s) on the stack"
);
});
@@ -49,9 +49,9 @@ test('lua_pushnumber', function (t) {
}, "JS Lua program ran without error");
- t.strictEqual(
+ t.deepEqual(
lauxlib.luaL_typename(L, -1),
- "number",
+ "number".split('').map(e => e.charCodeAt(0)),
"Correct element(s) on the stack"
);
@@ -76,9 +76,9 @@ test('lua_pushinteger', function (t) {
}, "JS Lua program ran without error");
- t.strictEqual(
+ t.deepEqual(
lauxlib.luaL_typename(L, -1),
- "number",
+ "number".split('').map(e => e.charCodeAt(0)),
"Correct element(s) on the stack"
);
@@ -90,7 +90,7 @@ test('lua_pushinteger', function (t) {
});
-test('lua_pushstring', function (t) {
+test('lua_pushliteral', function (t) {
let L;
t.plan(3);
@@ -99,18 +99,18 @@ test('lua_pushstring', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushstring(L, "hello");
+ lapi.lua_pushliteral(L, "hello");
}, "JS Lua program ran without error");
- t.strictEqual(
+ t.deepEqual(
lauxlib.luaL_typename(L, -1),
- "string",
+ "string".split('').map(e => e.charCodeAt(0)),
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"top is correct"
);
@@ -130,9 +130,9 @@ test('lua_pushboolean', function (t) {
}, "JS Lua program ran without error");
- t.strictEqual(
+ t.deepEqual(
lauxlib.luaL_typename(L, -1),
- "boolean",
+ "boolean".split('').map(e => e.charCodeAt(0)),
"Correct element(s) on the stack"
);
@@ -153,32 +153,32 @@ test('lua_pushvalue', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushstring(L, "hello");
+ lapi.lua_pushliteral(L, "hello");
lapi.lua_pushvalue(L, -1);
}, "JS Lua program ran without error");
- t.strictEqual(
+ t.deepEqual(
lauxlib.luaL_typename(L, -1),
- "string",
+ "string".split('').map(e => e.charCodeAt(0)),
"Correct element(s) on the stack"
);
- t.strictEqual(
+ t.deepEqual(
lauxlib.luaL_typename(L, -2),
- "string",
+ "string".split('').map(e => e.charCodeAt(0)),
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"hello",
"Correct element(s) on the stack"
);
@@ -198,14 +198,14 @@ test('lua_pushjsclosure', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushstring(L, "a value associated to the C closure");
+ lapi.lua_pushliteral(L, "a value associated to the C closure");
lapi.lua_pushjsclosure(L, fn, 1);
}, "JS Lua program ran without error");
- t.strictEqual(
+ t.deepEqual(
lauxlib.luaL_typename(L, -1),
- "function",
+ "function".split('').map(e => e.charCodeAt(0)),
"Correct element(s) on the stack"
);
});
@@ -228,9 +228,9 @@ test('lua_pushjsfunction', function (t) {
}, "JS Lua program ran without error");
- t.strictEqual(
+ t.deepEqual(
lauxlib.luaL_typename(L, -1),
- "function",
+ "function".split('').map(e => e.charCodeAt(0)),
"Correct element(s) on the stack"
);
});
@@ -244,7 +244,7 @@ test('lua_call (calling a light JS function)', function (t) {
t.doesNotThrow(function () {
let fn = function(L) {
- lapi.lua_pushstring(L, "hello");
+ lapi.lua_pushliteral(L, "hello");
return 1;
};
@@ -257,7 +257,7 @@ test('lua_call (calling a light JS function)', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"top is correct"
);
@@ -278,7 +278,7 @@ test('lua_call (calling a JS closure)', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushstring(L, "upvalue hello !");
+ lapi.lua_pushliteral(L, "upvalue hello !");
lapi.lua_pushjsclosure(L, fn, 1);
lapi.lua_call(L, 0, 1);
@@ -286,7 +286,7 @@ test('lua_call (calling a JS closure)', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"upvalue hello !",
"top is correct"
);
@@ -301,7 +301,7 @@ test('lua_pcall (calling a light JS function)', function (t) {
t.doesNotThrow(function () {
let fn = function(L) {
- lapi.lua_pushstring(L, "hello");
+ lapi.lua_pushliteral(L, "hello");
return 1;
};
@@ -314,7 +314,7 @@ test('lua_pcall (calling a light JS function)', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"top is correct"
);
@@ -353,15 +353,15 @@ test('lua_pop', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushstring(L, "hello");
- lapi.lua_pushstring(L, "world");
+ lapi.lua_pushliteral(L, "hello");
+ lapi.lua_pushliteral(L, "world");
lapi.lua_pop(L, 1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Correct element(s) on the stack"
);
@@ -382,14 +382,14 @@ test('lua_load and lua_call it', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_load(L, null, bc, "test-lua_load", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-lua_load"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, 1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"JS > Lua > JS \o/",
"Correct element(s) on the stack"
);
@@ -409,17 +409,17 @@ test('lua script reads js upvalues', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_load(L, null, bc, "test-lua_load", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-lua_load"), lua.to_luastring("binary"));
- lapi.lua_pushstring(L, "hello");
- lapi.lua_setglobal(L, "js");
+ lapi.lua_pushliteral(L, "hello");
+ lapi.lua_setglobal(L, lua.to_luastring("js"));
lapi.lua_call(L, 0, 1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -474,19 +474,19 @@ test('lua_settable, lua_gettable', function (t) {
lapi.lua_newtable(L);
- lapi.lua_pushstring(L, "key");
- lapi.lua_pushstring(L, "value");
+ lapi.lua_pushliteral(L, "key");
+ lapi.lua_pushliteral(L, "value");
lapi.lua_settable(L, -3);
- lapi.lua_pushstring(L, "key");
+ lapi.lua_pushliteral(L, "key");
lapi.lua_gettable(L, -2);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"value",
"Correct element(s) on the stack"
);
-}); \ No newline at end of file
+});
diff --git a/tests/lbaselib.js b/tests/lbaselib.js
index be741dc..dd91449 100644
--- a/tests/lbaselib.js
+++ b/tests/lbaselib.js
@@ -31,7 +31,7 @@ test('print', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-print", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-print"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -65,14 +65,14 @@ test('setmetatable, getmetatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-setmetatable-getmetatable", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-setmetatable-getmetatable"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"hello",
"Correct element(s) on the stack"
);
@@ -110,7 +110,7 @@ test('rawequal', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-rawequal", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-rawequal"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -156,32 +156,32 @@ test('rawset, rawget', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-rawequal", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-rawequal"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -4),
+ lapi.lua_tojsstring(L, -4),
"hello",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -3),
+ lapi.lua_tojsstring(L, -3),
"hello",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"bye",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"bye",
"Correct element(s) on the stack"
);
@@ -203,38 +203,38 @@ test('type', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-type", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-type"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -5),
+ lapi.lua_tojsstring(L, -5),
"number",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -4),
+ lapi.lua_tojsstring(L, -4),
"boolean",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -3),
+ lapi.lua_tojsstring(L, -3),
"string",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"table",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"nil",
"Correct element(s) on the stack"
);
@@ -256,7 +256,7 @@ test('error', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-error", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-error"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -279,14 +279,14 @@ test('error, protected', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-error", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-error"), lua.to_luastring("binary"));
lapi.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tostring(L, -1).endsWith("you fucked up"),
+ lapi.lua_tojsstring(L, -1).endsWith("you fucked up"),
"Error is on the stack"
);
});
@@ -311,14 +311,14 @@ test('pcall', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-pcall", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-pcall"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tostring(L, -1).endsWith("you fucked up"),
+ lapi.lua_tojsstring(L, -1).endsWith("you fucked up"),
"Error is on the stack"
);
});
@@ -347,21 +347,21 @@ test('xpcall', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-pcall", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-pcall"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
- console.log(lapi.lua_tostring(L, -1));
+ console.log(lapi.lua_tojsstring(L, -1));
t.ok(
- lapi.lua_tostring(L, -1).startsWith("Something's wrong:"),
+ lapi.lua_tojsstring(L, -1).startsWith("Something's wrong:"),
"msgh was called and modified the error"
);
t.ok(
- lapi.lua_tostring(L, -1).endsWith("you fucked up"),
+ lapi.lua_tojsstring(L, -1).endsWith("you fucked up"),
"msgh was called and modified the error"
);
});
@@ -389,7 +389,7 @@ test('ipairs', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-ipairs", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-ipairs"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -418,7 +418,7 @@ test('select', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-select", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-select"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -459,7 +459,7 @@ test('tonumber', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-tonumber", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-tonumber"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -506,14 +506,14 @@ test('assert', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-assert", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-assert"), lua.to_luastring("binary"));
lapi.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tostring(L, -1).endsWith("this doesn't makes sense"),
+ lapi.lua_tojsstring(L, -1).endsWith("this doesn't makes sense"),
"Error is on the stack"
);
});
@@ -534,7 +534,7 @@ test('rawlen', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-rawlen", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-rawlen"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -581,7 +581,7 @@ test('next', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-next", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-next"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -622,7 +622,7 @@ test('pairs', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-pairs", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-pairs"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -672,7 +672,7 @@ test('pairs with __pairs', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-pairs", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-pairs"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -683,4 +683,4 @@ test('pairs with __pairs', function (t) {
26,
"Correct element(s) on the stack"
);
-}); \ No newline at end of file
+});
diff --git a/tests/lcorolib.js b/tests/lcorolib.js
index 9c1d9b1..f709fa5 100644
--- a/tests/lcorolib.js
+++ b/tests/lcorolib.js
@@ -40,7 +40,7 @@ test('coroutine.create, coroutine.yield, coroutine.resume', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-coroutine", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-coroutine"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -83,20 +83,20 @@ test('coroutine.status', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-coroutine.status", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-coroutine.status"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"suspended",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"dead",
"Correct element(s) on the stack"
);
@@ -124,7 +124,7 @@ test('coroutine.isyieldable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-coroutine.isyieldable", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-coroutine.isyieldable"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -165,7 +165,7 @@ test('coroutine.running', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-coroutine.running", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-coroutine.running"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -206,7 +206,7 @@ test('coroutine.wrap', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-coroutine.wrap", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-coroutine.wrap"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -217,4 +217,4 @@ test('coroutine.wrap', function (t) {
625,
"Correct element(s) on the stack"
);
-}); \ No newline at end of file
+});
diff --git a/tests/ldebug.js b/tests/ldebug.js
index 0261305..e24b584 100644
--- a/tests/ldebug.js
+++ b/tests/ldebug.js
@@ -30,7 +30,7 @@ test('luaG_typeerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-typeerror", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
lapi.lua_pcall(L, 0, -1, 0);
@@ -38,7 +38,7 @@ test('luaG_typeerror', function (t) {
t.ok(
- lapi.lua_tostring(L, -1).endsWith("attempt to get length of a boolean value (local 'a')"),
+ lapi.lua_tojsstring(L, -1).endsWith("attempt to get length of a boolean value (local 'a')"),
"Correct error was thrown"
);
});
@@ -60,14 +60,14 @@ test('luaG_typeerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-typeerror", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
lapi.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tostring(L, -1).endsWith("attempt to index a boolean value (local 'a')"),
+ lapi.lua_tojsstring(L, -1).endsWith("attempt to index a boolean value (local 'a')"),
"Correct error was thrown"
);
});
@@ -89,14 +89,14 @@ test('luaG_typeerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-typeerror", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
lapi.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tostring(L, -1).endsWith("attempt to index a boolean value (local 'a')"),
+ lapi.lua_tojsstring(L, -1).endsWith("attempt to index a boolean value (local 'a')"),
"Correct error was thrown"
);
});
@@ -118,14 +118,14 @@ test('luaG_typeerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-typeerror", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
lapi.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tostring(L, -1).endsWith("attempt to index a boolean value (local 'a')"),
+ lapi.lua_tojsstring(L, -1).endsWith("attempt to index a boolean value (local 'a')"),
"Correct error was thrown"
);
});
@@ -146,14 +146,14 @@ test('luaG_concaterror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-typeerror", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
lapi.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tostring(L, -1).endsWith("attempt to concatenate a table value"),
+ lapi.lua_tojsstring(L, -1).endsWith("attempt to concatenate a table value"),
"Correct error was thrown"
);
});
@@ -174,14 +174,14 @@ test('luaG_opinterror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-typeerror", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
lapi.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tostring(L, -1).endsWith("attempt to perform arithmetic on a string value"),
+ lapi.lua_tojsstring(L, -1).endsWith("attempt to perform arithmetic on a string value"),
"Correct error was thrown"
);
});
@@ -202,14 +202,14 @@ test('luaG_tointerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-typeerror", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
lapi.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tostring(L, -1).endsWith("number has no integer representation"),
+ lapi.lua_tojsstring(L, -1).endsWith("number has no integer representation"),
"Correct error was thrown"
);
-}); \ No newline at end of file
+});
diff --git a/tests/lexparse.js b/tests/lexparse.js
index 704f875..edffe53 100644
--- a/tests/lexparse.js
+++ b/tests/lexparse.js
@@ -6,6 +6,7 @@ const beautify = require('js-beautify').js_beautify;
const tests = require("./tests.js");
const toByteCode = tests.toByteCode;
+const lua = require("../src/lua.js");
const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const linit = require('../src/linit.js');
@@ -28,12 +29,12 @@ test('LOADK, RETURN', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -44,7 +45,7 @@ test('LOADK, RETURN', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -68,12 +69,12 @@ test('MOVE', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -84,7 +85,7 @@ test('MOVE', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -108,12 +109,12 @@ test('Binary op', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -148,12 +149,12 @@ test('Unary op, LOADBOOL', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -186,12 +187,12 @@ test('NEWTABLE', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -228,12 +229,12 @@ test('CALL', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -274,12 +275,12 @@ test('Multiple return', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -315,12 +316,12 @@ test('TAILCALL', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -356,12 +357,12 @@ test('VARARG', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -395,12 +396,12 @@ test('LE, JMP', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -434,12 +435,12 @@ test('LT', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -473,12 +474,12 @@ test('EQ', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -513,12 +514,12 @@ test('TESTSET (and)', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -529,7 +530,7 @@ test('TESTSET (and)', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -553,12 +554,12 @@ test('TESTSET (or)', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -569,7 +570,7 @@ test('TESTSET (or)', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -597,12 +598,12 @@ test('TEST (false)', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -613,7 +614,7 @@ test('TEST (false)', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"goodbye",
"Program output is correct"
);
@@ -640,12 +641,12 @@ test('FORPREP, FORLOOP (int)', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -683,12 +684,12 @@ test('FORPREP, FORLOOP (float)', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -725,12 +726,12 @@ test('SETTABLE, GETTABLE', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -776,12 +777,12 @@ test('SETUPVAL, GETUPVAL', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -792,7 +793,7 @@ test('SETUPVAL, GETUPVAL', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"world",
"Program output is correct"
);
@@ -818,12 +819,12 @@ test('SETTABUP, GETTABUP', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -868,12 +869,12 @@ test('SELF', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -884,7 +885,7 @@ test('SELF', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -907,12 +908,12 @@ test('SETLIST', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -950,12 +951,12 @@ test('Variable SETLIST', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -988,12 +989,12 @@ test('Long SETLIST', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -1043,12 +1044,12 @@ test('TFORCALL, TFORLOOP', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -1084,12 +1085,12 @@ test('LEN', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -1133,12 +1134,12 @@ test('CONCAT', function (t) {
linit.luaL_openlibs(L);
let reader = function(L, data) {
- let code = luaCode;
+ let code = luaCode ? luaCode.trim() : null;
luaCode = null;
return code;
};
- lapi.lua_load(L, reader, luaCode, "test", "text");
+ lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "Lua program loaded without error");
@@ -1149,8 +1150,8 @@ test('CONCAT', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello 2 you",
"Program output is correct"
);
-}); \ No newline at end of file
+});
diff --git a/tests/lmathlib.js b/tests/lmathlib.js
index ae0c40b..6105af4 100644
--- a/tests/lmathlib.js
+++ b/tests/lmathlib.js
@@ -33,7 +33,7 @@ test('math.abs, math.sin, math.cos, math.tan, math.asin, math.acos, math.atan',
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -98,7 +98,7 @@ test('math.ceil, math.floor', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -134,7 +134,7 @@ test('math.deg, math.rad', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -170,7 +170,7 @@ test('math.log', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -212,7 +212,7 @@ test('math.exp', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -242,7 +242,7 @@ test('math.min, math.max', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -278,7 +278,7 @@ test('math.random', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -312,7 +312,7 @@ test('math.sqrt', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -342,7 +342,7 @@ test('math.tointeger', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -372,26 +372,26 @@ test('math.type', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -3),
+ lapi.lua_tojsstring(L, -3),
"integer",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"float",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
null,
"Correct element(s) on the stack"
);
@@ -414,7 +414,7 @@ test('math.ult', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -444,7 +444,7 @@ test('math.fmod', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -474,7 +474,7 @@ test('math.modf', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
diff --git a/tests/load.js b/tests/load.js
index 9b76ad3..9a53176 100644
--- a/tests/load.js
+++ b/tests/load.js
@@ -39,7 +39,7 @@ test('luaL_loadstring', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -72,7 +72,7 @@ test('load', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"js running lua running lua",
"Correct element(s) on the stack"
);
@@ -107,7 +107,7 @@ test('luaL_loadbuffer', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -140,7 +140,7 @@ test('loadfile', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -173,7 +173,7 @@ test('loadfile (binary)', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -205,7 +205,7 @@ test('dofile', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
diff --git a/tests/lstrlib.js b/tests/lstrlib.js
index 12df173..2bde19d 100644
--- a/tests/lstrlib.js
+++ b/tests/lstrlib.js
@@ -6,6 +6,7 @@ const beautify = require('js-beautify').js_beautify;
const tests = require("./tests.js");
const toByteCode = tests.toByteCode;
+const lua = require("../src/lua.js");
const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const linit = require('../src/linit.js');
@@ -74,7 +75,7 @@ test('string.char', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Correct element(s) on the stack"
);
@@ -105,13 +106,13 @@ test('string.upper, string.lower', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"HELLO",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Correct element(s) on the stack"
);
@@ -142,7 +143,7 @@ test('string.rep', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello, hello, hello",
"Correct element(s) on the stack"
);
@@ -173,7 +174,7 @@ test('string.reverse', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Correct element(s) on the stack"
);
@@ -247,7 +248,7 @@ test('string.format', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"%10 0000000023",
"Correct element(s) on the stack"
);
@@ -278,7 +279,7 @@ test('string.format', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"FFFFFFF",
"Correct element(s) on the stack"
);
@@ -309,7 +310,7 @@ test('string.format', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
'"a string with \\"quotes\\" and \\\n new line"',
"Correct element(s) on the stack"
);
@@ -350,67 +351,67 @@ test('string.sub', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -11),
+ lapi.lua_tojsstring(L, -11),
"234",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -10),
+ lapi.lua_tojsstring(L, -10),
"789",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -9),
+ lapi.lua_tojsstring(L, -9),
"",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -8),
+ lapi.lua_tojsstring(L, -8),
"7",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -7),
+ lapi.lua_tojsstring(L, -7),
"",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -6),
+ lapi.lua_tojsstring(L, -6),
"123456789",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -5),
+ lapi.lua_tojsstring(L, -5),
"123456789",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -4),
+ lapi.lua_tojsstring(L, -4),
"",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -3),
+ lapi.lua_tojsstring(L, -3),
"9",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"6789",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"456",
"Correct element(s) on the stack"
);
@@ -448,14 +449,14 @@ test('string.dump', function (t) {
let dv = lapi.lua_todataview(L, -1);
- lapi.lua_load(L, null, dv, "test", "binary");
+ lapi.lua_load(L, null, dv, lua.to_luastring("test"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello1212.5",
"Correct element(s) on the stack"
);
@@ -562,13 +563,13 @@ test('string.match', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"foo",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"123",
"Correct element(s) on the stack"
);
@@ -611,13 +612,13 @@ test('string.find', function (t) {
);
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"foo",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"123",
"Correct element(s) on the stack"
);
@@ -655,25 +656,25 @@ test('string.gmatch', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -4),
+ lapi.lua_tojsstring(L, -4),
"hello",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -3),
+ lapi.lua_tojsstring(L, -3),
"world",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"from",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"Lua",
"Correct element(s) on the stack"
);
@@ -704,7 +705,7 @@ test('string.gsub', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"hello hello world world",
"Correct element(s) on the stack"
);
@@ -741,7 +742,7 @@ test('string.gsub (number)', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"hello hello world",
"Correct element(s) on the stack"
);
@@ -778,7 +779,7 @@ test('string.gsub (pattern)', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"world hello Lua from",
"Correct element(s) on the stack"
);
@@ -817,7 +818,7 @@ test('string.gsub (function)', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"4+5 = 9",
"Correct element(s) on the stack"
);
@@ -856,7 +857,7 @@ test('string.gsub (table)', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"lua-5.3.tar.gz",
"Correct element(s) on the stack"
);
@@ -866,4 +867,4 @@ test('string.gsub (table)', function (t) {
2,
"Correct element(s) on the stack"
);
-}); \ No newline at end of file
+});
diff --git a/tests/ltablib.js b/tests/ltablib.js
index c8a1e73..81ffcbd 100644
--- a/tests/ltablib.js
+++ b/tests/ltablib.js
@@ -42,14 +42,14 @@ test('table.concat', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-table.concat", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-table.concat"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"3,4,5",
"Correct element(s) on the stack"
);
@@ -71,7 +71,7 @@ test('table.pack', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-table.pack", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-table.pack"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -102,7 +102,7 @@ test('table.unpack', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-table.unpack", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-table.unpack"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -146,7 +146,7 @@ test('table.insert', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-table.insert", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-table.insert"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -180,7 +180,7 @@ test('table.remove', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-table.remove", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-table.remove"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -213,7 +213,7 @@ test('table.move', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-table.move", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-table.move"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -246,7 +246,7 @@ test('table.sort (<)', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-table.sort", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-table.sort"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -279,7 +279,7 @@ test('table.sort with cmp function', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-table.sort", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test-table.sort"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
@@ -290,4 +290,4 @@ test('table.sort with cmp function', function (t) {
[5, 4, 3, 2, 1],
"Correct element(s) on the stack"
);
-}); \ No newline at end of file
+});
diff --git a/tests/ltm.js b/tests/ltm.js
index 9eedc4c..501b062 100644
--- a/tests/ltm.js
+++ b/tests/ltm.js
@@ -3,6 +3,7 @@
const test = require('tape');
const beautify = require('js-beautify').js_beautify;
+const lua = require("../src/lua.js");
const VM = require("../src/lvm.js");
const lapi = require("../src/lapi.js");
const linit = require("../src/linit.js");
@@ -31,7 +32,7 @@ test('__index, __newindex: with actual table', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
@@ -65,7 +66,7 @@ test('__newindex: with non table', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.throws(function () {
@@ -100,7 +101,7 @@ test('__index function in metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
@@ -109,7 +110,7 @@ test('__index function in metatable', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"__index",
"Program output is correct"
);
@@ -144,7 +145,7 @@ test('__newindex function in metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -186,7 +187,7 @@ test('__index table in metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -194,7 +195,7 @@ test('__index table in metatable', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -231,7 +232,7 @@ test('__newindex table in metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -239,7 +240,7 @@ test('__newindex table in metatable', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"world",
"Program output is correct"
);
@@ -287,7 +288,7 @@ test('__index table with own metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -295,7 +296,7 @@ test('__index table with own metatable', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -342,7 +343,7 @@ test('__newindex table with own metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -350,7 +351,7 @@ test('__newindex table with own metatable', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -445,7 +446,7 @@ test('binary __xxx functions in metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -499,7 +500,7 @@ test('__eq', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -539,7 +540,7 @@ test('__lt', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -579,7 +580,7 @@ test('__le', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -619,7 +620,7 @@ test('__le that uses __lt', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -663,7 +664,7 @@ test('__unm, __bnot', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -671,13 +672,13 @@ test('__unm, __bnot', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"world",
"Program output is correct"
);
t.strictEqual(
- lapi.lua_tostring(L, -2),
+ lapi.lua_tojsstring(L, -2),
"hello",
"Program output is correct"
);
@@ -710,7 +711,7 @@ test('__len', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -718,7 +719,7 @@ test('__len', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -751,7 +752,7 @@ test('__concat', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -759,7 +760,7 @@ test('__concat', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -792,7 +793,7 @@ test('__call', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test", "binary");
+ lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -804,4 +805,4 @@ test('__call', function (t) {
["hello", "world", "wow"],
"Program output is correct"
);
-}); \ No newline at end of file
+});
diff --git a/tests/lutf8lib.js b/tests/lutf8lib.js
index 38d8f8a..7832bae 100644
--- a/tests/lutf8lib.js
+++ b/tests/lutf8lib.js
@@ -107,7 +107,7 @@ test('utf8.char', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"( ͡° ͜ʖ ͡° )",
"Correct element(s) on the stack"
);
@@ -176,9 +176,9 @@ test('utf8.codes', function (t) {
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"[1,40] [2,32] [3,865] [5,176] [7,32] [8,860] [10,662] [12,32] [13,865] [15,176] [17,32] [18,41] ",
"Correct element(s) on the stack"
);
-}); \ No newline at end of file
+});
diff --git a/tests/lvm.js b/tests/lvm.js
index 69195d1..bda4c4f 100644
--- a/tests/lvm.js
+++ b/tests/lvm.js
@@ -26,7 +26,7 @@ test('LOADK, RETURN', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello world",
"Program output is correct"
);
@@ -50,7 +50,7 @@ test('MOVE', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello world",
"Program output is correct"
);
@@ -328,7 +328,7 @@ test('TESTSET (and)', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -353,7 +353,7 @@ test('TESTSET (or)', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -382,7 +382,7 @@ test('TEST (true)', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -411,7 +411,7 @@ test('TEST (false)', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"goodbye",
"Program output is correct"
);
@@ -532,7 +532,7 @@ test('SETUPVAL, GETUPVAL', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"world",
"Program output is correct"
);
@@ -594,7 +594,7 @@ test('SELF', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -794,8 +794,8 @@ test('CONCAT', function (t) {
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tostring(L, -1),
+ lapi.lua_tojsstring(L, -1),
"hello 2 you",
"Program output is correct"
);
-}); \ No newline at end of file
+});