summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--src/defs.js18
-rw-r--r--src/fengari.js18
-rw-r--r--src/fengaricore.js36
-rw-r--r--src/lauxlib.js93
-rw-r--r--src/lbaselib.js47
-rw-r--r--src/lcorolib.js3
-rw-r--r--src/ldblib.js83
-rw-r--r--src/linit.js4
-rw-r--r--src/liolib.js21
-rw-r--r--src/lmathlib.js21
-rw-r--r--src/loadlib.js95
-rw-r--r--src/loslib.js37
-rw-r--r--src/lstrlib.js133
-rw-r--r--src/ltablib.js32
-rw-r--r--src/lua.js14
-rw-r--r--src/lutf8lib.js29
-rw-r--r--tests/lapi.js15
-rw-r--r--tests/lauxlib.js9
-rw-r--r--tests/lbaselib.js35
-rw-r--r--tests/lcorolib.js12
-rw-r--r--tests/ldblib.js28
-rw-r--r--tests/ldebug.js15
-rw-r--r--tests/lexparse.js114
-rw-r--r--tests/lmathlib.js28
-rw-r--r--tests/load.js14
-rw-r--r--tests/loadlib.js10
-rw-r--r--tests/loslib.js12
-rw-r--r--tests/lstrlib.js46
-rw-r--r--tests/ltablib.js18
-rw-r--r--tests/ltm.js36
-rw-r--r--tests/lua.js15
-rw-r--r--tests/lutf8lib.js11
-rw-r--r--tests/lvm.js5
-rwxr-xr-xtests/manual-tests/debug-cli.js3
-rw-r--r--tests/test-suite/api.js193
-rw-r--r--tests/test-suite/attrib.js26
-rw-r--r--tests/test-suite/bitwise.js34
-rw-r--r--tests/test-suite/calls.js68
-rw-r--r--tests/test-suite/closure.js33
-rw-r--r--tests/test-suite/code.js62
-rw-r--r--tests/test-suite/constructs.js14
-rw-r--r--tests/test-suite/coroutine.js143
-rw-r--r--tests/test-suite/db.js60
-rw-r--r--tests/test-suite/errors.js144
-rw-r--r--tests/test-suite/events.js58
-rw-r--r--tests/test-suite/goto.js26
-rw-r--r--tests/test-suite/literals.js62
-rw-r--r--tests/test-suite/locals.js26
-rw-r--r--tests/test-suite/ltests.js63
-rw-r--r--tests/test-suite/math.js142
-rw-r--r--tests/test-suite/nextvar.js110
-rw-r--r--tests/test-suite/pm.js70
-rw-r--r--tests/test-suite/sort.js56
-rw-r--r--tests/test-suite/strings.js38
-rw-r--r--tests/test-suite/tpack.js40
-rw-r--r--tests/test-suite/utf8.js20
-rw-r--r--tests/test-suite/vararg.js18
-rw-r--r--tests/tests.js3
59 files changed, 1333 insertions, 1288 deletions
diff --git a/README.md b/README.md
index a40b3b9..a70caf5 100644
--- a/README.md
+++ b/README.md
@@ -45,7 +45,7 @@ Fengari implements Lua 5.3 semantics and will hopefully follow future Lua releas
Lua strings are 8-bits clean and can embed `\0`. Which means that invalid UTF-8/16 strings are valid Lua strings. Lua functions like `string.dump` even use strings as a way of storing binary data.
-To address that issue, Fengari uses [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) objects containing the raw bytes to implement lua strings. To push a JS string on the stack you can use `lua_pushliteral` which will convert it to an array of bytes before pushing it. To get a Lua string on the stack as a JS string you can use `lua_tojsstring` which will attempt to convert it to a UTF-16 JS string. The latter won't give you what you expect if the Lua string is not a valid UTF-16 sequence. You can also convert strings with `lua.luastring_of`, `lua.to_luastring`, `lua.to_jsstring` and `lua.to_uristring`.
+To address that issue, Fengari uses [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) objects containing the raw bytes to implement lua strings. To push a JS string on the stack you can use `lua_pushliteral` which will convert it to an array of bytes before pushing it. To get a Lua string on the stack as a JS string you can use `lua_tojsstring` which will attempt to convert it to a UTF-16 JS string. The latter won't give you what you expect if the Lua string is not a valid UTF-16 sequence. You can also convert strings with `luastring_of`, `to_luastring`, `to_jsstring` and `to_uristring`.
### Integers
diff --git a/src/defs.js b/src/defs.js
index fc18707..c1720c3 100644
--- a/src/defs.js
+++ b/src/defs.js
@@ -22,16 +22,6 @@ const LUA_RELEASE = LUA_VERSION + "." + LUA_VERSION_RELEASE;
const LUA_COPYRIGHT = LUA_RELEASE + " Copyright (C) 1994-2017 Lua.org, PUC-Rio";
const LUA_AUTHORS = "R. Ierusalimschy, L. H. de Figueiredo, W. Celes";
-const FENGARI_VERSION_MAJOR = "0";
-const FENGARI_VERSION_MINOR = "0";
-const FENGARI_VERSION_NUM = 1;
-const FENGARI_VERSION_RELEASE = "1";
-
-const FENGARI_VERSION = "Fengari " + FENGARI_VERSION_MAJOR + "." + FENGARI_VERSION_MINOR;
-const FENGARI_RELEASE = FENGARI_VERSION + "." + FENGARI_VERSION_RELEASE;
-const FENGARI_AUTHORS = "B. Giannangeli, Daurnimator";
-const FENGARI_COPYRIGHT = FENGARI_RELEASE + " Copyright (C) 2017-2018 " + FENGARI_AUTHORS + "\nBased on: " + LUA_COPYRIGHT;
-
const LUA_VERSUFFIX = "_" + LUA_VERSION_MAJOR + "_" + LUA_VERSION_MINOR;
const LUA_INIT_VAR = "LUA_INIT";
@@ -437,14 +427,6 @@ if (typeof process === "undefined") {
}
module.exports.CT = CT;
-module.exports.FENGARI_AUTHORS = FENGARI_AUTHORS;
-module.exports.FENGARI_COPYRIGHT = FENGARI_COPYRIGHT;
-module.exports.FENGARI_RELEASE = FENGARI_RELEASE;
-module.exports.FENGARI_VERSION = FENGARI_VERSION;
-module.exports.FENGARI_VERSION_MAJOR = FENGARI_VERSION_MAJOR;
-module.exports.FENGARI_VERSION_MINOR = FENGARI_VERSION_MINOR;
-module.exports.FENGARI_VERSION_NUM = FENGARI_VERSION_NUM;
-module.exports.FENGARI_VERSION_RELEASE = FENGARI_VERSION_RELEASE;
module.exports.LUA_AUTHORS = LUA_AUTHORS;
module.exports.LUA_COPYRIGHT = LUA_COPYRIGHT;
module.exports.LUA_HOOKCALL = LUA_HOOKCALL;
diff --git a/src/fengari.js b/src/fengari.js
index 3d35334..b37f7d6 100644
--- a/src/fengari.js
+++ b/src/fengari.js
@@ -1,5 +1,23 @@
"use strict";
+const core = require("./fengaricore.js");
+
+module.exports.FENGARI_AUTHORS = core.FENGARI_AUTHORS;
+module.exports.FENGARI_COPYRIGHT = core.FENGARI_COPYRIGHT;
+module.exports.FENGARI_RELEASE = core.FENGARI_RELEASE;
+module.exports.FENGARI_VERSION = core.FENGARI_VERSION;
+module.exports.FENGARI_VERSION_MAJOR = core.FENGARI_VERSION_MAJOR;
+module.exports.FENGARI_VERSION_MINOR = core.FENGARI_VERSION_MINOR;
+module.exports.FENGARI_VERSION_NUM = core.FENGARI_VERSION_NUM;
+module.exports.FENGARI_VERSION_RELEASE = core.FENGARI_VERSION_RELEASE;
+
+module.exports.luastring_eq = core.luastring_eq;
+module.exports.luastring_indexOf = core.luastring_indexOf;
+module.exports.luastring_of = core.luastring_of;
+module.exports.to_jsstring = core.to_jsstring;
+module.exports.to_luastring = core.to_luastring;
+module.exports.to_uristring = core.to_uristring;
+
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
const lualib = require('./lualib.js');
diff --git a/src/fengaricore.js b/src/fengaricore.js
new file mode 100644
index 0000000..1fd0354
--- /dev/null
+++ b/src/fengaricore.js
@@ -0,0 +1,36 @@
+/* Fengari specific functions
+ *
+ * This file includes fengari-specific data or and functionality for users to
+ * manipulate fengari's string type.
+ * The fields are exposed to the user on the 'fengari' entry point; however to
+ * avoid a dependency on defs.js from lauxlib.js they are defined in this file.
+ */
+
+const defs = require("./defs.js");
+
+const FENGARI_VERSION_MAJOR = "0";
+const FENGARI_VERSION_MINOR = "0";
+const FENGARI_VERSION_NUM = 1;
+const FENGARI_VERSION_RELEASE = "1";
+const FENGARI_VERSION = "Fengari " + FENGARI_VERSION_MAJOR + "." + FENGARI_VERSION_MINOR;
+const FENGARI_RELEASE = FENGARI_VERSION + "." + FENGARI_VERSION_RELEASE;
+const FENGARI_AUTHORS = "B. Giannangeli, Daurnimator";
+const FENGARI_COPYRIGHT = FENGARI_RELEASE + " Copyright (C) 2017-2018 " + FENGARI_AUTHORS + "\nBased on: " + defs.LUA_COPYRIGHT;
+
+module.exports.FENGARI_AUTHORS = FENGARI_AUTHORS;
+module.exports.FENGARI_COPYRIGHT = FENGARI_COPYRIGHT;
+module.exports.FENGARI_RELEASE = FENGARI_RELEASE;
+module.exports.FENGARI_VERSION = FENGARI_VERSION;
+module.exports.FENGARI_VERSION_MAJOR = FENGARI_VERSION_MAJOR;
+module.exports.FENGARI_VERSION_MINOR = FENGARI_VERSION_MINOR;
+module.exports.FENGARI_VERSION_NUM = FENGARI_VERSION_NUM;
+module.exports.FENGARI_VERSION_RELEASE = FENGARI_VERSION_RELEASE;
+module.exports.is_luastring = defs.is_luastring;
+module.exports.luastring_eq = defs.luastring_eq;
+module.exports.luastring_from = defs.luastring_from;
+module.exports.luastring_indexOf = defs.luastring_indexOf;
+module.exports.luastring_of = defs.luastring_of;
+module.exports.to_jsstring = defs.to_jsstring;
+module.exports.to_luastring = defs.to_luastring;
+module.exports.to_uristring = defs.to_uristring;
+module.exports.from_userstring = defs.from_userstring;
diff --git a/src/lauxlib.js b/src/lauxlib.js
index 52ea3a2..5dc42c2 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -1,22 +1,23 @@
"use strict";
-const lua = require('./lua.js');
+const lua = require('./lua.js');
+const {luastring_eq, to_luastring, to_uristring} = require("./fengaricore.js");
/* extra error code for 'luaL_loadfilex' */
const LUA_ERRFILE = lua.LUA_ERRERR+1;
/* key, in the registry, for table of loaded modules */
-const LUA_LOADED_TABLE = lua.to_luastring("_LOADED");
+const LUA_LOADED_TABLE = to_luastring("_LOADED");
/* key, in the registry, for table of preloaded loaders */
-const LUA_PRELOAD_TABLE = lua.to_luastring("_PRELOAD");
+const LUA_PRELOAD_TABLE = to_luastring("_PRELOAD");
-const LUA_FILEHANDLE = lua.to_luastring("FILE*");
+const LUA_FILEHANDLE = to_luastring("FILE*");
const LUAL_NUMSIZES = 4*16 + 8;
-const __name = lua.to_luastring("__name");
-const __tostring = lua.to_luastring("__tostring");
+const __name = to_luastring("__name");
+const __tostring = to_luastring("__tostring");
const empty = new Uint8Array(0);
@@ -65,7 +66,7 @@ const findfield = function(L, objidx, level) {
*/
const pushglobalfuncname = function(L, ar) {
let top = lua.lua_gettop(L);
- lua.lua_getinfo(L, lua.to_luastring("f"), ar); /* push function */
+ lua.lua_getinfo(L, to_luastring("f"), ar); /* push function */
lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
if (findfield(L, top + 1, 2)) {
let name = lua.lua_tostring(L, -1);
@@ -84,15 +85,15 @@ const pushglobalfuncname = function(L, ar) {
const pushfuncname = function(L, ar) {
if (pushglobalfuncname(L, ar)) { /* try first a global name */
- lua.lua_pushfstring(L, lua.to_luastring("function '%s'"), lua.lua_tostring(L, -1));
+ lua.lua_pushfstring(L, to_luastring("function '%s'"), lua.lua_tostring(L, -1));
lua.lua_remove(L, -2); /* remove name */
}
else if (ar.namewhat.length !== 0) /* is there a name from code? */
- lua.lua_pushfstring(L, lua.to_luastring("%s '%s'"), ar.namewhat, ar.name); /* use it */
+ lua.lua_pushfstring(L, to_luastring("%s '%s'"), ar.namewhat, ar.name); /* use it */
else if (ar.what && ar.what[0] === 'm'.charCodeAt(0)) /* main? */
lua.lua_pushliteral(L, "main chunk");
else if (ar.what && ar.what[0] === 'L'.charCodeAt(0)) /* for Lua functions, use <file:line> */
- lua.lua_pushfstring(L, lua.to_luastring("function <%s:%d>"), ar.short_src, ar.linedefined);
+ lua.lua_pushfstring(L, to_luastring("function <%s:%d>"), ar.short_src, ar.linedefined);
else /* nothing left... */
lua.lua_pushliteral(L, "?");
};
@@ -118,7 +119,7 @@ const luaL_traceback = function(L, L1, msg, level) {
let last = lastlevel(L1);
let n1 = last - level > LEVELS1 + LEVELS2 ? LEVELS1 : -1;
if (msg)
- lua.lua_pushfstring(L, lua.to_luastring("%s\n"), msg);
+ lua.lua_pushfstring(L, to_luastring("%s\n"), msg);
luaL_checkstack(L, 10, null);
lua.lua_pushliteral(L, "stack traceback:");
while (lua.lua_getstack(L1, level++, ar)) {
@@ -126,8 +127,8 @@ const luaL_traceback = function(L, L1, msg, level) {
lua.lua_pushliteral(L, "\n\t..."); /* add a '...' */
level = last - LEVELS2 + 1; /* and skip to last ones */
} else {
- lua.lua_getinfo(L1, lua.to_luastring("Slnt", true), ar);
- lua.lua_pushfstring(L, lua.to_luastring("\n\t%s:"), ar.short_src);
+ lua.lua_getinfo(L1, to_luastring("Slnt", true), ar);
+ lua.lua_pushfstring(L, to_luastring("\n\t%s:"), ar.short_src);
if (ar.currentline > 0)
lua.lua_pushliteral(L, `${ar.currentline}:`);
lua.lua_pushliteral(L, " in ");
@@ -153,20 +154,20 @@ const luaL_argerror = function(L, arg, extramsg) {
let ar = new lua.lua_Debug();
if (!lua.lua_getstack(L, 0, ar)) /* no stack frame? */
- return luaL_error(L, lua.to_luastring("bad argument #%d (%s)"), arg, extramsg);
+ return luaL_error(L, to_luastring("bad argument #%d (%s)"), arg, extramsg);
- lua.lua_getinfo(L, lua.to_luastring("n"), ar);
+ lua.lua_getinfo(L, to_luastring("n"), ar);
- if (lua.luastring_eq(ar.namewhat, lua.to_luastring("method"))) {
+ if (luastring_eq(ar.namewhat, to_luastring("method"))) {
arg--; /* do not count 'self' */
if (arg === 0) /* error is in the self argument itself? */
- return luaL_error(L, lua.to_luastring("calling '%s' on bad self (%s)"), ar.name, extramsg);
+ return luaL_error(L, to_luastring("calling '%s' on bad self (%s)"), ar.name, extramsg);
}
if (ar.name === null)
- ar.name = pushglobalfuncname(L, ar) ? lua.lua_tostring(L, -1) : lua.to_luastring("?");
+ ar.name = pushglobalfuncname(L, ar) ? lua.lua_tostring(L, -1) : to_luastring("?");
- return luaL_error(L, lua.to_luastring("bad argument #%d to '%s' (%s)"), arg, ar.name, extramsg);
+ return luaL_error(L, to_luastring("bad argument #%d to '%s' (%s)"), arg, ar.name, extramsg);
};
const typeerror = function(L, arg, tname) {
@@ -174,24 +175,24 @@ const typeerror = function(L, arg, tname) {
if (luaL_getmetafield(L, arg, __name) === lua.LUA_TSTRING)
typearg = lua.lua_tostring(L, -1);
else if (lua.lua_type(L, arg) === lua.LUA_TLIGHTUSERDATA)
- typearg = lua.to_luastring("light userdata", true);
+ typearg = to_luastring("light userdata", true);
else
typearg = luaL_typename(L, arg);
- let msg = lua.lua_pushfstring(L, lua.to_luastring("%s expected, got %s"), tname, typearg);
+ let msg = lua.lua_pushfstring(L, to_luastring("%s expected, got %s"), tname, typearg);
return luaL_argerror(L, arg, msg);
};
const luaL_where = function(L, level) {
let ar = new lua.lua_Debug();
if (lua.lua_getstack(L, level, ar)) {
- lua.lua_getinfo(L, lua.to_luastring("Sl", true), ar);
+ lua.lua_getinfo(L, to_luastring("Sl", true), ar);
if (ar.currentline > 0) {
- lua.lua_pushfstring(L, lua.to_luastring("%s:%d: "), ar.short_src, ar.currentline);
+ lua.lua_pushfstring(L, to_luastring("%s:%d: "), ar.short_src, ar.currentline);
return;
}
}
- lua.lua_pushstring(L, lua.to_luastring(""));
+ lua.lua_pushstring(L, to_luastring(""));
};
const luaL_error = function(L, fmt, ...argp) {
@@ -209,9 +210,9 @@ const luaL_fileresult = function(L, stat, fname, e) {
} else {
lua.lua_pushnil(L);
if (fname)
- lua.lua_pushfstring(L, lua.to_luastring("%s: %s"), fname, lua.to_luastring(e.message));
+ lua.lua_pushfstring(L, to_luastring("%s: %s"), fname, to_luastring(e.message));
else
- lua.lua_pushstring(L, lua.to_luastring(e.message));
+ lua.lua_pushstring(L, to_luastring(e.message));
lua.lua_pushinteger(L, -e.errno);
return 3;
}
@@ -288,7 +289,7 @@ const luaL_checkoption = function(L, arg, def, lst) {
for (let i = 0; lst[i]; i++)
if (lst[i].join('|') === name.join('|'))
return i;
- return luaL_argerror(L, arg, lua.lua_pushfstring(L, lua.to_luastring("invalid option '%s'"), name));
+ return luaL_argerror(L, arg, lua.lua_pushfstring(L, to_luastring("invalid option '%s'"), name));
};
const tag_error = function(L, arg, tag) {
@@ -312,7 +313,7 @@ const luaL_argcheck = function(L, cond, arg, extramsg) {
const luaL_checkany = function(L, arg) {
if (lua.lua_type(L, arg) === lua.LUA_TNONE)
- luaL_argerror(L, arg, lua.to_luastring("value expected", true));
+ luaL_argerror(L, arg, to_luastring("value expected", true));
};
const luaL_checktype = function(L, arg, t) {
@@ -340,7 +341,7 @@ const luaL_optstring = luaL_optlstring;
const interror = function(L, arg) {
if (lua.lua_isnumber(L, arg))
- luaL_argerror(L, arg, lua.to_luastring("number has no integer representation", true));
+ luaL_argerror(L, arg, to_luastring("number has no integer representation", true));
else
tag_error(L, arg, lua.LUA_TNUMBER);
};
@@ -489,17 +490,17 @@ const luaL_len = function(L, idx) {
lua.lua_len(L, idx);
let l = lua.lua_tointegerx(L, -1);
if (l === false)
- luaL_error(L, lua.to_luastring("object length is not an integer", true));
+ luaL_error(L, to_luastring("object length is not an integer", true));
lua.lua_pop(L, 1); /* remove object */
return l;
};
-const p_I = lua.to_luastring("%I");
-const p_f = lua.to_luastring("%f");
+const p_I = to_luastring("%I");
+const p_f = to_luastring("%f");
const luaL_tolstring = function(L, idx) {
if (luaL_callmeta(L, idx, __tostring)) {
if (!lua.lua_isstring(L, -1))
- luaL_error(L, lua.to_luastring("'__tostring' must return a string"));
+ luaL_error(L, to_luastring("'__tostring' must return a string"));
} else {
let t = lua.lua_type(L, idx);
switch(t) {
@@ -522,7 +523,7 @@ const luaL_tolstring = function(L, idx) {
default: {
let tt = luaL_getmetafield(L, idx, __name);
let kind = tt === lua.LUA_TSTRING ? lua.lua_tostring(L, -1) : luaL_typename(L, idx);
- lua.lua_pushfstring(L, lua.to_luastring("%s: %p"), kind, lua.lua_topointer(L, idx));
+ lua.lua_pushfstring(L, to_luastring("%s: %p"), kind, lua.lua_topointer(L, idx));
if (tt !== lua.LUA_TNIL)
lua.lua_remove(L, -2);
break;
@@ -608,12 +609,12 @@ const luaL_getsubtable = function(L, idx, fname) {
** Returns with only the table at the stack.
*/
const luaL_setfuncs = function(L, l, nup) {
- luaL_checkstack(L, nup, lua.to_luastring("too many upvalues", true));
+ luaL_checkstack(L, nup, to_luastring("too many upvalues", true));
for (let lib in l) { /* fill the table with given functions */
for (let i = 0; i < nup; i++) /* copy upvalues to the top */
lua.lua_pushvalue(L, -nup);
lua.lua_pushcclosure(L, l[lib], nup); /* closure with those upvalues */
- lua.lua_setfield(L, -(nup + 2), lua.to_luastring(lib));
+ lua.lua_setfield(L, -(nup + 2), to_luastring(lib));
}
lua.lua_pop(L, nup); /* remove upvalues */
};
@@ -628,9 +629,9 @@ const luaL_setfuncs = function(L, l, nup) {
const luaL_checkstack = function(L, space, msg) {
if (!lua.lua_checkstack(L, space)) {
if (msg)
- luaL_error(L, lua.to_luastring("stack overflow (%s)"), msg);
+ luaL_error(L, to_luastring("stack overflow (%s)"), msg);
else
- luaL_error(L, lua.to_luastring('stack overflow', true));
+ luaL_error(L, to_luastring('stack overflow', true));
}
};
@@ -682,7 +683,7 @@ const luaL_unref = function(L, t, ref) {
const errfile = function(L, what, fnameindex, error) {
let serr = error.message;
let filename = lua.lua_tostring(L, fnameindex).subarray(1);
- lua.lua_pushfstring(L, lua.to_luastring("cannot %s %s: %s"), lua.to_luastring(what), filename, lua.to_luastring(serr));
+ lua.lua_pushfstring(L, to_luastring("cannot %s %s: %s"), to_luastring(what), filename, to_luastring(serr));
lua.lua_remove(L, fnameindex);
return LUA_ERRFILE;
};
@@ -768,8 +769,8 @@ if (typeof process === "undefined") {
if (filename === null) {
throw new Error("Can't read stdin in the browser");
} else {
- lua.lua_pushfstring(L, lua.to_luastring("@%s"), filename);
- let path = lua.to_uristring(filename);
+ lua.lua_pushfstring(L, to_luastring("@%s"), filename);
+ let path = to_uristring(filename);
let xhr = new XMLHttpRequest();
xhr.open("GET", path, false);
/* XXX: Synchronous xhr in main thread always returns a js string
@@ -781,7 +782,7 @@ if (typeof process === "undefined") {
xhr.send();
if (xhr.status >= 200 && xhr.status <= 299) {
if (typeof xhr.response === "string") {
- lf.f = lua.to_luastring(xhr.response);
+ lf.f = to_luastring(xhr.response);
} else {
lf.f = new Uint8Array(xhr.response);
}
@@ -851,7 +852,7 @@ if (typeof process === "undefined") {
lua.lua_pushliteral(L, "=stdin");
lf.f = process.stdin.fd;
} else {
- lua.lua_pushfstring(L, lua.to_luastring("@%s"), filename);
+ lua.lua_pushfstring(L, to_luastring("@%s"), filename);
try {
lf.f = fs.openSync(filename, "r");
} catch (e) {
@@ -910,11 +911,11 @@ const luaL_checkversion = function(L) {
let sz = LUAL_NUMSIZES;
let v = lua.lua_version(L);
if (sz != LUAL_NUMSIZES) /* check numeric types */
- luaL_error(L, lua.to_luastring("core and library have incompatible numeric types"));
+ luaL_error(L, to_luastring("core and library have incompatible numeric types"));
if (v != lua.lua_version(null))
- luaL_error(L, lua.to_luastring("multiple Lua VMs detected"));
+ luaL_error(L, to_luastring("multiple Lua VMs detected"));
else if (v !== ver)
- luaL_error(L, lua.to_luastring("version mismatch: app. needs %f, Lua core provides %f"), ver, v);
+ luaL_error(L, to_luastring("version mismatch: app. needs %f, Lua core provides %f"), ver, v);
};
module.exports.LUA_ERRFILE = LUA_ERRFILE;
diff --git a/src/lbaselib.js b/src/lbaselib.js
index ca03b7f..78a32ed 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -2,6 +2,7 @@
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
+const {to_jsstring, to_luastring} = require("./fengaricore.js");
let lua_writestring;
let lua_writeline;
@@ -23,7 +24,7 @@ if (typeof process === "undefined") {
lua_writestring = function(s) {
try {
/* If the string is valid utf8, then we can use to_jsstring */
- s = lua.to_jsstring(s);
+ s = to_jsstring(s);
} catch(e) {
/* otherwise push copy of raw array */
let copy = new Uint8Array(s.length);
@@ -47,15 +48,15 @@ if (typeof process === "undefined") {
}
const luaB_print = function(L) {
let n = lua.lua_gettop(L); /* number of arguments */
- lua.lua_getglobal(L, lua.to_luastring("tostring", true));
+ lua.lua_getglobal(L, to_luastring("tostring", true));
for (let i = 1; i <= n; i++) {
lua.lua_pushvalue(L, -1); /* function to be called */
lua.lua_pushvalue(L, i); /* value to print */
lua.lua_call(L, 1, 1);
let s = lua.lua_tolstring(L, -1);
if (s === null)
- return lauxlib.luaL_error(L, lua.to_luastring("'tostring' must return a string to 'print'", true));
- if (i > 1) lua_writestring(lua.to_luastring("\t"));
+ return lauxlib.luaL_error(L, to_luastring("'tostring' must return a string to 'print'", true));
+ if (i > 1) lua_writestring(to_luastring("\t"));
lua_writestring(s);
lua.lua_pop(L, 1);
}
@@ -76,16 +77,16 @@ const luaB_getmetatable = function(L) {
lua.lua_pushnil(L);
return 1; /* no metatable */
}
- lauxlib.luaL_getmetafield(L, 1, lua.to_luastring("__metatable", true));
+ lauxlib.luaL_getmetafield(L, 1, to_luastring("__metatable", true));
return 1; /* returns either __metatable field (if present) or metatable */
};
const luaB_setmetatable = function(L) {
let t = lua.lua_type(L, 2);
lauxlib.luaL_checktype(L, 1, lua.LUA_TTABLE);
- lauxlib.luaL_argcheck(L, t === lua.LUA_TNIL || t === lua.LUA_TTABLE, 2, lua.to_luastring("nil or table expected", true));
- if (lauxlib.luaL_getmetafield(L, 1, lua.to_luastring("__metatable", true)) !== lua.LUA_TNIL)
- return lauxlib.luaL_error(L, lua.to_luastring("cannot change a protected metatable", true));
+ lauxlib.luaL_argcheck(L, t === lua.LUA_TNIL || t === lua.LUA_TTABLE, 2, to_luastring("nil or table expected", true));
+ if (lauxlib.luaL_getmetafield(L, 1, to_luastring("__metatable", true)) !== lua.LUA_TNIL)
+ return lauxlib.luaL_error(L, to_luastring("cannot change a protected metatable", true));
lua.lua_settop(L, 2);
lua.lua_setmetatable(L, 1);
return 1;
@@ -100,7 +101,7 @@ const luaB_rawequal = function(L) {
const luaB_rawlen = function(L) {
let t = lua.lua_type(L, 1);
- lauxlib.luaL_argcheck(L, t === lua.LUA_TTABLE || t === lua.LUA_TSTRING, 1, lua.to_luastring("table or string expected", true));
+ lauxlib.luaL_argcheck(L, t === lua.LUA_TTABLE || t === lua.LUA_TSTRING, 1, to_luastring("table or string expected", true));
lua.lua_pushinteger(L, lua.lua_rawlen(L, 1));
return 1;
};
@@ -126,16 +127,16 @@ const opts = [
"stop", "restart", "collect",
"count", "step", "setpause", "setstepmul",
"isrunning"
-].map((e) => lua.to_luastring(e));
+].map((e) => to_luastring(e));
const luaB_collectgarbage = function(L) {
- lauxlib.luaL_checkoption(L, 1, lua.to_luastring("collect"), opts);
+ lauxlib.luaL_checkoption(L, 1, to_luastring("collect"), opts);
lauxlib.luaL_optinteger(L, 2, 0);
- lauxlib.luaL_error(L, lua.to_luastring("lua_gc not implemented"));
+ lauxlib.luaL_error(L, to_luastring("lua_gc not implemented"));
};
const luaB_type = function(L) {
let t = lua.lua_type(L, 1);
- lauxlib.luaL_argcheck(L, t !== lua.LUA_TNONE, 1, lua.to_luastring("value expected", true));
+ lauxlib.luaL_argcheck(L, t !== lua.LUA_TNONE, 1, to_luastring("value expected", true));
lua.lua_pushstring(L, lua.lua_typename(L, t));
return 1;
};
@@ -166,7 +167,7 @@ const luaB_next = function(L) {
};
const luaB_pairs = function(L) {
- return pairsmeta(L, lua.to_luastring("__pairs", true), 0, luaB_next);
+ return pairsmeta(L, to_luastring("__pairs", true), 0, luaB_next);
};
/*
@@ -195,7 +196,7 @@ const luaB_ipairs = function(L) {
const b_str2int = function(s, base) {
try {
- s = lua.to_jsstring(s);
+ s = to_jsstring(s);
} catch (e) {
return null;
}
@@ -229,7 +230,7 @@ const luaB_tonumber = function(L) {
let base = lauxlib.luaL_checkinteger(L, 2);
lauxlib.luaL_checktype(L, 1, lua.LUA_TSTRING); /* no numbers as strings */
let s = lua.lua_tostring(L, 1);
- lauxlib.luaL_argcheck(L, 2 <= base && base <= 36, 2, lua.to_luastring("base out of range", true));
+ lauxlib.luaL_argcheck(L, 2 <= base && base <= 36, 2, to_luastring("base out of range", true));
let n = b_str2int(s, base);
if (n !== null) {
lua.lua_pushinteger(L, n);
@@ -273,7 +274,7 @@ const luaB_select = function(L) {
let i = lauxlib.luaL_checkinteger(L, 1);
if (i < 0) i = n + i;
else if (i > n) i = n;
- lauxlib.luaL_argcheck(L, 1 <= i, 1, lua.to_luastring("index out of range", true));
+ lauxlib.luaL_argcheck(L, 1 <= i, 1, to_luastring("index out of range", true));
return n - i;
}
};
@@ -347,28 +348,28 @@ const RESERVEDSLOT = 5;
** reserved slot inside the stack.
*/
const generic_reader = function(L, ud) {
- lauxlib.luaL_checkstack(L, 2, lua.to_luastring("too many nested functions", true));
+ lauxlib.luaL_checkstack(L, 2, to_luastring("too many nested functions", true));
lua.lua_pushvalue(L, 1); /* get function */
lua.lua_call(L, 0, 1); /* call it */
if (lua.lua_isnil(L, -1)) {
lua.lua_pop(L, 1); /* pop result */
return null;
} else if (!lua.lua_isstring(L, -1))
- lauxlib.luaL_error(L, lua.to_luastring("reader function must return a string", true));
+ lauxlib.luaL_error(L, to_luastring("reader function must return a string", true));
lua.lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
return lua.lua_tostring(L, RESERVEDSLOT);
};
const luaB_load = function(L) {
let s = lua.lua_tostring(L, 1);
- let mode = lauxlib.luaL_optstring(L, 3, lua.to_luastring("bt", true));
+ let mode = lauxlib.luaL_optstring(L, 3, to_luastring("bt", true));
let env = !lua.lua_isnone(L, 4) ? 4 : 0; /* 'env' index or 0 if no 'env' */
let status;
if (s !== null) { /* loading a string? */
let chunkname = lauxlib.luaL_optstring(L, 2, s);
status = lauxlib.luaL_loadbufferx(L, s, s.length, chunkname, mode);
} else { /* loading from a reader function */
- let chunkname = lauxlib.luaL_optstring(L, 2, lua.to_luastring("=(load)", true));
+ let chunkname = lauxlib.luaL_optstring(L, 2, to_luastring("=(load)", true));
lauxlib.luaL_checktype(L, 1, lua.LUA_TFUNCTION);
lua.lua_settop(L, RESERVEDSLOT); /* create reserved slot */
status = lua.lua_load(L, generic_reader, null, chunkname, mode);
@@ -428,10 +429,10 @@ const luaopen_base = function(L) {
lauxlib.luaL_setfuncs(L, base_funcs, 0);
/* set global _G */
lua.lua_pushvalue(L, -1);
- lua.lua_setfield(L, -2, lua.to_luastring("_G", true));
+ lua.lua_setfield(L, -2, to_luastring("_G", true));
/* set global _VERSION */
lua.lua_pushliteral(L, lua.LUA_VERSION);
- lua.lua_setfield(L, -2, lua.to_luastring("_VERSION", true));
+ lua.lua_setfield(L, -2, to_luastring("_VERSION", true));
return 1;
};
diff --git a/src/lcorolib.js b/src/lcorolib.js
index a72d22b..bcdae8b 100644
--- a/src/lcorolib.js
+++ b/src/lcorolib.js
@@ -2,10 +2,11 @@
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
+const {to_luastring} = require("./fengaricore.js");
const getco = function(L) {
let co = lua.lua_tothread(L, 1);
- lauxlib.luaL_argcheck(L, co, 1, lua.to_luastring("thread expected", true));
+ lauxlib.luaL_argcheck(L, co, 1, to_luastring("thread expected", true));
return co;
};
diff --git a/src/ldblib.js b/src/ldblib.js
index 7e08dc5..9698f7a 100644
--- a/src/ldblib.js
+++ b/src/ldblib.js
@@ -4,6 +4,7 @@ const assert = require('assert');
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
+const {luastring_indexOf, to_luastring} = require("./fengaricore.js");
/*
** If L1 != L, L1 can be in any state, and therefore there are no
@@ -12,7 +13,7 @@ const lauxlib = require('./lauxlib.js');
*/
const checkstack = function(L, L1, n) {
if (L !== L1 && !lua.lua_checkstack(L1, n))
- lauxlib.luaL_error(L, lua.to_luastring("stack overflow", true));
+ lauxlib.luaL_error(L, to_luastring("stack overflow", true));
};
const db_getregistry = function(L) {
@@ -30,7 +31,7 @@ const db_getmetatable = function(L) {
const db_setmetatable = function(L) {
const t = lua.lua_type(L, 2);
- lauxlib.luaL_argcheck(L, t == lua.LUA_TNIL || t == lua.LUA_TTABLE, 2, lua.to_luastring("nil or table expected", true));
+ lauxlib.luaL_argcheck(L, t == lua.LUA_TNIL || t == lua.LUA_TTABLE, 2, to_luastring("nil or table expected", true));
lua.lua_settop(L, 2);
lua.lua_setmetatable(L, 1);
return 1; /* return 1st argument */
@@ -120,10 +121,10 @@ const db_getinfo = function(L) {
let thread = getthread(L);
let arg = thread.arg;
let L1 = thread.thread;
- let options = lauxlib.luaL_optstring(L, arg + 2, lua.to_luastring("flnStu", true));
+ let options = lauxlib.luaL_optstring(L, arg + 2, to_luastring("flnStu", true));
checkstack(L, L1, 3);
if (lua.lua_isfunction(L, arg + 1)) { /* info about a function? */
- options = lua.lua_pushfstring(L, lua.to_luastring(">%s"), options); /* add '>' to 'options' */
+ options = lua.lua_pushfstring(L, to_luastring(">%s"), options); /* add '>' to 'options' */
lua.lua_pushvalue(L, arg + 1); /* move function to 'L1' stack */
lua.lua_xmove(L, L1, 1);
} else { /* stack level */
@@ -134,32 +135,32 @@ const db_getinfo = function(L) {
}
if (!lua.lua_getinfo(L1, options, ar))
- lauxlib.luaL_argerror(L, arg + 2, lua.to_luastring("invalid option", true));
+ lauxlib.luaL_argerror(L, arg + 2, to_luastring("invalid option", true));
lua.lua_newtable(L); /* table to collect results */
- if (lua.luastring_indexOf(options, 'S'.charCodeAt(0)) > -1) {
- settabss(L, lua.to_luastring("source", true), ar.source);
- settabss(L, lua.to_luastring("short_src", true), ar.short_src);
- settabsi(L, lua.to_luastring("linedefined", true), ar.linedefined);
- settabsi(L, lua.to_luastring("lastlinedefined", true), ar.lastlinedefined);
- settabss(L, lua.to_luastring("what", true), ar.what);
+ if (luastring_indexOf(options, 'S'.charCodeAt(0)) > -1) {
+ settabss(L, to_luastring("source", true), ar.source);
+ settabss(L, to_luastring("short_src", true), ar.short_src);
+ settabsi(L, to_luastring("linedefined", true), ar.linedefined);
+ settabsi(L, to_luastring("lastlinedefined", true), ar.lastlinedefined);
+ settabss(L, to_luastring("what", true), ar.what);
}
- if (lua.luastring_indexOf(options, 'l'.charCodeAt(0)) > -1)
- settabsi(L, lua.to_luastring("currentline", true), ar.currentline);
- if (lua.luastring_indexOf(options, 'u'.charCodeAt(0)) > -1) {
- settabsi(L, lua.to_luastring("nups", true), ar.nups);
- settabsi(L, lua.to_luastring("nparams", true), ar.nparams);
- settabsb(L, lua.to_luastring("isvararg", true), ar.isvararg);
+ if (luastring_indexOf(options, 'l'.charCodeAt(0)) > -1)
+ settabsi(L, to_luastring("currentline", true), ar.currentline);
+ if (luastring_indexOf(options, 'u'.charCodeAt(0)) > -1) {
+ settabsi(L, to_luastring("nups", true), ar.nups);
+ settabsi(L, to_luastring("nparams", true), ar.nparams);
+ settabsb(L, to_luastring("isvararg", true), ar.isvararg);
}
- if (lua.luastring_indexOf(options, 'n'.charCodeAt(0)) > -1) {
- settabss(L, lua.to_luastring("name", true), ar.name);
- settabss(L, lua.to_luastring("namewhat", true), ar.namewhat);
+ if (luastring_indexOf(options, 'n'.charCodeAt(0)) > -1) {
+ settabss(L, to_luastring("name", true), ar.name);
+ settabss(L, to_luastring("namewhat", true), ar.namewhat);
}
- if (lua.luastring_indexOf(options, 't'.charCodeAt(0)) > -1)
- settabsb(L, lua.to_luastring("istailcall", true), ar.istailcall);
- if (lua.luastring_indexOf(options, 'L'.charCodeAt(0)) > -1)
- treatstackoption(L, L1, lua.to_luastring("activelines", true));
- if (lua.luastring_indexOf(options, 'f'.charCodeAt(0)) > -1)
- treatstackoption(L, L1, lua.to_luastring("func", true));
+ if (luastring_indexOf(options, 't'.charCodeAt(0)) > -1)
+ settabsb(L, to_luastring("istailcall", true), ar.istailcall);
+ if (luastring_indexOf(options, 'L'.charCodeAt(0)) > -1)
+ treatstackoption(L, L1, to_luastring("activelines", true));
+ if (luastring_indexOf(options, 'f'.charCodeAt(0)) > -1)
+ treatstackoption(L, L1, to_luastring("func", true));
return 1; /* return table */
};
@@ -176,7 +177,7 @@ const db_getlocal = function(L) {
} else { /* stack-level argument */
let level = lauxlib.luaL_checkinteger(L, arg + 1);
if (!lua.lua_getstack(L1, level, ar)) /* out of range? */
- return lauxlib.luaL_argerror(L, arg+1, lua.to_luastring("level out of range", true));
+ return lauxlib.luaL_argerror(L, arg+1, to_luastring("level out of range", true));
checkstack(L, L1, 1);
let name = lua.lua_getlocal(L1, ar, nvar);
if (name) {
@@ -200,7 +201,7 @@ const db_setlocal = function(L) {
let level = lauxlib.luaL_checkinteger(L, arg + 1);
let nvar = lauxlib.luaL_checkinteger(L, arg + 2);
if (!lua.lua_getstack(L1, level, ar)) /* out of range? */
- return lauxlib.luaL_argerror(L, arg + 1, lua.to_luastring("level out of range", true));
+ return lauxlib.luaL_argerror(L, arg + 1, to_luastring("level out of range", true));
lauxlib.luaL_checkany(L, arg + 3);
lua.lua_settop(L, arg + 3);
checkstack(L, L1, 1);
@@ -242,7 +243,7 @@ const db_setupvalue = function(L) {
const checkupval = function(L, argf, argnup) {
let nup = lauxlib.luaL_checkinteger(L, argnup); /* upvalue index */
lauxlib.luaL_checktype(L, argf, lua.LUA_TFUNCTION); /* closure */
- lauxlib.luaL_argcheck(L, (lua.lua_getupvalue(L, argf, nup) !== null), argnup, lua.to_luastring("invalid upvalue index", true));
+ lauxlib.luaL_argcheck(L, (lua.lua_getupvalue(L, argf, nup) !== null), argnup, to_luastring("invalid upvalue index", true));
return nup;
};
@@ -255,8 +256,8 @@ const db_upvalueid = function(L) {
const db_upvaluejoin = function(L) {
let n1 = checkupval(L, 1, 2);
let n2 = checkupval(L, 3, 4);
- lauxlib.luaL_argcheck(L, !lua.lua_iscfunction(L, 1), 1, lua.to_luastring("Lua function expected", true));
- lauxlib.luaL_argcheck(L, !lua.lua_iscfunction(L, 3), 3, lua.to_luastring("Lua function expected", true));
+ lauxlib.luaL_argcheck(L, !lua.lua_iscfunction(L, 1), 1, to_luastring("Lua function expected", true));
+ lauxlib.luaL_argcheck(L, !lua.lua_iscfunction(L, 3), 3, to_luastring("Lua function expected", true));
lua.lua_upvaluejoin(L, 1, n1, 3, n2);
return 0;
};
@@ -265,9 +266,9 @@ const db_upvaluejoin = function(L) {
** The hook table at registry[HOOKKEY] maps threads to their current
** hook function. (We only need the unique address of 'HOOKKEY'.)
*/
-const HOOKKEY = lua.to_luastring("__hooks__", true);
+const HOOKKEY = to_luastring("__hooks__", true);
-const hooknames = ["call", "return", "line", "count", "tail call"].map(e => lua.to_luastring(e));
+const hooknames = ["call", "return", "line", "count", "tail call"].map(e => to_luastring(e));
/*
** Call hook function registered at hook table for the current
@@ -281,7 +282,7 @@ const hookf = function(L, ar) {
if (ar.currentline >= 0)
lua.lua_pushinteger(L, ar.currentline); /* push current line */
else lua.lua_pushnil(L);
- assert(lua.lua_getinfo(L, lua.to_luastring("lS"), ar));
+ assert(lua.lua_getinfo(L, to_luastring("lS"), ar));
lua.lua_call(L, 2, 0); /* call hook function */
}
};
@@ -291,9 +292,9 @@ const hookf = function(L, ar) {
*/
const makemask = function(smask, count) {
let mask = 0;
- if (lua.luastring_indexOf(smask, "c".charCodeAt(0)) > -1) mask |= lua.LUA_MASKCALL;
- if (lua.luastring_indexOf(smask, "r".charCodeAt(0)) > -1) mask |= lua.LUA_MASKRET;
- if (lua.luastring_indexOf(smask, "l".charCodeAt(0)) > -1) mask |= lua.LUA_MASKLINE;
+ if (luastring_indexOf(smask, "c".charCodeAt(0)) > -1) mask |= lua.LUA_MASKCALL;
+ if (luastring_indexOf(smask, "r".charCodeAt(0)) > -1) mask |= lua.LUA_MASKRET;
+ if (luastring_indexOf(smask, "l".charCodeAt(0)) > -1) mask |= lua.LUA_MASKLINE;
if (count > 0) mask |= lua.LUA_MASKCOUNT;
return mask;
};
@@ -328,8 +329,8 @@ const db_sethook = function(L) {
lua.lua_createtable(L, 0, 2); /* create a hook table */
lua.lua_pushvalue(L, -1);
lua.lua_rawsetp(L, lua.LUA_REGISTRYINDEX, HOOKKEY); /* set it in position */
- lua.lua_pushstring(L, lua.to_luastring("k"));
- lua.lua_setfield(L, -2, lua.to_luastring("__mode", true)); /** hooktable.__mode = "k" */
+ lua.lua_pushstring(L, to_luastring("k"));
+ lua.lua_setfield(L, -2, to_luastring("__mode", true)); /** hooktable.__mode = "k" */
lua.lua_pushvalue(L, -1);
lua.lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
}
@@ -424,8 +425,8 @@ if (getinput) {
if (input.length === 0)
continue;
- let buffer = lua.to_luastring(input);
- if (lauxlib.luaL_loadbuffer(L, buffer, buffer.length, lua.to_luastring("=(debug command)", true))
+ let buffer = to_luastring(input);
+ if (lauxlib.luaL_loadbuffer(L, buffer, buffer.length, to_luastring("=(debug command)", true))
|| lua.lua_pcall(L, 0, 0, 0)) {
lauxlib.lua_writestringerror(lua.lua_tojsstring(L, -1), "\n");
}
diff --git a/src/linit.js b/src/linit.js
index 97cbfc9..5656bae 100644
--- a/src/linit.js
+++ b/src/linit.js
@@ -2,6 +2,8 @@
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
+const {to_luastring} = require("./fengaricore.js");
+
const lbaselib = require('./lbaselib.js');
const lcorolib = require('./lcorolib.js');
const lmathlib = require('./lmathlib.js');
@@ -30,7 +32,7 @@ const luaL_openlibs = function(L) {
/* "require" functions from 'loadedlibs' and set results to global table */
for (let lib in loadedlibs) {
- lauxlib.luaL_requiref(L, lua.to_luastring(lib), loadedlibs[lib], 1);
+ lauxlib.luaL_requiref(L, to_luastring(lib), loadedlibs[lib], 1);
lua.lua_pop(L, 1); /* remove lib */
}
};
diff --git a/src/liolib.js b/src/liolib.js
index 66ef3db..462e7ed 100644
--- a/src/liolib.js
+++ b/src/liolib.js
@@ -5,11 +5,12 @@ const fs = require('fs');
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
+const {to_luastring} = require("./fengaricore.js");
const IO_PREFIX = "_IO_";
const IOPREF_LEN = IO_PREFIX.length;
-const IO_INPUT = lua.to_luastring(IO_PREFIX + "input");
-const IO_OUTPUT = lua.to_luastring(IO_PREFIX + "output");
+const IO_INPUT = to_luastring(IO_PREFIX + "input");
+const IO_OUTPUT = to_luastring(IO_PREFIX + "output");
const tolstream = function(L) {
return lauxlib.luaL_checkudata(L, 1, lauxlib.LUA_FILEHANDLE);
@@ -36,14 +37,14 @@ const f_tostring = function(L) {
if (isclosed(p))
lua.lua_pushliteral(L, "file (closed)");
else
- lua.lua_pushstring(L, lua.to_luastring(`file (${p.f.toString()})`));
+ lua.lua_pushstring(L, to_luastring(`file (${p.f.toString()})`));
return 1;
};
const tofile = function(L) {
let p = tolstream(L);
if (isclosed(p))
- lauxlib.luaL_error(L, lua.to_luastring("attempt to use a closed file"));
+ lauxlib.luaL_error(L, to_luastring("attempt to use a closed file"));
assert(p.f);
return p.f;
};
@@ -74,7 +75,7 @@ const getiofile = function(L, findex) {
lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, findex);
let p = lua.lua_touserdata(L, -1);
if (isclosed(p))
- lauxlib.luaL_error(L, lua.to_luastring("standard %s file is closed"), findex.subarray(IOPREF_LEN));
+ lauxlib.luaL_error(L, to_luastring("standard %s file is closed"), findex.subarray(IOPREF_LEN));
return p.f;
};
@@ -82,7 +83,7 @@ const g_iofile = function(L, f, mode) {
if (!lua.lua_isnoneornil(L, 1)) {
let filename = lua.lua_tostring(L, 1);
if (filename)
- lauxlib.luaL_error(L, lua.to_luastring("opening files not yet implemented"));
+ lauxlib.luaL_error(L, to_luastring("opening files not yet implemented"));
else {
tofile(L); /* check that it's a valid file handle */
lua.lua_pushvalue(L, 1);
@@ -160,7 +161,7 @@ const flib = {
const createmeta = function(L) {
lauxlib.luaL_newmetatable(L, lauxlib.LUA_FILEHANDLE); /* create metatable for file handles */
lua.lua_pushvalue(L, -1); /* push metatable */
- lua.lua_setfield(L, -2, lua.to_luastring("__index", true)); /* metatable.__index = metatable */
+ lua.lua_setfield(L, -2, to_luastring("__index", true)); /* metatable.__index = metatable */
lauxlib.luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */
lua.lua_pop(L, 1); /* pop new metatable */
};
@@ -188,9 +189,9 @@ const luaopen_io = function(L) {
lauxlib.luaL_newlib(L, iolib);
createmeta(L);
/* create (and set) default files */
- createstdfile(L, process.stdin, IO_INPUT, lua.to_luastring("stdin"));
- createstdfile(L, process.stdout, IO_OUTPUT, lua.to_luastring("stdout"));
- createstdfile(L, process.stderr, null, lua.to_luastring("stderr"));
+ createstdfile(L, process.stdin, IO_INPUT, to_luastring("stdin"));
+ createstdfile(L, process.stdout, IO_OUTPUT, to_luastring("stdout"));
+ createstdfile(L, process.stderr, null, to_luastring("stderr"));
return 1;
};
diff --git a/src/lmathlib.js b/src/lmathlib.js
index e056fd8..328356b 100644
--- a/src/lmathlib.js
+++ b/src/lmathlib.js
@@ -3,6 +3,7 @@
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
const luaconf = require('./luaconf.js');
+const {to_luastring} = require("./fengaricore.js");
const math_random = function(L) {
let low, up;
@@ -21,13 +22,13 @@ const math_random = function(L) {
up = lauxlib.luaL_checkinteger(L, 2);
break;
}
- default: return lauxlib.luaL_error(L, lua.to_luastring("wrong number of arguments", true));
+ default: return lauxlib.luaL_error(L, to_luastring("wrong number of arguments", true));
}
/* random integer in the interval [low, up] */
- lauxlib.luaL_argcheck(L, low <= up, 1, lua.to_luastring("interval is empty", true));
+ lauxlib.luaL_argcheck(L, low <= up, 1, to_luastring("interval is empty", true));
lauxlib.luaL_argcheck(L, low >= 0 || up <= luaconf.LUA_MAXINTEGER + low, 1,
- lua.to_luastring("interval too large", true));
+ to_luastring("interval too large", true));
r *= (up - low) + 1;
lua.lua_pushinteger(L, Math.floor(r) + low);
@@ -162,7 +163,7 @@ const math_rad = function(L) {
const math_min = function(L) {
let n = lua.lua_gettop(L); /* number of arguments */
let imin = 1; /* index of current minimum value */
- lauxlib.luaL_argcheck(L, n >= 1, 1, lua.to_luastring("value expected", true));
+ lauxlib.luaL_argcheck(L, n >= 1, 1, to_luastring("value expected", true));
for (let i = 2; i <= n; i++){
if (lua.lua_compare(L, i, imin, lua.LUA_OPLT))
imin = i;
@@ -174,7 +175,7 @@ const math_min = function(L) {
const math_max = function(L) {
let n = lua.lua_gettop(L); /* number of arguments */
let imax = 1; /* index of current minimum value */
- lauxlib.luaL_argcheck(L, n >= 1, 1, lua.to_luastring("value expected", true));
+ lauxlib.luaL_argcheck(L, n >= 1, 1, to_luastring("value expected", true));
for (let i = 2; i <= n; i++){
if (lua.lua_compare(L, imax, i, lua.LUA_OPLT))
imax = i;
@@ -201,7 +202,7 @@ const math_fmod = function(L) {
let d = lua.lua_tointeger(L, 2);
/* no special case needed for -1 in javascript */
if (d === 0) {
- lauxlib.luaL_argerror(L, 2, lua.to_luastring("zero", true));
+ lauxlib.luaL_argerror(L, 2, to_luastring("zero", true));
} else
lua.lua_pushinteger(L, (lua.lua_tointeger(L, 1) % d)|0);
} else {
@@ -253,13 +254,13 @@ const mathlib = {
const luaopen_math = function(L) {
lauxlib.luaL_newlib(L, mathlib);
lua.lua_pushnumber(L, Math.PI);
- lua.lua_setfield(L, -2, lua.to_luastring("pi", true));
+ lua.lua_setfield(L, -2, to_luastring("pi", true));
lua.lua_pushnumber(L, Infinity);
- lua.lua_setfield(L, -2, lua.to_luastring("huge", true));
+ lua.lua_setfield(L, -2, to_luastring("huge", true));
lua.lua_pushinteger(L, luaconf.LUA_MAXINTEGER);
- lua.lua_setfield(L, -2, lua.to_luastring("maxinteger", true));
+ lua.lua_setfield(L, -2, to_luastring("maxinteger", true));
lua.lua_pushinteger(L, luaconf.LUA_MININTEGER);
- lua.lua_setfield(L, -2, lua.to_luastring("mininteger", true));
+ lua.lua_setfield(L, -2, to_luastring("mininteger", true));
return 1;
};
diff --git a/src/loadlib.js b/src/loadlib.js
index 2e68ffd..2dc6d73 100644
--- a/src/loadlib.js
+++ b/src/loadlib.js
@@ -3,6 +3,7 @@
const fengari = require('./fengari.js');
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
+const {luastring_indexOf, to_jsstring, to_luastring, to_uristring} = require("./fengaricore.js");
const global_env = (function() {
/* global WorkerGlobalScope */ /* see https://github.com/sindresorhus/globals/issues/127 */
@@ -21,7 +22,7 @@ const global_env = (function() {
}
})();
-const CLIBS = lua.to_luastring("__CLIBS__", true);
+const CLIBS = to_luastring("__CLIBS__", true);
const LUA_PATH_VAR = "LUA_PATH";
const LUA_CPATH_VAR = "LUA_CPATH";
@@ -37,13 +38,13 @@ const LUA_CSUBSEP = lua.LUA_DIRSEP;
const LUA_LSUBSEP = lua.LUA_DIRSEP;
/* prefix for open functions in C libraries */
-const LUA_POF = lua.to_luastring("luaopen_");
+const LUA_POF = to_luastring("luaopen_");
/* separator for open functions in C libraries */
-const LUA_OFSEP = lua.to_luastring("_");
+const LUA_OFSEP = to_luastring("_");
const LIB_FAIL = "open";
-const AUXMARK = lua.to_luastring("\x01");
+const AUXMARK = to_luastring("\x01");
/*
@@ -55,13 +56,13 @@ const AUXMARK = lua.to_luastring("\x01");
let lsys_load;
if (typeof process === "undefined") {
lsys_load = function(L, path, seeglb) {
- path = lua.to_uristring(path);
+ path = to_uristring(path);
let xhr = new XMLHttpRequest();
xhr.open("GET", path, false);
xhr.send();
if (xhr.status < 200 || xhr.status >= 300) {
- lua.lua_pushstring(L, lua.to_luastring(`${xhr.status}: ${xhr.statusText}`));
+ lua.lua_pushstring(L, to_luastring(`${xhr.status}: ${xhr.statusText}`));
return null;
}
@@ -73,7 +74,7 @@ if (typeof process === "undefined") {
try {
func = Function("fengari", code);
} catch (e) {
- lua.lua_pushstring(L, lua.to_luastring(`${e.name}: ${e.message}`));
+ lua.lua_pushstring(L, to_luastring(`${e.name}: ${e.message}`));
return null;
}
let res = func(fengari);
@@ -82,20 +83,20 @@ if (typeof process === "undefined") {
} else if (res === void 0) { /* assume library added symbols to global environment */
return global_env;
} else {
- lua.lua_pushstring(L, lua.to_luastring(`library returned unexpected type (${typeof res})`));
+ lua.lua_pushstring(L, to_luastring(`library returned unexpected type (${typeof res})`));
return null;
}
};
} else {
const pathlib = require('path');
lsys_load = function(L, path, seeglb) {
- path = lua.to_jsstring(path);
+ path = to_jsstring(path);
/* relative paths should be relative to cwd, not this js file */
path = pathlib.resolve(process.cwd(), path);
try {
return require(path);
} catch (e) {
- lua.lua_pushstring(L, lua.to_luastring(e.message));
+ lua.lua_pushstring(L, to_luastring(e.message));
return null;
}
};
@@ -107,12 +108,12 @@ if (typeof process === "undefined") {
** error string in the stack.
*/
const lsys_sym = function(L, lib, sym) {
- let f = lib[lua.to_jsstring(sym)];
+ let f = lib[to_jsstring(sym)];
if (f && typeof f === 'function')
return f;
else {
- lua.lua_pushfstring(L, lua.to_luastring("undefined symbol: %s"), sym);
+ lua.lua_pushfstring(L, to_luastring("undefined symbol: %s"), sym);
return null;
}
};
@@ -121,7 +122,7 @@ const lsys_sym = function(L, lib, sym) {
** return registry.LUA_NOENV as a boolean
*/
const noenv = function(L) {
- lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, lua.to_luastring("LUA_NOENV"));
+ lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, to_luastring("LUA_NOENV"));
let b = lua.lua_toboolean(L, -1);
lua.lua_pop(L, 1); /* remove value */
return b;
@@ -143,7 +144,7 @@ if (typeof process !== "undefined") { // Only with Node
} else {
/* TODO: use async/await ? */
readable = function(path) {
- path = lua.to_uristring(path);
+ path = to_uristring(path);
let xhr = new XMLHttpRequest();
/* Following GET request done by searcher_Web will be cached */
xhr.open("GET", path, false);
@@ -217,21 +218,21 @@ const env = (function() {
*/
const setpath = function(L, fieldname, envname, dft) {
let nver = `${envname}${lua.LUA_VERSUFFIX}`;
- lua.lua_pushstring(L, lua.to_luastring(nver));
+ lua.lua_pushstring(L, to_luastring(nver));
let path = env[nver]; /* use versioned name */
if (path === undefined) /* no environment variable? */
path = env[envname]; /* try unversioned name */
if (path === undefined || noenv(L)) /* no environment variable? */
- lua.lua_pushstring(L, lua.to_luastring(dft)); /* use default */
+ lua.lua_pushstring(L, to_luastring(dft)); /* use default */
else {
/* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
path = lauxlib.luaL_gsub(
L,
- lua.to_luastring(path),
- lua.to_luastring(lua.LUA_PATH_SEP + lua.LUA_PATH_SEP, true),
- lua.to_luastring(lua.LUA_PATH_SEP + lua.to_jsstring(AUXMARK) + lua.LUA_PATH_SEP, true)
+ to_luastring(path),
+ to_luastring(lua.LUA_PATH_SEP + lua.LUA_PATH_SEP, true),
+ to_luastring(lua.LUA_PATH_SEP + to_jsstring(AUXMARK) + lua.LUA_PATH_SEP, true)
);
- lauxlib.luaL_gsub(L, path, AUXMARK, lua.to_luastring(dft));
+ lauxlib.luaL_gsub(L, path, AUXMARK, to_luastring(dft));
lua.lua_remove(L, -2); /* remove result from 1st 'gsub' */
}
lua.lua_setfield(L, -3, fieldname); /* package[fieldname] = path value */
@@ -265,7 +266,7 @@ const addtoclib = function(L, path, plib) {
const pushnexttemplate = function(L, path) {
while (path[0] === lua.LUA_PATH_SEP.charCodeAt(0)) path = path.subarray(1); /* skip separators */
if (path.length === 0) return null; /* no more templates */
- let l = lua.luastring_indexOf(path, lua.LUA_PATH_SEP.charCodeAt(0)); /* find next separator */
+ let l = luastring_indexOf(path, lua.LUA_PATH_SEP.charCodeAt(0)); /* find next separator */
if (l < 0) l = path.length;
lua.lua_pushlstring(L, path, l); /* template */
return path.subarray(l);
@@ -277,11 +278,11 @@ const searchpath = function(L, name, path, sep, dirsep) {
if (sep[0] !== 0) /* non-empty separator? */
name = lauxlib.luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */
while ((path = pushnexttemplate(L, path)) !== null) {
- let filename = lauxlib.luaL_gsub(L, lua.lua_tostring(L, -1), lua.to_luastring(lua.LUA_PATH_MARK, true), name);
+ let filename = lauxlib.luaL_gsub(L, lua.lua_tostring(L, -1), to_luastring(lua.LUA_PATH_MARK, true), name);
lua.lua_remove(L, -2); /* remove path template */
if (readable(filename)) /* does file exist and is readable? */
return filename; /* return that file name */
- lua.lua_pushfstring(L, lua.to_luastring("\n\tno file '%s'"), filename);
+ lua.lua_pushfstring(L, to_luastring("\n\tno file '%s'"), filename);
lua.lua_remove(L, -2); /* remove file name */
lauxlib.luaL_addvalue(msg);
}
@@ -294,8 +295,8 @@ const ll_searchpath = function(L) {
L,
lauxlib.luaL_checkstring(L, 1),
lauxlib.luaL_checkstring(L, 2),
- lauxlib.luaL_optstring(L, 3, lua.to_luastring(".")),
- lauxlib.luaL_optstring(L, 4, lua.to_luastring(lua.LUA_DIRSEP))
+ lauxlib.luaL_optstring(L, 3, to_luastring(".")),
+ lauxlib.luaL_optstring(L, 4, to_luastring(lua.LUA_DIRSEP))
);
if (f !== null) return 1;
else { /* error message is on top of the stack */
@@ -309,8 +310,8 @@ const findfile = function(L, name, pname, dirsep) {
lua.lua_getfield(L, lua.lua_upvalueindex(1), pname);
let path = lua.lua_tostring(L, -1);
if (path === null)
- lauxlib.luaL_error(L, lua.to_luastring("'package.%s' must be a string"), pname);
- return searchpath(L, name, path, lua.to_luastring("."), dirsep);
+ lauxlib.luaL_error(L, to_luastring("'package.%s' must be a string"), pname);
+ return searchpath(L, name, path, to_luastring("."), dirsep);
};
const checkload = function(L, stat, filename) {
@@ -318,13 +319,13 @@ const checkload = function(L, stat, filename) {
lua.lua_pushstring(L, filename); /* will be 2nd argument to module */
return 2; /* return open function and file name */
} else
- return lauxlib.luaL_error(L, lua.to_luastring("error loading module '%s' from file '%s':\n\t%s"),
+ return lauxlib.luaL_error(L, to_luastring("error loading module '%s' from file '%s':\n\t%s"),
lua.lua_tostring(L, 1), filename, lua.lua_tostring(L, -1));
};
const searcher_Lua = function(L) {
let name = lauxlib.luaL_checkstring(L, 1);
- let filename = findfile(L, name, lua.to_luastring("path", true), lua.to_luastring(LUA_LSUBSEP, true));
+ let filename = findfile(L, name, to_luastring("path", true), to_luastring(LUA_LSUBSEP, true));
if (filename === null) return 1; /* module not found in this path */
return checkload(L, lauxlib.luaL_loadfile(L, filename) === lua.LUA_OK, filename);
};
@@ -339,39 +340,39 @@ const searcher_Lua = function(L) {
*/
const loadfunc = function(L, filename, modname) {
let openfunc;
- modname = lauxlib.luaL_gsub(L, modname, lua.to_luastring("."), LUA_OFSEP);
- let mark = lua.luastring_indexOf(modname, LUA_IGMARK.charCodeAt(0));
+ modname = lauxlib.luaL_gsub(L, modname, to_luastring("."), LUA_OFSEP);
+ let mark = luastring_indexOf(modname, LUA_IGMARK.charCodeAt(0));
if (mark >= 0) {
openfunc = lua.lua_pushlstring(L, modname, mark);
- openfunc = lua.lua_pushfstring(L, lua.to_luastring("%s%s"), LUA_POF, openfunc);
+ openfunc = lua.lua_pushfstring(L, to_luastring("%s%s"), LUA_POF, openfunc);
let stat = lookforfunc(L, filename, openfunc);
if (stat !== ERRFUNC) return stat;
modname = mark + 1; /* else go ahead and try old-style name */
}
- openfunc = lua.lua_pushfstring(L, lua.to_luastring("%s%s"), LUA_POF, modname);
+ openfunc = lua.lua_pushfstring(L, to_luastring("%s%s"), LUA_POF, modname);
return lookforfunc(L, filename, openfunc);
};
const searcher_C = function(L) {
let name = lauxlib.luaL_checkstring(L, 1);
- let filename = findfile(L, name, lua.to_luastring("cpath", true), lua.to_luastring(LUA_CSUBSEP, true));
+ let filename = findfile(L, name, to_luastring("cpath", true), to_luastring(LUA_CSUBSEP, true));
if (filename === null) return 1; /* module not found in this path */
return checkload(L, (loadfunc(L, filename, name) === 0), filename);
};
const searcher_Croot = function(L) {
let name = lauxlib.luaL_checkstring(L, 1);
- let p = lua.luastring_indexOf(name, '.'.charCodeAt(0));
+ let p = luastring_indexOf(name, '.'.charCodeAt(0));
let stat;
if (p < 0) return 0; /* is root */
lua.lua_pushlstring(L, name, p);
- let filename = findfile(L, lua.lua_tostring(L, -1), lua.to_luastring("cpath", true), lua.to_luastring(LUA_CSUBSEP, true));
+ let filename = findfile(L, lua.lua_tostring(L, -1), to_luastring("cpath", true), to_luastring(LUA_CSUBSEP, true));
if (filename === null) return 1; /* root not found */
if ((stat = loadfunc(L, filename, name)) !== 0) {
if (stat != ERRFUNC)
return checkload(L, 0, filename); /* real error */
else { /* open function not found */
- lua.lua_pushstring(L, lua.to_luastring("\n\tno module '%s' in file '%s'"), name, filename);
+ lua.lua_pushstring(L, to_luastring("\n\tno module '%s' in file '%s'"), name, filename);
return 1;
}
}
@@ -383,7 +384,7 @@ const searcher_preload = function(L) {
let name = lauxlib.luaL_checkstring(L, 1);
lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, lauxlib.LUA_PRELOAD_TABLE);
if (lua.lua_getfield(L, -1, name) === lua.LUA_TNIL) /* not found? */
- lua.lua_pushfstring(L, lua.to_luastring("\n\tno field package.preload['%s']"), name);
+ lua.lua_pushfstring(L, to_luastring("\n\tno field package.preload['%s']"), name);
return 1;
};
@@ -391,8 +392,8 @@ const findloader = function(L, name, ctx, k) {
let msg = new lauxlib.luaL_Buffer(); /* to build error message */
lauxlib.luaL_buffinit(L, msg);
/* push 'package.searchers' to index 3 in the stack */
- if (lua.lua_getfield(L, lua.lua_upvalueindex(1), lua.to_luastring("searchers", true)) !== lua.LUA_TTABLE)
- lauxlib.luaL_error(L, lua.to_luastring("'package.searchers' must be a table"));
+ if (lua.lua_getfield(L, lua.lua_upvalueindex(1), to_luastring("searchers", true)) !== lua.LUA_TTABLE)
+ lauxlib.luaL_error(L, to_luastring("'package.searchers' must be a table"));
let ctx2 = {name: name, i: 1, msg: msg, ctx: ctx, k: k};
return findloader_cont(L, lua.LUA_OK, ctx2);
};
@@ -404,7 +405,7 @@ const findloader_cont = function(L, status, ctx) {
if (lua.lua_rawgeti(L, 3, ctx.i) === lua.LUA_TNIL) { /* no more searchers? */
lua.lua_pop(L, 1); /* remove nil */
lauxlib.luaL_pushresult(ctx.msg); /* create error message */
- lauxlib.luaL_error(L, lua.to_luastring("module '%s' not found:%s"), ctx.name, lua.lua_tostring(L, -1));
+ lauxlib.luaL_error(L, to_luastring("module '%s' not found:%s"), ctx.name, lua.lua_tostring(L, -1));
}
lua.lua_pushstring(L, ctx.name);
lua.lua_callk(L, 1, 2, ctx, findloader_cont); /* call it */
@@ -475,7 +476,7 @@ const createsearcherstable = function(L) {
lua.lua_pushcclosure(L, searchers[i], 1);
lua.lua_rawseti(L, -2, i+1);
}
- lua.lua_setfield(L, -2, lua.to_luastring("searchers", true)); /* put it in field 'searchers' */
+ lua.lua_setfield(L, -2, to_luastring("searchers", true)); /* put it in field 'searchers' */
};
/*
@@ -494,18 +495,18 @@ const luaopen_package = function(L) {
lauxlib.luaL_newlib(L, pk_funcs); /* create 'package' table */
createsearcherstable(L);
/* set paths */
- setpath(L, lua.to_luastring("path", true), LUA_PATH_VAR, lua.LUA_PATH_DEFAULT);
- setpath(L, lua.to_luastring("cpath", true), LUA_CPATH_VAR, lua.LUA_CPATH_DEFAULT);
+ setpath(L, to_luastring("path", true), LUA_PATH_VAR, lua.LUA_PATH_DEFAULT);
+ setpath(L, to_luastring("cpath", true), LUA_CPATH_VAR, lua.LUA_CPATH_DEFAULT);
/* store config information */
lua.lua_pushliteral(L, lua.LUA_DIRSEP + "\n" + lua.LUA_PATH_SEP + "\n" + lua.LUA_PATH_MARK + "\n" +
lua.LUA_EXEC_DIR + "\n" + LUA_IGMARK + "\n");
- lua.lua_setfield(L, -2, lua.to_luastring("config", true));
+ lua.lua_setfield(L, -2, to_luastring("config", true));
/* set field 'loaded' */
lauxlib.luaL_getsubtable(L, lua.LUA_REGISTRYINDEX, lauxlib.LUA_LOADED_TABLE);
- lua.lua_setfield(L, -2, lua.to_luastring("loaded", true));
+ lua.lua_setfield(L, -2, to_luastring("loaded", true));
/* set field 'preload' */
lauxlib.luaL_getsubtable(L, lua.LUA_REGISTRYINDEX, lauxlib.LUA_PRELOAD_TABLE);
- lua.lua_setfield(L, -2, lua.to_luastring("preload", true));
+ lua.lua_setfield(L, -2, to_luastring("preload", true));
lua.lua_pushglobaltable(L);
lua.lua_pushvalue(L, -2); /* set 'package' as upvalue for next lib */
lauxlib.luaL_setfuncs(L, ll_funcs, 1); /* open lib into global table */
diff --git a/src/loslib.js b/src/loslib.js
index b5f3ddb..2266e53 100644
--- a/src/loslib.js
+++ b/src/loslib.js
@@ -2,25 +2,26 @@
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
+const {luastring_indexOf, to_jsstring, to_luastring} = require("./fengaricore.js");
const strftime = require('strftime');
/* options for ANSI C 89 (only 1-char options) */
-const L_STRFTIMEC89 = lua.to_luastring("aAbBcdHIjmMpSUwWxXyYZ%");
+const L_STRFTIMEC89 = to_luastring("aAbBcdHIjmMpSUwWxXyYZ%");
const LUA_STRFTIMEOPTIONS = L_STRFTIMEC89;
/* options for ISO C 99 and POSIX */
-// const L_STRFTIMEC99 = lua.to_luastring("aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%||EcECExEXEyEYOdOeOHOIOmOMOSOuOUOVOwOWOy"); /* two-char options */
+// const L_STRFTIMEC99 = to_luastring("aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%||EcECExEXEyEYOdOeOHOIOmOMOSOuOUOVOwOWOy"); /* two-char options */
// const LUA_STRFTIMEOPTIONS = L_STRFTIMEC99;
/* options for Windows */
-// const L_STRFTIMEWIN = lua.to_luastring("aAbBcdHIjmMpSUwWxXyYzZ%||#c#x#d#H#I#j#m#M#S#U#w#W#y#Y"); /* two-char options */
+// const L_STRFTIMEWIN = to_luastring("aAbBcdHIjmMpSUwWxXyYzZ%||#c#x#d#H#I#j#m#M#S#U#w#W#y#Y"); /* two-char options */
// const LUA_STRFTIMEOPTIONS = L_STRFTIMEWIN;
const setfield = function(L, key, value) {
lua.lua_pushinteger(L, value);
- lua.lua_setfield(L, -2, lua.to_luastring(key, true));
+ lua.lua_setfield(L, -2, to_luastring(key, true));
};
const setallfields = function(L, time, utc) {
@@ -39,18 +40,18 @@ const setallfields = function(L, time, utc) {
const L_MAXDATEFIELD = (Number.MAX_SAFE_INTEGER / 2);
const getfield = function(L, key, d, delta) {
- let t = lua.lua_getfield(L, -1, lua.to_luastring(key, true)); /* get field and its type */
+ let t = lua.lua_getfield(L, -1, to_luastring(key, true)); /* get field and its type */
let res = lua.lua_tointegerx(L, -1);
if (res === false) { /* field is not an integer? */
if (t !== lua.LUA_TNIL) /* some other value? */
- return lauxlib.luaL_error(L, lua.to_luastring("field '%s' is not an integer"), key);
+ return lauxlib.luaL_error(L, to_luastring("field '%s' is not an integer"), key);
else if (d < 0) /* absent field; no default? */
- return lauxlib.luaL_error(L, lua.to_luastring("field '%s' missing in date table"), key);
+ return lauxlib.luaL_error(L, to_luastring("field '%s' missing in date table"), key);
res = d;
}
else {
if (!(-L_MAXDATEFIELD <= res && res <= L_MAXDATEFIELD))
- return lauxlib.luaL_error(L, lua.to_luastring("field '%s' is out-of-bound"), key);
+ return lauxlib.luaL_error(L, to_luastring("field '%s' is out-of-bound"), key);
res -= delta;
}
lua.lua_pop(L, 1);
@@ -78,7 +79,7 @@ const checkoption = function(L, conv, i, buff) {
}
}
lauxlib.luaL_argerror(L, 1,
- lua.lua_pushfstring(L, lua.to_luastring("invalid conversion specifier '%%%s'"), conv));
+ lua.lua_pushfstring(L, to_luastring("invalid conversion specifier '%%%s'"), conv));
};
/* maximum size for an individual 'strftime' item */
@@ -86,7 +87,7 @@ const checkoption = function(L, conv, i, buff) {
const os_date = function(L) {
- let s = lauxlib.luaL_optlstring(L, 1, lua.to_luastring("%c"));
+ let s = lauxlib.luaL_optlstring(L, 1, to_luastring("%c"));
let t = lauxlib.luaL_opt(L, l_checktime, 2, new Date().getTime() / 1000) * 1000;
let stm = new Date(t);
let utc = false;
@@ -97,7 +98,7 @@ const os_date = function(L) {
}
if (stm === null) /* invalid date? */
- lauxlib.luaL_error(L, lua.to_luastring("time result cannot be represented in this installation", true));
+ lauxlib.luaL_error(L, to_luastring("time result cannot be represented in this installation", true));
if (s[i] === "*".charCodeAt(0) && s[i+1] === "t".charCodeAt(0)) {
lua.lua_createtable(L, 0, 9); /* 9 = number of fields */
setallfields(L, stm, utc);
@@ -112,11 +113,11 @@ const os_date = function(L) {
} else {
i++; /* skip '%' */
i = checkoption(L, s, i, cc.subarray(1)); /* copy specifier to 'cc' */
- let len = lua.luastring_indexOf(cc, 0);
+ let len = luastring_indexOf(cc, 0);
if (len !== -1)
cc = cc.subarray(0, len);
- let buff = strftime(lua.to_jsstring(cc), stm);
- lauxlib.luaL_addstring(b, lua.to_luastring(buff));
+ let buff = strftime(to_jsstring(cc), stm);
+ lauxlib.luaL_addstring(b, to_luastring(buff));
}
}
lauxlib.luaL_pushresult(b);
@@ -144,7 +145,7 @@ const os_time = function(L) {
const l_checktime = function(L, arg) {
let t = lauxlib.luaL_checkinteger(L, arg);
- // lauxlib.luaL_argcheck(L, t, arg, lua.to_luastring("time out-of-bounds"));
+ // lauxlib.luaL_argcheck(L, t, arg, to_luastring("time out-of-bounds"));
return t;
};
@@ -186,7 +187,7 @@ if (typeof process === "undefined") {
syslib.getenv = function(L) {
let key = lauxlib.luaL_checkstring(L, 1);
- key = lua.to_jsstring(key); /* https://github.com/nodejs/node/issues/16961 */
+ key = to_jsstring(key); /* https://github.com/nodejs/node/issues/16961 */
if (Object.prototype.hasOwnProperty.call(process.env, key)) {
lua.lua_pushliteral(L, process.env[key]);
} else {
@@ -233,8 +234,8 @@ if (typeof process === "undefined") {
syslib.tmpname = function(L) {
let name = lua_tmpname();
if (!name)
- return lauxlib.luaL_error(L, lua.to_luastring("unable to generate a unique filename"));
- lua.lua_pushstring(L, lua.to_luastring(name));
+ return lauxlib.luaL_error(L, to_luastring("unable to generate a unique filename"));
+ lua.lua_pushstring(L, to_luastring(name));
return 1;
};
diff --git a/src/lstrlib.js b/src/lstrlib.js
index 6986411..5477750 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -6,6 +6,7 @@ const sprintf = require('sprintf-js').sprintf;
const lauxlib = require('./lauxlib.js');
const lua = require('./lua.js');
const luaconf = require('./luaconf.js');
+const {luastring_indexOf, to_jsstring, to_luastring} = require("./fengaricore.js");
const sL_ESC = '%';
const L_ESC = sL_ESC.charCodeAt(0);
@@ -22,7 +23,7 @@ const MAXSIZE = 2147483647;
/* Give natural (i.e. strings end at the first \0) length of a string represented by an array of bytes */
const strlen = function(s) {
- let len = lua.luastring_indexOf(s, 0);
+ let len = luastring_indexOf(s, 0);
return len > -1 ? len : s.length;
};
@@ -76,7 +77,7 @@ const str_dump = function(L) {
lua.lua_settop(L, 1);
lauxlib.luaL_buffinit(L, b);
if (lua.lua_dump(L, writer, b, strip) !== 0)
- return lauxlib.luaL_error(L, lua.to_luastring("unable to dump given function"));
+ return lauxlib.luaL_error(L, to_luastring("unable to dump given function"));
lauxlib.luaL_pushresult(b);
return 1;
};
@@ -88,17 +89,17 @@ const L_NBFD = 1;
const num2straux = function(x) {
/* if 'inf' or 'NaN', format it like '%g' */
if (Object.is(x, Infinity))
- return lua.to_luastring('inf');
+ return to_luastring('inf');
else if (Object.is(x, -Infinity))
- return lua.to_luastring('-inf');
+ return to_luastring('-inf');
else if (Number.isNaN(x))
- return lua.to_luastring('nan');
+ return to_luastring('nan');
else if (x === 0) { /* can be -0... */
/* create "0" or "-0" followed by exponent */
let zero = sprintf(luaconf.LUA_NUMBER_FMT + "x0p+0", x);
if (Object.is(x, -0))
zero = "-" + zero;
- return lua.to_luastring(zero);
+ return to_luastring(zero);
} else {
let buff = "";
let fe = luaconf.frexp(x); /* 'x' fraction and exponent */
@@ -112,7 +113,7 @@ const num2straux = function(x) {
buff += (m * (1<<L_NBFD)).toString(16);
e -= L_NBFD; /* this digit goes before the radix point */
buff += sprintf("p%+d", e); /* add exponent */
- return lua.to_luastring(buff);
+ return to_luastring(buff);
}
};
@@ -122,7 +123,7 @@ const lua_number2strx = function(L, fmt, x) {
for (let i = 0; i < buff.length; i++)
buff[i] = String.fromCharCode(buff[i]).toUpperCase().charCodeAt(0);
} else if (fmt[SIZELENMOD] !== 'a'.charCodeAt(0))
- lauxlib.luaL_error(L, lua.to_luastring("modifiers for format '%%a'/'%%A' not implemented"));
+ lauxlib.luaL_error(L, to_luastring("modifiers for format '%%a'/'%%A' not implemented"));
return buff;
};
@@ -166,9 +167,9 @@ const addquoted = function(b, s, len) {
} else if (iscntrl(s[i])) {
let buff;
if (!isdigit(s[i+1]))
- buff = lua.to_luastring(sprintf("\\%d", s[i]));
+ buff = to_luastring(sprintf("\\%d", s[i]));
else
- buff = lua.to_luastring(sprintf("\\%03d", s[i]));
+ buff = to_luastring(sprintf("\\%03d", s[i]));
lauxlib.luaL_addstring(b, buff);
} else
lauxlib.luaL_addchar(b, s[i]);
@@ -181,9 +182,9 @@ const addquoted = function(b, s, len) {
** Ensures the 'buff' string uses a dot as the radix character.
*/
const checkdp = function(buff) {
- if (lua.luastring_indexOf(buff, '.'.charCodeAt(0)) < 0) { /* no dot? */
+ if (luastring_indexOf(buff, '.'.charCodeAt(0)) < 0) { /* no dot? */
let point = luaconf.lua_getlocaledecpoint().charCodeAt(0); /* try locale point */
- let ppoint = lua.luastring_indexOf(buff, point);
+ let ppoint = luastring_indexOf(buff, point);
if (ppoint) buff[ppoint] = '.'; /* change it to a dot */
}
};
@@ -199,14 +200,14 @@ const addliteral = function(L, b, arg) {
let buff;
if (!lua.lua_isinteger(L, arg)) { /* float? */
let n = lua.lua_tonumber(L, arg); /* write as hexa ('%a') */
- buff = lua_number2strx(L, lua.to_luastring(`%${luaconf.LUA_INTEGER_FRMLEN}a`), n);
+ buff = lua_number2strx(L, to_luastring(`%${luaconf.LUA_INTEGER_FRMLEN}a`), n);
checkdp(buff); /* ensure it uses a dot */
} else { /* integers */
let n = lua.lua_tointeger(L, arg);
let format = (n === luaconf.LUA_MININTEGER) /* corner case? */
? "0x%" + luaconf.LUA_INTEGER_FRMLEN + "x" /* use hexa */
: luaconf.LUA_INTEGER_FMT; /* else use default format */
- buff = lua.to_luastring(sprintf(format, n));
+ buff = to_luastring(sprintf(format, n));
}
lauxlib.luaL_addstring(b, buff);
break;
@@ -217,16 +218,16 @@ const addliteral = function(L, b, arg) {
break;
}
default: {
- lauxlib.luaL_argerror(L, arg, lua.to_luastring("value has no literal form", true));
+ lauxlib.luaL_argerror(L, arg, to_luastring("value has no literal form", true));
}
}
};
const scanformat = function(L, strfrmt, i, form) {
let p = i;
- while (strfrmt[p] !== 0 && lua.luastring_indexOf(FLAGS, strfrmt[p]) >= 0) p++; /* skip flags */
+ while (strfrmt[p] !== 0 && luastring_indexOf(FLAGS, strfrmt[p]) >= 0) p++; /* skip flags */
if (p - i >= FLAGS.length)
- lauxlib.luaL_error(L, lua.to_luastring("invalid format (repeated flags)", true));
+ lauxlib.luaL_error(L, to_luastring("invalid format (repeated flags)", true));
if (isdigit(strfrmt[p])) p++; /* skip width */
if (isdigit(strfrmt[p])) p++; /* (2 digits at most) */
if (strfrmt[p] === '.'.charCodeAt(0)) {
@@ -235,7 +236,7 @@ const scanformat = function(L, strfrmt, i, form) {
if (isdigit(strfrmt[p])) p++; /* (2 digits at most) */
}
if (isdigit(strfrmt[p]))
- lauxlib.luaL_error(L, lua.to_luastring("invalid format (width or precision too long)", true));
+ lauxlib.luaL_error(L, to_luastring("invalid format (width or precision too long)", true));
form[0] = "%".charCodeAt(0);
for (let j = 0; j < p - i + 1; j++)
form[j+1] = strfrmt[i+j];
@@ -270,7 +271,7 @@ const str_format = function(L) {
} else { /* format item */
let form = []; /* to store the format ('%...') */
if (++arg > top)
- lauxlib.luaL_argerror(L, arg, lua.to_luastring("no value", true));
+ lauxlib.luaL_argerror(L, arg, to_luastring("no value", true));
i = scanformat(L, strfrmt, i, form);
switch (String.fromCharCode(strfrmt[i++])) {
case 'c': {
@@ -282,7 +283,7 @@ const str_format = function(L) {
case 'o': case 'u': case 'x': case 'X': {
let n = lauxlib.luaL_checkinteger(L, arg);
addlenmod(form, luaconf.LUA_INTEGER_FRMLEN.split('').map(e => e.charCodeAt(0)));
- lauxlib.luaL_addstring(b, lua.to_luastring(sprintf(String.fromCharCode(...form), n)));
+ lauxlib.luaL_addstring(b, to_luastring(sprintf(String.fromCharCode(...form), n)));
break;
}
case 'a': case 'A': {
@@ -294,7 +295,7 @@ const str_format = function(L) {
case 'g': case 'G': {
let n = lauxlib.luaL_checknumber(L, arg);
addlenmod(form, luaconf.LUA_INTEGER_FRMLEN.split('').map(e => e.charCodeAt(0)));
- lauxlib.luaL_addstring(b, lua.to_luastring(sprintf(String.fromCharCode(...form), n)));
+ lauxlib.luaL_addstring(b, to_luastring(sprintf(String.fromCharCode(...form), n)));
break;
}
case 'q': {
@@ -306,20 +307,20 @@ const str_format = function(L) {
if (form.length <= 2 || form[2] === 0) { /* no modifiers? */
lauxlib.luaL_addvalue(b); /* keep entire string */
} else {
- lauxlib.luaL_argcheck(L, s.length === strlen(s), arg, lua.to_luastring("string contains zeros", true));
- if (lua.luastring_indexOf(form, '.'.charCodeAt(0)) < 0 && s.length >= 100) {
+ lauxlib.luaL_argcheck(L, s.length === strlen(s), arg, to_luastring("string contains zeros", true));
+ if (luastring_indexOf(form, '.'.charCodeAt(0)) < 0 && s.length >= 100) {
/* no precision and string is too long to be formatted */
lauxlib.luaL_addvalue(b); /* keep entire string */
} else { /* format the string into 'buff' */
// TODO: will fail if s is not valid UTF-8
- lauxlib.luaL_addstring(b, lua.to_luastring(sprintf(String.fromCharCode(...form), lua.to_jsstring(s))));
+ lauxlib.luaL_addstring(b, to_luastring(sprintf(String.fromCharCode(...form), to_jsstring(s))));
lua.lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
}
}
break;
}
default: { /* also treat cases 'pnLlh' */
- return lauxlib.luaL_error(L, lua.to_luastring("invalid option '%%%c' to 'format'"), strfrmt[i-1]);
+ return lauxlib.luaL_error(L, to_luastring("invalid option '%%%c' to 'format'"), strfrmt[i-1]);
}
}
}
@@ -393,7 +394,7 @@ const getnum = function(fmt, df) {
const getnumlimit = function(h, fmt, df) {
let sz = getnum(fmt, df);
if (sz > MAXINTSIZE || sz <= 0)
- lauxlib.luaL_error(h.L, lua.to_luastring("integral size (%d) out of limits [1,%d]"), sz, MAXINTSIZE);
+ lauxlib.luaL_error(h.L, to_luastring("integral size (%d) out of limits [1,%d]"), sz, MAXINTSIZE);
return sz;
};
@@ -427,7 +428,7 @@ const getoption = function(h, fmt) {
case 'c'.charCodeAt(0): {
r.size = getnum(fmt, -1);
if (r.size === -1)
- lauxlib.luaL_error(h.L, lua.to_luastring("missing size for format option 'c'"));
+ lauxlib.luaL_error(h.L, to_luastring("missing size for format option 'c'"));
r.opt = KOption.Kchar;
return r;
}
@@ -439,7 +440,7 @@ const getoption = function(h, fmt) {
case '>'.charCodeAt(0): h.islittle = false; break;
case '='.charCodeAt(0): h.islittle = true; break;
case '!'.charCodeAt(0): h.maxalign = getnumlimit(h, fmt, MAXALIGN); break;
- default: lauxlib.luaL_error(h.L, lua.to_luastring("invalid format option '%c'"), r.opt);
+ default: lauxlib.luaL_error(h.L, to_luastring("invalid format option '%c'"), r.opt);
}
r.opt = KOption.Knop;
@@ -468,13 +469,13 @@ const getdetails = function(h, totalsize, fmt) {
let align = r.size; /* usually, alignment follows size */
if (r.opt === KOption.Kpaddalign) { /* 'X' gets alignment from following option */
if (fmt.off >= fmt.s.length || fmt.s[fmt.off] === 0)
- lauxlib.luaL_argerror(h.L, 1, lua.to_luastring("invalid next option for option 'X'", true));
+ lauxlib.luaL_argerror(h.L, 1, to_luastring("invalid next option for option 'X'", true));
else {
let o = getoption(h, fmt);
align = o.size;
o = o.opt;
if (o === KOption.Kchar || align === 0)
- lauxlib.luaL_argerror(h.L, 1, lua.to_luastring("invalid next option for option 'X'", true));
+ lauxlib.luaL_argerror(h.L, 1, to_luastring("invalid next option for option 'X'", true));
}
}
if (align <= 1 || r.opt === KOption.Kchar) /* need no alignment? */
@@ -483,7 +484,7 @@ const getdetails = function(h, totalsize, fmt) {
if (align > h.maxalign) /* enforce maximum alignment */
align = h.maxalign;
if ((align & (align -1)) !== 0) /* is 'align' not a power of 2? */
- lauxlib.luaL_argerror(h.L, 1, lua.to_luastring("format asks for alignment not power of 2", true));
+ lauxlib.luaL_argerror(h.L, 1, to_luastring("format asks for alignment not power of 2", true));
r.ntoalign = (align - (totalsize & (align - 1))) & (align - 1);
}
return r;
@@ -534,7 +535,7 @@ const str_pack = function(L) {
let n = lauxlib.luaL_checkinteger(L, arg);
if (size < SZINT) { /* need overflow check? */
let lim = 1 << (size * 8) - 1;
- lauxlib.luaL_argcheck(L, -lim <= n && n < lim, arg, lua.to_luastring("integer overflow", true));
+ lauxlib.luaL_argcheck(L, -lim <= n && n < lim, arg, to_luastring("integer overflow", true));
}
packint(b, n, h.islittle, size, n < 0);
break;
@@ -542,7 +543,7 @@ const str_pack = function(L) {
case KOption.Kuint: { /* unsigned integers */
let n = lauxlib.luaL_checkinteger(L, arg);
if (size < SZINT)
- lauxlib.luaL_argcheck(L, (n>>>0) < (1 << (size * NB)), arg, lua.to_luastring("unsigned overflow", true));
+ lauxlib.luaL_argcheck(L, (n>>>0) < (1 << (size * NB)), arg, to_luastring("unsigned overflow", true));
packint(b, n>>>0, h.islittle, size, false);
break;
}
@@ -558,7 +559,7 @@ const str_pack = function(L) {
case KOption.Kchar: { /* fixed-size string */
let s = lauxlib.luaL_checkstring(L, arg);
let len = s.length;
- lauxlib.luaL_argcheck(L, len <= size, arg, lua.to_luastring("string longer than given size", true));
+ lauxlib.luaL_argcheck(L, len <= size, arg, to_luastring("string longer than given size", true));
lauxlib.luaL_addlstring(b, s, len); /* add string */
while (len++ < size) /* pad extra space */
lauxlib.luaL_addchar(b, LUAL_PACKPADBYTE);
@@ -569,7 +570,7 @@ const str_pack = function(L) {
let len = s.length;
lauxlib.luaL_argcheck(L,
size >= 4 /* sizeof(size_t) */ || len < (1 << (size * NB)),
- arg, lua.to_luastring("string length does not fit in given size", true));
+ arg, to_luastring("string length does not fit in given size", true));
packint(b, len, h.islittle, size, 0); /* pack length */
lauxlib.luaL_addlstring(b, s, len);
totalsize += len;
@@ -578,7 +579,7 @@ const str_pack = function(L) {
case KOption.Kzstr: { /* zero-terminated string */
let s = lauxlib.luaL_checkstring(L, arg);
let len = s.length;
- lauxlib.luaL_argcheck(L, lua.luastring_indexOf(s, 0) < 0, arg, lua.to_luastring("strings contains zeros", true));
+ lauxlib.luaL_argcheck(L, luastring_indexOf(s, 0) < 0, arg, to_luastring("strings contains zeros", true));
lauxlib.luaL_addlstring(b, s, len);
lauxlib.luaL_addchar(b, 0); /* add zero at the end */
totalsize += len + 1;
@@ -607,14 +608,14 @@ const str_reverse = function(L) {
const str_lower = function(L) {
let s = lauxlib.luaL_checkstring(L, 1);
// TODO: will fail on invalid UTF-8
- lua.lua_pushstring(L, lua.to_luastring(lua.to_jsstring(s).toLowerCase()));
+ lua.lua_pushstring(L, to_luastring(to_jsstring(s).toLowerCase()));
return 1;
};
const str_upper = function(L) {
let s = lauxlib.luaL_checkstring(L, 1);
// TODO: will fail on invalid UTF-8
- lua.lua_pushstring(L, lua.to_luastring(lua.to_jsstring(s).toUpperCase()));
+ lua.lua_pushstring(L, to_luastring(to_jsstring(s).toUpperCase()));
return 1;
};
@@ -622,11 +623,11 @@ const str_rep = function(L) {
let s = lauxlib.luaL_checkstring(L, 1);
let l = s.length;
let n = lauxlib.luaL_checkinteger(L, 2);
- let sep = lauxlib.luaL_optstring(L, 3, lua.to_luastring(""));
+ let sep = lauxlib.luaL_optstring(L, 3, to_luastring(""));
let lsep = sep.length;
if (n <= 0) lua.lua_pushliteral(L, "");
else if (l + lsep < l || l + lsep > MAXSIZE / n) /* may overflow? */
- return lauxlib.luaL_error(L, lua.to_luastring("resulting string too large"));
+ return lauxlib.luaL_error(L, to_luastring("resulting string too large"));
else {
let totallen = n * l + (n - 1) * lsep;
let b = new lauxlib.luaL_Buffer();
@@ -656,10 +657,10 @@ const str_byte = function(L) {
if (pose > l) pose = l;
if (posi > pose) return 0; /* empty interval; return no values */
if (pose - posi >= Number.MAX_SAFE_INTEGER) /* arithmetic overflow? */
- return lauxlib.luaL_error(L, lua.to_luastring("string slice too long", true));
+ return lauxlib.luaL_error(L, to_luastring("string slice too long", true));
let n = (pose - posi) + 1;
- lauxlib.luaL_checkstack(L, n, lua.to_luastring("string slice too long", true));
+ lauxlib.luaL_checkstack(L, n, to_luastring("string slice too long", true));
for (let i = 0; i < n; i++)
lua.lua_pushinteger(L, s[posi + i - 1]);
return n;
@@ -678,12 +679,12 @@ const str_packsize = function(L) {
let size = details.size;
let ntoalign = details.ntoalign;
size += ntoalign; /* total space used by option */
- lauxlib.luaL_argcheck(L, totalsize <= MAXSIZE - size, 1, lua.to_luastring("format result too large", true));
+ lauxlib.luaL_argcheck(L, totalsize <= MAXSIZE - size, 1, to_luastring("format result too large", true));
totalsize += size;
switch (opt) {
case KOption.Kstring: /* strings with length count */
case KOption.Kzstr: /* zero-terminated string */
- lauxlib.luaL_argerror(L, 1, lua.to_luastring("variable-length format", true));
+ lauxlib.luaL_argerror(L, 1, to_luastring("variable-length format", true));
/* call never return, but to avoid warnings: *//* fall through */
default: break;
}
@@ -716,7 +717,7 @@ const unpackint = function(L, str, islittle, size, issigned) {
let mask = !issigned || res >= 0 ? 0 : MC;
for (let i = limit; i < size; i++) {
if (str[islittle ? i : size - 1 - i] !== mask)
- lauxlib.luaL_error(L, lua.to_luastring("%d-byte integer does not fit into Lua Integer"), size);
+ lauxlib.luaL_error(L, to_luastring("%d-byte integer does not fit into Lua Integer"), size);
}
}
return res;
@@ -743,17 +744,17 @@ const str_unpack = function(L) {
let ld = data.length;
let pos = posrelat(lauxlib.luaL_optinteger(L, 3, 1), ld) - 1;
let n = 0; /* number of results */
- lauxlib.luaL_argcheck(L, pos <= ld && pos >= 0, 3, lua.to_luastring("initial position out of string", true));
+ lauxlib.luaL_argcheck(L, pos <= ld && pos >= 0, 3, to_luastring("initial position out of string", true));
while (fmt.off < fmt.s.length) {
let details = getdetails(h, pos, fmt);
let opt = details.opt;
let size = details.size;
let ntoalign = details.ntoalign;
if (/*ntoalign + size > ~pos ||*/ pos + ntoalign + size > ld)
- lauxlib.luaL_argerror(L, 2, lua.to_luastring("data string too short", true));
+ lauxlib.luaL_argerror(L, 2, to_luastring("data string too short", true));
pos += ntoalign; /* skip alignment */
/* stack space for item + next position */
- lauxlib.luaL_checkstack(L, 2, lua.to_luastring("too many results", true));
+ lauxlib.luaL_checkstack(L, 2, to_luastring("too many results", true));
n++;
switch (opt) {
case KOption.Kint:
@@ -773,13 +774,13 @@ const str_unpack = function(L) {
}
case KOption.Kstring: {
let len = unpackint(L, data.subarray(pos), h.islittle, size, 0);
- lauxlib.luaL_argcheck(L, pos + len + size <= ld, 2, lua.to_luastring("data string too short", true));
+ lauxlib.luaL_argcheck(L, pos + len + size <= ld, 2, to_luastring("data string too short", true));
lua.lua_pushstring(L, data.subarray(pos + size, pos + size + len));
pos += len; /* skip string */
break;
}
case KOption.Kzstr: {
- let e = lua.luastring_indexOf(data, 0, pos);
+ let e = luastring_indexOf(data, 0, pos);
if (e === -1) e = data.length - pos;
lua.lua_pushstring(L, data.subarray(pos, e));
pos = e + 1; /* skip string plus final '\0' */
@@ -817,7 +818,7 @@ class MatchState {
const check_capture = function(ms, l) {
l = l - '1'.charCodeAt(0);
if (l < 0 || l >= ms.level || ms.capture[l].len === CAP_UNFINISHED)
- return lauxlib.luaL_error(ms.L, lua.to_luastring("invalid capture index %%%d"), l + 1);
+ return lauxlib.luaL_error(ms.L, to_luastring("invalid capture index %%%d"), l + 1);
return l;
};
@@ -825,21 +826,21 @@ const capture_to_close = function(ms) {
let level = ms.level;
for (level--; level >= 0; level--)
if (ms.capture[level].len === CAP_UNFINISHED) return level;
- return lauxlib.luaL_error(ms.L, lua.to_luastring("invalid pattern capture"));
+ return lauxlib.luaL_error(ms.L, to_luastring("invalid pattern capture"));
};
const classend = function(ms, p) {
switch(ms.p[p++]) {
case L_ESC: {
if (p === ms.p_end)
- lauxlib.luaL_error(ms.L, lua.to_luastring("malformed pattern (ends with '%%')"));
+ lauxlib.luaL_error(ms.L, to_luastring("malformed pattern (ends with '%%')"));
return p + 1;
}
case '['.charCodeAt(0): {
if (ms.p[p] === '^'.charCodeAt(0)) p++;
do { /* look for a ']' */
if (p === ms.p_end)
- lauxlib.luaL_error(ms.L, lua.to_luastring("malformed pattern (missing ']')"));
+ lauxlib.luaL_error(ms.L, to_luastring("malformed pattern (missing ']')"));
if (ms.p[p++] === L_ESC && p < ms.p_end)
p++; /* skip escapes (e.g. '%]') */
} while (ms.p[p] !== ']'.charCodeAt(0));
@@ -906,7 +907,7 @@ const singlematch = function(ms, s, p, ep) {
const matchbalance = function(ms, s, p) {
if (p >= ms.p_end - 1)
- lauxlib.luaL_error(ms.L, lua.to_luastring("malformed pattern (missing arguments to '%%b'"));
+ lauxlib.luaL_error(ms.L, to_luastring("malformed pattern (missing arguments to '%%b'"));
if (ms.src[s] !== ms.p[p])
return null;
else {
@@ -949,7 +950,7 @@ const min_expand = function(ms, s, p, ep) {
const start_capture = function(ms, s, p, what) {
let level = ms.level;
- if (level >= LUA_MAXCAPTURES) lauxlib.luaL_error(ms.L, lua.to_luastring("too many captures", true));
+ if (level >= LUA_MAXCAPTURES) lauxlib.luaL_error(ms.L, to_luastring("too many captures", true));
ms.capture[level] = ms.capture[level] ? ms.capture[level] : {};
ms.capture[level].init = s;
ms.capture[level].len = what;
@@ -975,7 +976,7 @@ const array_cmp = function(a, ai, b, bi, len) {
return true;
let aj = ai+len;
loop: for (;;) {
- ai = lua.luastring_indexOf(a, b[bi], ai);
+ ai = luastring_indexOf(a, b[bi], ai);
if (ai === -1 || ai >= aj)
return false;
for (let j = 1; j < len; j++) {
@@ -1001,7 +1002,7 @@ const match = function(ms, s, p) {
let gotoinit = true;
if (ms.matchdepth-- === 0)
- lauxlib.luaL_error(ms.L, lua.to_luastring("pattern too complex", true));
+ lauxlib.luaL_error(ms.L, to_luastring("pattern too complex", true));
while (gotoinit || gotodefault) {
gotoinit = false;
@@ -1039,7 +1040,7 @@ const match = function(ms, s, p) {
case 'f'.charCodeAt(0): { /* frontier? */
p += 2;
if (ms.p[p] !== '['.charCodeAt(0))
- lauxlib.luaL_error(ms.L, lua.to_luastring("missing '[' after '%%f' in pattern"));
+ lauxlib.luaL_error(ms.L, to_luastring("missing '[' after '%%f' in pattern"));
let ep = classend(ms, p); /* points to what is next */
let previous = s === ms.src_init ? 0 : ms.src[s-1];
if (!matchbracketclass(ms, previous, p, ep - 1) && matchbracketclass(ms, (s===ms.src_end)?0:ms.src[s], p, ep - 1)) {
@@ -1108,10 +1109,10 @@ const push_onecapture = function(ms, i, s, e) {
if (i === 0)
lua.lua_pushlstring(ms.L, ms.src.subarray(s, e), e - s); /* add whole match */
else
- lauxlib.luaL_error(ms.L, lua.to_luastring("invalid capture index %%%d"), i + 1);
+ lauxlib.luaL_error(ms.L, to_luastring("invalid capture index %%%d"), i + 1);
} else {
let l = ms.capture[i].len;
- if (l === CAP_UNFINISHED) lauxlib.luaL_error(ms.L, lua.to_luastring("unfinished capture", true));
+ if (l === CAP_UNFINISHED) lauxlib.luaL_error(ms.L, to_luastring("unfinished capture", true));
if (l === CAP_POSITION)
lua.lua_pushinteger(ms.L, ms.capture[i].init - ms.src_init + 1);
else
@@ -1121,7 +1122,7 @@ const push_onecapture = function(ms, i, s, e) {
const push_captures = function(ms, s, e) {
let nlevels = ms.level === 0 && ms.src.subarray(s) ? 1 : ms.level;
- lauxlib.luaL_checkstack(ms.L, nlevels, lua.to_luastring("too many catpures", true));
+ lauxlib.luaL_checkstack(ms.L, nlevels, to_luastring("too many catpures", true));
for (let i = 0; i < nlevels; i++)
push_onecapture(ms, i, s, e);
return nlevels; /* number of strings pushed */
@@ -1275,7 +1276,7 @@ const add_s = function(ms, b, s, e) {
i++; /* skip ESC */
if (!isdigit(news[i])) {
if (news[i] !== L_ESC)
- lauxlib.luaL_error(L, lua.to_luastring("invalid use of '%c' in replacement string"), L_ESC);
+ lauxlib.luaL_error(L, to_luastring("invalid use of '%c' in replacement string"), L_ESC);
lauxlib.luaL_addchar(b, news[i]);
} else if (news[i] === '0'.charCodeAt(0))
lauxlib.luaL_addlstring(b, ms.src.subarray(s, e), e - s);
@@ -1312,7 +1313,7 @@ const add_value = function(ms, b, s, e, tr) {
lua.lua_pop(L, 1);
lua.lua_pushlstring(L, ms.src.subarray(s, e), e - s); /* keep original text */
} else if (!lua.lua_isstring(L, -1))
- lauxlib.luaL_error(L, lua.to_luastring("invalid replacement value (a %s)"), lauxlib.luaL_typename(L, -1));
+ lauxlib.luaL_error(L, to_luastring("invalid replacement value (a %s)"), lauxlib.luaL_typename(L, -1));
lauxlib.luaL_addvalue(b); /* add result to accumulator */
};
@@ -1329,7 +1330,7 @@ const str_gsub = function(L) {
let ms = new MatchState(L);
let b = new lauxlib.luaL_Buffer();
lauxlib.luaL_argcheck(L, tr === lua.LUA_TNUMBER || tr === lua.LUA_TSTRING || tr === lua.LUA_TFUNCTION || tr === lua.LUA_TTABLE, 3,
- lua.to_luastring("string/function/table expected", true));
+ to_luastring("string/function/table expected", true));
lauxlib.luaL_buffinit(L, b);
if (anchor) {
p = p.subarray(1); lp--; /* skip anchor character */
@@ -1381,7 +1382,7 @@ const createmetatable = function(L) {
lua.lua_setmetatable(L, -2); /* set table as metatable for strings */
lua.lua_pop(L, 1); /* pop dummy string */
lua.lua_pushvalue(L, -2); /* get string library */
- lua.lua_setfield(L, -2, lua.to_luastring("__index", true)); /* metatable.__index = string */
+ lua.lua_setfield(L, -2, to_luastring("__index", true)); /* metatable.__index = string */
lua.lua_pop(L, 1); /* pop metatable */
};
diff --git a/src/ltablib.js b/src/ltablib.js
index 9998f3c..a24a275 100644
--- a/src/ltablib.js
+++ b/src/ltablib.js
@@ -5,7 +5,7 @@ const assert = require('assert');
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
const luaconf = require('./luaconf.js');
-
+const {to_luastring} = require("./fengaricore.js");
/*
** Operations that an object must define to mimic a table
@@ -29,9 +29,9 @@ const checktab = function(L, arg, what) {
if (lua.lua_type(L, arg) !== lua.LUA_TTABLE) { /* is it not a table? */
let n = 1;
if (lua.lua_getmetatable(L, arg) && /* must have metatable */
- (!(what & TAB_R) || checkfield(L, lua.to_luastring("__index", true), ++n)) &&
- (!(what & TAB_W) || checkfield(L, lua.to_luastring("__newindex", true), ++n)) &&
- (!(what & TAB_L) || checkfield(L, lua.to_luastring("__len", true), ++n))) {
+ (!(what & TAB_R) || checkfield(L, to_luastring("__index", true), ++n)) &&
+ (!(what & TAB_W) || checkfield(L, to_luastring("__newindex", true), ++n)) &&
+ (!(what & TAB_L) || checkfield(L, to_luastring("__len", true), ++n))) {
lua.lua_pop(L, n); /* pop metatable and tested metamethods */
}
else
@@ -47,7 +47,7 @@ const aux_getn = function(L, n, w) {
const addfield = function(L, b, i) {
lua.lua_geti(L, 1, i);
if (!lua.lua_isstring(L, -1))
- lauxlib.luaL_error(L, lua.to_luastring("invalid value (%s) at index %d in table for 'concat'"),
+ lauxlib.luaL_error(L, to_luastring("invalid value (%s) at index %d in table for 'concat'"),
lauxlib.luaL_typename(L, -1), i);
lauxlib.luaL_addvalue(b);
@@ -62,7 +62,7 @@ const tinsert = function(L) {
break;
case 3: {
pos = lauxlib.luaL_checkinteger(L, 2); /* 2nd argument is the position */
- lauxlib.luaL_argcheck(L, 1 <= pos && pos <= e, 2, lua.to_luastring("position out of bounds", true));
+ lauxlib.luaL_argcheck(L, 1 <= pos && pos <= e, 2, to_luastring("position out of bounds", true));
for (let i = e; i > pos; i--) { /* move up elements */
lua.lua_geti(L, 1, i - 1);
lua.lua_seti(L, 1, i); /* t[i] = t[i - 1] */
@@ -70,7 +70,7 @@ const tinsert = function(L) {
break;
}
default: {
- return lauxlib.luaL_error(L, lua.to_luastring("wrong number of arguments to 'insert'", true));
+ return lauxlib.luaL_error(L, to_luastring("wrong number of arguments to 'insert'", true));
}
}
@@ -82,7 +82,7 @@ const tremove = function(L) {
let size = aux_getn(L, 1, TAB_RW);
let pos = lauxlib.luaL_optinteger(L, 2, size);
if (pos !== size) /* validate 'pos' if given */
- lauxlib.luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, lua.to_luastring("position out of bounds", true));
+ lauxlib.luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, to_luastring("position out of bounds", true));
lua.lua_geti(L, 1, pos); /* result = t[pos] */
for (; pos < size; pos++) {
lua.lua_geti(L, 1, pos + 1);
@@ -107,9 +107,9 @@ const tmove = function(L) {
checktab(L, 1, TAB_R);
checktab(L, tt, TAB_W);
if (e >= f) { /* otherwise, nothing to move */
- lauxlib.luaL_argcheck(L, f > 0 || e < luaconf.LUA_MAXINTEGER + f, 3, lua.to_luastring("too many elements to move", true));
+ lauxlib.luaL_argcheck(L, f > 0 || e < luaconf.LUA_MAXINTEGER + f, 3, to_luastring("too many elements to move", true));
let n = e - f + 1; /* number of elements to move */
- lauxlib.luaL_argcheck(L, t <= luaconf.LUA_MAXINTEGER - n + 1, 4, lua.to_luastring("destination wrap around", true));
+ lauxlib.luaL_argcheck(L, t <= luaconf.LUA_MAXINTEGER - n + 1, 4, to_luastring("destination wrap around", true));
if (t > e || t <= f || (tt !== 1 && lua.lua_compare(L, 1, tt, lua.LUA_OPEQ) !== 1)) {
for (let i = 0; i < n; i++) {
@@ -130,7 +130,7 @@ const tmove = function(L) {
const tconcat = function(L) {
let last = aux_getn(L, 1, TAB_R);
- let sep = lauxlib.luaL_optlstring(L, 2, lua.to_luastring(""));
+ let sep = lauxlib.luaL_optlstring(L, 2, to_luastring(""));
let lsep = sep.length;
let i = lauxlib.luaL_optinteger(L, 3, 1);
last = lauxlib.luaL_optinteger(L, 4, last);
@@ -158,7 +158,7 @@ const pack = function(L) {
for (let i = n; i >= 1; i--) /* assign elements */
lua.lua_seti(L, 1, i);
lua.lua_pushinteger(L, n);
- lua.lua_setfield(L, 1, lua.to_luastring("n")); /* t.n = number of elements */
+ lua.lua_setfield(L, 1, to_luastring("n")); /* t.n = number of elements */
return 1; /* return table */
};
@@ -168,7 +168,7 @@ const unpack = function(L) {
if (i > e) return 0; /* empty range */
let n = e - i; /* number of elements minus 1 (avoid overflows) */
if (n >= Number.MAX_SAFE_INTEGER || !lua.lua_checkstack(L, ++n))
- return lauxlib.luaL_error(L, lua.to_luastring("too many results to unpack", true));
+ return lauxlib.luaL_error(L, to_luastring("too many results to unpack", true));
for (; i < e; i++) /* push arg[i..e - 1] (to avoid overflows) */
lua.lua_geti(L, 1, i);
lua.lua_geti(L, 1, e); /* push last element */
@@ -208,14 +208,14 @@ const partition = function(L, lo, up) {
/* next loop: repeat ++i while a[i] < P */
while (lua.lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) {
if (i == up - 1) /* a[i] < P but a[up - 1] == P ?? */
- lauxlib.luaL_error(L, lua.to_luastring("invalid order function for sorting"));
+ lauxlib.luaL_error(L, to_luastring("invalid order function for sorting"));
lua.lua_pop(L, 1); /* remove a[i] */
}
/* after the loop, a[i] >= P and a[lo .. i - 1] < P */
/* next loop: repeat --j while P < a[j] */
while (lua.lua_geti(L, 1, --j), sort_comp(L, -3, -1)) {
if (j < i) /* j < i but a[j] > P ?? */
- lauxlib.luaL_error(L, lua.to_luastring("invalid order function for sorting"));
+ lauxlib.luaL_error(L, to_luastring("invalid order function for sorting"));
lua.lua_pop(L, 1); /* remove a[j] */
}
/* after the loop, a[j] <= P and a[j + 1 .. up] >= P */
@@ -292,7 +292,7 @@ const auxsort = function(L, lo, up, rnd) {
const sort = function(L) {
let n = aux_getn(L, 1, TAB_RW);
if (n > 1) { /* non-trivial interval? */
- lauxlib.luaL_argcheck(L, n < luaconf.LUA_MAXINTEGER, 1, lua.to_luastring("array too big", true));
+ lauxlib.luaL_argcheck(L, n < luaconf.LUA_MAXINTEGER, 1, to_luastring("array too big", true));
if (!lua.lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
lauxlib.luaL_checktype(L, 2, lua.LUA_TFUNCTION); /* must be a function */
lua.lua_settop(L, 2); /* make sure there are two arguments */
diff --git a/src/lua.js b/src/lua.js
index a5b290c..6bbb1a0 100644
--- a/src/lua.js
+++ b/src/lua.js
@@ -6,14 +6,6 @@ const ldebug = require("./ldebug.js");
const ldo = require("./ldo.js");
const lstate = require("./lstate.js");
-module.exports.FENGARI_AUTHORS = defs.FENGARI_AUTHORS;
-module.exports.FENGARI_COPYRIGHT = defs.FENGARI_COPYRIGHT;
-module.exports.FENGARI_RELEASE = defs.FENGARI_RELEASE;
-module.exports.FENGARI_VERSION = defs.FENGARI_VERSION;
-module.exports.FENGARI_VERSION_MAJOR = defs.FENGARI_VERSION_MAJOR;
-module.exports.FENGARI_VERSION_MINOR = defs.FENGARI_VERSION_MINOR;
-module.exports.FENGARI_VERSION_NUM = defs.FENGARI_VERSION_NUM;
-module.exports.FENGARI_VERSION_RELEASE = defs.FENGARI_VERSION_RELEASE;
module.exports.LUA_AUTHORS = defs.LUA_AUTHORS;
module.exports.LUA_COPYRIGHT = defs.LUA_COPYRIGHT;
module.exports.LUA_ERRERR = defs.thread_status.LUA_ERRERR;
@@ -78,12 +70,6 @@ module.exports.LUA_VERSUFFIX = defs.LUA_VERSUFFIX;
module.exports.LUA_YIELD = defs.thread_status.LUA_YIELD;
module.exports.lua_Debug = defs.lua_Debug;
module.exports.lua_upvalueindex = defs.lua_upvalueindex;
-module.exports.luastring_eq = defs.luastring_eq;
-module.exports.luastring_indexOf = defs.luastring_indexOf;
-module.exports.luastring_of = defs.luastring_of;
-module.exports.to_jsstring = defs.to_jsstring;
-module.exports.to_luastring = defs.to_luastring;
-module.exports.to_uristring = defs.to_uristring;
module.exports.LUA_CDIR = defs.LUA_CDIR;
module.exports.LUA_CPATH_DEFAULT = defs.LUA_CPATH_DEFAULT;
module.exports.LUA_EXEC_DIR = defs.LUA_EXEC_DIR;
diff --git a/src/lutf8lib.js b/src/lutf8lib.js
index 58533cf..9cf7f14 100644
--- a/src/lutf8lib.js
+++ b/src/lutf8lib.js
@@ -2,6 +2,7 @@
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
+const {luastring_of, to_luastring} = require("./fengaricore.js");
const MAXUNICODE = 0x10FFFF;
@@ -59,8 +60,8 @@ const utflen = function(L) {
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, lua.to_luastring("initial position out of string"));
- lauxlib.luaL_argcheck(L, --posj < len, 3, lua.to_luastring("final position out of string"));
+ lauxlib.luaL_argcheck(L, 1 <= posi && --posi <= len, 2, to_luastring("initial position out of string"));
+ lauxlib.luaL_argcheck(L, --posj < len, 3, to_luastring("final position out of string"));
while (posi <= posj) {
let dec = utf8_decode(s, posi);
@@ -76,10 +77,10 @@ const utflen = function(L) {
return 1;
};
-const p_U = lua.to_luastring("%U");
+const p_U = to_luastring("%U");
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", true));
+ lauxlib.luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, to_luastring("value out of range", true));
lua.lua_pushfstring(L, p_U, code);
};
@@ -112,14 +113,14 @@ const byteoffset = function(L) {
let posi = n >= 0 ? 1 : s.length + 1;
posi = u_posrelat(lauxlib.luaL_optinteger(L, 3, posi), s.length);
- lauxlib.luaL_argcheck(L, 1 <= posi && --posi <= s.length, 3, lua.to_luastring("position out of range", true));
+ lauxlib.luaL_argcheck(L, 1 <= posi && --posi <= s.length, 3, to_luastring("position out of range", true));
if (n === 0) {
/* find beginning of current byte sequence */
while (posi > 0 && iscont(s[posi])) posi--;
} else {
if (iscont(s[posi]))
- lauxlib.luaL_error(L, lua.to_luastring("initial position is a continuation byte", true));
+ lauxlib.luaL_error(L, to_luastring("initial position is a continuation byte", true));
if (n < 0) {
while (n < 0 && posi > 0) { /* move back */
@@ -156,19 +157,19 @@ const codepoint = function(L) {
let posi = u_posrelat(lauxlib.luaL_optinteger(L, 2, 1), s.length);
let pose = u_posrelat(lauxlib.luaL_optinteger(L, 3, posi), s.length);
- lauxlib.luaL_argcheck(L, posi >= 1, 2, lua.to_luastring("out of range", true));
- lauxlib.luaL_argcheck(L, pose <= s.length, 3, lua.to_luastring("out of range", true));
+ lauxlib.luaL_argcheck(L, posi >= 1, 2, to_luastring("out of range", true));
+ lauxlib.luaL_argcheck(L, pose <= s.length, 3, to_luastring("out of range", true));
if (posi > pose) return 0; /* empty interval; return no values */
if (pose - posi >= Number.MAX_SAFE_INTEGER)
- return lauxlib.luaL_error(L, lua.to_luastring("string slice too long", true));
+ return lauxlib.luaL_error(L, to_luastring("string slice too long", true));
let n = (pose - posi) + 1;
- lauxlib.luaL_checkstack(L, n, lua.to_luastring("string slice too long", true));
+ lauxlib.luaL_checkstack(L, n, to_luastring("string slice too long", true));
n = 0;
for (posi -= 1; posi < pose;) {
let dec = utf8_decode(s, posi);
if (dec === null)
- return lauxlib.luaL_error(L, lua.to_luastring("invalid UTF-8 code", true));
+ return lauxlib.luaL_error(L, to_luastring("invalid UTF-8 code", true));
lua.lua_pushinteger(L, dec.code);
posi = dec.pos;
n++;
@@ -193,7 +194,7 @@ const iter_aux = function(L) {
else {
let dec = utf8_decode(s, n);
if (dec === null || iscont(s[dec.pos]))
- return lauxlib.luaL_error(L, lua.to_luastring("invalid UTF-8 code", true));
+ return lauxlib.luaL_error(L, to_luastring("invalid UTF-8 code", true));
lua.lua_pushinteger(L, n + 1);
lua.lua_pushinteger(L, dec.code);
return 2;
@@ -217,12 +218,12 @@ const funcs = {
};
/* pattern to match a single UTF-8 character */
-const UTF8PATT = lua.luastring_of(91, 0, 45, 127, 194, 45, 244, 93, 91, 128, 45, 191, 93, 42);
+const UTF8PATT = luastring_of(91, 0, 45, 127, 194, 45, 244, 93, 91, 128, 45, 191, 93, 42);
const luaopen_utf8 = function(L) {
lauxlib.luaL_newlib(L, funcs);
lua.lua_pushstring(L, UTF8PATT);
- lua.lua_setfield(L, -2, lua.to_luastring("charpattern", true));
+ lua.lua_setfield(L, -2, to_luastring("charpattern", true));
return 1;
};
diff --git a/tests/lapi.js b/tests/lapi.js
index a63ae66..56859d8 100644
--- a/tests/lapi.js
+++ b/tests/lapi.js
@@ -5,8 +5,9 @@ const test = require('tape');
const tests = require("./tests.js");
const toByteCode = tests.toByteCode;
-const lauxlib = require("../src/lauxlib.js");
const lua = require('../src/lua.js');
+const lauxlib = require("../src/lauxlib.js");
+const {to_luastring} = require("../src/fengaricore.js");
test('luaL_newstate, lua_pushnil, luaL_typename', function (t) {
let L;
@@ -369,7 +370,7 @@ test('lua_load with no chunkname', function (t) {
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
- lua.lua_load(L, function(L, s) { let r = s.code; s.code = null; return r; }, {code: lua.to_luastring("return 'hello'")}, null, null);
+ lua.lua_load(L, function(L, s) { let r = s.code; s.code = null; return r; }, {code: to_luastring("return 'hello'")}, null, null);
lua.lua_call(L, 0, 1);
}, "JS Lua program ran without error");
@@ -395,7 +396,7 @@ test('lua_load and lua_call it', function (t) {
L = lauxlib.luaL_newstate();
- lua.lua_load(L, function(L, s) { let r = s.bc; s.bc = null; return r; }, {bc: bc}, lua.to_luastring("test-lua_load"), lua.to_luastring("binary"));
+ lua.lua_load(L, function(L, s) { let r = s.bc; s.bc = null; return r; }, {bc: bc}, to_luastring("test-lua_load"), to_luastring("binary"));
lua.lua_call(L, 0, 1);
@@ -420,10 +421,10 @@ test('lua script reads js upvalues', function (t) {
L = lauxlib.luaL_newstate();
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_pushliteral(L, "hello");
- lua.lua_setglobal(L, lua.to_luastring("js"));
+ lua.lua_setglobal(L, to_luastring("js"));
lua.lua_call(L, 0, 1);
@@ -518,7 +519,7 @@ test('lua_atnativeerror', function(t) {
lua.lua_atnativeerror(L, function(L) {
let e = lua.lua_touserdata(L, 1);
t.strictEqual(e, errob);
- lua.lua_pushstring(L, lua.to_luastring("runtime error!"));
+ lua.lua_pushstring(L, to_luastring("runtime error!"));
return 1;
});
lua.lua_pushcfunction(L, function(L) {
@@ -532,7 +533,7 @@ test('lua_atnativeerror', function(t) {
lua.lua_atnativeerror(L, function(L) {
let e = lua.lua_touserdata(L, 1);
t.strictEqual(e, errob);
- lauxlib.luaL_error(L, lua.to_luastring("runtime error!"));
+ lauxlib.luaL_error(L, to_luastring("runtime error!"));
});
lua.lua_pushcfunction(L, function(L) {
throw errob;
diff --git a/tests/lauxlib.js b/tests/lauxlib.js
index d484edb..8d57ecb 100644
--- a/tests/lauxlib.js
+++ b/tests/lauxlib.js
@@ -1,9 +1,10 @@
"use strict";
-const test = require('tape');
+const test = require('tape');
-const lua = require('../src/lua.js');
-const lauxlib = require("../src/lauxlib.js");
+const lua = require('../src/lua.js');
+const lauxlib = require("../src/lauxlib.js");
+const {to_luastring} = require("../src/fengaricore.js");
test('luaL_ref, lua_rawgeti, luaL_unref, LUA_REGISTRYINDEX', function (t) {
let L;
@@ -12,7 +13,7 @@ test('luaL_ref, lua_rawgeti, luaL_unref, LUA_REGISTRYINDEX', function (t) {
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
- lua.lua_pushstring(L, lua.to_luastring("hello references!"));
+ lua.lua_pushstring(L, to_luastring("hello references!"));
let r = lauxlib.luaL_ref(L, lua.LUA_REGISTRYINDEX); // pops a value, stores it and returns a reference
lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, r); // pushes a value associated with the reference
diff --git a/tests/lbaselib.js b/tests/lbaselib.js
index 6558c1f..6bef0d8 100644
--- a/tests/lbaselib.js
+++ b/tests/lbaselib.js
@@ -5,6 +5,7 @@ const test = require('tape');
const lua = require('../src/lua.js');
const lauxlib = require('../src/lauxlib.js');
const lualib = require('../src/lualib.js');
+const {to_luastring} = require("../src/fengaricore.js");
test('print', function (t) {
@@ -20,7 +21,7 @@ test('print', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -52,7 +53,7 @@ test('setmetatable, getmetatable', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -95,7 +96,7 @@ test('rawequal', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -139,7 +140,7 @@ test('rawset, rawget', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -184,7 +185,7 @@ test('type', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -235,7 +236,7 @@ test('error', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -256,7 +257,7 @@ test('error, protected', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_pcall(L, 0, -1, 0);
@@ -286,7 +287,7 @@ test('pcall', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -320,7 +321,7 @@ test('xpcall', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -358,7 +359,7 @@ test('ipairs', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -385,7 +386,7 @@ test('select', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -428,7 +429,7 @@ test('tonumber', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -478,7 +479,7 @@ test('assert', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_pcall(L, 0, -1, 0);
@@ -504,7 +505,7 @@ test('rawlen', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -549,7 +550,7 @@ test('next', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -588,7 +589,7 @@ test('pairs', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -636,7 +637,7 @@ test('pairs with __pairs', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
diff --git a/tests/lcorolib.js b/tests/lcorolib.js
index e1868b2..42f9677 100644
--- a/tests/lcorolib.js
+++ b/tests/lcorolib.js
@@ -6,7 +6,7 @@ const lua = require('../src/lua.js');
const lauxlib = require('../src/lauxlib.js');
const lualib = require('../src/lualib.js');
const lstate = require('../src/lstate.js');
-
+const {to_luastring} = require("../src/fengaricore.js");
test('coroutine.create, coroutine.yield, coroutine.resume', function (t) {
let luaCode = `
@@ -29,7 +29,7 @@ test('coroutine.create, coroutine.yield, coroutine.resume', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -70,7 +70,7 @@ test('coroutine.status', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -109,7 +109,7 @@ test('coroutine.isyieldable', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -148,7 +148,7 @@ test('coroutine.running', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -187,7 +187,7 @@ test('coroutine.wrap', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
diff --git a/tests/ldblib.js b/tests/ldblib.js
index 209e60e..8a30e48 100644
--- a/tests/ldblib.js
+++ b/tests/ldblib.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../src/lua.js');
const lauxlib = require('../src/lauxlib.js');
const lualib = require('../src/lualib.js');
-
+const {to_luastring} = require("../src/fengaricore.js");
test('debug.sethook', function (t) {
let luaCode = `
@@ -32,7 +32,7 @@ test('debug.sethook', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -75,7 +75,7 @@ test('debug.gethook', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -87,7 +87,7 @@ test('debug.gethook', function (t) {
t.deepEqual(
lua.lua_typename(L, lua.lua_type(L, -3)),
- lua.to_luastring("function"),
+ to_luastring("function"),
"Correct element(s) on the stack"
);
@@ -134,7 +134,7 @@ test('debug.getlocal', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -181,7 +181,7 @@ test('debug.setlocal', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -235,7 +235,7 @@ test('debug.upvalueid', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -278,7 +278,7 @@ test('debug.upvaluejoin', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -322,8 +322,8 @@ test('debug.traceback (with a global)', function (t) {
lualib.luaL_openlibs(L);
- luaCode = lua.to_luastring(luaCode);
- lauxlib.luaL_loadbuffer(L, luaCode, luaCode.length, lua.to_luastring("traceback-test"));
+ luaCode = to_luastring(luaCode);
+ lauxlib.luaL_loadbuffer(L, luaCode, luaCode.length, to_luastring("traceback-test"));
}, "Lua program loaded without error");
@@ -379,8 +379,8 @@ test('debug.traceback (with a upvalue)', function (t) {
lualib.luaL_openlibs(L);
- luaCode = lua.to_luastring(luaCode);
- lauxlib.luaL_loadbuffer(L, luaCode, luaCode.length, lua.to_luastring("traceback-test"));
+ luaCode = to_luastring(luaCode);
+ lauxlib.luaL_loadbuffer(L, luaCode, luaCode.length, to_luastring("traceback-test"));
}, "Lua program loaded without error");
@@ -431,8 +431,8 @@ test('debug.getinfo', function (t) {
lualib.luaL_openlibs(L);
- luaCode = lua.to_luastring(luaCode);
- lauxlib.luaL_loadbuffer(L, luaCode, luaCode.length, lua.to_luastring("getinfo-test"));
+ luaCode = to_luastring(luaCode);
+ lauxlib.luaL_loadbuffer(L, luaCode, luaCode.length, to_luastring("getinfo-test"));
}, "Lua program loaded without error");
diff --git a/tests/ldebug.js b/tests/ldebug.js
index 857345e..49474e9 100644
--- a/tests/ldebug.js
+++ b/tests/ldebug.js
@@ -5,6 +5,7 @@ const test = require('tape');
const lua = require('../src/lua.js');
const lauxlib = require('../src/lauxlib.js');
const lualib = require('../src/lualib.js');
+const {to_luastring} = require("../src/fengaricore.js");
test('luaG_typeerror', function (t) {
let luaCode = `
@@ -20,7 +21,7 @@ test('luaG_typeerror', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_pcall(L, 0, -1, 0);
@@ -48,7 +49,7 @@ test('luaG_typeerror', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_pcall(L, 0, -1, 0);
@@ -75,7 +76,7 @@ test('luaG_typeerror', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_pcall(L, 0, -1, 0);
@@ -102,7 +103,7 @@ test('luaG_typeerror', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_pcall(L, 0, -1, 0);
@@ -128,7 +129,7 @@ test('luaG_concaterror', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_pcall(L, 0, -1, 0);
@@ -154,7 +155,7 @@ test('luaG_opinterror', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_pcall(L, 0, -1, 0);
@@ -180,7 +181,7 @@ test('luaG_tointerror', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_pcall(L, 0, -1, 0);
diff --git a/tests/lexparse.js b/tests/lexparse.js
index ca57605..57aaa22 100644
--- a/tests/lexparse.js
+++ b/tests/lexparse.js
@@ -7,7 +7,7 @@ const lauxlib = require('../src/lauxlib.js');
const lualib = require('../src/lualib.js');
const lapi = require('../src/lapi.js');
const lstring = require("../src/lstring.js");
-
+const {to_luastring} = require("../src/fengaricore.js");
// Roughly the same tests as test/lvm.js to cover all opcodes
test('LOADK, RETURN', function (t) {
@@ -27,10 +27,10 @@ test('LOADK, RETURN', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -67,10 +67,10 @@ test('MOVE', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -107,10 +107,10 @@ test('Binary op', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -147,10 +147,10 @@ test('Unary op, LOADBOOL', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -185,10 +185,10 @@ test('NEWTABLE', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -227,10 +227,10 @@ test('CALL', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -273,10 +273,10 @@ test('Multiple return', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -314,10 +314,10 @@ test('TAILCALL', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -355,10 +355,10 @@ test('VARARG', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -394,10 +394,10 @@ test('LE, JMP', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -433,10 +433,10 @@ test('LT', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -472,10 +472,10 @@ test('EQ', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -512,10 +512,10 @@ test('TESTSET (and)', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -552,10 +552,10 @@ test('TESTSET (or)', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -596,10 +596,10 @@ test('TEST (false)', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -639,10 +639,10 @@ test('FORPREP, FORLOOP (int)', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -682,10 +682,10 @@ test('FORPREP, FORLOOP (float)', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -724,10 +724,10 @@ test('SETTABLE, GETTABLE', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -744,7 +744,7 @@ test('SETTABLE, GETTABLE', function (t) {
);
t.strictEqual(
- lua.lua_topointer(L, -1).strong.get(lstring.luaS_hash(lua.to_luastring("two"))).value.jsstring(),
+ lua.lua_topointer(L, -1).strong.get(lstring.luaS_hash(to_luastring("two"))).value.jsstring(),
"world",
"Program output is correct"
);
@@ -775,10 +775,10 @@ test('SETUPVAL, GETUPVAL', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -817,10 +817,10 @@ test('SETTABUP, GETTABUP', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -837,7 +837,7 @@ test('SETTABUP, GETTABUP', function (t) {
);
t.strictEqual(
- lua.lua_topointer(L, -1).strong.get(lstring.luaS_hash(lua.to_luastring("two"))).value.jsstring(),
+ lua.lua_topointer(L, -1).strong.get(lstring.luaS_hash(to_luastring("two"))).value.jsstring(),
"world",
"Program output is correct"
);
@@ -867,10 +867,10 @@ test('SELF', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -906,10 +906,10 @@ test('SETLIST', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -949,10 +949,10 @@ test('Variable SETLIST', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -987,10 +987,10 @@ test('Long SETLIST', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -1042,10 +1042,10 @@ test('TFORCALL, TFORLOOP', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -1083,10 +1083,10 @@ test('LEN', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
@@ -1132,10 +1132,10 @@ test('CONCAT', function (t) {
let reader = function(L, data) {
let code = luaCode ? luaCode.trim() : null;
luaCode = null;
- return code ? lua.to_luastring(code) : null;
+ return code ? to_luastring(code) : null;
};
- lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+ lua.lua_load(L, reader, luaCode, to_luastring("test"), to_luastring("text"));
}, "Lua program loaded without error");
diff --git a/tests/lmathlib.js b/tests/lmathlib.js
index a06812c..b50c59c 100644
--- a/tests/lmathlib.js
+++ b/tests/lmathlib.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../src/lua.js');
const lauxlib = require('../src/lauxlib.js');
const lualib = require('../src/lualib.js');
-
+const {to_luastring} = require("../src/fengaricore.js");
test('math.abs, math.sin, math.cos, math.tan, math.asin, math.acos, math.atan', function (t) {
let luaCode = `
@@ -21,7 +21,7 @@ test('math.abs, math.sin, math.cos, math.tan, math.asin, math.acos, math.atan',
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -84,7 +84,7 @@ test('math.ceil, math.floor', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -117,7 +117,7 @@ test('math.deg, math.rad', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -150,7 +150,7 @@ test('math.log', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -189,7 +189,7 @@ test('math.exp', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -216,7 +216,7 @@ test('math.min, math.max', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -249,7 +249,7 @@ test('math.random', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -280,7 +280,7 @@ test('math.sqrt', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -307,7 +307,7 @@ test('math.tointeger', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -334,7 +334,7 @@ test('math.type', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -373,7 +373,7 @@ test('math.ult', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -400,7 +400,7 @@ test('math.fmod', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -427,7 +427,7 @@ test('math.modf', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
diff --git a/tests/load.js b/tests/load.js
index 49756a5..8555014 100644
--- a/tests/load.js
+++ b/tests/load.js
@@ -8,7 +8,7 @@ const toByteCode = tests.toByteCode;
const lua = require('../src/lua.js');
const lauxlib = require('../src/lauxlib.js');
const lualib = require('../src/lualib.js');
-
+const {to_luastring} = require("../src/fengaricore.js");
test('luaL_loadstring', function (t) {
let luaCode = `
@@ -24,7 +24,7 @@ test('luaL_loadstring', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -56,7 +56,7 @@ test('load', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -90,7 +90,7 @@ test('luaL_loadbuffer', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadbuffer(L, bc, null, lua.to_luastring("test"));
+ lauxlib.luaL_loadbuffer(L, bc, null, to_luastring("test"));
}, "Lua program loaded without error");
@@ -122,7 +122,7 @@ test('loadfile', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -154,7 +154,7 @@ test('loadfile (binary)', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -185,7 +185,7 @@ test('dofile', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/loadlib.js b/tests/loadlib.js
index c4c98ea..dba2a3a 100644
--- a/tests/loadlib.js
+++ b/tests/loadlib.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../src/lua.js');
const lauxlib = require('../src/lauxlib.js');
const lualib = require('../src/lualib.js');
-
+const {to_luastring} = require("../src/fengaricore.js");
test('require an existing module', function (t) {
let luaCode = `
@@ -20,7 +20,7 @@ test('require an existing module', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -50,7 +50,7 @@ test('require a file', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -81,7 +81,7 @@ test('package.loadlib', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -112,7 +112,7 @@ test('package.searchpath', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/loslib.js b/tests/loslib.js
index 83d6c81..904ca9c 100644
--- a/tests/loslib.js
+++ b/tests/loslib.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../src/lua.js');
const lauxlib = require('../src/lauxlib.js');
const lualib = require('../src/lualib.js');
-
+const {to_luastring} = require("../src/fengaricore.js");
test('os.time', function (t) {
let luaCode = `
@@ -20,7 +20,7 @@ test('os.time', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -54,7 +54,7 @@ test('os.time (with format)', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -87,7 +87,7 @@ test('os.difftime', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -121,7 +121,7 @@ test('os.date', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -152,7 +152,7 @@ test('os.getenv', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/lstrlib.js b/tests/lstrlib.js
index bdf68d8..50e9996 100644
--- a/tests/lstrlib.js
+++ b/tests/lstrlib.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../src/lua.js');
const lauxlib = require('../src/lauxlib.js');
const lualib = require('../src/lualib.js');
-
+const {to_luastring} = require("../src/fengaricore.js");
test('string.len', function (t) {
let luaCode = `
@@ -21,7 +21,7 @@ test('string.len', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -59,7 +59,7 @@ test('string.char', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -90,7 +90,7 @@ test('string.upper, string.lower', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -127,7 +127,7 @@ test('string.rep', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -158,7 +158,7 @@ test('string.reverse', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -189,7 +189,7 @@ test('string.byte', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -232,7 +232,7 @@ test('string.format', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -263,7 +263,7 @@ test('string.format', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -294,7 +294,7 @@ test('string.format', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -335,7 +335,7 @@ test('string.sub', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -434,7 +434,7 @@ test('string.dump', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode.trim()));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode.trim()));
}, "Lua program loaded without error");
@@ -444,7 +444,7 @@ test('string.dump', function (t) {
let str = lua.lua_tostring(L, -1);
- lua.lua_load(L, function(L, s) { let r = s.str; s.str = null; return r; }, {str: str}, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, function(L, s) { let r = s.str; s.str = null; return r; }, {str: str}, to_luastring("test"), to_luastring("binary"));
lua.lua_call(L, 0, -1);
@@ -474,7 +474,7 @@ test('string.pack/unpack/packsize', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -510,7 +510,7 @@ test('string.find without pattern', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -547,7 +547,7 @@ test('string.match', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -584,7 +584,7 @@ test('string.find', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -640,7 +640,7 @@ test('string.gmatch', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -689,7 +689,7 @@ test('string.gsub', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -726,7 +726,7 @@ test('string.gsub (number)', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -763,7 +763,7 @@ test('string.gsub (pattern)', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -802,7 +802,7 @@ test('string.gsub (function)', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -841,7 +841,7 @@ test('string.gsub (table)', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/ltablib.js b/tests/ltablib.js
index 2adf1fe..660ac85 100644
--- a/tests/ltablib.js
+++ b/tests/ltablib.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../src/lua.js');
const lauxlib = require('../src/lauxlib.js');
const lualib = require('../src/lualib.js');
-
+const {to_luastring} = require("../src/fengaricore.js");
const inttable2array = function(t) {
let a = [];
@@ -31,7 +31,7 @@ test('table.concat', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -58,7 +58,7 @@ test('table.pack', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -87,7 +87,7 @@ test('table.unpack', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -129,7 +129,7 @@ test('table.insert', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -161,7 +161,7 @@ test('table.remove', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -192,7 +192,7 @@ test('table.move', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -223,7 +223,7 @@ test('table.sort (<)', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
@@ -254,7 +254,7 @@ test('table.sort with cmp function', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
diff --git a/tests/ltm.js b/tests/ltm.js
index 0d9bc1a..156d63b 100644
--- a/tests/ltm.js
+++ b/tests/ltm.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../src/lua.js');
const lauxlib = require('../src/lauxlib.js');
const lualib = require('../src/lualib.js');
-
+const {to_luastring} = require("../src/fengaricore.js");
test('__index, __newindex: with actual table', function (t) {
let luaCode = `
@@ -20,7 +20,7 @@ test('__index, __newindex: with actual table', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, -1);
}, "Program executed without errors");
@@ -50,7 +50,7 @@ test('__newindex: with non table', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.throws(function () {
@@ -81,7 +81,7 @@ test('__index function in metatable', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
@@ -121,7 +121,7 @@ test('__newindex function in metatable', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -159,7 +159,7 @@ test('__index table in metatable', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -200,7 +200,7 @@ test('__newindex table in metatable', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -252,7 +252,7 @@ test('__index table with own metatable', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -303,7 +303,7 @@ test('__newindex table with own metatable', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -402,7 +402,7 @@ test('binary __xxx functions in metatable', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -452,7 +452,7 @@ test('__eq', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -488,7 +488,7 @@ test('__lt', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -524,7 +524,7 @@ test('__le', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -560,7 +560,7 @@ test('__le that uses __lt', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -600,7 +600,7 @@ test('__unm, __bnot', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -643,7 +643,7 @@ test('__len', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -680,7 +680,7 @@ test('__concat', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
@@ -717,7 +717,7 @@ test('__call', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
diff --git a/tests/lua.js b/tests/lua.js
index 82df6ff..0d9cf2e 100644
--- a/tests/lua.js
+++ b/tests/lua.js
@@ -5,8 +5,7 @@ const test = require('tape');
const lua = require('../src/lua.js');
const lauxlib = require('../src/lauxlib.js');
const lualib = require('../src/lualib.js');
-const lapi = require('../src/lapi.js');
-
+const {to_luastring} = require("../src/fengaricore.js");
// TODO: remove
test.skip('locals.lua', function (t) {
@@ -24,13 +23,13 @@ test.skip('locals.lua', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
});
@@ -51,13 +50,13 @@ test.skip('constructs.lua', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
});
@@ -76,13 +75,13 @@ test.skip('strings.lua', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
});
diff --git a/tests/lutf8lib.js b/tests/lutf8lib.js
index ae40d3c..baccceb 100644
--- a/tests/lutf8lib.js
+++ b/tests/lutf8lib.js
@@ -5,6 +5,7 @@ const test = require('tape');
const lua = require("../src/lua.js");
const lauxlib = require("../src/lauxlib.js");
const lualib = require("../src/lualib.js");
+const {to_luastring} = require("../src/fengaricore.js");
test('utf8.offset', function (t) {
let luaCode = `
@@ -19,7 +20,7 @@ test('utf8.offset', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -50,7 +51,7 @@ test('utf8.codepoint', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -93,7 +94,7 @@ test('utf8.char', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -124,7 +125,7 @@ test('utf8.len', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -160,7 +161,7 @@ test('utf8.codes', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/lvm.js b/tests/lvm.js
index 08c0c5e..7fba553 100644
--- a/tests/lvm.js
+++ b/tests/lvm.js
@@ -4,6 +4,7 @@ const test = require('tape');
const lua = require("../src/lua.js");
const lstring = require("../src/lstring.js");
+const {to_luastring} = require("../src/fengaricore.js");
const getState = require("./tests.js").getState;
@@ -459,7 +460,7 @@ test('SETTABLE, GETTABLE', function (t) {
);
t.deepEqual(
- L.stack[L.top - 1].value.strong.get(lstring.luaS_hash(lua.to_luastring("two"))).value.jsstring(), // "two"
+ L.stack[L.top - 1].value.strong.get(lstring.luaS_hash(to_luastring("two"))).value.jsstring(), // "two"
"world",
"Program output is correct"
);
@@ -518,7 +519,7 @@ test('SETTABUP, GETTABUP', function (t) {
);
t.deepEqual(
- L.stack[L.top - 1].value.strong.get(lstring.luaS_hash(lua.to_luastring("two"))).value.jsstring(), // "two"
+ L.stack[L.top - 1].value.strong.get(lstring.luaS_hash(to_luastring("two"))).value.jsstring(), // "two"
"world", // "world"
"Program output is correct"
);
diff --git a/tests/manual-tests/debug-cli.js b/tests/manual-tests/debug-cli.js
index 3feb981..dc49a0e 100755
--- a/tests/manual-tests/debug-cli.js
+++ b/tests/manual-tests/debug-cli.js
@@ -4,6 +4,7 @@
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
+const {to_luastring} = require("../../src/fengaricore.js");
let luaCode = `
a = "debug me"
@@ -14,6 +15,6 @@ L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);
-lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+lauxlib.luaL_loadstring(L, to_luastring(luaCode));
lua.lua_call(L, 0, 0);
diff --git a/tests/test-suite/api.js b/tests/test-suite/api.js
index 87f96b3..0061c88 100644
--- a/tests/test-suite/api.js
+++ b/tests/test-suite/api.js
@@ -5,6 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
+const {to_luastring} = require("../../src/fengaricore.js");
const ltests = require('./ltests.js');
@@ -32,7 +33,7 @@ test("[test-suite] api: registry", function (t) {
a = T.testC("pushvalue R; return 1")
assert(a == debug.getregistry())
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -43,7 +44,7 @@ test("[test-suite] api: registry", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -62,7 +63,7 @@ test("[test-suite] api: absindex", function (t) {
assert(T.testC("settop 10; absindex 1; return 1") == 1)
assert(T.testC("settop 10; absindex R; return 1") < -10)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -73,7 +74,7 @@ test("[test-suite] api: absindex", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -99,7 +100,7 @@ test("[test-suite] api: testing alignment", function (t) {
a,b,c = f()
assert(a == 2 and b == 3 and not c)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -110,7 +111,7 @@ test("[test-suite] api: testing alignment", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -164,7 +165,7 @@ test("[test-suite] api: test that all trues are equal", function (t) {
t = pack(T.testC("copy -3 -1; return *", 2, 3, 4, 5))
tcheck(t, {n=4,2,3,4,3})
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -175,7 +176,7 @@ test("[test-suite] api: test that all trues are equal", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -212,7 +213,7 @@ test("[test-suite] api: testing 'rotate'", function (t) {
tcheck(t, {10, 20, 30, 40})
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -223,7 +224,7 @@ test("[test-suite] api: testing 'rotate'", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -265,7 +266,7 @@ test("[test-suite] api: testing non-function message handlers", function (t) {
t = pack(T.testC("concat 5; return *", "alo", 2, 3, "joao", 12))
tcheck(t, {n=1,"alo23joao12"})
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -276,7 +277,7 @@ test("[test-suite] api: testing non-function message handlers", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -294,7 +295,7 @@ test("[test-suite] api: testing MULTRET", function (t) {
function (a,b) return 1,2,3,4,a,b end, "alo", "joao"))
tcheck(t, {n=6,1,2,3,4,"alo", "joao"})
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -305,7 +306,7 @@ test("[test-suite] api: testing MULTRET", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -327,7 +328,7 @@ test("[test-suite] api: test returning more results than fit in the caller stack
assert(b == "10")
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -338,7 +339,7 @@ test("[test-suite] api: test returning more results than fit in the caller stack
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -362,7 +363,7 @@ test("[test-suite] api: testing globals", function (t) {
]]}
assert(a[2] == 14 and a[3] == "a31" and a[4] == nil and _G.a == "a31")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -373,7 +374,7 @@ test("[test-suite] api: testing globals", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -420,7 +421,7 @@ test("[test-suite] api: testing arith", function (t) {
assert(T.testC("arith _; arith +; arith %; return 1", b, a, c)[1] ==
8 % (4 + (-3)*2))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -431,7 +432,7 @@ test("[test-suite] api: testing arith", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -448,7 +449,7 @@ test("[test-suite] api: errors in arithmetic", function (t) {
checkerr("divide by zero", T.testC, "arith \\\\", 10, 0)
checkerr("%%0", T.testC, "arith %", 10, 0)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -459,7 +460,7 @@ test("[test-suite] api: errors in arithmetic", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -481,7 +482,7 @@ test("[test-suite] api: testing lessthan and lessequal", function (t) {
assert(not T.testC("compare LT 2 -3, return 1", "4", "2", "2", "3", "2", "2"))
assert(not T.testC("compare LT -3 2, return 1", "3", "2", "2", "4", "2", "2"))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -492,7 +493,7 @@ test("[test-suite] api: testing lessthan and lessequal", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -524,7 +525,7 @@ test("[test-suite] api: non-valid indices produce false", function (t) {
a,b = T.testC("compare LE 5 -6, return 2", a1, 2, 2, a1, 2, 20)
assert(a == 20 and b == true)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -535,7 +536,7 @@ test("[test-suite] api: non-valid indices produce false", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -575,7 +576,7 @@ test("[test-suite] api: testing length", function (t) {
]], t)
assert(a == print and c == 1)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -586,7 +587,7 @@ test("[test-suite] api: testing length", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -617,7 +618,7 @@ test("[test-suite] api: testing __concat", function (t) {
-- concat with 1 element
assert(T.testC("concat 1; return 1", "xuxu") == "xuxu")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -628,7 +629,7 @@ test("[test-suite] api: testing __concat", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -672,7 +673,7 @@ test("[test-suite] api: testing lua_is", function (t) {
assert(count(io.stdin) == 1)
assert(count(nil, 15) == 100)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -683,7 +684,7 @@ test("[test-suite] api: testing lua_is", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -733,7 +734,7 @@ test("[test-suite] api: testing lua_to...", function (t) {
a = to("tocfunction", math.deg)
assert(a(3) == math.deg(3) and a == math.deg)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -744,7 +745,7 @@ test("[test-suite] api: testing lua_to...", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -771,7 +772,7 @@ test("[test-suite] api: testing panic function", function (t) {
-- "argerror" without frames
assert(T.checkpanic("loadstring 4") ==
"bad argument #4 (string expected, got no value)")
-
+
--[[ TODO: T.totalmem
-- memory error
@@ -792,7 +793,7 @@ test("[test-suite] api: testing panic function", function (t) {
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -803,7 +804,7 @@ test("[test-suite] api: testing panic function", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -848,7 +849,7 @@ test("[test-suite] api: testing deep JS stack", { skip: true }, function (t) {
assert(next(t) == nil)
prog, g, t = nil
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -859,7 +860,7 @@ test("[test-suite] api: testing deep JS stack", { skip: true }, function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -891,7 +892,7 @@ test("[test-suite] api: testing errors", function (t) {
check3("%.", T.testC("loadfile 2; return *", "."))
check3("xxxx", T.testC("loadfile 2; return *", "xxxx"))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -902,7 +903,7 @@ test("[test-suite] api: testing errors", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -929,7 +930,7 @@ test("[test-suite] api: test errors in non protected threads", { skip: true }, f
checkerrnopro("getglobal 'f'; call 0 0;", "stack overflow")
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -940,7 +941,7 @@ test("[test-suite] api: test errors in non protected threads", { skip: true }, f
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -992,7 +993,7 @@ test("[test-suite] api: testing table access", function (t) {
assert(a[b] == 19)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1003,7 +1004,7 @@ test("[test-suite] api: testing table access", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1032,7 +1033,7 @@ test("[test-suite] api: testing getfield/setfield with long keys", function (t)
_012345678901234567890123456789012345678901234567890123456789 = nil
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1043,7 +1044,7 @@ test("[test-suite] api: testing getfield/setfield with long keys", function (t)
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1066,7 +1067,7 @@ test("[test-suite] api: testing next", function (t) {
t = pack(T.testC("next; pop 1; next; return *", a, nil))
tcheck(t, {n=1,a})
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1077,7 +1078,7 @@ test("[test-suite] api: testing next", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1106,7 +1107,7 @@ test("[test-suite] api: testing upvalues", function (t) {
-- T.checkmemory()
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1117,7 +1118,7 @@ test("[test-suite] api: testing upvalues", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1142,7 +1143,7 @@ test("[test-suite] api: testing absent upvalues from JS-function pointers", func
T.upvalue(f, 2, "xuxu")
assert(T.upvalue(f, 2) == "xuxu")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1153,7 +1154,7 @@ test("[test-suite] api: testing absent upvalues from JS-function pointers", func
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1179,7 +1180,7 @@ test("[test-suite] api: large closures", function (t) {
assert(not A("isnil U256; return 1"))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1190,7 +1191,7 @@ test("[test-suite] api: large closures", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1226,7 +1227,7 @@ test("[test-suite] api: testing get/setuservalue", function (t) {
-- collectgarbage() -- number should not be a problem for collector
assert(debug.getuservalue(b) == 134)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1237,7 +1238,7 @@ test("[test-suite] api: testing get/setuservalue", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1257,7 +1258,7 @@ test("[test-suite] api: testing get/setuservalue", { skip: true }, function (t)
T.gcstate("pause") -- complete collection
assert(debug.getuservalue(b).x == 100) -- uvalue should be there
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1268,7 +1269,7 @@ test("[test-suite] api: testing get/setuservalue", { skip: true }, function (t)
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1294,7 +1295,7 @@ test("[test-suite] api: long chain of userdata", { skip: true }, function (t) {
assert(debug.getuservalue(b).x == 100)
b = nil
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1305,7 +1306,7 @@ test("[test-suite] api: long chain of userdata", { skip: true }, function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1366,7 +1367,7 @@ test("[test-suite] api: reuse of references", { skip: true }, function (t) {
assert(type(T.getref(a)) == 'table')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1377,7 +1378,7 @@ test("[test-suite] api: reuse of references", { skip: true }, function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1494,7 +1495,7 @@ test("[test-suite] api: collect in cl the `val' of all collected userdata", { sk
collectgarbage()
assert(#cl == 1 and cl[1] == x) -- old 'x' must be collected
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1505,7 +1506,7 @@ test("[test-suite] api: collect in cl the `val' of all collected userdata", { sk
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1550,7 +1551,7 @@ test("[test-suite] api: test whether udate collection frees memory in the right
collectgarbage("restart")
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1561,7 +1562,7 @@ test("[test-suite] api: test whether udate collection frees memory in the right
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1582,7 +1583,7 @@ test("[test-suite] api: testing lua_equal", function (t) {
assert(not T.testC("compare EQ 2 3; return 1"))
assert(not T.testC("compare EQ 2 3; return 1", 3))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1593,7 +1594,7 @@ test("[test-suite] api: testing lua_equal", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1624,7 +1625,7 @@ test("[test-suite] api: testing lua_equal with fallbacks", function (t) {
assert(f(10) ~= f(10))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1635,7 +1636,7 @@ test("[test-suite] api: testing lua_equal with fallbacks", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1670,7 +1671,7 @@ test("[test-suite] api: testing changing hooks during hooks", function (t) {
assert(t[5] == "line" and t[6] == line + 2)
assert(t[7] == nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1681,7 +1682,7 @@ test("[test-suite] api: testing changing hooks during hooks", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1722,7 +1723,7 @@ test("[test-suite] api: testing errors during GC", { skip: true }, function (t)
assert(A == 10) -- number of normal collections
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1733,7 +1734,7 @@ test("[test-suite] api: testing errors during GC", { skip: true }, function (t)
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1757,7 +1758,7 @@ test("[test-suite] api: test for userdata vals", function (t) {
assert(type(tostring(a[1])) == "string")
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1768,7 +1769,7 @@ test("[test-suite] api: test for userdata vals", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1828,7 +1829,7 @@ test("[test-suite] api: testing multiple states", function (t) {
T.closestate(L1)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1839,7 +1840,7 @@ test("[test-suite] api: testing multiple states", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1859,7 +1860,7 @@ test("[test-suite] api: testing memory limits", { skip: true }, function (t) {
checkerr("not enough memory", load"local a={}; for i=1,100000 do a[i]=i end")
T.totalmem(0) -- restore high limit
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1870,7 +1871,7 @@ test("[test-suite] api: testing memory limits", { skip: true }, function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1914,7 +1915,7 @@ test("[test-suite] api: testing memory errors when creating a new state", { skip
b = testamem("state creation", T.newstate)
T.closestate(b); -- close new state
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1925,7 +1926,7 @@ test("[test-suite] api: testing memory errors when creating a new state", { skip
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + memprefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode));
}, "Lua program loaded without error");
@@ -1952,7 +1953,7 @@ test("[test-suite] api: get main thread from registry (at index LUA_RIDX_MAINTHR
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + memprefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode));
}, "Lua program loaded without error");
@@ -1980,7 +1981,7 @@ test("[test-suite] api: test thread creation after stressing GC", { skip: true }
return T.doonnewstack("x=1") == 0 -- try to create thread
end)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1991,7 +1992,7 @@ test("[test-suite] api: test thread creation after stressing GC", { skip: true }
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + memprefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode));
}, "Lua program loaded without error");
@@ -2009,7 +2010,7 @@ test("[test-suite] api: testing memory x compiler", { skip: true }, function (t)
return load("x=1") -- try to do load a string
end)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -2020,7 +2021,7 @@ test("[test-suite] api: testing memory x compiler", { skip: true }, function (t)
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + memprefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode));
}, "Lua program loaded without error");
@@ -2055,7 +2056,7 @@ test("[test-suite] api: testing memory x dofile", { skip: true }, function (t) {
assert(os.remove(t))
assert(_G.a == "aaax")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -2066,7 +2067,7 @@ test("[test-suite] api: testing memory x dofile", { skip: true }, function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + memprefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode));
}, "Lua program loaded without error");
@@ -2138,7 +2139,7 @@ test("[test-suite] api: other generic tests", { skip: true }, function (t) {
end)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -2149,7 +2150,7 @@ test("[test-suite] api: other generic tests", { skip: true }, function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + memprefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode));
}, "Lua program loaded without error");
@@ -2175,7 +2176,7 @@ test("[test-suite] api: testing some auxlib functions", function (t) {
assert(gsub("...", ".", "/.") == "/././.")
assert(gsub("...", "...", "") == "")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -2186,7 +2187,7 @@ test("[test-suite] api: testing some auxlib functions", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -2247,7 +2248,7 @@ test("[test-suite] api: testing luaL_newmetatable", function (t) {
r.xuxu = nil; r.xuxu1 = nil
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -2258,7 +2259,7 @@ test("[test-suite] api: testing luaL_newmetatable", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/attrib.js b/tests/test-suite/attrib.js
index fcd3271..7445a5e 100644
--- a/tests/test-suite/attrib.js
+++ b/tests/test-suite/attrib.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
test("[test-suite] attrib: testing require", function (t) {
let luaCode = `
@@ -53,7 +53,7 @@ test("[test-suite] attrib: testing require", function (t) {
package.path = oldpath
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -62,7 +62,7 @@ test("[test-suite] attrib: testing require", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -169,7 +169,7 @@ test("[test-suite] attrib: testing assignments, logical operators, and construct
a[1], f(a)[2], b, c = {['alo']=assert}, 10, a[1], a[f], 6, 10, 23, f(a), 2
a[1].alo(a[2]==10 and b==10 and c==print)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -178,7 +178,7 @@ test("[test-suite] attrib: testing assignments, logical operators, and construct
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -245,7 +245,7 @@ test("[test-suite] attrib: test of large float/integer indices ", function (t) {
assert(a[maxintF] == 20 and a[maxintF - 1.0] == 11 and
a[-maxintF] == 22 and a[-maxintF + 1.0] == 13)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -254,7 +254,7 @@ test("[test-suite] attrib: test of large float/integer indices ", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -277,7 +277,7 @@ test("[test-suite] attrib: test conflicts in multiple assignment", function (t)
b[3] == 1)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -286,7 +286,7 @@ test("[test-suite] attrib: test conflicts in multiple assignment", function (t)
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -315,7 +315,7 @@ test("[test-suite] attrib: repeat test with upvalues", function (t) {
assert(t[1] == 10)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -324,7 +324,7 @@ test("[test-suite] attrib: repeat test with upvalues", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -351,7 +351,7 @@ test("[test-suite] attrib: bug in 5.2 beta", function (t) {
local a, b = foo()()
assert(a == 3 and b == 14)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -360,7 +360,7 @@ test("[test-suite] attrib: bug in 5.2 beta", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/bitwise.js b/tests/test-suite/bitwise.js
index df57f15..17e3c84 100644
--- a/tests/test-suite/bitwise.js
+++ b/tests/test-suite/bitwise.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
const prefix = `
package.preload.bit32 = function () --{
@@ -176,7 +176,7 @@ test("[test-suite] bitwise: testing bitwise operations", function (t) {
-- embedded zeros
assert(not pcall(function () return "0xffffffffffffffff\\0" | 0 end))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -185,7 +185,7 @@ test("[test-suite] bitwise: testing bitwise operations", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -208,7 +208,7 @@ test("[test-suite] bitwise: testing bitwise library", function (t) {
assert(bit32.band() == bit32.band(0xffffffff))
assert(bit32.band(1,2) == 0)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -217,7 +217,7 @@ test("[test-suite] bitwise: testing bitwise library", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -285,7 +285,7 @@ test("[test-suite] bitwise: out-of-range numbers", function (t) {
assert(0x12345678 >> 32 == 0)
assert(0x12345678 >> -32 == 0x1234567800000000)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -294,7 +294,7 @@ test("[test-suite] bitwise: out-of-range numbers", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -340,7 +340,7 @@ test("[test-suite] bitwise: some special cases", function (t) {
assert(bit32.rshift(bit32.rshift(b, 4), -4) == bit32.band(b, bit32.bnot(0xf)))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -349,7 +349,7 @@ test("[test-suite] bitwise: some special cases", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -379,7 +379,7 @@ test("[test-suite] bitwise: for this test, use at most 24 bits (mantissa of a si
assert(not pcall(bit32.lshift, 45, print))
assert(not pcall(bit32.rshift, 45, print))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -388,7 +388,7 @@ test("[test-suite] bitwise: for this test, use at most 24 bits (mantissa of a si
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -422,7 +422,7 @@ test("[test-suite] bitwise: testing extract/replace", function (t) {
assert(bit32.replace(-1, 0, 31) == (1 << 31) - 1)
assert(bit32.replace(-1, 0, 1, 2) == (1 << 32) - 7)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -431,7 +431,7 @@ test("[test-suite] bitwise: testing extract/replace", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -449,7 +449,7 @@ test("[test-suite] bitwise: testing conversion of floats", function (t) {
assert(bit32.bor(3.0) == 3)
assert(bit32.bor(-4.0) == 0xfffffffc)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -458,7 +458,7 @@ test("[test-suite] bitwise: testing conversion of floats", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -480,7 +480,7 @@ test("[test-suite] bitwise: large floats and large-enough integers?", function (
assert(bit32.bor(-2.0^48 - 6.0) == 0xfffffffa)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -489,7 +489,7 @@ test("[test-suite] bitwise: large floats and large-enough integers?", function (
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/calls.js b/tests/test-suite/calls.js
index fdd5eac..2044e5c 100644
--- a/tests/test-suite/calls.js
+++ b/tests/test-suite/calls.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
test("[test-suite] calls: test 'type'", function (t) {
let luaCode = `
@@ -22,7 +22,7 @@ test("[test-suite] calls: test 'type'", function (t) {
assert(type(f) == 'function')
assert(not pcall(type))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -31,7 +31,7 @@ test("[test-suite] calls: test 'type'", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -56,11 +56,11 @@ test("[test-suite] calls: test error in 'print'", function (t) {
_ENV.tostring = function () return {} end
local st, msg = pcall(print, 1)
assert(st == false and string.find(msg, "must return a string"))
-
+
_ENV.tostring = tostring
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -69,7 +69,7 @@ test("[test-suite] calls: test error in 'print'", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -96,7 +96,7 @@ test("[test-suite] calls: testing local-function recursion", function (t) {
end
assert(fact == false)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -105,7 +105,7 @@ test("[test-suite] calls: testing local-function recursion", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -203,7 +203,7 @@ test("[test-suite] calls: testing declarations", function (t) {
(function (x) a=x end)(23)
assert(a == 23 and (function (x) return x*2 end)(20) == 40)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -212,7 +212,7 @@ test("[test-suite] calls: testing declarations", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -261,7 +261,7 @@ test("[test-suite] calls: testing closures", function (t) {
Z, F, f = nil
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -270,7 +270,7 @@ test("[test-suite] calls: testing closures", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -319,7 +319,7 @@ test("[test-suite] calls: testing multiple returns", function (t) {
a = ret2{ unlpack{1,2,3}, unlpack{3,2,1}, unlpack{"a", "b"}}
assert(a[1] == 1 and a[2] == 3 and a[3] == "a" and a[4] == "b")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -328,7 +328,7 @@ test("[test-suite] calls: testing multiple returns", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -348,7 +348,7 @@ test("[test-suite] calls: testing calls with 'incorrect' arguments", function (t
assert(math.sin(1,2) == math.sin(1))
table.sort({10,9,8,4,19,23,0,0}, function (a,b) return a<b end, "extra arg")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -357,7 +357,7 @@ test("[test-suite] calls: testing calls with 'incorrect' arguments", function (t
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -420,7 +420,7 @@ test("[test-suite] calls: test for generic load", function (t) {
cannotload("unexpected symbol", load("*a = 123"))
cannotload("hhi", load(function () error("hhi") end))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -429,7 +429,7 @@ test("[test-suite] calls: test for generic load", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -446,7 +446,7 @@ test("[test-suite] calls: any value is valid for _ENV", function (t) {
let luaCode = `
assert(load("return _ENV", nil, nil, 123)() == 123)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -455,7 +455,7 @@ test("[test-suite] calls: any value is valid for _ENV", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -483,7 +483,7 @@ test("[test-suite] calls: load when _ENV is not first upvalue", function (t) {
assert(assert(load("return XX + ...", nil, nil, {XX = 13}))(4) == 17)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -492,7 +492,7 @@ test("[test-suite] calls: load when _ENV is not first upvalue", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -528,7 +528,7 @@ test("[test-suite] calls: test generic load with nested functions", function (t)
a = assert(load(read1(x)))
assert(a()(2)(3)(10) == 15)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -537,7 +537,7 @@ test("[test-suite] calls: test generic load with nested functions", function (t)
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -568,7 +568,7 @@ test("[test-suite] calls: test for dump/undump with upvalues", function (t) {
x("set")
assert(x() == 24)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -577,7 +577,7 @@ test("[test-suite] calls: test for dump/undump with upvalues", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -615,7 +615,7 @@ test("[test-suite] calls: test for dump/undump with many upvalues", function (t)
assert(f() == 10 * nup)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -624,7 +624,7 @@ test("[test-suite] calls: test for dump/undump with many upvalues", function (t)
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -647,7 +647,7 @@ test("[test-suite] calls: test for long method names", function (t) {
assert(t:_012345678901234567890123456789012345678901234567890123456789() == 1)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -656,7 +656,7 @@ test("[test-suite] calls: test for long method names", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -675,7 +675,7 @@ test("[test-suite] calls: test for bug in parameter adjustment", function (t) {
assert((function () local a; return a end)(4) == nil)
assert((function (a) return a end)() == nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -684,7 +684,7 @@ test("[test-suite] calls: test for bug in parameter adjustment", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -734,7 +734,7 @@ test("[test-suite] calls: testing binary chunks", function (t) {
assert(assert(load(c))() == 10)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -743,7 +743,7 @@ test("[test-suite] calls: testing binary chunks", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/closure.js b/tests/test-suite/closure.js
index 464a5b5..79a2226 100644
--- a/tests/test-suite/closure.js
+++ b/tests/test-suite/closure.js
@@ -5,6 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
+const {to_luastring} = require("../../src/fengaricore.js");
test("[test-suite] closure: testing equality", function (t) {
let luaCode = `
@@ -20,7 +21,7 @@ test("[test-suite] closure: testing equality", function (t) {
end
assert(f() == f())
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -29,7 +30,7 @@ test("[test-suite] closure: testing equality", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -73,7 +74,7 @@ test("[test-suite] closure: testing closures with 'for' control variable", funct
r,s = a[2].get()
assert(r == "a" and s == "b")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -82,7 +83,7 @@ test("[test-suite] closure: testing closures with 'for' control variable", funct
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -113,7 +114,7 @@ test("[test-suite] closure: testing closures with 'for' control variable x break
assert(({f()})[1] == 1)
assert(({f()})[2] == "a")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -122,7 +123,7 @@ test("[test-suite] closure: testing closures with 'for' control variable x break
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -169,7 +170,7 @@ test("[test-suite] closure: testing closure x break x return x errors", function
assert(b('get') == 'xuxu')
b('set', 10); assert(b('get') == 14)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -178,7 +179,7 @@ test("[test-suite] closure: testing closure x break x return x errors", function
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -204,7 +205,7 @@ test("[test-suite] closure: testing multi-level closure", function (t) {
w = 1.345
assert(y(20)(30) == 60+w)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -213,7 +214,7 @@ test("[test-suite] closure: testing multi-level closure", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -236,7 +237,7 @@ test("[test-suite] closure: testing closures x repeat-until", function (t) {
until i > 10 or a[i]() ~= x
assert(i == 11 and a[1]() == 1 and a[3]() == 3 and i == 4)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -245,7 +246,7 @@ test("[test-suite] closure: testing closures x repeat-until", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -289,7 +290,7 @@ test("[test-suite] closure: testing closures created in 'then' and 'else' parts
assert(a[i](i * 10) == i % 3 and a[i]() == i * 10)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -298,7 +299,7 @@ test("[test-suite] closure: testing closures created in 'then' and 'else' parts
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -321,7 +322,7 @@ test("[test-suite] closure: test for correctly closing upvalues in tail calls of
end
t()
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -330,7 +331,7 @@ test("[test-suite] closure: test for correctly closing upvalues in tail calls of
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/code.js b/tests/test-suite/code.js
index 26ca021..57c97cb 100644
--- a/tests/test-suite/code.js
+++ b/tests/test-suite/code.js
@@ -5,10 +5,10 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
+const {to_luastring} = require("../../src/fengaricore.js");
const ltests = require('./ltests.js');
-
test("[test-suite] code: testing reuse in constant table", function (t) {
let luaCode = `
local function checkKlist (func, list)
@@ -31,7 +31,7 @@ test("[test-suite] code: testing reuse in constant table", function (t) {
checkKlist(foo, {3, 0, 0.0, 3.78/4, -3.78/4, -3.79/4, 3.0})
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -42,7 +42,7 @@ test("[test-suite] code: testing reuse in constant table", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -83,7 +83,7 @@ test("[test-suite] code: some basic instructions", function (t) {
(function () end){f()}
end, 'CLOSURE', 'NEWTABLE', 'GETTABUP', 'CALL', 'SETLIST', 'CALL', 'RETURN')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -94,7 +94,7 @@ test("[test-suite] code: some basic instructions", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -126,7 +126,7 @@ test("[test-suite] code: sequence of LOADNILs", function (t) {
assert(a == nil and b == nil and c == nil and d == nil)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -137,7 +137,7 @@ test("[test-suite] code: sequence of LOADNILs", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -153,7 +153,7 @@ test("[test-suite] code: single return", function (t) {
let luaCode = `
check (function (a,b,c) return a end, 'RETURN')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -164,7 +164,7 @@ test("[test-suite] code: single return", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -187,7 +187,7 @@ test("[test-suite] code: infinite loops", function (t) {
check(function () repeat local x = 1 until true end,
'LOADK', 'RETURN')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -198,7 +198,7 @@ test("[test-suite] code: infinite loops", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -215,7 +215,7 @@ test("[test-suite] code: concat optimization", function (t) {
check(function (a,b,c,d) return a..b..c..d end,
'MOVE', 'MOVE', 'MOVE', 'MOVE', 'CONCAT', 'RETURN')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -226,7 +226,7 @@ test("[test-suite] code: concat optimization", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -245,7 +245,7 @@ test("[test-suite] code: not", function (t) {
check(function () return not not true end, 'LOADBOOL', 'RETURN')
check(function () return not not 1 end, 'LOADBOOL', 'RETURN')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -256,7 +256,7 @@ test("[test-suite] code: not", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -280,7 +280,7 @@ test("[test-suite] code: direct access to locals", function (t) {
'DIV', 'ADD', 'GETTABLE', 'SUB', 'GETTABLE', 'POW',
'UNM', 'SETTABLE', 'SETTABLE', 'RETURN')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -291,7 +291,7 @@ test("[test-suite] code: direct access to locals", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -327,7 +327,7 @@ test("[test-suite] code: direct access to constants", function (t) {
end,
'LOADNIL', 'SETTABLE', 'RETURN')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -338,7 +338,7 @@ test("[test-suite] code: direct access to constants", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -373,7 +373,7 @@ test("[test-suite] code: constant folding", function (t) {
checkK(function () return ~~-100024.0 end, -100024)
checkK(function () return ((100 << 6) << -4) >> 2 end, 100)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -384,7 +384,7 @@ test("[test-suite] code: constant folding", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -403,7 +403,7 @@ test("[test-suite] code: no folding", function (t) {
check(function () return 0%0 end, 'MOD', 'RETURN')
check(function () return -4//0 end, 'IDIV', 'RETURN')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -414,7 +414,7 @@ test("[test-suite] code: no folding", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -437,7 +437,7 @@ test("[test-suite] code: bug in constant folding for 5.1", function (t) {
b[a], a = c, b
a, b = c, a
a = a
- end,
+ end,
'LOADNIL',
'MOVE', 'MOVE', 'SETTABLE',
'MOVE', 'MOVE', 'MOVE', 'SETTABLE',
@@ -445,7 +445,7 @@ test("[test-suite] code: bug in constant folding for 5.1", function (t) {
-- no code for a = a
'RETURN')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -456,7 +456,7 @@ test("[test-suite] code: bug in constant folding for 5.1", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -482,7 +482,7 @@ test("[test-suite] code: x == nil , x ~= nil", function (t) {
checkequal(function (l) local a; return 0 <= a and a <= l end,
function (l) local a; return not (not(a >= 0) or not(a <= l)) end)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -493,7 +493,7 @@ test("[test-suite] code: x == nil , x ~= nil", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -515,7 +515,7 @@ test("[test-suite] code: if-goto optimizations", function (t) {
else goto l3
end
end
- ::l1:: ::l2:: ::l3:: ::l4::
+ ::l1:: ::l2:: ::l3:: ::l4::
end, 'EQ', 'JMP', 'EQ', 'JMP', 'EQ', 'JMP', 'EQ', 'JMP', 'JMP', 'RETURN')
checkequal(
@@ -529,7 +529,7 @@ test("[test-suite] code: if-goto optimizations", function (t) {
function (a) while true do if not(a < 10) then break end; a = a + 1; end end
)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -540,7 +540,7 @@ test("[test-suite] code: if-goto optimizations", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/constructs.js b/tests/test-suite/constructs.js
index 89bcce7..93bbf1a 100644
--- a/tests/test-suite/constructs.js
+++ b/tests/test-suite/constructs.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
const checkload = `
local function checkload (s, msg)
@@ -28,7 +28,7 @@ test('[test-suite] constructs: testing semicolons', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkload + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode));
}, "Lua program loaded without error");
@@ -54,7 +54,7 @@ test('[test-suite] constructs: invalid operations should not raise errors when n
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkload + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode));
}, "Lua program loaded without error");
@@ -119,7 +119,7 @@ test('[test-suite] constructs: testing priorities', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkload + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode));
}, "Lua program loaded without error");
@@ -305,7 +305,7 @@ test('[test-suite] constructs: silly loops', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkload + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode));
}, "Lua program loaded without error");
@@ -392,7 +392,7 @@ test.skip('[test-suite] constructs: huge loops, upvalue', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkload + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode));
}, "Lua program loaded without error");
@@ -428,7 +428,7 @@ test("[test-suite] constructs: testing some syntax errors (chosen through 'gcov'
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkload + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/coroutine.js b/tests/test-suite/coroutine.js
index b85f0de..969c65e 100644
--- a/tests/test-suite/coroutine.js
+++ b/tests/test-suite/coroutine.js
@@ -5,6 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
+const {to_luastring} = require("../../src/fengaricore.js");
const ltests = require('./ltests.js');
@@ -64,7 +65,7 @@ test("[test-suite] coroutine: is main thread", function (t) {
assert(not coroutine.isyieldable())
assert(not pcall(coroutine.yield))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -73,7 +74,7 @@ test("[test-suite] coroutine: is main thread", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -91,7 +92,7 @@ test("[test-suite] coroutine: trivial errors", function (t) {
assert(not pcall(coroutine.resume, 0))
assert(not pcall(coroutine.status, 0))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -100,7 +101,7 @@ test("[test-suite] coroutine: trivial errors", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -158,7 +159,7 @@ test("[test-suite] coroutine: tests for multiple yield/resume arguments", functi
s, a = coroutine.resume(f, "xuxu")
assert(not s and string.find(a, "dead") and coroutine.status(f) == "dead")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -167,7 +168,7 @@ test("[test-suite] coroutine: tests for multiple yield/resume arguments", functi
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -192,7 +193,7 @@ test("[test-suite] coroutine: yields in tail calls", function (t) {
for i=1,10 do _G.x = i; assert(f(i) == i) end
_G.x = 'xuxu'; assert(f('xuxu') == 'a')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -201,7 +202,7 @@ test("[test-suite] coroutine: yields in tail calls", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -228,7 +229,7 @@ test("[test-suite] coroutine: recursive", function (t) {
s = s*i
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -237,7 +238,7 @@ test("[test-suite] coroutine: recursive", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -281,7 +282,7 @@ test("[test-suite] coroutine: sieve", function (t) {
assert(#a == 25 and a[#a] == 97)
x, a = nil
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -290,7 +291,7 @@ test("[test-suite] coroutine: sieve", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -333,7 +334,7 @@ test("[test-suite] coroutine: yielding across JS boundaries", function (t) {
r, msg = co(100)
assert(not r and msg == 240)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -342,7 +343,7 @@ test("[test-suite] coroutine: yielding across JS boundaries", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -371,7 +372,7 @@ test("[test-suite] coroutine: unyieldable JS call", function (t) {
assert(co() == "aa")
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -380,7 +381,7 @@ test("[test-suite] coroutine: unyieldable JS call", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -416,7 +417,7 @@ test("[test-suite] coroutine: errors in coroutines", function (t) {
a,b = coroutine.resume(x)
assert(not a and string.find(b, "dead") and coroutine.status(x) == "dead")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -425,7 +426,7 @@ test("[test-suite] coroutine: errors in coroutines", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -456,7 +457,7 @@ test("[test-suite] coroutine: co-routines x for loop", function (t) {
end
assert(a == 5^4)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -465,7 +466,7 @@ test("[test-suite] coroutine: co-routines x for loop", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -499,7 +500,7 @@ test("[test-suite] coroutine: old bug: attempt to resume itself", function (t) {
assert(coroutine.resume(co, co) == false)
assert(coroutine.resume(co, co) == false)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -508,7 +509,7 @@ test("[test-suite] coroutine: old bug: attempt to resume itself", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -534,7 +535,7 @@ test("[test-suite] coroutine: old bug: other old bug when attempting to resume i
assert(not st and string.find(res, "non%-suspended"))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -543,7 +544,7 @@ test("[test-suite] coroutine: old bug: other old bug when attempting to resume i
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -570,7 +571,7 @@ test("[test-suite] coroutine: attempt to resume 'normal' coroutine", function (t
assert(a and b == 3)
assert(coroutine.status(co1) == 'dead')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -579,7 +580,7 @@ test("[test-suite] coroutine: attempt to resume 'normal' coroutine", function (t
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -598,7 +599,7 @@ test("[test-suite] coroutine: infinite recursion of coroutines", function (t) {
assert(not pcall(a, a))
a = nil
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -607,7 +608,7 @@ test("[test-suite] coroutine: infinite recursion of coroutines", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -634,7 +635,7 @@ test("[test-suite] coroutine: access to locals of erroneous coroutines", functio
assert(_G.f() == 11)
assert(_G.f() == 12)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -643,7 +644,7 @@ test("[test-suite] coroutine: access to locals of erroneous coroutines", functio
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -665,7 +666,7 @@ test("[test-suite] coroutine: leaving a pending coroutine open", function (t) {
_X()
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -674,7 +675,7 @@ test("[test-suite] coroutine: leaving a pending coroutine open", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -714,7 +715,7 @@ test("[test-suite] coroutine: stack overflow", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -774,7 +775,7 @@ test("[test-suite] coroutine: testing yields inside metamethods", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -812,7 +813,7 @@ test("[test-suite] coroutine: tests for comparsion operators", function (t) {
until res ~= 10
return res
end
-
+
local function test ()
local a1 = setmetatable({x=1}, mt1)
local a2 = setmetatable({x=2}, mt2)
@@ -824,7 +825,7 @@ test("[test-suite] coroutine: tests for comparsion operators", function (t) {
assert(2 >= a2)
return true
end
-
+
run(test)
end
@@ -838,7 +839,7 @@ test("[test-suite] coroutine: tests for comparsion operators", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -870,7 +871,7 @@ test("[test-suite] coroutine: getuptable & setuptable", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -905,7 +906,7 @@ test("[test-suite] coroutine: testing yields inside 'for' iterators", function (
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -950,7 +951,7 @@ test("[test-suite] coroutine: testing yields inside hooks", function (t) {
assert(B // A == 7) -- fact(7) // fact(6)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -961,7 +962,7 @@ test("[test-suite] coroutine: testing yields inside hooks", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(jsprefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(jsprefix + luaCode));
}, "Lua program loaded without error");
@@ -993,7 +994,7 @@ test("[test-suite] coroutine: testing yields inside line hook", function (t) {
_G.X = nil; co(); assert(_G.X == line + 3 and _G.XX == 20)
assert(co() == 10)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1004,7 +1005,7 @@ test("[test-suite] coroutine: testing yields inside line hook", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(jsprefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(jsprefix + luaCode));
}, "Lua program loaded without error");
@@ -1034,7 +1035,7 @@ test("[test-suite] coroutine: testing yields in count hook", function (t) {
repeat c = c + 1; local a = co() until a == 10
assert(_G.XX == 20 and c >= 5)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1045,7 +1046,7 @@ test("[test-suite] coroutine: testing yields in count hook", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(jsprefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(jsprefix + luaCode));
}, "Lua program loaded without error");
@@ -1084,7 +1085,7 @@ test("[test-suite] coroutine: testing yields inside line hook", function (t) {
assert(_G.XX == 20 and c >= 5)
_G.X = nil; _G.XX = nil
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1095,7 +1096,7 @@ test("[test-suite] coroutine: testing yields inside line hook", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(jsprefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(jsprefix + luaCode));
}, "Lua program loaded without error");
@@ -1136,7 +1137,7 @@ test("[test-suite] coroutine: testing debug library on a coroutine suspended ins
assert(not coroutine.resume(c))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1147,7 +1148,7 @@ test("[test-suite] coroutine: testing debug library on a coroutine suspended ins
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1172,7 +1173,7 @@ test("[test-suite] coroutine: testing debug library on last function in a suspen
assert(b == 10)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1183,7 +1184,7 @@ test("[test-suite] coroutine: testing debug library on last function in a suspen
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1218,7 +1219,7 @@ test("[test-suite] coroutine: reusing a thread", function (t) {
assert(X == 'a a a' and Y == 'OK')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1229,7 +1230,7 @@ test("[test-suite] coroutine: reusing a thread", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1267,7 +1268,7 @@ test("[test-suite] coroutine: resuming running coroutine", function (t) {
assert(a == coroutine.running() and string.find(b, "non%-suspended") and
c == "ERRRUN" and d == 4)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1278,7 +1279,7 @@ test("[test-suite] coroutine: resuming running coroutine", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1322,7 +1323,7 @@ test("[test-suite] coroutine: using a main thread as a coroutine", function (t)
T.closestate(state)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1333,7 +1334,7 @@ test("[test-suite] coroutine: using a main thread as a coroutine", function (t)
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1386,7 +1387,7 @@ test("[test-suite] coroutine: tests for coroutine API", function (t) {
a[9] == "YIELD" and a[10] == 4)
assert(not pcall(co)) -- coroutine is dead now
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1397,7 +1398,7 @@ test("[test-suite] coroutine: tests for coroutine API", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1419,7 +1420,7 @@ test("[test-suite] coroutine: tests for coroutine API", function (t) {
assert(co(23,16) == 5)
assert(co(23,16) == 10)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1430,7 +1431,7 @@ test("[test-suite] coroutine: tests for coroutine API", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1476,7 +1477,7 @@ test("[test-suite] coroutine: testing coroutines with C bodies", function (t) {
assert(a == 'YIELD' and b == 'a' and c == 102 and d == 'OK')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1487,7 +1488,7 @@ test("[test-suite] coroutine: testing coroutines with C bodies", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1531,7 +1532,7 @@ test("[test-suite] coroutine: testing chain of suspendable C calls", function (t
-- three '34's (one from each pending C call)
assert(#a == 3 and a[1] == a[2] and a[2] == a[3] and a[3] == 34)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1542,7 +1543,7 @@ test("[test-suite] coroutine: testing chain of suspendable C calls", function (t
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1562,11 +1563,11 @@ test("[test-suite] coroutine: testing yields with continuations", function (t) {
cannot be here!
]],
[[ # 1st continuation
- yieldk 0 3
+ yieldk 0 3
cannot be here!
]],
[[ # 2nd continuation
- yieldk 0 4
+ yieldk 0 4
cannot be here!
]],
[[ # 3th continuation
@@ -1608,7 +1609,7 @@ test("[test-suite] coroutine: testing yields with continuations", function (t) {
assert(not pcall(co)) -- coroutine should be dead
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1619,7 +1620,7 @@ test("[test-suite] coroutine: testing yields with continuations", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1641,7 +1642,7 @@ test("[test-suite] coroutine: bug in nCcalls", function (t) {
local a = {co()}
assert(a[10] == "hi")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1652,7 +1653,7 @@ test("[test-suite] coroutine: bug in nCcalls", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/db.js b/tests/test-suite/db.js
index ff13ecb..9209ab9 100644
--- a/tests/test-suite/db.js
+++ b/tests/test-suite/db.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
const prefix = `
local function dostring(s) return assert(load(s))() end
@@ -51,7 +51,7 @@ test("[test-suite] db: getinfo, ...line...", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -99,7 +99,7 @@ test("[test-suite] db: test file and string names truncation", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -158,7 +158,7 @@ test("[test-suite] db: local", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -236,7 +236,7 @@ test("[test-suite] db: line hook", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -263,7 +263,7 @@ test("[test-suite] db: invalid levels in [gs]etlocal", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -299,7 +299,7 @@ test("[test-suite] db: parameter names", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -348,7 +348,7 @@ test("[test-suite] db: vararg", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -375,7 +375,7 @@ test("[test-suite] db: access to vararg in non-vararg function", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -483,7 +483,7 @@ test("[test-suite] db: test hook presence in debug info", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -529,7 +529,7 @@ test("[test-suite] db: tests for manipulating non-registered locals (C and Lua t
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -590,7 +590,7 @@ test("[test-suite] db: testing access to function arguments", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -649,7 +649,7 @@ test("[test-suite] db: testing access to local variables in return hook (bug in
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -701,7 +701,7 @@ test("[test-suite] db: testing upvalue access", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -743,7 +743,7 @@ test("[test-suite] db: testing count hooks", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -822,7 +822,7 @@ test("[test-suite] db: tests for tail calls", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -864,7 +864,7 @@ test("[test-suite] db: testing local function information", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -901,7 +901,7 @@ test("[test-suite] db: testing traceback", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -938,7 +938,7 @@ test("[test-suite] db: testing nparams, nups e isvararg", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1028,8 +1028,8 @@ test("[test-suite] db: testing debugging of coroutines", function (t) {
lualib.luaL_openlibs(L);
- let b = lua.to_luastring(luaCode);
- if (lauxlib.luaL_loadbuffer(L, b, b.length, lua.to_luastring("@db.lua")) !== lua.LUA_OK)
+ let b = to_luastring(luaCode);
+ if (lauxlib.luaL_loadbuffer(L, b, b.length, to_luastring("@db.lua")) !== lua.LUA_OK)
throw Error(lua.lua_tojsstring(L, -1));
}, "Lua program loaded without error");
@@ -1069,7 +1069,7 @@ test("[test-suite] db: check get/setlocal in coroutines", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1116,7 +1116,7 @@ test("[test-suite] db: check traceback of suspended (or dead with error) corouti
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1159,7 +1159,7 @@ test("[test-suite] db: check test acessing line numbers of a coroutine from a re
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1211,7 +1211,7 @@ test("[test-suite] db: test tagmethod information", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1243,7 +1243,7 @@ test("[test-suite] db: testing for-iterator name", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1302,8 +1302,8 @@ test("[test-suite] db: testing traceback sizes", function (t) {
lualib.luaL_openlibs(L);
- let b = lua.to_luastring(luaCode);
- if (lauxlib.luaL_loadbuffer(L, b, b.length, lua.to_luastring("@db.lua")) !== lua.LUA_OK)
+ let b = to_luastring(luaCode);
+ if (lauxlib.luaL_loadbuffer(L, b, b.length, to_luastring("@db.lua")) !== lua.LUA_OK)
throw Error(lua.lua_tojsstring(L, -1));
}, "Lua program loaded without error");
@@ -1371,7 +1371,7 @@ test("[test-suite] db: testing debug functions on chunk without debug info", fun
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -1427,7 +1427,7 @@ test("[test-suite] db: tests for 'source' in binary dumps", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/errors.js b/tests/test-suite/errors.js
index a6bc351..0b05e9d 100644
--- a/tests/test-suite/errors.js
+++ b/tests/test-suite/errors.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
const prefix = `
-- avoid problems with 'strict' module (which may generate other error messages)
@@ -48,7 +48,7 @@ test("[test-suite] errors: test error message with no extra info", function (t)
let luaCode = `
assert(doit("error('hi', 0)") == 'hi')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -57,7 +57,7 @@ test("[test-suite] errors: test error message with no extra info", function (t)
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -74,7 +74,7 @@ test("[test-suite] errors: test error message with no info", function (t) {
let luaCode = `
assert(doit("error()") == nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -83,7 +83,7 @@ test("[test-suite] errors: test error message with no info", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -115,7 +115,7 @@ test("[test-suite] errors: test common errors/errors that crashed in the past",
]], "'}' expected (to close '{' at line 1)", "<eof>", 3)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -124,7 +124,7 @@ test("[test-suite] errors: test common errors/errors that crashed in the past",
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -161,7 +161,7 @@ test("[test-suite] errors: tests for better error messages", function (t) {
checkmessage("local a,b,c; (function () a = b+1 end)()", "upvalue 'b'")
assert(not doit"local aaa={bbb={ddd=next}}; aaa.bbb:ddd(nil)")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -170,7 +170,7 @@ test("[test-suite] errors: tests for better error messages", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -195,7 +195,7 @@ test("[test-suite] errors: upvalues being indexed do not go to the stack", funct
checkmessage("aaa='2'; b=nil;x=aaa*b", "global 'b'")
checkmessage("aaa={}; x=-aaa", "global 'aaa'")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -204,7 +204,7 @@ test("[test-suite] errors: upvalues being indexed do not go to the stack", funct
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -232,7 +232,7 @@ test("[test-suite] errors: short circuit", function (t) {
checkmessage("print('10' < 10)", "string with number")
checkmessage("print(10 < '23')", "number with string")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -241,7 +241,7 @@ test("[test-suite] errors: short circuit", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -274,7 +274,7 @@ test("[test-suite] errors: float->integer conversions", function (t) {
checkmessage("a = 24 // 0", "divide by zero")
checkmessage("a = 1 % 0", "'n%0'")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -283,7 +283,7 @@ test("[test-suite] errors: float->integer conversions", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -306,7 +306,7 @@ test("[test-suite] errors: passing light userdata instead of full userdata", fun
]], "light userdata")
_G.D = nil
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -315,7 +315,7 @@ test("[test-suite] errors: passing light userdata instead of full userdata", fun
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -343,7 +343,7 @@ test("[test-suite] errors: named objects (field '__name')", function (t) {
_G.XX = nil
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -352,7 +352,7 @@ test("[test-suite] errors: named objects (field '__name')", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -370,7 +370,7 @@ test("[test-suite] errors: global functions", function (t) {
checkmessage("(io.write or print){}", "io.write")
checkmessage("(collectgarbage or print){}", "collectgarbage")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -379,7 +379,7 @@ test("[test-suite] errors: global functions", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -408,7 +408,7 @@ test("[test-suite] errors: errors in functions without debug info", function (t)
checkerr("^%?:%-1:.*table value", f)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -417,7 +417,7 @@ test("[test-suite] errors: errors in functions without debug info", function (t)
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -443,7 +443,7 @@ test("[test-suite] errors: tests for field accesses after RK limit", function (t
checkmessage(s.."; local t = {}; a = t.bbb + 1", "field 'bbb'")
checkmessage(s.."; local t = {}; t:bbb()", "method 'bbb'")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -452,7 +452,7 @@ test("[test-suite] errors: tests for field accesses after RK limit", function (t
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -478,7 +478,7 @@ test("[test-suite] errors: global", function (t) {
{d = x and aaa[x or y]}}
]], "global 'aaa'")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -487,7 +487,7 @@ test("[test-suite] errors: global", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -507,7 +507,7 @@ test("[test-suite] errors: field", function (t) {
if math.sin(1) == 0 then return 3 end -- return
x.a()]], "field 'a'")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -516,7 +516,7 @@ test("[test-suite] errors: field", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -540,7 +540,7 @@ test("[test-suite] errors: global insert", function (t) {
insert(prefix, a)
end]], "global 'insert'")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -549,7 +549,7 @@ test("[test-suite] errors: global insert", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -568,7 +568,7 @@ test("[test-suite] errors: sin", function (t) {
return math.sin("a")
]], "'sin'")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -577,7 +577,7 @@ test("[test-suite] errors: sin", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -596,7 +596,7 @@ test("[test-suite] errors: concatenate", function (t) {
checkmessage([[x = "a" .. false]], "concatenate")
checkmessage([[x = {} .. 2]], "concatenate")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -605,7 +605,7 @@ test("[test-suite] errors: concatenate", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -628,7 +628,7 @@ test("[test-suite] errors: unknown global", function (t) {
main()
]], "global 'NoSuchName'")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -637,7 +637,7 @@ test("[test-suite] errors: unknown global", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -660,7 +660,7 @@ test("[test-suite] errors: __index", function (t) {
checkmessage("table.sort({1,2,3}, table.sort)", "'table.sort'")
checkmessage("string.gsub('s', 's', setmetatable)", "'setmetatable'")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -669,7 +669,7 @@ test("[test-suite] errors: __index", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -696,7 +696,7 @@ test("[test-suite] errors: tests for errors in coroutines", function (t) {
f = coroutine.wrap(function () table.sort({1,2,3}, coroutine.yield) end)
checkerr("yield across", f)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -705,7 +705,7 @@ test("[test-suite] errors: tests for errors in coroutines", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -735,7 +735,7 @@ test("[test-suite] errors: testing size of 'source' info", function (t) {
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -744,7 +744,7 @@ test("[test-suite] errors: testing size of 'source' info", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -812,7 +812,7 @@ test("[test-suite] errors: testing line error", function (t) {
X=1;lineerror((p), 2)
X=2;lineerror((p), 1)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -821,7 +821,7 @@ test("[test-suite] errors: testing line error", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -847,7 +847,7 @@ test("[test-suite] errors: several tests that exhaust the Lua stack", function (
assert(checkstackmessage(doit('y()')))
assert(checkstackmessage(doit('y()')))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -856,7 +856,7 @@ test("[test-suite] errors: several tests that exhaust the Lua stack", function (
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -890,7 +890,7 @@ test("[test-suite] errors: error lines in stack overflow", function (t) {
end
assert(i > 15)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -899,7 +899,7 @@ test("[test-suite] errors: error lines in stack overflow", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -927,7 +927,7 @@ test("[test-suite] errors: error in error handling", function (t) {
end
f(3)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -936,7 +936,7 @@ test("[test-suite] errors: error in error handling", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -966,7 +966,7 @@ test("[test-suite] errors: too many results", function (t) {
end
checkerr("too many results", f)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -975,7 +975,7 @@ test("[test-suite] errors: too many results", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1006,7 +1006,7 @@ test("[test-suite] errors: non string messages", function (t) {
-- 'assert' with extra arguments
res, msg = pcall(assert, false, "X", t)
assert(not res and msg == "X")
-
+
-- 'assert' with no message
res, msg = pcall(function () assert(false) end)
local line = string.match(msg, "%w+%.lua:(%d+): assertion failed!$")
@@ -1024,7 +1024,7 @@ test("[test-suite] errors: non string messages", function (t) {
assert(not res and string.find(msg, "value expected"))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1033,7 +1033,7 @@ test("[test-suite] errors: non string messages", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadbuffer(L, lua.to_luastring(prefix + luaCode), null, lua.to_luastring("@errors.lua"));
+ lauxlib.luaL_loadbuffer(L, to_luastring(prefix + luaCode), null, to_luastring("@errors.lua"));
}, "Lua program loaded without error");
@@ -1053,7 +1053,7 @@ test("[test-suite] errors: xpcall with arguments", function (t) {
a, b, c = xpcall(string.find, function (x) return {} end, true, "al")
assert(not a and type(b) == "table" and c == nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1062,7 +1062,7 @@ test("[test-suite] errors: xpcall with arguments", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1084,7 +1084,7 @@ test("[test-suite] errors: testing tokens in error messages", function (t) {
checksyntax("while << do end", "", "<<", 1)
checksyntax("for >> do end", "", ">>", 1)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1093,7 +1093,7 @@ test("[test-suite] errors: testing tokens in error messages", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1110,7 +1110,7 @@ test("[test-suite] errors: test invalid non-printable char in a chunk", function
let luaCode = `
checksyntax("a\\1a = 1", "", "<\\\\1>", 1)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1119,7 +1119,7 @@ test("[test-suite] errors: test invalid non-printable char in a chunk", function
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1139,7 +1139,7 @@ test("[test-suite] errors: test 255 as first char in a chunk", function (t) {
doit('I = load("a=9+"); a=3')
assert(a==3 and I == nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1148,7 +1148,7 @@ test("[test-suite] errors: test 255 as first char in a chunk", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1170,7 +1170,7 @@ test("[test-suite] errors: lots of errors", function (t) {
doit('a = 4+nil')
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1179,7 +1179,7 @@ test("[test-suite] errors: lots of errors", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1217,7 +1217,7 @@ test("[test-suite] errors: testing syntax limits", function (t) {
checkmessage("a = f(x" .. string.rep(",x", 260) .. ")", "too many registers")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1226,7 +1226,7 @@ test("[test-suite] errors: testing syntax limits", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1263,7 +1263,7 @@ test("[test-suite] errors: upvalues limit", function (t) {
assert(c > 255 and string.find(b, "too many upvalues") and
string.find(b, "line 5"))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1272,7 +1272,7 @@ test("[test-suite] errors: upvalues limit", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1295,7 +1295,7 @@ test("[test-suite] errors: local variables limit", function (t) {
local a,b = load(s)
assert(string.find(b, "line 2") and string.find(b, "too many local variables"))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1304,7 +1304,7 @@ test("[test-suite] errors: local variables limit", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/events.js b/tests/test-suite/events.js
index 9a15e93..143bdf5 100644
--- a/tests/test-suite/events.js
+++ b/tests/test-suite/events.js
@@ -5,10 +5,10 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
+const {to_luastring} = require("../../src/fengaricore.js");
const ltests = require('./ltests.js');
-
test("[test-suite] events: testing metatable", function (t) {
let luaCode = `
X = 20; B = 30
@@ -182,7 +182,7 @@ test("[test-suite] events: testing metatable", function (t) {
assert(1.5 >> a == 1.5)
assert(cap[0] == "shr" and cap[1] == 1.5 and cap[2] == a)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -191,7 +191,7 @@ test("[test-suite] events: testing metatable", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -216,7 +216,7 @@ test("[test-suite] events: test for rawlen", function (t) {
-- rawlen for long strings
assert(rawlen(string.rep('a', 1000)) == 1000)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -225,7 +225,7 @@ test("[test-suite] events: test for rawlen", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -277,7 +277,7 @@ test("[test-suite] events: test comparison", function (t) {
test() -- retest comparisons, now using both 'lt' and 'le'
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -286,7 +286,7 @@ test("[test-suite] events: test comparison", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -360,7 +360,7 @@ test("[test-suite] events: test 'partial order'", function (t) {
t[Set{1,3,5}] = 1
assert(t[Set{1,3,5}] == nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -369,7 +369,7 @@ test("[test-suite] events: test 'partial order'", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -403,7 +403,7 @@ test("[test-suite] events: __eq between userdata", function (t) {
assert(u2 == u1 and u2 == u3 and u3 == u2)
assert(u2 ~= {}) -- different types cannot be equal
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -414,7 +414,7 @@ test("[test-suite] events: __eq between userdata", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -455,7 +455,7 @@ test("[test-suite] events: concat", function (t) {
x = 0 .."a".."b"..c..d.."e".."f".."g"
assert(x.val == "0abcdefg")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -466,7 +466,7 @@ test("[test-suite] events: concat", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -490,7 +490,7 @@ test("[test-suite] events: concat metamethod x numbers (bug in 5.1.1)", function
assert(c..5 == c and 5 .. c == c)
assert(4 .. c .. 5 == c and 4 .. 5 .. 6 .. 7 .. c == c)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -501,7 +501,7 @@ test("[test-suite] events: concat metamethod x numbers (bug in 5.1.1)", function
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -529,7 +529,7 @@ test("[test-suite] events: test comparison compatibilities", function (t) {
setmetatable(d, t2)
assert(c == d and c < d and not(d <= c))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -540,7 +540,7 @@ test("[test-suite] events: test comparison compatibilities", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -564,16 +564,16 @@ test("[test-suite] events: test for several levels of callstest for several leve
end
end
}
-
+
local a = setmetatable({}, tt)
local b = setmetatable({f=a}, tt)
local c = setmetatable({f=b}, tt)
-
+
i = 0
x = c(3,4,5)
assert(i == 3 and x[1] == 3 and x[3] == 5)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -584,7 +584,7 @@ test("[test-suite] events: test for several levels of callstest for several leve
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -606,7 +606,7 @@ test("[test-suite] events: __index on _ENV", function (t) {
rawset(a, "x", 1, 2, 3)
assert(a.x == 1 and rawget(a, "x", 3) == 1)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -617,7 +617,7 @@ test("[test-suite] events: __index on _ENV", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -661,7 +661,7 @@ test("[test-suite] events: testing metatables for basic types", function (t) {
debug.setmetatable(nil, {})
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -672,7 +672,7 @@ test("[test-suite] events: testing metatables for basic types", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -691,7 +691,7 @@ test("[test-suite] events: loops in delegation", function (t) {
assert(not pcall(function (a,b) return a[b] end, a, 10))
assert(not pcall(function (a,b,c) a[b] = c end, a, 10, true))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -702,7 +702,7 @@ test("[test-suite] events: loops in delegation", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -729,7 +729,7 @@ test("[test-suite] events: bug in 5.1", function (t) {
child.foo = 10 --> CRASH (on some machines)
assert(T == parent and K == "foo" and V == 10)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -740,7 +740,7 @@ test("[test-suite] events: bug in 5.1", function (t) {
ltests.luaopen_tests(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/goto.js b/tests/test-suite/goto.js
index 5acf633..dc52c73 100644
--- a/tests/test-suite/goto.js
+++ b/tests/test-suite/goto.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
test("[test-suite] goto: error messages", function (t) {
let luaCode = `
@@ -45,7 +45,7 @@ test("[test-suite] goto: error messages", function (t) {
until xuxu < x
]], "local 'xuxu'")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -54,7 +54,7 @@ test("[test-suite] goto: error messages", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -124,7 +124,7 @@ test("[test-suite] goto", function (t) {
::l1:: ; ::l2:: ;;
else end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -133,7 +133,7 @@ test("[test-suite] goto", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -164,7 +164,7 @@ test("[test-suite] goto: to repeat a label in a different function is OK", funct
::l6:: foo()
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -173,7 +173,7 @@ test("[test-suite] goto: to repeat a label in a different function is OK", funct
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -203,7 +203,7 @@ test("[test-suite] goto: bug in 5.2 -> 5.3.2", function (t) {
assert(x == 2 and y == true)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -212,7 +212,7 @@ test("[test-suite] goto: bug in 5.2 -> 5.3.2", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -288,7 +288,7 @@ test("[test-suite] goto: testing closing of upvalues", function (t) {
end
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -297,7 +297,7 @@ test("[test-suite] goto: testing closing of upvalues", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -342,7 +342,7 @@ test("[test-suite] goto: testing if x goto optimizations", function (t) {
assert(testG(4) == 5)
assert(testG(5) == 10)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -351,7 +351,7 @@ test("[test-suite] goto: testing if x goto optimizations", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/literals.js b/tests/test-suite/literals.js
index 0078cf8..6e3205e 100644
--- a/tests/test-suite/literals.js
+++ b/tests/test-suite/literals.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
const dostring = `
local function dostring (x) return assert(load(x), "")() end
@@ -16,7 +16,7 @@ test("[test-suite] literals: dostring", function (t) {
dostring("x \\v\\f = \\t\\r 'a\\0a' \\v\\f\\f")
assert(x == 'a\\0a' and string.len(x) == 3)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -25,7 +25,7 @@ test("[test-suite] literals: dostring", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(dostring + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode));
}, "Lua program loaded without error");
@@ -46,7 +46,7 @@ test("[test-suite] literals: escape sequences", function (t) {
"'\\]])
assert(string.find("\\b\\f\\n\\r\\t\\v", "^%c%c%c%c%c%c$"))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -55,7 +55,7 @@ test("[test-suite] literals: escape sequences", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -78,7 +78,7 @@ test("[test-suite] literals: assume ASCII just for tests", function (t) {
assert(010 .. 020 .. -030 == "1020-30")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -87,7 +87,7 @@ test("[test-suite] literals: assume ASCII just for tests", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -125,7 +125,7 @@ assert("abc\\z
ghi\\z
" == 'abcdefghi')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -134,7 +134,7 @@ assert("abc\\z
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -163,7 +163,7 @@ test("[test-suite] literals: UTF-8 sequences", function (t) {
-- limits for 4-byte sequences
assert("\\u{10000}\\u{10FFFF}" == "\\xF0\\x90\\x80\\x80\\z\\xF4\\x8F\\xBF\\xBF")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -172,7 +172,7 @@ test("[test-suite] literals: UTF-8 sequences", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -229,7 +229,7 @@ test("[test-suite] literals: Error in escape sequences", function (t) {
lexerror("'alo \\\\z", "<eof>")
lexerror([['alo \\98]], "<eof>")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -238,7 +238,7 @@ test("[test-suite] literals: Error in escape sequences", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -260,7 +260,7 @@ test("[test-suite] literals: valid characters in variable names", function (t) {
not load("a" .. s .. "1 = 1", ""))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -269,7 +269,7 @@ test("[test-suite] literals: valid characters in variable names", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -295,7 +295,7 @@ test("[test-suite] literals: long variable names", function (t) {
assert(_G[var1] == 5 and _G[var2] == 6 and f() == -1)
var1, var2, f = nil
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -304,7 +304,7 @@ test("[test-suite] literals: long variable names", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(dostring + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode));
}, "Lua program loaded without error");
@@ -321,7 +321,7 @@ test("[test-suite] literals: escapes", function (t) {
let luaCode = `assert("\\n\\t" == [[\n\n\t]])
assert([[\n\n $debug]] == "\\n $debug")
assert([[ [ ]] ~= [[ ] ]])`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -330,7 +330,7 @@ assert([[ [ ]] ~= [[ ] ]])`, L;
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(dostring + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode));
}, "Lua program loaded without error");
@@ -396,7 +396,7 @@ assert(x)
prog = nil
a = nil
b = nil`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -405,7 +405,7 @@ b = nil`, L;
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(dostring + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode));
}, "Lua program loaded without error");
@@ -438,7 +438,7 @@ for _, n in pairs{"\\n", "\\r", "\\n\\r", "\\r\\n"} do
assert(dostring(prog) == nn)
assert(_G.x == "hi\\n" and _G.y == "\\nhello\\r\\n\\n")
end`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -447,7 +447,7 @@ end`, L;
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(dostring + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode));
}, "Lua program loaded without error");
@@ -480,7 +480,7 @@ x y z [==[ blu foo
]
]=]==]
error error]=]===]`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -489,7 +489,7 @@ error error]=]===]`, L;
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(dostring + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode));
}, "Lua program loaded without error");
@@ -518,7 +518,7 @@ end
for s in coroutine.wrap(function () gen("", len) end) do
assert(s == load("return [====[\\n"..s.."]====]", "")())
end`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -527,7 +527,7 @@ end`, L;
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(dostring + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode));
}, "Lua program loaded without error");
@@ -547,7 +547,7 @@ test("[test-suite] literals: testing %q x line ends", function (t) {
local c = string.format("return %q", s)
assert(assert(load(c))() == s)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -556,7 +556,7 @@ test("[test-suite] literals: testing %q x line ends", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(dostring + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode));
}, "Lua program loaded without error");
@@ -577,7 +577,7 @@ test("[test-suite] literals: testing errors", function (t) {
assert(not load"a = '\\\\345'")
assert(not load"a = [=x]")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -586,7 +586,7 @@ test("[test-suite] literals: testing errors", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(dostring + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/locals.js b/tests/test-suite/locals.js
index cc82e38..d1dc3e4 100644
--- a/tests/test-suite/locals.js
+++ b/tests/test-suite/locals.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
test('[test-suite] locals: bug in 5.1', function (t) {
let luaCode = `
@@ -18,7 +18,7 @@ test('[test-suite] locals: bug in 5.1', function (t) {
local function f(x) x = nil; local y; return x, y end
assert(f(10) == nil and select(2, f(20)) == nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -27,7 +27,7 @@ test('[test-suite] locals: bug in 5.1', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -90,7 +90,7 @@ test('[test-suite] locals: local scope', function (t) {
f(2)
assert(type(f) == 'function')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -99,7 +99,7 @@ test('[test-suite] locals: local scope', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -130,7 +130,7 @@ test('[test-suite] locals: test for global table of loaded chunks', function (t)
f()
assert(c.a == 3)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -139,7 +139,7 @@ test('[test-suite] locals: test for global table of loaded chunks', function (t)
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(getenv + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(getenv + luaCode));
}, "Lua program loaded without error");
@@ -173,7 +173,7 @@ test('[test-suite] locals: old test for limits for special instructions (now jus
until p <= 0
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -182,7 +182,7 @@ test('[test-suite] locals: old test for limits for special instructions (now jus
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -202,7 +202,7 @@ test('[test-suite] locals: testing lexical environments', function (t) {
do
local dummy
local _ENV = (function (...) return ... end)(_G, dummy) -- {
-
+
do local _ENV = {assert=assert}; assert(true) end
mt = {_G = _G}
local foo,x
@@ -217,7 +217,7 @@ test('[test-suite] locals: testing lexical environments', function (t) {
assert(getenv(foo) == mt)
x = foo('hi'); assert(mt.A == 'hi' and A == 1000)
assert(x('*') == mt.A .. '*')
-
+
do local _ENV = {assert=assert, A=10};
do local _ENV = {assert=assert, A=20};
assert(A==20);x=A
@@ -227,7 +227,7 @@ test('[test-suite] locals: testing lexical environments', function (t) {
assert(x==20)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -236,7 +236,7 @@ test('[test-suite] locals: testing lexical environments', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(getenv + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(getenv + luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/ltests.js b/tests/test-suite/ltests.js
index 5847746..11de5c3 100644
--- a/tests/test-suite/ltests.js
+++ b/tests/test-suite/ltests.js
@@ -4,6 +4,7 @@ const assert = require("assert");
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
+const {luastring_indexOf, to_jsstring, to_luastring} = require("../../src/fengaricore.js");
const ljstype = require('../../src/ljstype.js');
const lopcodes = require('../../src/lopcodes.js');
const sprintf = require('sprintf-js').sprintf;
@@ -40,7 +41,7 @@ const getnum = function(L, L1, pc) {
pc.offset++;
}
if (!ljstype.lisdigit(pc.script[pc.offset]))
- lauxlib.luaL_error(L, lua.to_luastring("number expected (%s)"), pc.script);
+ lauxlib.luaL_error(L, to_luastring("number expected (%s)"), pc.script);
while (ljstype.lisdigit(pc.script[pc.offset])) res = res*10 + pc.script[pc.offset++] - '0'.charCodeAt(0);
return sig*res;
};
@@ -52,7 +53,7 @@ const getstring = function(L, buff, pc) {
let quote = pc.script[pc.offset++];
while (pc.script[pc.offset] !== quote) {
if (pc.script[pc.offset] === 0 || pc.offset >= pc.script.length)
- lauxlib.luaL_error(L, lua.to_luastring("unfinished string in JS script", true));
+ lauxlib.luaL_error(L, to_luastring("unfinished string in JS script", true));
buff[i++] = pc.script[pc.offset++];
}
pc.offset++;
@@ -67,13 +68,13 @@ const getindex = function(L, L1, pc) {
skip(pc);
switch (pc.script[pc.offset++]) {
case 'R'.charCodeAt(0): return lua.LUA_REGISTRYINDEX;
- case 'G'.charCodeAt(0): return lauxlib.luaL_error(L, lua.to_luastring("deprecated index 'G'", true));
+ case 'G'.charCodeAt(0): return lauxlib.luaL_error(L, to_luastring("deprecated index 'G'", true));
case 'U'.charCodeAt(0): return lua.lua_upvalueindex(getnum(L, L1, pc));
default: pc.offset--; return getnum(L, L1, pc);
}
};
-const codes = ["OK", "YIELD", "ERRRUN", "ERRSYNTAX", "ERRMEM", "ERRGCMM", "ERRERR"].map(e => lua.to_luastring(e));
+const codes = ["OK", "YIELD", "ERRRUN", "ERRSYNTAX", "ERRMEM", "ERRGCMM", "ERRERR"].map(e => to_luastring(e));
const pushcode = function(L, code) {
lua.lua_pushstring(L, codes[code]);
@@ -82,7 +83,7 @@ const pushcode = function(L, code) {
const printstack = function(L) {
let n = lua.lua_gettop(L);
for (let i = 1; i <= n; i++) {
- console.log("${i}: %{lua.to_jsstring(lauxlib.luaL_tolstring(L, i, null))}\n");
+ console.log("${i}: %{to_jsstring(lauxlib.luaL_tolstring(L, i, null))}\n");
lua.lua_pop(L, 1);
}
console.log("");
@@ -101,9 +102,9 @@ const ops = "+-*%^/\\&|~<>_!".split('').map(e => e.charCodeAt(0));
const runJS = function(L, L1, pc) {
let buff = new Uint8Array(300);
let status = 0;
- if (!pc || !pc.script) return lauxlib.luaL_error(L, lua.to_luastring("attempt to runJS null script"));
+ if (!pc || !pc.script) return lauxlib.luaL_error(L, to_luastring("attempt to runJS null script"));
for (;;) {
- let inst = lua.to_jsstring(getstring(L, buff, pc));
+ let inst = to_jsstring(getstring(L, buff, pc));
if (inst.length === 0) return 0;
switch (inst) {
case "absindex": {
@@ -475,7 +476,7 @@ const runJS = function(L, L1, pc) {
return lua.lua_yieldk(L1, nres, i, Cfunck);
}
default:
- lauxlib.luaL_error(L, lua.to_luastring("unknown instruction %s"), buff);
+ lauxlib.luaL_error(L, to_luastring("unknown instruction %s"), buff);
}
}
};
@@ -552,7 +553,7 @@ const newstate = function(L) {
const getstate = function(L) {
let L1 = lua.lua_touserdata(L, 1);
- lauxlib.luaL_argcheck(L, L1 !== null, 1, lua.to_luastring("state expected", true));
+ lauxlib.luaL_argcheck(L, L1 !== null, 1, to_luastring("state expected", true));
return L1;
};
@@ -578,16 +579,16 @@ const loadlib = function(L) {
"table": luaopen_table
};
let L1 = getstate(L);
- lauxlib.luaL_requiref(L1, lua.to_luastring("package", true), luaopen_package, 0);
+ lauxlib.luaL_requiref(L1, to_luastring("package", true), luaopen_package, 0);
assert(lua.lua_type(L1, -1) == lua.LUA_TTABLE);
/* 'requiref' should not reload module already loaded... */
- lauxlib.luaL_requiref(L1, lua.to_luastring("package", true), null, 1); /* seg. fault if it reloads */
+ lauxlib.luaL_requiref(L1, to_luastring("package", true), null, 1); /* seg. fault if it reloads */
/* ...but should return the same module */
assert(lua.lua_compare(L1, -1, -2, lua.LUA_OPEQ));
lauxlib.luaL_getsubtable(L1, lua.LUA_REGISTRYINDEX, lauxlib.LUA_PRELOAD_TABLE);
for (let name in libs) {
lua.lua_pushcfunction(L1, libs[name]);
- lua.lua_setfield(L1, -2, lua.to_luastring(name, true));
+ lua.lua_setfield(L1, -2, to_luastring(name, true));
}
return 0;
};
@@ -637,8 +638,8 @@ const newuserdata = function(L) {
*/
const Chook = function(L, ar) {
let scpt;
- let events = ["call", "ret", "line", "count", "tailcall"].map(e => lua.to_luastring(e));
- lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, lua.to_luastring("JS_HOOK", true));
+ let events = ["call", "ret", "line", "count", "tailcall"].map(e => to_luastring(e));
+ lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, to_luastring("JS_HOOK", true));
lua.lua_pushlightuserdata(L, L);
lua.lua_gettable(L, -2); /* get C_HOOK[L] (script saved by sethookaux) */
scpt = lua.lua_tostring(L, -1); /* not very religious (string will be popped) */
@@ -661,7 +662,7 @@ class Aux {
const panicback = function(L) {
let b = new Aux();
lua.lua_checkstack(L, 1); /* open space for 'Aux' struct */
- lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, lua.to_luastring("_jmpbuf", true)); /* get 'Aux' struct */
+ lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, to_luastring("_jmpbuf", true)); /* get 'Aux' struct */
b = lua.lua_touserdata(L, -1);
lua.lua_pop(L, 1); /* remove 'Aux' struct */
runJS(b.L, L, { script: b.paniccode, offset: 0 }); /* run optional panic code */
@@ -671,7 +672,7 @@ const panicback = function(L) {
const checkpanic = function(L) {
let b = new Aux();
let code = lauxlib.luaL_checkstring(L, 1);
- b.paniccode = lauxlib.luaL_optstring(L, 2, lua.to_luastring("", true));
+ b.paniccode = lauxlib.luaL_optstring(L, 2, to_luastring("", true));
b.L = L;
let L1 = lua.lua_newstate(); /* create new state */
if (L1 === null) { /* error? */
@@ -680,7 +681,7 @@ const checkpanic = function(L) {
}
lua.lua_atpanic(L1, panicback); /* set its panic function */
lua.lua_pushlightuserdata(L1, b);
- lua.lua_setfield(L1, lua.LUA_REGISTRYINDEX, lua.to_luastring("_jmpbuf", true)); /* store 'Aux' struct */
+ lua.lua_setfield(L1, lua.LUA_REGISTRYINDEX, to_luastring("_jmpbuf", true)); /* store 'Aux' struct */
try { /* set jump buffer */
runJS(L, L1, { script: code, offset: 0 }); /* run code unprotected */
lua.lua_pushliteral(L, "no errors");
@@ -700,12 +701,12 @@ const sethookaux = function(L, mask, count, scpt) {
lua.lua_sethook(L, null, 0, 0); /* turn off hooks */
return;
}
- lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, lua.to_luastring("JS_HOOK", true)); /* get C_HOOK table */
+ lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, to_luastring("JS_HOOK", true)); /* get C_HOOK table */
if (!lua.lua_istable(L, -1)) { /* no hook table? */
lua.lua_pop(L, 1); /* remove previous value */
lua.lua_newtable(L); /* create new C_HOOK table */
lua.lua_pushvalue(L, -1);
- lua.lua_setfield(L, lua.LUA_REGISTRYINDEX, lua.to_luastring("JS_HOOK", true)); /* register it */
+ lua.lua_setfield(L, lua.LUA_REGISTRYINDEX, to_luastring("JS_HOOK", true)); /* register it */
}
lua.lua_pushlightuserdata(L, L);
lua.lua_pushstring(L, scpt);
@@ -721,9 +722,9 @@ const sethook = function(L) {
const smask = lauxlib.luaL_checkstring(L, 2);
let count = lauxlib.luaL_optinteger(L, 3, 0);
let mask = 0;
- if (lua.luastring_indexOf(smask, 'c'.charCodeAt(0)) >= 0) mask |= lua.LUA_MASKCALL;
- if (lua.luastring_indexOf(smask, 'r'.charCodeAt(0)) >= 0) mask |= lua.LUA_MASKRET;
- if (lua.luastring_indexOf(smask, 'l'.charCodeAt(0)) >= 0) mask |= lua.LUA_MASKLINE;
+ if (luastring_indexOf(smask, 'c'.charCodeAt(0)) >= 0) mask |= lua.LUA_MASKCALL;
+ if (luastring_indexOf(smask, 'r'.charCodeAt(0)) >= 0) mask |= lua.LUA_MASKRET;
+ if (luastring_indexOf(smask, 'l'.charCodeAt(0)) >= 0) mask |= lua.LUA_MASKLINE;
if (count > 0) mask |= lua.LUA_MASKCOUNT;
sethookaux(L, mask, count, scpt);
}
@@ -736,9 +737,9 @@ const Cfunc = function(L) {
const Cfunck = function(L, status, ctx) {
pushcode(L, status);
- lua.lua_setglobal(L, lua.to_luastring("status", true));
+ lua.lua_setglobal(L, to_luastring("status", true));
lua.lua_pushinteger(L, ctx);
- lua.lua_setglobal(L, lua.to_luastring("ctx", true));
+ lua.lua_setglobal(L, to_luastring("ctx", true));
return runJS(L, L, { script: lua.lua_tostring(L, ctx), offset: 0 });
};
@@ -751,7 +752,7 @@ const makeCfunc = function(L) {
const coresume = function(L) {
let status;
let co = lua.lua_tothread(L, 1);
- lauxlib.luaL_argcheck(L, co, 1, lua.to_luastring("coroutine expected", true));
+ lauxlib.luaL_argcheck(L, co, 1, to_luastring("coroutine expected", true));
status = lua.lua_resume(co, L, 0);
if (status != lua.LUA_OK && status !== lua.LUA_YIELD) {
lua.lua_pushboolean(L, 0);
@@ -800,16 +801,16 @@ const buildop = function(p, pc) {
break;
}
- return lua.to_luastring(result);
+ return to_luastring(result);
};
const listcode = function(L) {
lauxlib.luaL_argcheck(L, lua.lua_isfunction(L, 1) && !lua.lua_iscfunction(L, 1),
- 1, lua.to_luastring("Lua function expected", true));
+ 1, to_luastring("Lua function expected", true));
let p = obj_at(L, 1);
lua.lua_newtable(L);
- setnameval(L, lua.to_luastring("maxstack", true), p.maxstacksize);
- setnameval(L, lua.to_luastring("numparams", true), p.numparams);
+ setnameval(L, to_luastring("maxstack", true), p.maxstacksize);
+ setnameval(L, to_luastring("numparams", true), p.numparams);
for (let pc = 0; pc < p.code.length; pc++) {
lua.lua_pushinteger(L, pc+1);
lua.lua_pushstring(L, buildop(p, pc));
@@ -821,7 +822,7 @@ const listcode = function(L) {
const listk = function(L) {
lauxlib.luaL_argcheck(L,
lua.lua_isfunction(L, 1) && !lua.lua_iscfunction(L, 1),
- 1, lua.to_luastring("Lua function expected"), true);
+ 1, to_luastring("Lua function expected"), true);
let p = obj_at(L, 1);
lua.lua_createtable(L, p.k.length, 0);
for (let i = 0; i < p.k.length; i++) {
@@ -859,7 +860,7 @@ const luaB_opentests = function(L) {
};
const luaopen_tests = function(L) {
- lauxlib.luaL_requiref(L, lua.to_luastring("T"), luaB_opentests, 1);
+ lauxlib.luaL_requiref(L, to_luastring("T"), luaB_opentests, 1);
lua.lua_pop(L, 1); /* remove lib */
};
diff --git a/tests/test-suite/math.js b/tests/test-suite/math.js
index 0052bc2..9fb6fa5 100644
--- a/tests/test-suite/math.js
+++ b/tests/test-suite/math.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
const prefix = `
local minint = math.mininteger
@@ -59,7 +59,7 @@ test("[test-suite] math: int bits", function (t) {
assert(minint == 1 << (intbits - 1))
assert(maxint == minint - 1)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -68,7 +68,7 @@ test("[test-suite] math: int bits", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -98,7 +98,7 @@ test("[test-suite] math: number of bits in the mantissa of a floating-point numb
assert(math.type(0) == "integer" and math.type(0.0) == "float"
and math.type("10") == nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -107,7 +107,7 @@ test("[test-suite] math: number of bits in the mantissa of a floating-point numb
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -162,7 +162,7 @@ test("[test-suite] math: basic float notation", function (t) {
assert(eqT(a, minint) and eqT(b, 0.0))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -171,7 +171,7 @@ test("[test-suite] math: basic float notation", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -189,7 +189,7 @@ test("[test-suite] math: math.huge", function (t) {
assert(math.huge > 10e30)
assert(-math.huge < -10e30)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -198,7 +198,7 @@ test("[test-suite] math: math.huge", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -219,7 +219,7 @@ test("[test-suite] math: integer arithmetic", function (t) {
assert(minint * minint == 0)
assert(maxint * maxint * maxint == maxint)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -228,7 +228,7 @@ test("[test-suite] math: integer arithmetic", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -274,7 +274,7 @@ test("[test-suite] math: testing floor division and conversions", function (t) {
assert(minint // -2 == 2^(intbits - 2))
assert(maxint // -1 == -maxint)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -283,7 +283,7 @@ test("[test-suite] math: testing floor division and conversions", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -311,7 +311,7 @@ test("[test-suite] math: negative exponents", function (t) {
end
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -320,7 +320,7 @@ test("[test-suite] math: negative exponents", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -351,7 +351,7 @@ test("[test-suite] math: comparison between floats and integers (border cases)",
assert(minint + 0.0 == minint)
assert(minint + 0.0 == -2.0^(intbits - 1))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -360,7 +360,7 @@ test("[test-suite] math: comparison between floats and integers (border cases)",
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -460,7 +460,7 @@ test("[test-suite] math: order between floats and integers", function (t) {
assert(not (minint < NaN))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -469,7 +469,7 @@ test("[test-suite] math: order between floats and integers", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -491,7 +491,7 @@ test("[test-suite] math: avoiding errors at compile time", function (t) {
checkcompt(msgf2i, ("return 1 | 2.0^%d"):format(intbits - 1))
checkcompt(msgf2i, "return 2.3 ~ '0.0'")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -500,7 +500,7 @@ test("[test-suite] math: avoiding errors at compile time", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -544,7 +544,7 @@ test("[test-suite] math: testing overflow errors when converting from float to i
-- 'minint' should be representable as a float no matter the precision
assert(f2i(minint + 0.0) == minint)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -553,7 +553,7 @@ test("[test-suite] math: testing overflow errors when converting from float to i
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -573,7 +573,7 @@ test("[test-suite] math: testing numeric strings", function (t) {
assert(" -2 " + 1 == -1)
assert(" -0xa " + 1 == -9)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -582,7 +582,7 @@ test("[test-suite] math: testing numeric strings", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -631,7 +631,7 @@ test("[test-suite] math: Literal integer Overflows (new behavior in 5.3.3)", fun
assert(eqT(-10000000000000000000000.0, -10000000000000000000000))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -640,7 +640,7 @@ test("[test-suite] math: Literal integer Overflows (new behavior in 5.3.3)", fun
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -660,7 +660,7 @@ test("[test-suite] math: 'tonumber' with numbers", function (t) {
assert(eqT(tonumber(maxint), maxint) and eqT(tonumber(minint), minint))
assert(tonumber(1/0) == 1/0)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -669,7 +669,7 @@ test("[test-suite] math: 'tonumber' with numbers", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -722,7 +722,7 @@ test("[test-suite] math: 'tonumber' with strings", function (t) {
assert(tonumber('\\t10000000000\\t', i) == i10)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -731,7 +731,7 @@ test("[test-suite] math: 'tonumber' with strings", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -760,7 +760,7 @@ test("[test-suite] math: tests with very long numerals", function (t) {
assert(tonumber('0xe03' .. string.rep('0', 1000) .. 'p-4000') == 3587.0)
assert(tonumber('0x.' .. string.rep('0', 1000) .. '74p4004') == 0x7.4)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -769,7 +769,7 @@ test("[test-suite] math: tests with very long numerals", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -816,7 +816,7 @@ test("[test-suite] math: testing 'tonumber' for invalid formats", function (t) {
assert(f(tonumber('e 1')) == nil)
assert(f(tonumber(' 3.4.5 ')) == nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -825,7 +825,7 @@ test("[test-suite] math: testing 'tonumber' for invalid formats", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -853,7 +853,7 @@ test("[test-suite] math: testing 'tonumber' for invalid hexadecimal formats", fu
assert(tonumber('0x0.51p') == nil)
assert(tonumber('0x5p+-2') == nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -862,7 +862,7 @@ test("[test-suite] math: testing 'tonumber' for invalid hexadecimal formats", fu
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -887,7 +887,7 @@ test("[test-suite] math: testing hexadecimal numerals", function (t) {
-- possible confusion with decimal exponent
assert(0E+1 == 0 and 0xE+1 == 15 and 0xe-1 == 13)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -896,7 +896,7 @@ test("[test-suite] math: testing hexadecimal numerals", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -935,7 +935,7 @@ test("[test-suite] math: floating hexas", function (t) {
assert(tonumber('+1.23E18') == 1.23*10.0^18)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -944,7 +944,7 @@ test("[test-suite] math: floating hexas", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -969,7 +969,7 @@ test("[test-suite] math: testing order operators", function (t) {
assert(('a'>='a') and not('a'>='b') and ('b'>='a'))
assert(1.3 < 1.4 and 1.3 <= 1.4 and not (1.3 < 1.3) and 1.3 <= 1.3)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -978,7 +978,7 @@ test("[test-suite] math: testing order operators", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1010,7 +1010,7 @@ test("[test-suite] math: testing mod operator", function (t) {
assert(minint % -2 == 0)
assert(maxint % -2 == -1)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1019,7 +1019,7 @@ test("[test-suite] math: testing mod operator", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1047,7 +1047,7 @@ test("[test-suite] math: non-portable tests because Windows C library cannot com
assert(-1 % math.huge == math.huge)
assert(-1 % -math.huge == -1)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1056,7 +1056,7 @@ test("[test-suite] math: non-portable tests because Windows C library cannot com
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1103,7 +1103,7 @@ test("[test-suite] math: testing unsigned comparisons", function (t) {
assert(tonumber(' 1.3e-2 ') == 1.3e-2)
assert(tonumber(' -1.00000000000001 ') == -1.00000000000001)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1112,7 +1112,7 @@ test("[test-suite] math: testing unsigned comparisons", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1131,7 +1131,7 @@ test("[test-suite] math: testing constant limits", function (t) {
assert(8388608 + -8388608 == 0)
assert(8388607 + -8388607 == 0)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1140,7 +1140,7 @@ test("[test-suite] math: testing constant limits", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1198,7 +1198,7 @@ test("[test-suite] math: testing floor & ceil", function (t) {
assert(math.tointeger(0/0) == nil) -- NaN
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1207,7 +1207,7 @@ test("[test-suite] math: testing floor & ceil", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1242,7 +1242,7 @@ test("[test-suite] math: testing fmod for integers", function (t) {
checkerror("zero", math.fmod, 3, 0)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1251,7 +1251,7 @@ test("[test-suite] math: testing fmod for integers", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1282,7 +1282,7 @@ test("[test-suite] math: testing max/min", function (t) {
assert(eqT(math.min(maxint - 2, maxint, maxint - 1), maxint - 2))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1291,7 +1291,7 @@ test("[test-suite] math: testing max/min", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1310,7 +1310,7 @@ test("[test-suite] math: testing implicit convertions", function (t) {
assert(a*b == 200 and a+b == 30 and a-b == -10 and a/b == 0.5 and -b == -20)
assert(a == '10' and b == '20')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1319,7 +1319,7 @@ test("[test-suite] math: testing implicit convertions", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1369,7 +1369,7 @@ test("[test-suite] math: testing -0 and NaN", function (t) {
assert(a3 == a5)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1378,7 +1378,7 @@ test("[test-suite] math: testing -0 and NaN", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1410,7 +1410,7 @@ test("[test-suite] math: test random for floats", function (t) {
::ok::
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1419,7 +1419,7 @@ test("[test-suite] math: test random for floats", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1466,7 +1466,7 @@ test("[test-suite] math: test random for small intervals", function (t) {
aux({maxint - 3, maxint})
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1475,7 +1475,7 @@ test("[test-suite] math: test random for small intervals", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1524,7 +1524,7 @@ test("[test-suite] math: test random for large intervals", function (t) {
assert(not pcall(math.random, 1, 2, 3)) -- too many arguments
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1533,7 +1533,7 @@ test("[test-suite] math: test random for large intervals", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1552,7 +1552,7 @@ test("[test-suite] math: test random for empty interval", function (t) {
assert(not pcall(math.random, maxint, maxint - 1))
assert(not pcall(math.random, maxint, minint))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1561,7 +1561,7 @@ test("[test-suite] math: test random for empty interval", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1580,7 +1580,7 @@ test("[test-suite] math: interval too large", function (t) {
assert(not pcall(math.random, -1, maxint))
assert(not pcall(math.random, minint // 2, maxint // 2 + 1))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1589,7 +1589,7 @@ test("[test-suite] math: interval too large", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/nextvar.js b/tests/test-suite/nextvar.js
index ad75f93..3e05490 100644
--- a/tests/test-suite/nextvar.js
+++ b/tests/test-suite/nextvar.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
const prefix = `
local function checkerror (msg, f, ...)
@@ -27,7 +27,7 @@ test("[test-suite] nextvar: testing size operator", function (t) {
assert(#a == i)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -36,7 +36,7 @@ test("[test-suite] nextvar: testing size operator", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -59,7 +59,7 @@ test("[test-suite] nextvar: testing ipairs", function (t) {
for _ in ipairs{x=12, y=24} do assert(nil) end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -68,7 +68,7 @@ test("[test-suite] nextvar: testing ipairs", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -92,7 +92,7 @@ test("[test-suite] nextvar: test for 'false' x ipair", function (t) {
end
assert(i == 4)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -101,7 +101,7 @@ test("[test-suite] nextvar: test for 'false' x ipair", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -118,7 +118,7 @@ test("[test-suite] nextvar: iterator function is always the same", function (t)
let luaCode = `
assert(type(ipairs{}) == 'function' and ipairs{} == ipairs{})
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -127,7 +127,7 @@ test("[test-suite] nextvar: iterator function is always the same", function (t)
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -171,7 +171,7 @@ test("[test-suite] nextvar: JS tests", { skip: true }, function (t) {
a = math.ceil(a*1.3)
end
-
+
local function check (t, na, nh)
local a, h = T.querytab(t)
if a ~= na or h ~= nh then
@@ -195,7 +195,7 @@ test("[test-suite] nextvar: JS tests", { skip: true }, function (t) {
for i=1,lim do
s = s..i..','
local s = s
- for k=0,lim do
+ for k=0,lim do
local t = load(s..'}', '')()
assert(#t == i)
check(t, fb(i), mp2(k))
@@ -272,7 +272,7 @@ test("[test-suite] nextvar: JS tests", { skip: true }, function (t) {
local a = {}
for i=1,lim do a[i] = true; foo(i, table.unpack(a)) end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -281,7 +281,7 @@ test("[test-suite] nextvar: JS tests", { skip: true }, function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -302,7 +302,7 @@ test("[test-suite] nextvar: test size operation on empty tables", function (t) {
assert(#{nil, nil, nil} == 0)
assert(#{nil, nil, nil, nil} == 0)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -311,7 +311,7 @@ test("[test-suite] nextvar: test size operation on empty tables", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -332,7 +332,7 @@ test("[test-suite] nextvar: test size operation on empty tables", function (t) {
assert(#{nil, nil, nil} == 0)
assert(#{nil, nil, nil, nil} == 0)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -341,7 +341,7 @@ test("[test-suite] nextvar: test size operation on empty tables", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -393,7 +393,7 @@ test("[test-suite] nextvar: next uses always the same iteration function", funct
_G["xxx"] = 1
assert(xxx==find("xxx"))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -402,7 +402,7 @@ test("[test-suite] nextvar: next uses always the same iteration function", funct
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -419,7 +419,7 @@ test("[test-suite] nextvar: invalid key to 'next'", function (t) {
let luaCode = `
checkerror("invalid key", next, {10,20}, 3)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -428,7 +428,7 @@ test("[test-suite] nextvar: invalid key to 'next'", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -446,7 +446,7 @@ test("[test-suite] nextvar: both 'pairs' and 'ipairs' need an argument", functio
checkerror("bad argument", pairs)
checkerror("bad argument", ipairs)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -455,7 +455,7 @@ test("[test-suite] nextvar: both 'pairs' and 'ipairs' need an argument", functio
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -485,7 +485,7 @@ test("[test-suite] nextvar: fmod table", function (t) {
assert(n.n == 9000)
a = nil
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -494,7 +494,7 @@ test("[test-suite] nextvar: fmod table", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -522,7 +522,7 @@ test("[test-suite] nextvar: check next", function (t) {
checknext{1,2,3,4,x=1,y=2,z=3}
checknext{1,2,3,4,5,x=1,y=2,z=3}
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -531,7 +531,7 @@ test("[test-suite] nextvar: check next", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -555,7 +555,7 @@ test("[test-suite] nextvar: # operator", function (t) {
assert(#a == i)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -564,7 +564,7 @@ test("[test-suite] nextvar: # operator", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -596,7 +596,7 @@ test("[test-suite] nextvar: maxn", function (t) {
table.maxn = nil
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -605,7 +605,7 @@ test("[test-suite] nextvar: maxn", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -624,7 +624,7 @@ test("[test-suite] nextvar: int overflow", function (t) {
for i=0,50 do a[2^i] = true end
assert(a[#a])
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -633,7 +633,7 @@ test("[test-suite] nextvar: int overflow", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -721,7 +721,7 @@ test("[test-suite] nextvar: erasing values", function (t) {
assert(table.remove(a, 2) == 20)
assert(a[#a] == 30 and #a == 2)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -730,7 +730,7 @@ test("[test-suite] nextvar: erasing values", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -791,7 +791,7 @@ test("[test-suite] nextvar: testing table library with metamethods", function (t
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -800,7 +800,7 @@ test("[test-suite] nextvar: testing table library with metamethods", function (t
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -839,12 +839,12 @@ test("[test-suite] nextvar: JS tests", { skip: true }, function (t) {
mt.__newindex = nil
mt.__len = nil
local tab2 = {}
- local u2 = T.newuserdata(0)
+ local u2 = T.newuserdata(0)
debug.setmetatable(u2, {__newindex = function (_, k, v) tab2[k] = v end})
table.move(u, 1, 4, 1, u2)
assert(#tab2 == 4 and tab2[1] == tab[1] and tab2[4] == tab[4])
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -853,7 +853,7 @@ test("[test-suite] nextvar: JS tests", { skip: true }, function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -883,7 +883,7 @@ test("[test-suite] nextvar: next", function (t) {
a = nil; for i=1,1 do assert(not a); a=1 end; assert(a)
a = nil; for i=1,1,-1 do assert(not a); a=1 end; assert(a)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -892,7 +892,7 @@ test("[test-suite] nextvar: next", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -926,7 +926,7 @@ test("[test-suite] nextvar: testing floats in numeric for", function (t) {
a = 0; for i=1.0, 0.99999, -1 do a=a+1 end; assert(a==1)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -935,7 +935,7 @@ test("[test-suite] nextvar: testing floats in numeric for", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -952,7 +952,7 @@ test("[test-suite] nextvar: conversion", function (t) {
let luaCode = `
a = 0; for i="10","1","-2" do a=a+1 end; assert(a==5)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -961,7 +961,7 @@ test("[test-suite] nextvar: conversion", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1030,7 +1030,7 @@ test("[test-suite] nextvar: checking types", function (t) {
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1039,7 +1039,7 @@ test("[test-suite] nextvar: checking types", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1071,7 +1071,7 @@ test("[test-suite] nextvar: testing generic 'for'", function (t) {
end
assert(x == 5)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1080,7 +1080,7 @@ test("[test-suite] nextvar: testing generic 'for'", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1123,7 +1123,7 @@ test("[test-suite] nextvar: testing __pairs and __ipairs metamethod", function (
a.n = 5
a[3] = 30
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1132,7 +1132,7 @@ test("[test-suite] nextvar: testing __pairs and __ipairs metamethod", function (
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -1149,7 +1149,7 @@ test("[test-suite] nextvar: testing ipairs with metamethods", function (t) {
let luaCode = `
a = {n=10}
setmetatable(a, { __index = function (t,k)
- if k <= t.n then return k * 10 end
+ if k <= t.n then return k * 10 end
end})
i = 0
for k,v in ipairs(a) do
@@ -1158,7 +1158,7 @@ test("[test-suite] nextvar: testing ipairs with metamethods", function (t) {
end
assert(i == a.n)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -1167,7 +1167,7 @@ test("[test-suite] nextvar: testing ipairs with metamethods", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/pm.js b/tests/test-suite/pm.js
index ae3512e..214d498 100644
--- a/tests/test-suite/pm.js
+++ b/tests/test-suite/pm.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
test("[test-suite] pm: pattern matching", function (t) {
let luaCode = `
@@ -86,7 +86,7 @@ test("[test-suite] pm: pattern matching", function (t) {
assert(f("0alo alo", "%x*") == "0a")
assert(f("alo alo", "%C+") == "alo alo")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -95,7 +95,7 @@ test("[test-suite] pm: pattern matching", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -125,7 +125,7 @@ test("[test-suite] pm: tonumber", function (t) {
-- assert(f1('=======', '^(=*)=%1$') == '=======')
assert(string.match('==========', '^([=]*)=%1$') == nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -134,7 +134,7 @@ test("[test-suite] pm: tonumber", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -177,7 +177,7 @@ test("[test-suite] pm: range", function (t) {
assert(strset('%Z') == strset('[\\1-\\255]'))
assert(strset('.') == strset('[\\1-\\255%z]'))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -186,7 +186,7 @@ test("[test-suite] pm: range", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -210,7 +210,7 @@ test("[test-suite] pm: classes", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadfile(L, lua.to_luastring("tests/test-suite/pm-classes.lua"));
+ lauxlib.luaL_loadfile(L, to_luastring("tests/test-suite/pm-classes.lua"));
}, "Lua program loaded without error");
@@ -234,7 +234,7 @@ test("[test-suite] pm: gsub", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadfile(L, lua.to_luastring("tests/test-suite/pm-gsub.lua"));
+ lauxlib.luaL_loadfile(L, to_luastring("tests/test-suite/pm-gsub.lua"));
}, "Lua program loaded without error");
@@ -262,7 +262,7 @@ test("[test-suite] pm: empty matches", function (t) {
assert(res == "-a-b-c-d-")
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -271,7 +271,7 @@ test("[test-suite] pm: empty matches", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -316,7 +316,7 @@ test("[test-suite] pm: gsub", function (t) {
end)
assert(s == r and t[1] == 1 and t[3] == 3 and t[7] == 4 and t[13] == 4)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -325,7 +325,7 @@ test("[test-suite] pm: gsub", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -348,7 +348,7 @@ test("[test-suite] pm: gsub isbalanced", function (t) {
assert(not isbalanced("(9 ((8) 7) a b (\\0 c) a"))
assert(string.gsub("alo 'oi' alo", "%b''", '"') == 'alo " alo')
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -357,7 +357,7 @@ test("[test-suite] pm: gsub isbalanced", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -397,7 +397,7 @@ test("[test-suite] pm: capture", function (t) {
checkerror("invalid capture index %%1", string.gsub, "alo", "(%1)", "a")
checkerror("invalid use of '%%'", string.gsub, "alo", ".", "%x")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -406,7 +406,7 @@ test("[test-suite] pm: capture", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -434,7 +434,7 @@ test("[test-suite] pm: bug since 2.5 (C-stack overflow) (TODO: _soft)", function
assert(not r and string.find(m, "too complex"))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -443,7 +443,7 @@ test("[test-suite] pm: bug since 2.5 (C-stack overflow) (TODO: _soft)", function
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -471,7 +471,7 @@ test("[test-suite] pm: big strings (TODO: _soft)", function (t) {
assert(not pcall(string.gsub, a, 'b'))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -480,7 +480,7 @@ test("[test-suite] pm: big strings (TODO: _soft)", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -502,7 +502,7 @@ test("[test-suite] pm: recursive nest of gsubs", function (t) {
local x = "abcdef"
assert(rev(rev(x)) == x)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -511,7 +511,7 @@ test("[test-suite] pm: recursive nest of gsubs", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -536,7 +536,7 @@ test("[test-suite] pm: gsub with tables", function (t) {
t = {}; setmetatable(t, {__index = function (t,s) return string.upper(s) end})
assert(string.gsub("a alo b hi", "%w%w+", t) == "a ALO b HI")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -545,7 +545,7 @@ test("[test-suite] pm: gsub with tables", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -584,7 +584,7 @@ test("[test-suite] pm: gmatch", function (t) {
for k,v in pairs(t) do assert(k+1 == v+0); a=a+1 end
assert(a == 3)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -593,7 +593,7 @@ test("[test-suite] pm: gmatch", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -634,7 +634,7 @@ test("[test-suite] pm: tests for '%f' ('frontiers')", function (t) {
end
assert(#a == 0)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -643,7 +643,7 @@ test("[test-suite] pm: tests for '%f' ('frontiers')", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -676,7 +676,7 @@ test("[test-suite] pm: malformed patterns", function (t) {
malform("%")
malform("%f", "missing")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -685,7 +685,7 @@ test("[test-suite] pm: malformed patterns", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -708,7 +708,7 @@ test("[test-suite] pm: \\0 in patterns", function (t) {
assert(string.match("abc\\0\\0\\0", "%\\0+") == "\\0\\0\\0")
assert(string.match("abc\\0\\0\\0", "%\\0%\\0?") == "\\0\\0")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -717,7 +717,7 @@ test("[test-suite] pm: \\0 in patterns", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -735,7 +735,7 @@ test("[test-suite] pm: magic char after \\0", function (t) {
assert(string.find("abc\\0\\0","\\0.") == 4)
assert(string.find("abcx\\0\\0abc\\0abc","x\\0\\0abc\\0a.") == 4)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -744,7 +744,7 @@ test("[test-suite] pm: magic char after \\0", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/sort.js b/tests/test-suite/sort.js
index 9cee400..c52f30c 100644
--- a/tests/test-suite/sort.js
+++ b/tests/test-suite/sort.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
const prefix = `
local unpack = table.unpack
@@ -59,7 +59,7 @@ test("[test-suite] sort: testing unpack", function (t) {
a,x = unpack({1,2}, 1, 1)
assert(a==1 and x==nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -68,7 +68,7 @@ test("[test-suite] sort: testing unpack", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -111,7 +111,7 @@ test("[test-suite] sort: testing unpack", function (t) {
a, b = unpack(t, minI + 1, minI); assert(a == nil and b == nil)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -120,7 +120,7 @@ test("[test-suite] sort: testing unpack", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -141,7 +141,7 @@ test("[test-suite] sort: testing unpack", function (t) {
checkerror("object length is not an integer", table.insert, t, 1)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -150,7 +150,7 @@ test("[test-suite] sort: testing unpack", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -166,7 +166,7 @@ test("[test-suite] sort: testing unpack", function (t) {
test("[test-suite] sort: testing pack", function (t) {
let luaCode = `
a = table.pack()
- assert(a[1] == nil and a.n == 0)
+ assert(a[1] == nil and a.n == 0)
a = table.pack(table)
assert(a[1] == table and a.n == 1)
@@ -174,7 +174,7 @@ test("[test-suite] sort: testing pack", function (t) {
a = table.pack(nil, nil, nil, nil)
assert(a[1] == nil and a.n == 4)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -183,7 +183,7 @@ test("[test-suite] sort: testing pack", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -203,8 +203,8 @@ test("[test-suite] sort: testing move", function (t) {
checkerror("table expected", table.move, 1, 2, 3, 4)
local function eqT (a, b)
- for k, v in pairs(a) do assert(b[k] == v) end
- for k, v in pairs(b) do assert(a[k] == v) end
+ for k, v in pairs(a) do assert(b[k] == v) end
+ for k, v in pairs(b) do assert(a[k] == v) end
end
local a = table.move({10,20,30}, 1, 3, 2) -- move forward
@@ -269,7 +269,7 @@ test("[test-suite] sort: testing move", function (t) {
assert(not stat and msg == b)
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -278,7 +278,7 @@ test("[test-suite] sort: testing move", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -320,7 +320,7 @@ test("[test-suite] sort: testing long move", function (t) {
checkerror("wrap around", table.move, {}, 1, 2, maxI)
checkerror("wrap around", table.move, {}, minI, -2, 2)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -329,7 +329,7 @@ test("[test-suite] sort: testing long move", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -350,7 +350,7 @@ test("[test-suite] sort: testing sort, strange lengths", function (t) {
a = setmetatable({}, {__len = function () return maxI end})
checkerror("too big", table.sort, a)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -359,7 +359,7 @@ test("[test-suite] sort: testing sort, strange lengths", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -383,7 +383,7 @@ test("[test-suite] sort: test checks for invalid order functions", function (t)
check{1,2,3,4,5}
check{1,2,3,4,5,6}
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -392,7 +392,7 @@ test("[test-suite] sort: test checks for invalid order functions", function (t)
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -420,7 +420,7 @@ test("[test-suite] sort: sort alpha", function (t) {
table.sort(a)
check(a)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -429,7 +429,7 @@ test("[test-suite] sort: sort alpha", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -477,7 +477,7 @@ test("[test-suite] sort: sort perm", function (t) {
perm{1,2,3,4,5,6}
perm{2,2,3,3,5,6}
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -486,7 +486,7 @@ test("[test-suite] sort: sort perm", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -527,7 +527,7 @@ test("[test-suite] sort: Invert-sorting", function (t) {
for i,v in pairs(a) do assert(v == false) end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -536,7 +536,7 @@ test("[test-suite] sort: Invert-sorting", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -576,7 +576,7 @@ test("[test-suite] sort: sorting", function (t) {
check(a, tt.__lt)
check(a)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -585,7 +585,7 @@ test("[test-suite] sort: sorting", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/strings.js b/tests/test-suite/strings.js
index 0efedcb..cbffe5c 100644
--- a/tests/test-suite/strings.js
+++ b/tests/test-suite/strings.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
const checkerror = `
local maxi, mini = math.maxinteger, math.mininteger
@@ -45,7 +45,7 @@ test('[test-suite] strings: string comparisons', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -87,7 +87,7 @@ test('[test-suite] strings: string.sub', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -125,7 +125,7 @@ test('[test-suite] strings: string.find', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -157,7 +157,7 @@ test('[test-suite] strings: string.len and #', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -214,7 +214,7 @@ test('[test-suite] strings: string.byte/string.char', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -251,7 +251,7 @@ test('[test-suite] strings: repetitions with separator', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -303,7 +303,7 @@ test('[test-suite] strings: tostring', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -350,7 +350,7 @@ test('[test-suite] strings: string.format', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -391,7 +391,7 @@ test('[test-suite] strings: %q', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -418,7 +418,7 @@ test('[test-suite] strings: embedded zeros error', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -461,7 +461,7 @@ test('[test-suite] strings: format x tostring', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -498,7 +498,7 @@ test('[test-suite] strings: longest number that can be formatted', function (t)
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -547,7 +547,7 @@ test('[test-suite] strings: large numbers for format', function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -604,7 +604,7 @@ test("[test-suite] strings: 'format %a %A'", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -644,7 +644,7 @@ test("[test-suite] strings: errors in format", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -695,7 +695,7 @@ test("[test-suite] strings: table.concat", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -751,7 +751,7 @@ test.skip("[test-suite] strings: locale", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
@@ -782,7 +782,7 @@ test("[test-suite] strings: bug in Lua 5.3.2: 'gmatch' iterator does not work ac
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/tpack.js b/tests/test-suite/tpack.js
index ebce4e4..745c151 100644
--- a/tests/test-suite/tpack.js
+++ b/tests/test-suite/tpack.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
const prefix = `
local pack = string.pack
@@ -55,7 +55,7 @@ test("[test-suite] tpack: maximum size for integers", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -91,7 +91,7 @@ test("[test-suite] tpack: minimum behavior for integer formats", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -130,7 +130,7 @@ test("[test-suite] tpack: minimum behavior for integer formats", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -175,7 +175,7 @@ test("[test-suite] tpack: minimum behavior for integer formats", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -209,7 +209,7 @@ test("[test-suite] tpack: minimum behavior for integer formats", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -242,7 +242,7 @@ test("[test-suite] tpack: sign extension", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -273,7 +273,7 @@ test("[test-suite] tpack: mixed endianness", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -308,7 +308,7 @@ test("[test-suite] tpack: testing invalid formats", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -343,7 +343,7 @@ test("[test-suite] tpack: overflow in option size (error will be in digit after
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -384,7 +384,7 @@ test("[test-suite] tpack: overflow in packing", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -418,7 +418,7 @@ test("[test-suite] tpack: Lua integer size", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -458,7 +458,7 @@ test("[test-suite] tpack: testing pack/unpack of floating-point numbers", functi
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -524,7 +524,7 @@ test("[test-suite] tpack: testing pack/unpack of strings", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -544,7 +544,7 @@ test("[test-suite] tpack: testing multiple types and sequence", function (t) {
assert(#x == packsize("<b h b f d f n i"))
local a, b, c, d, e, f, g, h = unpack("<b h b f d f n i", x)
assert(a == 1 and b == 2 and c == 3 and d == 4 and e == 5 and f == 6 and
- g == 7 and h == 8)
+ g == 7 and h == 8)
end
`, L;
@@ -556,7 +556,7 @@ test("[test-suite] tpack: testing multiple types and sequence", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -577,7 +577,7 @@ test("[test-suite] tpack: testing alignment", function (t) {
assert(#x == packsize(">!8 b Xh i4 i8 c1 Xi8"))
assert(x == "\\xf4" .. "\\0\\0\\0" ..
"\\0\\0\\0\\100" ..
- "\\0\\0\\0\\0\\0\\0\\0\\xC8" ..
+ "\\0\\0\\0\\0\\0\\0\\0\\xC8" ..
"\\xEC" .. "\\0\\0\\0\\0\\0\\0\\0")
local a, b, c, d, pos = unpack(">!8 c1 Xh i4 i8 b Xi8 XI XH", x)
assert(a == "\\xF4" and b == 100 and c == 200 and d == -20 and (pos - 1) == #x)
@@ -622,7 +622,7 @@ test("[test-suite] tpack: testing alignment", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
@@ -665,7 +665,7 @@ test("[test-suite] tpack: testing initial position", function (t) {
checkerror("out of string", unpack, "c0", x, 0)
checkerror("out of string", unpack, "c0", x, #x + 2)
checkerror("out of string", unpack, "c0", x, -(#x + 1))
-
+
end
`, L;
@@ -677,7 +677,7 @@ test("[test-suite] tpack: testing initial position", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/utf8.js b/tests/test-suite/utf8.js
index 91941bf..173dffd 100644
--- a/tests/test-suite/utf8.js
+++ b/tests/test-suite/utf8.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
const prefix = `
local function checkerror (msg, f, ...)
@@ -107,7 +107,7 @@ test("[test-suite] utf8: offset", function (t) {
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);
- if (lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
+ if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
throw new SyntaxError(lua.lua_tojsstring(L, -1));
}, "Lua program loaded without error");
@@ -136,7 +136,7 @@ test("[test-suite] utf8: error indication in utf8.len", function (t) {
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);
- if (lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
+ if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
throw new SyntaxError(lua.lua_tojsstring(L, -1));
}, "Lua program loaded without error");
@@ -162,7 +162,7 @@ test("[test-suite] utf8: error in initial position for offset", function (t) {
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);
- if (lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
+ if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
throw new SyntaxError(lua.lua_tojsstring(L, -1));
}, "Lua program loaded without error");
@@ -206,7 +206,7 @@ test("[test-suite] utf8: codepoints", function (t) {
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);
- if (lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
+ if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
throw new SyntaxError(lua.lua_tojsstring(L, -1));
}, "Lua program loaded without error");
@@ -226,7 +226,7 @@ test("[test-suite] utf8: UTF-8 representation for 0x11ffff (value out of valid r
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);
- if (lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
+ if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
throw new SyntaxError(lua.lua_tojsstring(L, -1));
}, "Lua program loaded without error");
@@ -249,7 +249,7 @@ test("[test-suite] utf8: overlong sequences", function (t) {
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);
- if (lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
+ if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
throw new SyntaxError(lua.lua_tojsstring(L, -1));
}, "Lua program loaded without error");
@@ -272,7 +272,7 @@ test("[test-suite] utf8: invalid bytes", function (t) {
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);
- if (lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
+ if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
throw new SyntaxError(lua.lua_tojsstring(L, -1));
}, "Lua program loaded without error");
@@ -292,7 +292,7 @@ test("[test-suite] utf8: empty strings", function (t) {
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);
- if (lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
+ if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
throw new SyntaxError(lua.lua_tojsstring(L, -1));
}, "Lua program loaded without error");
@@ -339,7 +339,7 @@ test("[test-suite] utf8: minimum and maximum values for each sequence size", fun
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);
- if (lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
+ if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX)
throw new SyntaxError(lua.lua_tojsstring(L, -1));
}, "Lua program loaded without error");
diff --git a/tests/test-suite/vararg.js b/tests/test-suite/vararg.js
index dc90248..1cc5ace 100644
--- a/tests/test-suite/vararg.js
+++ b/tests/test-suite/vararg.js
@@ -5,7 +5,7 @@ const test = require('tape');
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
-
+const {to_luastring} = require("../../src/fengaricore.js");
test("[test-suite] vararg: testing vararg", function (t) {
let luaCode = `
@@ -73,7 +73,7 @@ test("[test-suite] vararg: testing vararg", function (t) {
while i <= lim do a[i] = i; i=i+1 end
assert(call(math.max, a) == lim)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -82,7 +82,7 @@ test("[test-suite] vararg: testing vararg", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -118,7 +118,7 @@ test("[test-suite] vararg: new-style varargs", function (t) {
a,b,c,d,e = f(4)
assert(a==nil and b==nil and c==nil and d==nil and e==nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -127,7 +127,7 @@ test("[test-suite] vararg: new-style varargs", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -168,7 +168,7 @@ test("[test-suite] vararg: varargs for main chunks", function (t) {
pcall(select, 10000)
pcall(select, -10000)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -177,7 +177,7 @@ test("[test-suite] vararg: varargs for main chunks", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
@@ -204,7 +204,7 @@ test("[test-suite] vararg: bug in 5.2.2", function (t) {
-- assertion fail here
f()
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -213,7 +213,7 @@ test("[test-suite] vararg: bug in 5.2.2", function (t) {
lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+ lauxlib.luaL_loadstring(L, to_luastring(luaCode));
}, "Lua program loaded without error");
diff --git a/tests/tests.js b/tests/tests.js
index 1ad9900..778cbef 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -2,6 +2,7 @@
const lua = require("../src/lua.js");
const lauxlib = require("../src/lauxlib.js");
+const {to_luastring} = require("../src/fengaricore.js");
const toByteCode = function(luaCode) {
let L = getState(luaCode);
@@ -19,7 +20,7 @@ const getState = function(luaCode) {
if (!L)
throw Error("unable to create lua_State");
- if (lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)) !== lua.LUA_OK)
+ if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) !== lua.LUA_OK)
throw Error(lua.lua_tojsstring(L, -1));
return L;