aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-04-26 17:55:37 +1000
committerdaurnimator <quae@daurnimator.com>2017-04-26 18:06:57 +1000
commitb688ef577a10e8b6f2cf948faaa8d1af70c7949c (patch)
tree0ff07d75f65442b92d8a95259b9ab6845e66b27a
parent53bd1fcc4b90f24427064419354ad07c552a93d5 (diff)
downloadfengari-b688ef577a10e8b6f2cf948faaa8d1af70c7949c.tar.gz
fengari-b688ef577a10e8b6f2cf948faaa8d1af70c7949c.tar.bz2
fengari-b688ef577a10e8b6f2cf948faaa8d1af70c7949c.zip
Export lapi.js functions from lua.js
-rw-r--r--src/lauxlib.js220
-rw-r--r--src/lbaselib.js187
-rw-r--r--src/lcorolib.js75
-rw-r--r--src/ldblib.js165
-rw-r--r--src/lmathlib.js113
-rw-r--r--src/loslib.js17
-rw-r--r--src/lstrlib.js132
-rw-r--r--src/ltablib.js82
-rw-r--r--src/lua.js99
-rw-r--r--src/lutf8lib.js32
-rw-r--r--tests/lapi.js109
-rw-r--r--tests/lbaselib.js133
-rw-r--r--tests/lcorolib.js37
-rw-r--r--tests/ldblib.js61
-rw-r--r--tests/ldebug.js49
-rw-r--r--tests/lexparse.js214
-rw-r--r--tests/lmathlib.js109
-rw-r--r--tests/load.js25
-rw-r--r--tests/loslib.js5
-rw-r--r--tests/lstrlib.js147
-rw-r--r--tests/ltablib.js53
-rw-r--r--tests/ltm.js105
-rw-r--r--tests/lutf8lib.js25
-rw-r--r--tests/lvm.js100
-rw-r--r--tests/manual-tests/debug-cli.js3
-rwxr-xr-xtests/manual-tests/lua-cli.js61
26 files changed, 1219 insertions, 1139 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js
index f3287f5..7b5f958 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -27,25 +27,25 @@ const LEVELS2 = 11; /* size of the second part of the stack */
** return 1 + string at top if find a good name.
*/
const findfield = function(L, objidx, level) {
- if (level === 0 || !lapi.lua_istable(L, -1))
+ if (level === 0 || !lua.lua_istable(L, -1))
return 0; /* not found */
- lapi.lua_pushnil(L); /* start 'next' loop */
+ lua.lua_pushnil(L); /* start 'next' loop */
- while (lapi.lua_next(L, -2)) { /* for each pair in table */
- if (lapi.lua_type(L, -2) === lua.LUA_TSTRING) { /* ignore non-string keys */
- if (lapi.lua_rawequal(L, objidx, -1)) { /* found object? */
- lapi.lua_pop(L, 1); /* remove value (but keep name) */
+ while (lua.lua_next(L, -2)) { /* for each pair in table */
+ if (lua.lua_type(L, -2) === lua.LUA_TSTRING) { /* ignore non-string keys */
+ if (lua.lua_rawequal(L, objidx, -1)) { /* found object? */
+ lua.lua_pop(L, 1); /* remove value (but keep name) */
return 1;
} else if (findfield(L, objidx, level - 1)) { /* try recursively */
- lapi.lua_remove(L, -2); /* remove table (but keep name) */
- lapi.lua_pushliteral(L, ".");
- lapi.lua_insert(L, -2); /* place '.' between the two names */
- lapi.lua_concat(L, 3);
+ lua.lua_remove(L, -2); /* remove table (but keep name) */
+ lua.lua_pushliteral(L, ".");
+ lua.lua_insert(L, -2); /* place '.' between the two names */
+ lua.lua_concat(L, 3);
return 1;
}
}
- lapi.lua_pop(L, 1); /* remove value */
+ lua.lua_pop(L, 1); /* remove value */
}
return 0; /* not found */
@@ -55,20 +55,20 @@ const findfield = function(L, objidx, level) {
** Search for a name for a function in all loaded modules
*/
const pushglobalfuncname = function(L, ar) {
- let top = lapi.lua_gettop(L);
+ let top = lua.lua_gettop(L);
ldebug.lua_getinfo(L, ['f'.charCodeAt(0)], ar); /* push function */
- lapi.lua_getfield(L, lua.LUA_REGISTRYINDEX, lua.to_luastring(LUA_LOADED_TABLE, true));
+ lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, lua.to_luastring(LUA_LOADED_TABLE, true));
if (findfield(L, top + 1, 2)) {
- let name = lapi.lua_tostring(L, -1);
+ let name = lua.lua_tostring(L, -1);
if (lobject.jsstring(name).startsWith("_G.")) { /* name start with '_G.'? */
- lapi.lua_pushstring(L, name.slice(3)); /* push name without prefix */
- lapi.lua_remove(L, -2); /* remove original name */
+ lua.lua_pushstring(L, name.slice(3)); /* push name without prefix */
+ lua.lua_remove(L, -2); /* remove original name */
}
- lapi.lua_copy(L, -1, top + 1); /* move name to proper place */
- lapi.lua_pop(L, 2); /* remove pushed values */
+ lua.lua_copy(L, -1, top + 1); /* move name to proper place */
+ lua.lua_pop(L, 2); /* remove pushed values */
return 1;
} else {
- lapi.lua_settop(L, top); /* remove function and global table */
+ lua.lua_settop(L, top); /* remove function and global table */
return 0;
}
};
@@ -77,17 +77,17 @@ const sv = s => s ? s : [];
const pushfuncname = function(L, ar) {
if (pushglobalfuncname(L, ar)) { /* try first a global name */
- lapi.lua_pushstring(L, lua.to_luastring("function '", true).concat(lapi.lua_tostring(L, -1)).concat(["'".charCodeAt(0)]));
- lapi.lua_remove(L, -2); /* remove name */
+ lua.lua_pushstring(L, lua.to_luastring("function '", true).concat(lua.lua_tostring(L, -1)).concat(["'".charCodeAt(0)]));
+ lua.lua_remove(L, -2); /* remove name */
}
else if (ar.namewhat) /* is there a name from code? */
- lapi.lua_pushstring(L, sv(ar.namewhat).concat(" ".charCodeAt(0), "'".charCodeAt(0), ...sv(ar.name.value), "'".charCodeAt(0))); /* use it */
+ lua.lua_pushstring(L, sv(ar.namewhat).concat(" ".charCodeAt(0), "'".charCodeAt(0), ...sv(ar.name.value), "'".charCodeAt(0))); /* use it */
else if (ar.what && ar.what[0] === 'm'.charCodeAt(0)) /* main? */
- lapi.lua_pushliteral(L, "main chunk");
+ lua.lua_pushliteral(L, "main chunk");
else if (ar.what && ar.what[0] != 'C'.charCodeAt(0)) /* for Lua functions, use <file:line> */
- lapi.lua_pushstring(L, lua.to_luastring("function <", true).concat(...sv(ar.short_src), ':'.charCodeAt(0), ...lua.to_luastring(`${ar.linedefined}>`)));
+ lua.lua_pushstring(L, lua.to_luastring("function <", true).concat(...sv(ar.short_src), ':'.charCodeAt(0), ...lua.to_luastring(`${ar.linedefined}>`)));
else /* nothing left... */
- lapi.lua_pushliteral(L, "?");
+ lua.lua_pushliteral(L, "?");
};
const lastlevel = function(L) {
@@ -107,34 +107,34 @@ const lastlevel = function(L) {
const luaL_traceback = function(L, L1, msg, level) {
let ar = new lua.lua_Debug();
- let top = lapi.lua_gettop(L);
+ let top = lua.lua_gettop(L);
let last = lastlevel(L1);
let n1 = last - level > LEVELS1 + LEVELS2 ? LEVELS1 : -1;
if (msg)
- lapi.lua_pushstring(L, msg.concat('\n'.charCodeAt(0)));
+ lua.lua_pushstring(L, msg.concat('\n'.charCodeAt(0)));
luaL_checkstack(L, 10, null);
- lapi.lua_pushliteral(L, "stack traceback:");
+ lua.lua_pushliteral(L, "stack traceback:");
while (ldebug.lua_getstack(L1, level++, ar)) {
if (n1-- === 0) { /* too many levels? */
- lapi.lua_pushliteral(L, "\n\t..."); /* add a '...' */
+ lua.lua_pushliteral(L, "\n\t..."); /* add a '...' */
level = last - LEVELS2 + 1; /* and skip to last ones */
} else {
ldebug.lua_getinfo(L1, lua.to_luastring("Slnt", true), ar);
- lapi.lua_pushstring(L, ['\n'.charCodeAt(0), '\t'.charCodeAt(0), '.'.charCodeAt(0), '.'.charCodeAt(0), '.'.charCodeAt(0)].concat(ar.short_src));
+ lua.lua_pushstring(L, ['\n'.charCodeAt(0), '\t'.charCodeAt(0), '.'.charCodeAt(0), '.'.charCodeAt(0), '.'.charCodeAt(0)].concat(ar.short_src));
if (ar.currentline > 0)
- lapi.lua_pushliteral(L, `${ar.currentline}:`);
- lapi.lua_pushliteral(L, " in ");
+ lua.lua_pushliteral(L, `${ar.currentline}:`);
+ lua.lua_pushliteral(L, " in ");
pushfuncname(L, ar);
if (ar.istailcall)
- lapi.lua_pushliteral(L, "\n\t(...tail calls..)");
- lapi.lua_concat(L, lapi.lua_gettop(L) - top);
+ lua.lua_pushliteral(L, "\n\t(...tail calls..)");
+ lua.lua_concat(L, lua.lua_gettop(L) - top);
}
}
- lapi.lua_concat(L, lapi.lua_gettop(L) - top);
+ lua.lua_concat(L, lua.lua_gettop(L) - top);
};
const panic = function(L) {
- throw new Error(`PANIC: unprotected error in call to Lua API (${lapi.lua_tojsstring(L, -1)})`);
+ throw new Error(`PANIC: unprotected error in call to Lua API (${lua.lua_tojsstring(L, -1)})`);
};
const luaL_argerror = function(L, arg, extramsg) {
@@ -152,7 +152,7 @@ const luaL_argerror = function(L, arg, extramsg) {
}
if (ar.name === null)
- ar.name = pushglobalfuncname(L, ar) ? lapi.lua_tostring(L, -1) : ["?".charCodeAt(0)];
+ ar.name = pushglobalfuncname(L, ar) ? lua.lua_tostring(L, -1) : ["?".charCodeAt(0)];
return luaL_error(L, lua.to_luastring(`bad argument #${arg} to '${lobject.jsstring(ar.name)}' (${lobject.jsstring(extramsg)})`));
};
@@ -160,13 +160,13 @@ const luaL_argerror = function(L, arg, extramsg) {
const typeerror = function(L, arg, tname) {
let typearg;
if (luaL_getmetafield(L, arg, lua.to_luastring("__name", true)) === lua.LUA_TSTRING)
- typearg = lapi.lua_tostring(L, -1);
- else if (lapi.lua_type(L, arg) === lua.LUA_TLIGHTUSERDATA)
+ typearg = lua.lua_tostring(L, -1);
+ else if (lua.lua_type(L, arg) === lua.LUA_TLIGHTUSERDATA)
typearg = lua.to_luastring("light userdata", true);
else
typearg = luaL_typename(L, arg);
- let msg = lapi.lua_pushstring(L, lua.to_luastring(`${lobject.jsstring(tname)} expected, got ${lobject.jsstring(typearg)}`));
+ let msg = lua.lua_pushstring(L, lua.to_luastring(`${lobject.jsstring(tname)} expected, got ${lobject.jsstring(typearg)}`));
return luaL_argerror(L, arg, msg);
};
@@ -175,11 +175,11 @@ const luaL_where = function(L, level) {
if (ldebug.lua_getstack(L, level, ar)) {
ldebug.lua_getinfo(L, lua.to_luastring("Sl", true), ar);
if (ar.currentline > 0) {
- lapi.lua_pushstring(L, lua.to_luastring(`${lobject.jsstring(ar.short_src)}:${ar.currentline}:`));
+ lua.lua_pushstring(L, lua.to_luastring(`${lobject.jsstring(ar.short_src)}:${ar.currentline}:`));
return;
}
}
- lapi.lua_pushstring(L, []);
+ lua.lua_pushstring(L, []);
};
const luaL_error = function(L, fmt, ...args) {
@@ -192,24 +192,24 @@ const luaL_error = function(L, fmt, ...args) {
});
fmt = lua.to_luastring(fmt);
- lapi.lua_pushstring(L, fmt);
+ lua.lua_pushstring(L, fmt);
- return lapi.lua_error(L);
+ return lua.lua_error(L);
};
const tag_error = function(L, arg, tag) {
- typeerror(L, arg, lapi.lua_typename(L, tag));
+ typeerror(L, arg, lua.lua_typename(L, tag));
};
const luaL_newstate = function() {
let L = lstate.lua_newstate();
- if (L) lapi.lua_atpanic(L, panic);
+ if (L) lua.lua_atpanic(L, panic);
return L;
};
const luaL_typename = function(L, i) {
- return lapi.lua_typename(L, lapi.lua_type(L, i));
+ return lua.lua_typename(L, lua.lua_type(L, i));
};
const luaL_argcheck = function(L, cond, arg, extramsg) {
@@ -217,12 +217,12 @@ const luaL_argcheck = function(L, cond, arg, extramsg) {
};
const luaL_checkany = function(L, arg) {
- if (lapi.lua_type(L, arg) === lua.LUA_TNONE)
+ if (lua.lua_type(L, arg) === lua.LUA_TNONE)
luaL_argerror(L, arg, lua.to_luastring("value expected", true));
};
const luaL_checktype = function(L, arg, t) {
- if (lapi.lua_type(L, arg) !== t)
+ if (lua.lua_type(L, arg) !== t)
tag_error(L, arg, t);
};
@@ -231,13 +231,13 @@ const luaL_checkstring = function(L, n) {
};
const luaL_checklstring = function(L, arg) {
- let s = lapi.lua_tolstring(L, arg);
+ let s = lua.lua_tolstring(L, arg);
if (s === null || s === undefined) tag_error(L, arg, lua.LUA_TSTRING);
return s;
};
const luaL_optlstring = function(L, arg, def) {
- if (lapi.lua_type(L, arg) <= 0) {
+ if (lua.lua_type(L, arg) <= 0) {
return def;
} else return luaL_checklstring(L, arg);
};
@@ -245,21 +245,21 @@ const luaL_optlstring = function(L, arg, def) {
const luaL_optstring = luaL_optlstring;
const interror = function(L, arg) {
- if (lapi.lua_isnumber(L, arg))
+ if (lua.lua_isnumber(L, arg))
luaL_argerror(L, arg, lua.to_luastring("number has no integer representation", true));
else
tag_error(L, arg, lua.LUA_TNUMBER);
};
const luaL_checknumber = function(L, arg) {
- let d = lapi.lua_tonumber(L, arg);
+ let d = lua.lua_tonumber(L, arg);
if (d === false)
tag_error(L, arg, lua.LUA_TNUMBER);
return d;
};
const luaL_checkinteger = function(L, arg) {
- let d = lapi.lua_tointeger(L, arg);
+ let d = lua.lua_tointeger(L, arg);
if (d === false)
interror(L, arg);
return d;
@@ -291,7 +291,7 @@ const luaL_addstring = luaL_addlstring;
const luaL_pushresult = function(B) {
let L = B.L;
- lapi.lua_pushstring(L, B.b);
+ lua.lua_pushstring(L, B.b);
};
const luaL_addchar = function(B, c) {
@@ -300,14 +300,14 @@ const luaL_addchar = function(B, c) {
const luaL_addvalue = function(B) {
let L = B.L;
- let s = lapi.lua_tostring(L, -1);
+ let s = lua.lua_tostring(L, -1);
// TODO: buffonstack ? necessary ?
luaL_addstring(B, s);
- lapi.lua_remove(L, -1);
+ lua.lua_remove(L, -1);
};
const luaL_opt = function(L, f, n, d) {
- return lapi.lua_type(L, n) <= 0 ? d : f(L, n);
+ return lua.lua_type(L, n) <= 0 ? d : f(L, n);
};
const getS = function(L, ud) {
@@ -317,7 +317,7 @@ const getS = function(L, ud) {
};
const luaL_loadbufferx = function(L, buff, size, name, mode) {
- return lapi.lua_load(L, getS, {string: buff}, name, mode);
+ return lua.lua_load(L, getS, {string: buff}, name, mode);
};
const luaL_loadbuffer = function(L, s, sz, n) {
@@ -329,64 +329,64 @@ const luaL_loadstring = function(L, s) {
};
const luaL_getmetafield = function(L, obj, event) {
- if (!lapi.lua_getmetatable(L, obj))
+ if (!lua.lua_getmetatable(L, obj))
return lua.LUA_TNIL;
else {
- lapi.lua_pushstring(L, event);
- let tt = lapi.lua_rawget(L, -2);
+ lua.lua_pushstring(L, event);
+ let tt = lua.lua_rawget(L, -2);
if (tt === lua.LUA_TNIL)
- lapi.lua_pop(L, 2);
+ lua.lua_pop(L, 2);
return tt;
}
};
const luaL_callmeta = function(L, obj, event) {
- obj = lapi.lua_absindex(L, obj);
+ obj = lua.lua_absindex(L, obj);
if (luaL_getmetafield(L, obj, event) === lua.LUA_TNIL)
return false;
- lapi.lua_pushvalue(L, obj);
- lapi.lua_call(L, 1, 1);
+ lua.lua_pushvalue(L, obj);
+ lua.lua_call(L, 1, 1);
return true;
};
const luaL_len = function(L, idx) {
- lapi.lua_len(L, idx);
- let l = lapi.lua_tointegerx(L, -1);
+ 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));
- lapi.lua_pop(L, 1); /* remove object */
+ lua.lua_pop(L, 1); /* remove object */
return l;
};
const luaL_tolstring = function(L, idx) {
if (luaL_callmeta(L, idx, lua.to_luastring("__tostring", true))) {
- if (!lapi.lua_isstring(L, -1))
+ if (!lua.lua_isstring(L, -1))
luaL_error(L, lua.to_luastring("'__tostring' must return a string", true));
} else {
- switch(lapi.lua_type(L, idx)) {
+ switch(lua.lua_type(L, idx)) {
case lua.LUA_TNUMBER:
case lua.LUA_TBOOLEAN:
- lapi.lua_pushstring(L, lua.to_luastring(`${lapi.index2addr(L, idx).value}`));
+ lua.lua_pushstring(L, lua.to_luastring(`${lapi.index2addr(L, idx).value}`));
break;
case lua.LUA_TSTRING:
- lapi.lua_pushstring(L, lapi.index2addr(L, idx).value);
+ lua.lua_pushstring(L, lapi.index2addr(L, idx).value);
break;
case lua.LUA_TNIL:
- lapi.lua_pushstring(L, lua.to_luastring(`nil`));
+ lua.lua_pushstring(L, lua.to_luastring(`nil`));
break;
default:
let tt = luaL_getmetafield(L, idx, lua.to_luastring("__name", true));
- let kind = tt === lua.LUA_TSTRING ? lapi.lua_tostring(L, -1) : luaL_typename(L, idx);
- lapi.lua_pushstring(L, lua.to_luastring(`${lobject.jsstring(kind)}: 0x${lapi.index2addr(L, -1).id.toString(16)}`));
+ let kind = tt === lua.LUA_TSTRING ? lua.lua_tostring(L, -1) : luaL_typename(L, idx);
+ lua.lua_pushstring(L, lua.to_luastring(`${lobject.jsstring(kind)}: 0x${lapi.index2addr(L, -1).id.toString(16)}`));
if (tt !== lua.LUA_TNIL)
- lapi.lua_remove(L, -2);
+ lua.lua_remove(L, -2);
break;
}
}
- return lapi.lua_tolstring(L, -1);
+ return lua.lua_tolstring(L, -1);
};
/*
@@ -397,19 +397,19 @@ const luaL_tolstring = function(L, idx) {
*/
const luaL_requiref = function(L, modname, openf, glb) {
luaL_getsubtable(L, lua.LUA_REGISTRYINDEX, lua.to_luastring(LUA_LOADED_TABLE));
- lapi.lua_getfield(L, -1, modname); /* LOADED[modname] */
- if (!lapi.lua_toboolean(L, -1)) { /* package not already loaded? */
- lapi.lua_pop(L, 1); /* remove field */
- lapi.lua_pushcfunction(L, openf);
- lapi.lua_pushstring(L, modname); /* argument to open function */
- lapi.lua_call(L, 1, 1); /* call 'openf' to open module */
- lapi.lua_pushvalue(L, -1); /* make copy of module (call result) */
- lapi.lua_setfield(L, -3, modname); /* LOADED[modname] = module */
+ lua.lua_getfield(L, -1, modname); /* LOADED[modname] */
+ if (!lua.lua_toboolean(L, -1)) { /* package not already loaded? */
+ lua.lua_pop(L, 1); /* remove field */
+ lua.lua_pushcfunction(L, openf);
+ lua.lua_pushstring(L, modname); /* argument to open function */
+ lua.lua_call(L, 1, 1); /* call 'openf' to open module */
+ lua.lua_pushvalue(L, -1); /* make copy of module (call result) */
+ lua.lua_setfield(L, -3, modname); /* LOADED[modname] = module */
}
- lapi.lua_remove(L, -2); /* remove LOADED table */
+ lua.lua_remove(L, -2); /* remove LOADED table */
if (glb) {
- lapi.lua_pushvalue(L, -1); /* copy of module */
- lapi.lua_setglobal(L, modname); /* _G[modname] = module */
+ lua.lua_pushvalue(L, -1); /* copy of module */
+ lua.lua_setglobal(L, modname); /* _G[modname] = module */
}
};
@@ -418,14 +418,14 @@ const luaL_requiref = function(L, modname, openf, glb) {
** into the stack
*/
const luaL_getsubtable = function(L, idx, fname) {
- if (lapi.lua_getfield(L, idx, fname) === lua.LUA_TTABLE)
+ if (lua.lua_getfield(L, idx, fname) === lua.LUA_TTABLE)
return true; /* table already there */
else {
- lapi.lua_pop(L, 1); /* remove previous result */
- idx = lapi.lua_absindex(L, idx);
- lapi.lua_newtable(L);
- lapi.lua_pushvalue(L, -1); /* copy to be left at top */
- lapi.lua_setfield(L, idx, fname); /* assign new table to field */
+ lua.lua_pop(L, 1); /* remove previous result */
+ idx = lua.lua_absindex(L, idx);
+ lua.lua_newtable(L);
+ lua.lua_pushvalue(L, -1); /* copy to be left at top */
+ lua.lua_setfield(L, idx, fname); /* assign new table to field */
return false; /* false, because did not find table there */
}
};
@@ -439,11 +439,11 @@ const luaL_setfuncs = function(L, l, nup) {
luaL_checkstack(L, nup, lua.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 */
- lapi.lua_pushvalue(L, -nup);
- lapi.lua_pushcclosure(L, l[lib], nup); /* closure with those upvalues */
- lapi.lua_setfield(L, -(nup + 2), lua.to_luastring(lib));
+ 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));
}
- lapi.lua_pop(L, nup); /* remove upvalues */
+ lua.lua_pop(L, nup); /* remove upvalues */
};
/*
@@ -454,7 +454,7 @@ const luaL_setfuncs = function(L, l, nup) {
** but without 'msg'.)
*/
const luaL_checkstack = function(L, space, msg) {
- if (!lapi.lua_checkstack(L, space)) {
+ if (!lua.lua_checkstack(L, space)) {
if (msg)
luaL_error(L, lua.to_luastring(`stack overflow (${lobject.jsstring(msg)})`));
else
@@ -463,7 +463,7 @@ const luaL_checkstack = function(L, space, msg) {
};
const luaL_newlib = function(L, l) {
- lapi.lua_createtable(L);
+ lua.lua_createtable(L);
luaL_setfuncs(L, l, 0);
};
@@ -510,9 +510,9 @@ if (typeof require === "function") {
const errfile = function(L, what, fnameindex, error) {
let serr = error.message;
- let filename = lapi.lua_tostring(L, fnameindex).slice(1);
- lapi.lua_pushstring(L, lua.to_luastring(`cannot ${what} ${lobject.jsstring(filename)}: ${serr}`));
- lapi.lua_remove(L, fnameindex);
+ let filename = lua.lua_tostring(L, fnameindex).slice(1);
+ lua.lua_pushstring(L, lua.to_luastring(`cannot ${what} ${lobject.jsstring(filename)}: ${serr}`));
+ lua.lua_remove(L, fnameindex);
return lua.LUA_ERRFILE;
};
@@ -566,13 +566,13 @@ if (typeof require === "function") {
const luaL_loadfilex = function(L, filename, mode) {
let lf = new LoadF();
- let fnameindex = lapi.lua_gettop(L) + 1; /* index of filename on the stack */
+ let fnameindex = lua.lua_gettop(L) + 1; /* index of filename on the stack */
if (filename === null) {
- lapi.lua_pushliteral(L, "=stdin");
+ lua.lua_pushliteral(L, "=stdin");
lf.f = process.stdin.fd;
} else {
let jsfilename = lobject.jsstring(filename);
- lapi.lua_pushliteral(L, `@${jsfilename}`);
+ lua.lua_pushliteral(L, `@${jsfilename}`);
try {
lf.f = fs.openSync(jsfilename, "r");
} catch (e) {
@@ -589,12 +589,12 @@ if (typeof require === "function") {
lf.binary = true;
}
- let status = lapi.lua_load(L, getF, lf, lapi.lua_tostring(L, -1), mode);
+ let status = lua.lua_load(L, getF, lf, lua.lua_tostring(L, -1), mode);
if (filename) fs.closeSync(lf.f); /* close file (even in case of errors) */
- lapi.lua_remove(L, fnameindex);
+ lua.lua_remove(L, fnameindex);
return status;
} catch (err) {
- lapi.lua_settop(L, fnameindex); /* ignore results from 'lua_load' */
+ lua.lua_settop(L, fnameindex); /* ignore results from 'lua_load' */
return errfile(L, "read", fnameindex, err);
}
};
diff --git a/src/lbaselib.js b/src/lbaselib.js
index aa02908..a1a8925 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -3,25 +3,24 @@
const assert = require('assert');
const lua = require('./lua.js');
-const lapi = require('./lapi.js');
const lauxlib = require('./lauxlib.js');
const lobject = require('./lobject.js');
const luaB_print = function(L) {
- let n = lapi.lua_gettop(L); /* number of arguments */
+ let n = lua.lua_gettop(L); /* number of arguments */
let str = [];
- lapi.lua_getglobal(L, lua.to_luastring("tostring", true));
+ lua.lua_getglobal(L, lua.to_luastring("tostring", true));
for (let i = 1; i <= n; i++) {
- lapi.lua_pushvalue(L, -1); /* function to be called */
- lapi.lua_pushvalue(L, i); /* value to print */
- lapi.lua_call(L, 1, 1);
- let s = lapi.lua_tolstring(L, -1);
+ 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) s = ["\t".charCodeAt(0)].concat(s);
str = str.concat(s);
- lapi.lua_pop(L, 1);
+ lua.lua_pop(L, 1);
}
// Don't use console.log if Node
@@ -39,8 +38,8 @@ const luaB_tostring = function(L) {
const luaB_getmetatable = function(L) {
lauxlib.luaL_checkany(L, 1);
- if (!lapi.lua_getmetatable(L, 1)) {
- lapi.lua_pushnil(L);
+ if (!lua.lua_getmetatable(L, 1)) {
+ lua.lua_pushnil(L);
return 1; /* no metatable */
}
lauxlib.luaL_getmetafield(L, 1, lua.to_luastring("__metatable", true));
@@ -48,35 +47,35 @@ const luaB_getmetatable = function(L) {
};
const luaB_setmetatable = function(L) {
- let t = lapi.lua_type(L, 2);
+ 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));
- lapi.lua_settop(L, 2);
- lapi.lua_setmetatable(L, 1);
+ lua.lua_settop(L, 2);
+ lua.lua_setmetatable(L, 1);
return 1;
};
const luaB_rawequal = function(L) {
lauxlib.luaL_checkany(L, 1);
lauxlib.luaL_checkany(L, 2);
- lapi.lua_pushboolean(L, lapi.lua_rawequal(L, 1, 2));
+ lua.lua_pushboolean(L, lua.lua_rawequal(L, 1, 2));
return 1;
};
const luaB_rawlen = function(L) {
- let t = lapi.lua_type(L, 1);
+ 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));
- lapi.lua_pushinteger(L, lapi.lua_rawlen(L, 1));
+ lua.lua_pushinteger(L, lua.lua_rawlen(L, 1));
return 1;
};
const luaB_rawget = function(L) {
lauxlib.luaL_checktype(L, 1, lua.LUA_TTABLE);
lauxlib.luaL_checkany(L, 2);
- lapi.lua_settop(L, 2);
- lapi.lua_rawget(L, 1);
+ lua.lua_settop(L, 2);
+ lua.lua_rawget(L, 1);
return 1;
};
@@ -84,39 +83,39 @@ const luaB_rawset = function(L) {
lauxlib.luaL_checktype(L, 1, lua.LUA_TTABLE);
lauxlib.luaL_checkany(L, 2);
lauxlib.luaL_checkany(L, 3);
- lapi.lua_settop(L, 3);
- lapi.lua_rawset(L, 1);
+ lua.lua_settop(L, 3);
+ lua.lua_rawset(L, 1);
return 1;
};
const luaB_type = function(L) {
- let t = lapi.lua_type(L, 1);
+ let t = lua.lua_type(L, 1);
lauxlib.luaL_argcheck(L, t !== lua.LUA_TNONE, 1, lua.to_luastring("value expected", true));
- lapi.lua_pushstring(L, lapi.lua_typename(L, t));
+ lua.lua_pushstring(L, lua.lua_typename(L, t));
return 1;
};
const pairsmeta = function(L, method, iszero, iter) {
lauxlib.luaL_checkany(L, 1);
if (lauxlib.luaL_getmetafield(L, 1, method) === lua.LUA_TNIL) { /* no metamethod? */
- lapi.lua_pushcfunction(L, iter); /* will return generator, */
- lapi.lua_pushvalue(L, 1); /* state, */
- if (iszero) lapi.lua_pushinteger(L, 0); /* and initial value */
- else lapi.lua_pushnil(L);
+ lua.lua_pushcfunction(L, iter); /* will return generator, */
+ lua.lua_pushvalue(L, 1); /* state, */
+ if (iszero) lua.lua_pushinteger(L, 0); /* and initial value */
+ else lua.lua_pushnil(L);
} else {
- lapi.lua_pushvalue(L, 1); /* argument 'self' to metamethod */
- lapi.lua_call(L, 1, 3); /* get 3 values from metamethod */
+ lua.lua_pushvalue(L, 1); /* argument 'self' to metamethod */
+ lua.lua_call(L, 1, 3); /* get 3 values from metamethod */
}
return 3;
};
const luaB_next = function(L) {
lauxlib.luaL_checktype(L, 1, lua.LUA_TTABLE);
- lapi.lua_settop(L, 2); /* create a 2nd argument if there isn't one */
- if (lapi.lua_next(L, 1))
+ lua.lua_settop(L, 2); /* create a 2nd argument if there isn't one */
+ if (lua.lua_next(L, 1))
return 2;
else {
- lapi.lua_pushnil(L);
+ lua.lua_pushnil(L);
return 1;
}
};
@@ -130,8 +129,8 @@ const luaB_pairs = function(L) {
*/
const ipairsaux = function(L) {
let i = lauxlib.luaL_checkinteger(L, 2) + 1;
- lapi.lua_pushinteger(L, i);
- return lapi.lua_geti(L, 1, i) === lua.LUA_TNIL ? 1 : 2;
+ lua.lua_pushinteger(L, i);
+ return lua.lua_geti(L, 1, i) === lua.LUA_TNIL ? 1 : 2;
};
/*
@@ -143,66 +142,66 @@ const luaB_ipairs = function(L) {
// return pairsmeta(L, "__ipairs", 1, ipairsaux);
lauxlib.luaL_checkany(L, 1);
- lapi.lua_pushcfunction(L, ipairsaux); /* iteration function */
- lapi.lua_pushvalue(L, 1); /* state */
- lapi.lua_pushinteger(L, 0); /* initial value */
+ lua.lua_pushcfunction(L, ipairsaux); /* iteration function */
+ lua.lua_pushvalue(L, 1); /* state */
+ lua.lua_pushinteger(L, 0); /* initial value */
return 3;
};
const luaB_tonumber = function(L) {
- if (lapi.lua_type(L, 2) <= 0) { /* standard conversion? */
+ if (lua.lua_type(L, 2) <= 0) { /* standard conversion? */
lauxlib.luaL_checkany(L, 1);
- if (lapi.lua_type(L, 1) === lua.LUA_TNUMBER) { /* already a number? */
- lapi.lua_settop(L, 1);
+ if (lua.lua_type(L, 1) === lua.LUA_TNUMBER) { /* already a number? */
+ lua.lua_settop(L, 1);
return 1;
} else {
- let s = lapi.lua_tostring(L, 1);
- if (s !== null && lapi.lua_stringtonumber(L, s) === s.length)
+ let s = lua.lua_tostring(L, 1);
+ if (s !== null && lua.lua_stringtonumber(L, s) === s.length)
return 1; /* successful conversion to number */
}
} else {
let base = lauxlib.luaL_checkinteger(L, 2);
lauxlib.luaL_checktype(L, 1, lua.LUA_TSTRING); /* no numbers as strings */
- let s = lapi.lua_tostring(L, 1);
+ let s = lua.lua_tostring(L, 1);
lauxlib.luaL_argcheck(L, 2 <= base && base <= 36, 2, lua.to_luastring("base out of range", true));
let n = parseInt(lobject.jsstring(s), base);
if (!isNaN(n)) {
- lapi.lua_pushinteger(L, n);
+ lua.lua_pushinteger(L, n);
return 1;
}
}
- lapi.lua_pushnil(L);
+ lua.lua_pushnil(L);
return 1;
};
const luaB_error = function(L) {
let level = lauxlib.luaL_optinteger(L, 2, 1);
- lapi.lua_settop(L, 1);
- if (lapi.lua_type(L, 1) === lua.LUA_TSTRING && level > 0) {
+ lua.lua_settop(L, 1);
+ if (lua.lua_type(L, 1) === lua.LUA_TSTRING && level > 0) {
lauxlib.luaL_where(L, level); /* add extra information */
- lapi.lua_pushvalue(L, 1);
- lapi.lua_concat(L, 2);
+ lua.lua_pushvalue(L, 1);
+ lua.lua_concat(L, 2);
}
- return lapi.lua_error(L);
+ return lua.lua_error(L);
};
const luaB_assert = function(L) {
- if (lapi.lua_toboolean(L, 1)) /* condition is true? */
- return lapi.lua_gettop(L); /* return all arguments */
+ if (lua.lua_toboolean(L, 1)) /* condition is true? */
+ return lua.lua_gettop(L); /* return all arguments */
else {
lauxlib.luaL_checkany(L, 1); /* there must be a condition */
- lapi.lua_remove(L, 1); /* remove it */
- lapi.lua_pushliteral(L, "assertion failed!"); /* default message */
- lapi.lua_settop(L, 1); /* leave only message (default if no other one) */
+ lua.lua_remove(L, 1); /* remove it */
+ lua.lua_pushliteral(L, "assertion failed!"); /* default message */
+ lua.lua_settop(L, 1); /* leave only message (default if no other one) */
return luaB_error(L); /* call 'error' */
}
};
const luaB_select = function(L) {
- let n = lapi.lua_gettop(L);
- if (lapi.lua_type(L, 1) === lua.LUA_TSTRING && lapi.lua_tostring(L, 1)[0] === "#".charCodeAt(0)) {
- lapi.lua_pushinteger(L, n - 1);
+ let n = lua.lua_gettop(L);
+ if (lua.lua_type(L, 1) === lua.LUA_TSTRING && lua.lua_tostring(L, 1)[0] === "#".charCodeAt(0)) {
+ lua.lua_pushinteger(L, n - 1);
return 1;
} else {
let i = lauxlib.luaL_checkinteger(L, 1);
@@ -222,18 +221,18 @@ const luaB_select = function(L) {
*/
const finishpcall = function(L, status, extra) {
if (status !== lua.LUA_OK && status !== lua.LUA_YIELD) { /* error? */
- lapi.lua_pushboolean(L, 0); /* first result (false) */
- lapi.lua_pushvalue(L, -2); /* error message */
+ lua.lua_pushboolean(L, 0); /* first result (false) */
+ lua.lua_pushvalue(L, -2); /* error message */
return 2; /* return false, msg */
} else
- return lapi.lua_gettop(L) - extra;
+ return lua.lua_gettop(L) - extra;
};
const luaB_pcall = function(L) {
lauxlib.luaL_checkany(L, 1);
- lapi.lua_pushboolean(L, 1); /* first result if no errors */
- lapi.lua_insert(L, 1); /* put it in place */
- let status = lapi.lua_pcallk(L, lapi.lua_gettop(L) - 2, lua.LUA_MULTRET, 0, 0, finishpcall);
+ lua.lua_pushboolean(L, 1); /* first result if no errors */
+ lua.lua_insert(L, 1); /* put it in place */
+ let status = lua.lua_pcallk(L, lua.lua_gettop(L) - 2, lua.LUA_MULTRET, 0, 0, finishpcall);
return finishpcall(L, status, 0);
};
@@ -243,12 +242,12 @@ const luaB_pcall = function(L) {
** 2 to 'finishpcall' to skip the 2 first values when returning results.
*/
const luaB_xpcall = function(L) {
- let n = lapi.lua_gettop(L);
+ let n = lua.lua_gettop(L);
lauxlib.luaL_checktype(L, 2, lua.LUA_TFUNCTION); /* check error function */
- lapi.lua_pushboolean(L, 1); /* first result */
- lapi.lua_pushvalue(L, 1); /* function */
- lapi.lua_rotate(L, 3, 2); /* move them below function's arguments */
- let status = lapi.lua_pcallk(L, n - 2, lua.LUA_MULTRET, 2, 2, finishpcall);
+ lua.lua_pushboolean(L, 1); /* first result */
+ lua.lua_pushvalue(L, 1); /* function */
+ lua.lua_rotate(L, 3, 2); /* move them below function's arguments */
+ let status = lua.lua_pcallk(L, n - 2, lua.LUA_MULTRET, 2, 2, finishpcall);
return finishpcall(L, status, 2);
};
@@ -256,14 +255,14 @@ const luaB_xpcall = function(L) {
const load_aux = function(L, status, envidx) {
if (status === lua.LUA_OK) {
if (envidx !== 0) { /* 'env' parameter? */
- lapi.lua_pushvalue(L, envidx); /* environment for loaded function */
- if (!lapi.lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */
- lapi.lua_pop(L, 1); /* remove 'env' if not used by previous call */
+ lua.lua_pushvalue(L, envidx); /* environment for loaded function */
+ if (!lua.lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */
+ lua.lua_pop(L, 1); /* remove 'env' if not used by previous call */
}
return 1;
} else { /* error (message is on top of the stack) */
- lapi.lua_pushnil(L);
- lapi.lua_insert(L, -2); /* put before error message */
+ lua.lua_pushnil(L);
+ lua.lua_insert(L, -2); /* put before error message */
return 2; /* return nil plus error message */
}
};
@@ -283,21 +282,21 @@ const RESERVEDSLOT = 5;
*/
const generic_reader = function(L, ud) {
lauxlib.luaL_checkstack(L, 2, lua.to_luastring("too many nested functions", true));
- lapi.lua_pushvalue(L, 1); /* get function */
- lapi.lua_call(L, 0, 1); /* call it */
- if (lapi.lua_isnil(L, -1)) {
- lapi.lua_pop(L, 1); /* pop result */
+ 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 (!lapi.lua_isstring(L, -1))
+ } else if (!lua.lua_isstring(L, -1))
lauxlib.luaL_error(L, lua.to_luastring("reader function must return a string", true));
- lapi.lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
- return lapi.lua_tostring(L, RESERVEDSLOT);
+ lua.lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
+ return lua.lua_tostring(L, RESERVEDSLOT);
};
const luaB_load = function(L) {
- let s = lapi.lua_tostring(L, 1);
+ let s = lua.lua_tostring(L, 1);
let mode = lauxlib.luaL_optstring(L, 3, lua.to_luastring("bt", true));
- let env = !lapi.lua_isnone(L, 4) ? 4 : 0; /* 'env' index or 0 if no 'env' */
+ 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);
@@ -305,8 +304,8 @@ const luaB_load = function(L) {
} else { /* loading from a reader function */
let chunkname = lauxlib.luaL_optstring(L, 2, lua.to_luastring("=(load)", true));
lauxlib.luaL_checktype(L, 1, lua.LUA_TFUNCTION);
- lapi.lua_settop(L, RESERVEDSLOT); /* create reserved slot */
- status = lapi.lua_load(L, generic_reader, null, chunkname, mode);
+ lua.lua_settop(L, RESERVEDSLOT); /* create reserved slot */
+ status = lua.lua_load(L, generic_reader, null, chunkname, mode);
}
return load_aux(L, status, env);
};
@@ -346,21 +345,21 @@ if (typeof require === "function") {
const luaB_loadfile = function(L) {
let fname = lauxlib.luaL_optstring(L, 1, null);
let mode = lauxlib.luaL_optstring(L, 2, null);
- let env = !lapi.lua_isnone(L, 3) ? 3 : 0; /* 'env' index or 0 if no 'env' */
+ let env = !lua.lua_isnone(L, 3) ? 3 : 0; /* 'env' index or 0 if no 'env' */
let status = lauxlib.luaL_loadfilex(L, fname, mode);
return load_aux(L, status, env);
};
const dofilecont = function(L, d1, d2) {
- return lapi.lua_gettop(L) - 1;
+ return lua.lua_gettop(L) - 1;
};
const luaB_dofile = function(L) {
let fname = lauxlib.luaL_optstring(L, 1, null);
- lapi.lua_settop(L, 1);
+ lua.lua_settop(L, 1);
if (lauxlib.luaL_loadfile(L, fname) !== lua.LUA_OK)
- return lapi.lua_error(L);
- lapi.lua_callk(L, 0, lua.LUA_MULTRET, 0, dofilecont);
+ return lua.lua_error(L);
+ lua.lua_callk(L, 0, lua.LUA_MULTRET, 0, dofilecont);
return dofilecont(L, 0, 0);
};
@@ -372,14 +371,14 @@ if (typeof require === "function") {
const luaopen_base = function(L) {
/* open lib into global table */
- lapi.lua_pushglobaltable(L);
+ lua.lua_pushglobaltable(L);
lauxlib.luaL_setfuncs(L, base_funcs, 0);
/* set global _G */
- lapi.lua_pushvalue(L, -1);
- lapi.lua_setfield(L, -2, lua.to_luastring("_G", true));
+ lua.lua_pushvalue(L, -1);
+ lua.lua_setfield(L, -2, lua.to_luastring("_G", true));
/* set global _VERSION */
- lapi.lua_pushliteral(L, lua.LUA_VERSION);
- lapi.lua_setfield(L, -2, lua.to_luastring("_VERSION", true));
+ lua.lua_pushliteral(L, lua.LUA_VERSION);
+ lua.lua_setfield(L, -2, lua.to_luastring("_VERSION", true));
return 1;
};
diff --git a/src/lcorolib.js b/src/lcorolib.js
index 98eebac..9c05e40 100644
--- a/src/lcorolib.js
+++ b/src/lcorolib.js
@@ -3,7 +3,6 @@
const assert = require('assert');
const lua = require('./lua.js');
-const lapi = require('./lapi.js');
const lauxlib = require('./lauxlib.js');
const lstate = require('./lstate.js');
const ldo = require('./ldo.js');
@@ -11,65 +10,65 @@ const ldebug = require('./ldebug.js');
const lobject = require('./lobject.js');
const getco = function(L) {
- let co = lapi.lua_tothread(L, 1);
+ let co = lua.lua_tothread(L, 1);
lauxlib.luaL_argcheck(L, co, 1, lua.to_luastring("thread expected", true));
return co;
};
const auxresume = function(L, co, narg) {
- if (!lapi.lua_checkstack(co, narg)) {
- lapi.lua_pushliteral(L, "too many arguments to resume");
+ if (!lua.lua_checkstack(co, narg)) {
+ lua.lua_pushliteral(L, "too many arguments to resume");
return -1; /* error flag */
}
- if (lapi.lua_status(co) === lua.LUA_OK && lapi.lua_gettop(co) === 0) {
- lapi.lua_pushliteral(L, "cannot resume dead coroutine");
+ if (lua.lua_status(co) === lua.LUA_OK && lua.lua_gettop(co) === 0) {
+ lua.lua_pushliteral(L, "cannot resume dead coroutine");
return -1; /* error flag */
}
- lapi.lua_xmove(L, co, narg);
+ lua.lua_xmove(L, co, narg);
let status = ldo.lua_resume(co, L, narg);
if (status === lua.LUA_OK || status === lua.LUA_YIELD) {
- let nres = lapi.lua_gettop(co);
- if (!lapi.lua_checkstack(L, nres + 1)) {
- lapi.lua_pop(co, nres); /* remove results anyway */
- lapi.lua_pushliteral(L, "too many results to resume");
+ let nres = lua.lua_gettop(co);
+ if (!lua.lua_checkstack(L, nres + 1)) {
+ lua.lua_pop(co, nres); /* remove results anyway */
+ lua.lua_pushliteral(L, "too many results to resume");
return -1; /* error flag */
}
- lapi.lua_xmove(co, L, nres); /* move yielded values */
+ lua.lua_xmove(co, L, nres); /* move yielded values */
return nres;
} else {
- lapi.lua_xmove(co, L, 1); /* move error message */
+ lua.lua_xmove(co, L, 1); /* move error message */
return -1; /* error flag */
}
};
const luaB_coresume = function(L) {
let co = getco(L);
- let r = auxresume(L, co, lapi.lua_gettop(L) - 1);
+ let r = auxresume(L, co, lua.lua_gettop(L) - 1);
if (r < 0) {
- lapi.lua_pushboolean(L, 0);
- lapi.lua_insert(L, -2);
+ lua.lua_pushboolean(L, 0);
+ lua.lua_insert(L, -2);
return 2; /* return false + error message */
} else {
- lapi.lua_pushboolean(L, 1);
- lapi.lua_insert(L, -(r + 1));
+ lua.lua_pushboolean(L, 1);
+ lua.lua_insert(L, -(r + 1));
return r + 1; /* return true + 'resume' returns */
}
};
const luaB_auxwrap = function(L) {
- let co = lapi.lua_tothread(L, lua.lua_upvalueindex(1));
- let r = auxresume(L, co, lapi.lua_gettop(L));
+ let co = lua.lua_tothread(L, lua.lua_upvalueindex(1));
+ let r = auxresume(L, co, lua.lua_gettop(L));
if (r < 0) {
- if (lapi.lua_type(L, -1) === lua.LUA_TSTRING) { /* error object is a string? */
+ if (lua.lua_type(L, -1) === lua.LUA_TSTRING) { /* error object is a string? */
lauxlib.luaL_where(L, 1); /* add extra info */
- lapi.lua_insert(L, -2);
- lapi.lua_concat(L, 2);
+ lua.lua_insert(L, -2);
+ lua.lua_concat(L, 2);
}
- return lapi.lua_error(L); /* propagate error */
+ return lua.lua_error(L); /* propagate error */
}
return r;
@@ -78,41 +77,41 @@ const luaB_auxwrap = function(L) {
const luaB_cocreate = function(L) {
lauxlib.luaL_checktype(L, 1, lua.LUA_TFUNCTION);
let NL = lstate.lua_newthread(L);
- lapi.lua_pushvalue(L, 1); /* move function to top */
- lapi.lua_xmove(L, NL, 1); /* move function from L to NL */
+ lua.lua_pushvalue(L, 1); /* move function to top */
+ lua.lua_xmove(L, NL, 1); /* move function from L to NL */
return 1;
};
const luaB_cowrap = function(L) {
luaB_cocreate(L);
- lapi.lua_pushcclosure(L, luaB_auxwrap, 1);
+ lua.lua_pushcclosure(L, luaB_auxwrap, 1);
return 1;
};
const luaB_yield = function(L) {
- return ldo.lua_yield(L, lapi.lua_gettop(L));
+ return ldo.lua_yield(L, lua.lua_gettop(L));
};
const luaB_costatus = function(L) {
let co = getco(L);
- if (L === co) lapi.lua_pushliteral(L, "running");
+ if (L === co) lua.lua_pushliteral(L, "running");
else {
- switch (lapi.lua_status(co)) {
+ switch (lua.lua_status(co)) {
case lua.LUA_YIELD:
- lapi.lua_pushliteral(L, "suspended");
+ lua.lua_pushliteral(L, "suspended");
break;
case lua.LUA_OK: {
let ar = new lua.lua_Debug();
if (ldebug.lua_getstack(co, 0, ar) > 0) /* does it have frames? */
- lapi.lua_pushliteral(L, "normal"); /* it is running */
- else if (lapi.lua_gettop(co) === 0)
- lapi.lua_pushliteral(L, "dead");
+ lua.lua_pushliteral(L, "normal"); /* it is running */
+ else if (lua.lua_gettop(co) === 0)
+ lua.lua_pushliteral(L, "dead");
else
- lapi.lua_pushliteral(L, "suspended"); /* initial state */
+ lua.lua_pushliteral(L, "suspended"); /* initial state */
break;
}
default: /* some error occurred */
- lapi.lua_pushliteral(L, "dead");
+ lua.lua_pushliteral(L, "dead");
break;
}
}
@@ -121,12 +120,12 @@ const luaB_costatus = function(L) {
};
const luaB_yieldable = function(L) {
- lapi.lua_pushboolean(L, ldo.lua_isyieldable(L));
+ lua.lua_pushboolean(L, ldo.lua_isyieldable(L));
return 1;
};
const luaB_corunning = function(L) {
- lapi.lua_pushboolean(L, lapi.lua_pushthread(L));
+ lua.lua_pushboolean(L, lua.lua_pushthread(L));
return 2;
};
diff --git a/src/ldblib.js b/src/ldblib.js
index 62422a8..c5ef8d4 100644
--- a/src/ldblib.js
+++ b/src/ldblib.js
@@ -3,7 +3,6 @@
const assert = require('assert');
const lua = require('./lua.js');
-const lapi = require('./lapi.js');
const lauxlib = require('./lauxlib.js');
const ldebug = require('./ldebug.js');
@@ -13,36 +12,36 @@ const ldebug = require('./ldebug.js');
** checked.
*/
const checkstack = function(L, L1, n) {
- if (L !== L1 && !lapi.lua_checkstack(L1, n))
+ if (L !== L1 && !lua.lua_checkstack(L1, n))
lauxlib.luaL_error(L, lua.to_luastring("stack overflow", true));
};
const db_getregistry = function(L) {
- lapi.lua_pushvalue(L, lua.LUA_REGISTRYINDEX);
+ lua.lua_pushvalue(L, lua.LUA_REGISTRYINDEX);
return 1;
};
const db_getmetatable = function(L) {
lauxlib.luaL_checkany(L, 1);
- if (!lapi.lua_getmetatable(L, 1)) {
- lapi.lua_pushnil(L); /* no metatable */
+ if (!lua.lua_getmetatable(L, 1)) {
+ lua.lua_pushnil(L); /* no metatable */
}
return 1;
};
const db_setmetatable = function(L) {
- const t = lapi.lua_type(L, 2);
+ 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));
- lapi.lua_settop(L, 2);
- lapi.lua_setmetatable(L, 1);
+ lua.lua_settop(L, 2);
+ lua.lua_setmetatable(L, 1);
return 1; /* return 1st argument */
};
const db_getuservalue = function(L) {
- if (lapi.lua_type(L, 1) !== lua.LUA_TUSERDATA)
- lapi.lua_pushnil(L);
+ if (lua.lua_type(L, 1) !== lua.LUA_TUSERDATA)
+ lua.lua_pushnil(L);
else
- lapi.lua_getuservalue(L, 1);
+ lua.lua_getuservalue(L, 1);
return 1;
};
@@ -50,8 +49,8 @@ const db_getuservalue = function(L) {
const db_setuservalue = function(L) {
lauxlib.luaL_checktype(L, 1, lua.LUA_TUSERDATA);
lauxlib.luaL_checkany(L, 2);
- lapi.lua_settop(L, 2);
- lapi.lua_setuservalue(L, 1);
+ lua.lua_settop(L, 2);
+ lua.lua_setuservalue(L, 1);
return 1;
};
@@ -62,10 +61,10 @@ const db_setuservalue = function(L) {
** access their other arguments)
*/
const getthread = function(L) {
- if (lapi.lua_isthread(L, 1)) {
+ if (lua.lua_isthread(L, 1)) {
return {
arg: 1,
- thread: lapi.lua_tothread(L, 1)
+ thread: lua.lua_tothread(L, 1)
};
} else {
return {
@@ -81,18 +80,18 @@ const getthread = function(L) {
** value can be a string, an int, or a boolean.
*/
const settabss = function(L, k, v) {
- lapi.lua_pushstring(L, v);
- lapi.lua_setfield(L, -2, k);
+ lua.lua_pushstring(L, v);
+ lua.lua_setfield(L, -2, k);
};
const settabsi = function(L, k, v) {
- lapi.lua_pushinteger(L, v);
- lapi.lua_setfield(L, -2, k);
+ lua.lua_pushinteger(L, v);
+ lua.lua_setfield(L, -2, k);
};
const settabsb = function(L, k, v) {
- lapi.lua_pushboolean(L, v);
- lapi.lua_setfield(L, -2, k);
+ lua.lua_pushboolean(L, v);
+ lua.lua_setfield(L, -2, k);
};
@@ -105,10 +104,10 @@ const settabsb = function(L, k, v) {
*/
const treatstackoption = function(L, L1, fname) {
if (L == L1)
- lapi.lua_rotate(L, -2, 1); /* exchange object and table */
+ lua.lua_rotate(L, -2, 1); /* exchange object and table */
else
- lapi.lua_xmove(L1, L, 1); /* move object to the "main" stack */
- lapi.lua_setfield(L, -2, fname); /* put object into table */
+ lua.lua_xmove(L1, L, 1); /* move object to the "main" stack */
+ lua.lua_setfield(L, -2, fname); /* put object into table */
};
/*
@@ -124,20 +123,20 @@ const db_getinfo = function(L) {
let L1 = thread.thread;
let options = lauxlib.luaL_optstring(L, arg + 2, lua.to_luastring("flnStu", true));
checkstack(L, L1, 3);
- if (lapi.lua_isfunction(L, arg + 1)) { /* info about a function? */
+ if (lua.lua_isfunction(L, arg + 1)) { /* info about a function? */
options = ['>'.charCodeAt(0)].concat(options); /* add '>' to 'options' */
- lapi.lua_pushvalue(L, arg + 1); /* move function to 'L1' stack */
- lapi.lua_xmove(L, L1, 1);
+ lua.lua_pushvalue(L, arg + 1); /* move function to 'L1' stack */
+ lua.lua_xmove(L, L1, 1);
} else { /* stack level */
if (!ldebug.lua_getstack(L1, lauxlib.luaL_checkinteger(L, arg + 1), ar)) {
- lapi.lua_pushnil(L); /* level out of range */
+ lua.lua_pushnil(L); /* level out of range */
return 1;
}
}
if (!ldebug.lua_getinfo(L1, options, ar))
lauxlib.luaL_argerror(L, arg + 2, lua.to_luastring("invalid option", true));
- lapi.lua_newtable(L); /* table to collect results */
+ lua.lua_newtable(L); /* table to collect results */
if (options.indexOf('S'.charCodeAt(0)) > -1) {
settabss(L, lua.to_luastring("source", true), ar.source.value);
settabss(L, lua.to_luastring("short_src", true), ar.short_src);
@@ -170,24 +169,24 @@ const db_getlocal = function(L) {
let arg = thread.arg;
let ar = new lua.lua_Debug();
let nvar = lauxlib.luaL_checkinteger(L, arg + 2); /* local-variable index */
- if (lapi.lua_isfunction(L, arg + 1)) {
- lapi.lua_pushvalue(L, arg + 1); /* push function */
- lapi.lua_pushstring(L, ldebug.lua_getlocal(L, null, nvar)); /* push local name */
+ if (lua.lua_isfunction(L, arg + 1)) {
+ lua.lua_pushvalue(L, arg + 1); /* push function */
+ lua.lua_pushstring(L, ldebug.lua_getlocal(L, null, nvar)); /* push local name */
return 1; /* return only name (there is no value) */
} else { /* stack-level argument */
let level = lauxlib.luaL_checkinteger(L, arg + 1);
if (!ldebug.lua_getstack(L1, level, ar)) /* out of range? */
- return lauxlib.luaL_argerror(L, arg+1, lapi.to_luastring("level out of range", true));
+ return lauxlib.luaL_argerror(L, arg+1, lua.to_luastring("level out of range", true));
checkstack(L, L1, 1);
let name = ldebug.lua_getlocal(L1, ar, nvar);
if (name) {
- lapi.lua_xmove(L1, L, 1); /* move local value */
- lapi.lua_pushstring(L, name.value); /* push name */
- lapi.lua_rotate(L, -2, 1); /* re-order */
+ lua.lua_xmove(L1, L, 1); /* move local value */
+ lua.lua_pushstring(L, name.value); /* push name */
+ lua.lua_rotate(L, -2, 1); /* re-order */
return 2;
}
else {
- lapi.lua_pushnil(L); /* no name (nor value) */
+ lua.lua_pushnil(L); /* no name (nor value) */
return 1;
}
}
@@ -203,13 +202,13 @@ const db_setlocal = function(L) {
if (!ldebug.lua_getstack(L1, level, ar)) /* out of range? */
return lauxlib.luaL_argerror(L, arg + 1, "level out of range");
lauxlib.luaL_checkany(L, arg + 3);
- lapi.lua_settop(L, arg + 3);
+ lua.lua_settop(L, arg + 3);
checkstack(L, L1, 1);
- lapi.lua_xmove(L, L1, 1);
+ lua.lua_xmove(L, L1, 1);
let name = ldebug.lua_setlocal(L1, ar, nvar);
if (name === null)
- lapi.lua_pop(L1, 1); /* pop value (if not popped by 'lua_setlocal') */
- lapi.lua_pushstring(L, name.value);
+ lua.lua_pop(L1, 1); /* pop value (if not popped by 'lua_setlocal') */
+ lua.lua_pushstring(L, name.value);
return 1;
};
@@ -219,10 +218,10 @@ const db_setlocal = function(L) {
const auxupvalue = function(L, get) {
let n = lauxlib.luaL_checkinteger(L, 2); /* upvalue index */
lauxlib.luaL_checktype(L, 1, lua.LUA_TFUNCTION); /* closure */
- let name = get ? lapi.lua_getupvalue(L, 1, n) : lapi.lua_setupvalue(L, 1, n);
+ let name = get ? lua.lua_getupvalue(L, 1, n) : lua.lua_setupvalue(L, 1, n);
if (name === null) return 0;
- lapi.lua_pushstring(L, name);
- lapi.lua_insert(L, -(get+1)); /* no-op if get is false */
+ lua.lua_pushstring(L, name);
+ lua.lua_insert(L, -(get+1)); /* no-op if get is false */
return get + 1;
};
@@ -243,22 +242,22 @@ 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, (lapi.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, lua.to_luastring("invalid upvalue index", true));
return nup;
};
const db_upvalueid = function(L) {
let n = checkupval(L, 1, 2);
- lapi.lua_pushlightuserdata(L, lapi.lua_upvalueid(L, 1, n));
+ lua.lua_pushlightuserdata(L, lua.lua_upvalueid(L, 1, n));
return 1;
};
const db_upvaluejoin = function(L) {
let n1 = checkupval(L, 1, 2);
let n2 = checkupval(L, 3, 4);
- lauxlib.luaL_argcheck(L, !lapi.lua_iscfunction(L, 1), 1, lua.to_luastring("Lua function expected", true));
- lauxlib.luaL_argcheck(L, !lapi.lua_iscfunction(L, 3), 3, lua.to_luastring("Lua function expected", true));
- lapi.lua_upvaluejoin(L, 1, n1, 3, n2);
+ 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));
+ lua.lua_upvaluejoin(L, 1, n1, 3, n2);
return 0;
};
@@ -275,15 +274,15 @@ const hooknames = ["call", "return", "line", "count", "tail call"].map(e => lua.
** thread (if there is one)
*/
const hookf = function(L, ar) {
- lapi.lua_rawgetp(L, lua.LUA_REGISTRYINDEX, HOOKKEY);
- lapi.lua_pushthread(L);
- if (lapi.lua_rawget(L, -2) === lua.LUA_TFUNCTION) { /* is there a hook function? */
- lapi.lua_pushstring(L, hooknames[ar.event]); /* push event name */
+ lua.lua_rawgetp(L, lua.LUA_REGISTRYINDEX, HOOKKEY);
+ lua.lua_pushthread(L);
+ if (lua.lua_rawget(L, -2) === lua.LUA_TFUNCTION) { /* is there a hook function? */
+ lua.lua_pushstring(L, hooknames[ar.event]); /* push event name */
if (ar.currentline >= 0)
- lapi.lua_pushinteger(L, ar.currentline); /* push current line */
- else lapi.lua_pushnil(L);
+ lua.lua_pushinteger(L, ar.currentline); /* push current line */
+ else lua.lua_pushnil(L);
assert(ldebug.lua_getinfo(L, ["l".charCodeAt(0), "S".charCodeAt(0)], ar));
- lapi.lua_call(L, 2, 0); /* call hook function */
+ lua.lua_call(L, 2, 0); /* call hook function */
}
};
@@ -315,8 +314,8 @@ const db_sethook = function(L) {
let thread = getthread(L);
let L1 = thread.thread;
let arg = thread.arg;
- if (lapi.lua_isnoneornil(L, arg+1)) { /* no hook? */
- lapi.lua_settop(L, arg+1);
+ if (lua.lua_isnoneornil(L, arg+1)) { /* no hook? */
+ lua.lua_settop(L, arg+1);
func = null; mask = 0; count = 0; /* turn off hooks */
}
else {
@@ -325,19 +324,19 @@ const db_sethook = function(L) {
count = lauxlib.luaL_optinteger(L, arg + 3, 0);
func = hookf; mask = makemask(smask, count);
}
- if (lapi.lua_rawgetp(L, lua.LUA_REGISTRYINDEX, HOOKKEY) === lua.LUA_TNIL) {
- lapi.lua_createtable(L, 0, 2); /* create a hook table */
- lapi.lua_pushvalue(L, -1);
- lapi.lua_rawsetp(L, lua.LUA_REGISTRYINDEX, HOOKKEY); /* set it in position */
- lapi.lua_pushstring(L, ["k".charCodeAt(0)]);
- lapi.lua_setfield(L, -2, lua.to_luastring("__mode", true)); /** hooktable.__mode = "k" */
- lapi.lua_pushvalue(L, -1);
- lapi.lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
+ if (lua.lua_rawgetp(L, lua.LUA_REGISTRYINDEX, HOOKKEY) === lua.LUA_TNIL) {
+ 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, ["k".charCodeAt(0)]);
+ lua.lua_setfield(L, -2, lua.to_luastring("__mode", true)); /** hooktable.__mode = "k" */
+ lua.lua_pushvalue(L, -1);
+ lua.lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
}
checkstack(L, L1, 1);
- lapi.lua_pushthread(L1); lapi.lua_xmove(L1, L, 1); /* key (thread) */
- lapi.lua_pushvalue(L, arg + 1); /* value (hook function) */
- lapi.lua_rawset(L, -3); /* hooktable[L1] = new Lua hook */
+ lua.lua_pushthread(L1); lua.lua_xmove(L1, L, 1); /* key (thread) */
+ lua.lua_pushvalue(L, arg + 1); /* value (hook function) */
+ lua.lua_rawset(L, -3); /* hooktable[L1] = new Lua hook */
ldebug.lua_sethook(L1, func, mask, count);
return 0;
};
@@ -350,18 +349,18 @@ const db_gethook = function(L) {
let mask = ldebug.lua_gethookmask(L1);
let hook = ldebug.lua_gethook(L1);
if (hook === null) /* no hook? */
- lapi.lua_pushnil(L);
+ lua.lua_pushnil(L);
else if (hook !== hookf) /* external hook? */
- lapi.lua_pushliteral(L, "external hook");
+ lua.lua_pushliteral(L, "external hook");
else { /* hook table must exist */
- lapi.lua_rawgetp(L, lua.LUA_REGISTRYINDEX, HOOKKEY);
+ lua.lua_rawgetp(L, lua.LUA_REGISTRYINDEX, HOOKKEY);
checkstack(L, L1, 1);
- lapi.lua_pushthread(L1); lapi.lua_xmove(L1, L, 1);
- lapi.lua_rawget(L, -2); /* 1st result = hooktable[L1] */
- lapi.lua_remove(L, -2); /* remove hook table */
+ lua.lua_pushthread(L1); lua.lua_xmove(L1, L, 1);
+ lua.lua_rawget(L, -2); /* 1st result = hooktable[L1] */
+ lua.lua_remove(L, -2); /* remove hook table */
}
- lapi.lua_pushstring(L, unmakemask(mask, buff)); /* 2nd result = mask */
- lapi.lua_pushinteger(L, ldebug.lua_gethookcount(L1)); /* 3rd result = count */
+ lua.lua_pushstring(L, unmakemask(mask, buff)); /* 2nd result = mask */
+ lua.lua_pushinteger(L, ldebug.lua_gethookcount(L1)); /* 3rd result = count */
return 3;
};
@@ -369,9 +368,9 @@ const db_traceback = function(L) {
let thread = getthread(L);
let L1 = thread.thread;
let arg = thread.arg;
- let msg = lapi.lua_tostring(L, arg + 1);
- if (msg === null && !lapi.lua_isnoneornil(L, arg + 1)) /* non-string 'msg'? */
- lapi.lua_pushvalue(L, arg + 1); /* return it untouched */
+ let msg = lua.lua_tostring(L, arg + 1);
+ if (msg === null && !lua.lua_isnoneornil(L, arg + 1)) /* non-string 'msg'? */
+ lua.lua_pushvalue(L, arg + 1); /* return it untouched */
else {
let level = lauxlib.luaL_optinteger(L, arg + 2, L === L1 ? 1 : 0);
lauxlib.luaL_traceback(L, L1, msg, level);
@@ -423,10 +422,10 @@ if (typeof require === "function") {
let buffer = lua.to_luastring(input);
if (lauxlib.luaL_loadbuffer(L, buffer, buffer.length, lua.to_luastring("=(debug command)", true))
- || lapi.lua_pcall(L, 0, 0, 0)) {
- lauxlib.lua_writestringerror(`${lapi.lua_tojsstring(L, -1)}\n`);
+ || lua.lua_pcall(L, 0, 0, 0)) {
+ lauxlib.lua_writestringerror(`${lua.lua_tojsstring(L, -1)}\n`);
}
- lapi.lua_settop(L, 0); /* remove eventual returns */
+ lua.lua_settop(L, 0); /* remove eventual returns */
}
};
diff --git a/src/lmathlib.js b/src/lmathlib.js
index 9603d2e..4f323c6 100644
--- a/src/lmathlib.js
+++ b/src/lmathlib.js
@@ -4,7 +4,6 @@ const assert = require('assert');
const seedrandom = require('seedrandom');
const lua = require('./lua.js');
-const lapi = require('./lapi.js');
const lauxlib = require('./lauxlib.js');
const lstate = require('./lstate.js');
const ldo = require('./ldo.js');
@@ -21,9 +20,9 @@ const math_randomseed = function(L) {
const math_random = function(L) {
let low, up;
let r = RNG();
- switch (lapi.lua_gettop(L)) { /* check number of arguments */
+ switch (lua.lua_gettop(L)) { /* check number of arguments */
case 0:
- lapi.lua_pushnumber(L, r); /* Number between 0 and 1 */
+ lua.lua_pushnumber(L, r); /* Number between 0 and 1 */
return 1;
case 1: {
low = 1;
@@ -44,55 +43,55 @@ const math_random = function(L) {
lua.to_luastring("interval too large", true));
r *= (up - low) + 1;
- lapi.lua_pushinteger(L, r + low);
+ lua.lua_pushinteger(L, r + low);
return 1;
};
const math_abs = function(L) {
- if (lapi.lua_isinteger(L, 1))
- lapi.lua_pushinteger(L, Math.abs(lapi.lua_tointeger(L, 1)));
+ if (lua.lua_isinteger(L, 1))
+ lua.lua_pushinteger(L, Math.abs(lua.lua_tointeger(L, 1)));
else
- lapi.lua_pushnumber(L, Math.abs(lauxlib.luaL_checknumber(L, 1)));
+ lua.lua_pushnumber(L, Math.abs(lauxlib.luaL_checknumber(L, 1)));
return 1;
};
const math_sin = function(L) {
- lapi.lua_pushnumber(L, Math.sin(lauxlib.luaL_checknumber(L, 1)));
+ lua.lua_pushnumber(L, Math.sin(lauxlib.luaL_checknumber(L, 1)));
return 1;
};
const math_cos = function(L) {
- lapi.lua_pushnumber(L, Math.cos(lauxlib.luaL_checknumber(L, 1)));
+ lua.lua_pushnumber(L, Math.cos(lauxlib.luaL_checknumber(L, 1)));
return 1;
};
const math_tan = function(L) {
- lapi.lua_pushnumber(L, Math.tan(lauxlib.luaL_checknumber(L, 1)));
+ lua.lua_pushnumber(L, Math.tan(lauxlib.luaL_checknumber(L, 1)));
return 1;
};
const math_asin = function(L) {
- lapi.lua_pushnumber(L, Math.asin(lauxlib.luaL_checknumber(L, 1)));
+ lua.lua_pushnumber(L, Math.asin(lauxlib.luaL_checknumber(L, 1)));
return 1;
};
const math_acos = function(L) {
- lapi.lua_pushnumber(L, Math.acos(lauxlib.luaL_checknumber(L, 1)));
+ lua.lua_pushnumber(L, Math.acos(lauxlib.luaL_checknumber(L, 1)));
return 1;
};
const math_atan = function(L) {
- lapi.lua_pushnumber(L, Math.atan(lauxlib.luaL_checknumber(L, 1)));
+ lua.lua_pushnumber(L, Math.atan(lauxlib.luaL_checknumber(L, 1)));
return 1;
};
const math_toint = function(L) {
- let n = lapi.lua_tointegerx(L, 1);
+ let n = lua.lua_tointegerx(L, 1);
if (n !== false)
- lapi.lua_pushinteger(L, n);
+ lua.lua_pushinteger(L, n);
else {
lauxlib.luaL_checkany(L, 1);
- lapi.lua_pushnil(L); /* value is not convertible to integer */
+ lua.lua_pushnil(L); /* value is not convertible to integer */
}
return 1;
};
@@ -100,14 +99,14 @@ const math_toint = function(L) {
const pushnumint = function(L, d) {
let n = luaconf.lua_numbertointeger(d);
if (n !== false) /* does 'd' fit in an integer? */
- lapi.lua_pushinteger(L, n); /* result is integer */
+ lua.lua_pushinteger(L, n); /* result is integer */
else
- lapi.lua_pushnumber(L, d); /* result is float */
+ lua.lua_pushnumber(L, d); /* result is float */
};
const math_floor = function(L) {
- if (lapi.lua_isinteger(L, 1))
- lapi.lua_settop(L, 1);
+ if (lua.lua_isinteger(L, 1))
+ lua.lua_settop(L, 1);
else
pushnumint(L, Math.floor(lauxlib.luaL_checknumber(L, 1)));
@@ -115,8 +114,8 @@ const math_floor = function(L) {
};
const math_ceil = function(L) {
- if (lapi.lua_isinteger(L, 1))
- lapi.lua_settop(L, 1);
+ if (lua.lua_isinteger(L, 1))
+ lua.lua_settop(L, 1);
else
pushnumint(L, Math.ceil(lauxlib.luaL_checknumber(L, 1)));
@@ -124,21 +123,21 @@ const math_ceil = function(L) {
};
const math_sqrt = function(L) {
- lapi.lua_pushnumber(L, Math.sqrt(lauxlib.luaL_checknumber(L, 1)));
+ lua.lua_pushnumber(L, Math.sqrt(lauxlib.luaL_checknumber(L, 1)));
return 1;
};
const math_ult = function(L) {
let a = lauxlib.luaL_checkinteger(L, 1);
let b = lauxlib.luaL_checkinteger(L, 2);
- lapi.lua_pushboolean(L, Math.abs(a) < Math.abs(b));
+ lua.lua_pushboolean(L, Math.abs(a) < Math.abs(b));
return 1;
};
const math_log = function(L) {
let x = lauxlib.luaL_checknumber(L, 1);
let res;
- if (lapi.lua_isnoneornil(L, 2))
+ if (lua.lua_isnoneornil(L, 2))
res = Math.log(x);
else {
let base = lauxlib.luaL_checknumber(L, 2);
@@ -149,87 +148,87 @@ const math_log = function(L) {
else
res = Math.log(x)/Math.log(base);
}
- lapi.lua_pushnumber(L, res);
+ lua.lua_pushnumber(L, res);
return 1;
};
const math_exp = function(L) {
- lapi.lua_pushnumber(L, Math.exp(lauxlib.luaL_checknumber(L, 1)));
+ lua.lua_pushnumber(L, Math.exp(lauxlib.luaL_checknumber(L, 1)));
return 1;
};
const math_deg = function(L) {
- lapi.lua_pushnumber(L, lauxlib.luaL_checknumber(L, 1) * (180 / Math.PI));
+ lua.lua_pushnumber(L, lauxlib.luaL_checknumber(L, 1) * (180 / Math.PI));
return 1;
};
const math_rad = function(L) {
- lapi.lua_pushnumber(L, lauxlib.luaL_checknumber(L, 1) * (Math.PI / 180));
+ lua.lua_pushnumber(L, lauxlib.luaL_checknumber(L, 1) * (Math.PI / 180));
return 1;
};
const math_min = function(L) {
- let n = lapi.lua_gettop(L); /* number of arguments */
+ 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));
for (let i = 2; i <= n; i++){
- if (lapi.lua_compare(L, i, imin, lua.LUA_OPLT))
+ if (lua.lua_compare(L, i, imin, lua.LUA_OPLT))
imin = i;
}
- lapi.lua_pushvalue(L, imin);
+ lua.lua_pushvalue(L, imin);
return 1;
};
const math_max = function(L) {
- let n = lapi.lua_gettop(L); /* number of arguments */
+ 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));
for (let i = 2; i <= n; i++){
- if (lapi.lua_compare(L, imax, i, lua.LUA_OPLT))
+ if (lua.lua_compare(L, imax, i, lua.LUA_OPLT))
imax = i;
}
- lapi.lua_pushvalue(L, imax);
+ lua.lua_pushvalue(L, imax);
return 1;
};
const math_type = function(L) {
- if (lapi.lua_type(L, 1) === lua.LUA_TNUMBER) {
- if (lapi.lua_isinteger(L, 1))
- lapi.lua_pushliteral(L, "integer");
+ if (lua.lua_type(L, 1) === lua.LUA_TNUMBER) {
+ if (lua.lua_isinteger(L, 1))
+ lua.lua_pushliteral(L, "integer");
else
- lapi.lua_pushliteral(L, "float");
+ lua.lua_pushliteral(L, "float");
} else {
lauxlib.luaL_checkany(L, 1);
- lapi.lua_pushnil(L);
+ lua.lua_pushnil(L);
}
return 1;
};
const math_fmod = function(L) {
- if (lapi.lua_isinteger(L, 1) && lapi.lua_isinteger(L, 2)) {
- let d = lapi.lua_tointeger(L, 2);
+ if (lua.lua_isinteger(L, 1) && lua.lua_isinteger(L, 2)) {
+ let d = lua.lua_tointeger(L, 2);
if (Math.abs(d) + 1 <= 1) {
lauxlib.luaL_argcheck(L, d !== 0, 2, lua.to_luastring("zero", true));
- lapi.lua_pushinteger(L, 0);
+ lua.lua_pushinteger(L, 0);
} else
- lapi.lua_pushinteger(L, lapi.lua_tointeger(L, 1) % d);
+ lua.lua_pushinteger(L, lua.lua_tointeger(L, 1) % d);
} else {
let a = lauxlib.luaL_checknumber(L, 1);
let b = lauxlib.luaL_checknumber(L, 2);
- lapi.lua_pushnumber(L, Number((a - (Math.floor(a / b) * b)).toPrecision(8)));
+ lua.lua_pushnumber(L, Number((a - (Math.floor(a / b) * b)).toPrecision(8)));
}
return 1;
};
const math_modf = function(L) {
- if (lapi.lua_isinteger(L, 1)) {
- lapi.lua_settop(L, 1); /* number is its own integer part */
- lapi.lua_pushnumber(L, 0); /* no fractional part */
+ if (lua.lua_isinteger(L, 1)) {
+ lua.lua_settop(L, 1); /* number is its own integer part */
+ lua.lua_pushnumber(L, 0); /* no fractional part */
} else {
let n = lauxlib.luaL_checknumber(L, 1);
let ip = n < 0 ? Math.ceil(n) : Math.floor(n);
pushnumint(L, ip);
- lapi.lua_pushnumber(L, n === ip ? 0 : n - ip);
+ lua.lua_pushnumber(L, n === ip ? 0 : n - ip);
}
return 2;
};
@@ -262,14 +261,14 @@ const mathlib = {
const luaopen_math = function(L) {
lauxlib.luaL_newlib(L, mathlib);
- lapi.lua_pushnumber(L, Math.PI);
- lapi.lua_setfield(L, -2, lua.to_luastring("pi", true));
- lapi.lua_pushnumber(L, Number.MAX_VALUE);
- lapi.lua_setfield(L, -2, lua.to_luastring("huge", true));
- lapi.lua_pushinteger(L, llimit.MAX_INT);
- lapi.lua_setfield(L, -2, lua.to_luastring("maxinteger", true));
- lapi.lua_pushinteger(L, llimit.MIN_INT);
- lapi.lua_setfield(L, -2, lua.to_luastring("mininteger", true));
+ lua.lua_pushnumber(L, Math.PI);
+ lua.lua_setfield(L, -2, lua.to_luastring("pi", true));
+ lua.lua_pushnumber(L, Number.MAX_VALUE);
+ lua.lua_setfield(L, -2, lua.to_luastring("huge", true));
+ lua.lua_pushinteger(L, llimit.MAX_INT);
+ lua.lua_setfield(L, -2, lua.to_luastring("maxinteger", true));
+ lua.lua_pushinteger(L, llimit.MIN_INT);
+ lua.lua_setfield(L, -2, lua.to_luastring("mininteger", true));
return 1;
};
diff --git a/src/loslib.js b/src/loslib.js
index 4a5c39d..348dcd6 100644
--- a/src/loslib.js
+++ b/src/loslib.js
@@ -3,14 +3,13 @@
const assert = require('assert');
const lua = require('./lua.js');
-const lapi = require('./lapi.js');
const lauxlib = require('./lauxlib.js');
const ldebug = require('./ldebug.js');
const llimit = require('./llimit.js');
const setfield = function(L, key, value) {
- lapi.lua_pushinteger(L, value);
- lapi.lua_setfield(L, -2, key);
+ lua.lua_pushinteger(L, value);
+ lua.lua_setfield(L, -2, key);
};
const setallfields = function(L, time) {
@@ -29,8 +28,8 @@ const setallfields = function(L, time) {
const L_MAXDATEFIELD = (llimit.MAX_INT / 2);
const getfield = function(L, key, d, delta) {
- let t = lapi.lua_getfield(L, -1, lua.to_luastring(key)); /* get field and its type */
- let res = lapi.lua_tointegerx(L, -1);
+ let t = lua.lua_getfield(L, -1, lua.to_luastring(key)); /* 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 '${key}' is not an integer`), true);
@@ -43,15 +42,15 @@ const getfield = function(L, key, d, delta) {
return lauxlib.luaL_error(L, lua.to_luastring(`field '${key}' is out-of-bound`), true);
res -= delta;
}
- lapi.lua_pop(L, 1);
+ lua.lua_pop(L, 1);
return res;
};
const os_time = function(L) {
let t = new Date();
- if (!lapi.lua_isnoneornil(L, 1)) /* called with arg */{
+ if (!lua.lua_isnoneornil(L, 1)) /* called with arg */{
lauxlib.luaL_checktype(L, 1, lua.LUA_TTABLE); /* make sure table is at the top */
- lapi.lua_settop(L, 1);
+ lua.lua_settop(L, 1);
t.setSeconds(getfield(L, "sec", 0, 0));
t.setSeconds(getfield(L, "min", 0, 0));
t.setSeconds(getfield(L, "hour", 12, 0));
@@ -61,7 +60,7 @@ const os_time = function(L) {
setallfields(L, t);
}
- lapi.lua_pushinteger(L, Math.floor(t / 1000));
+ lua.lua_pushinteger(L, Math.floor(t / 1000));
return 1;
};
diff --git a/src/lstrlib.js b/src/lstrlib.js
index 2bfe2ee..9bbf26a 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -46,25 +46,25 @@ const str_sub = function(L) {
if (start < 1) start = 1;
if (end > l) end = l;
if (start <= end)
- lapi.lua_pushstring(L, ts.value.slice(start - 1, (start - 1) + (end - start + 1)));
- else lapi.lua_pushliteral(L, "");
+ lua.lua_pushstring(L, ts.value.slice(start - 1, (start - 1) + (end - start + 1)));
+ else lua.lua_pushliteral(L, "");
return 1;
};
const str_len = function(L) {
- lapi.lua_pushinteger(L, lauxlib.luaL_checkstring(L, 1).length);
+ lua.lua_pushinteger(L, lauxlib.luaL_checkstring(L, 1).length);
return 1;
};
const str_char = function(L) {
- let n = lapi.lua_gettop(L); /* number of arguments */
+ let n = lua.lua_gettop(L); /* number of arguments */
let p = [];
for (let i = 1; i <= n; i++) {
let c = lauxlib.luaL_checkinteger(L, i);
lauxlib.luaL_argcheck(L, c >= 0 && c <= 255, "value out of range"); // Strings are 8-bit clean
p.push(c);
}
- lapi.lua_pushstring(L, p);
+ lua.lua_pushstring(L, p);
return 1;
};
@@ -76,12 +76,12 @@ const writer = function(L, b, size, B) {
const str_dump = function(L) {
let b = [];
- let strip = lapi.lua_toboolean(L, 2);
+ let strip = lua.lua_toboolean(L, 2);
lauxlib.luaL_checktype(L, 1, lua.LUA_TFUNCTION);
- lapi.lua_settop(L, 1);
- if (lapi.lua_dump(L, writer, b, strip) !== 0)
+ lua.lua_settop(L, 1);
+ if (lua.lua_dump(L, writer, b, strip) !== 0)
return lauxlib.luaL_error(L, lua.to_luastring("unable to dump given function"));
- lapi.lua_pushstring(L, b);
+ lua.lua_pushstring(L, b);
return 1;
};
@@ -216,19 +216,19 @@ const checkdp = function(buff) {
};
const addliteral = function(L, b, arg) {
- switch(lapi.lua_type(L, arg)) {
+ switch(lua.lua_type(L, arg)) {
case lua.LUA_TSTRING: {
- let s = lapi.lua_tostring(L, arg);
+ let s = lua.lua_tostring(L, arg);
addquoted(b, s, s.length);
break;
}
case lua.LUA_TNUMBER: {
- if (!lapi.lua_isinteger(L, arg)) { /* float? */
- let n = lapi.lua_tonumber(L, arg); /* write as hexa ('%a') */
+ if (!lua.lua_isinteger(L, arg)) { /* float? */
+ let n = lua.lua_tonumber(L, arg); /* write as hexa ('%a') */
concat(b, lua_number2strx(L, lua.to_luastring(`%${luaconf.LUA_INTEGER_FRMLEN}a`), n));
checkdp(b); /* ensure it uses a dot */
} else { /* integers */
- let n = lapi.lua_tointeger(L, arg);
+ let n = lua.lua_tointeger(L, arg);
concat(b, lua.to_luastring(sprintf("%d", n)));
}
break;
@@ -282,7 +282,7 @@ const addlenmod = function(form, lenmod) {
};
const str_format = function(L) {
- let top = lapi.lua_gettop(L);
+ let top = lua.lua_gettop(L);
let arg = 1;
let strfrmt = lauxlib.luaL_checkstring(L, arg);
let b = [];
@@ -340,17 +340,17 @@ const str_format = function(L) {
let s = lauxlib.luaL_tolstring(L, arg);
if (form.length <= 2 || form[2] === 0) { /* no modifiers? */
concat(b, s); /* keep entire string */
- lapi.lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
+ lua.lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
} else {
lauxlib.luaL_argcheck(L, s.length === strlen(s), arg, lua.to_luastring("string contains zeros", true));
if (form.indexOf('.'.charCodeAt(0)) < 0 && s.length >= 100) {
/* no precision and string is too long to be formatted */
concat(b, s); /* keep entire string */
- lapi.lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
+ lua.lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
} else { /* format the string into 'buff' */
// TODO: will failt if s is not valid UTF-8
concat(b, lua.to_luastring(sprintf(String.fromCharCode(...form), lobject.jsstring(s))));
- lapi.lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
+ lua.lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
}
}
break;
@@ -362,7 +362,7 @@ const str_format = function(L) {
}
}
- lapi.lua_pushstring(L, b);
+ lua.lua_pushstring(L, b);
return 1;
};
@@ -569,7 +569,7 @@ const str_pack = function(L) {
};
let arg = 1; /* current argument to pack */
let totalsize = 0; /* accumulate total size of result */
- lapi.lua_pushnil(L); /* mark to separate arguments from string buffer */
+ lua.lua_pushnil(L); /* mark to separate arguments from string buffer */
while (fmt.s.length - 1 > 0) {
let details = getdetails(h, totalsize, fmt);
let opt = details.opt;
@@ -634,24 +634,24 @@ const str_pack = function(L) {
break;
}
}
- lapi.lua_pushstring(L, b);
+ lua.lua_pushstring(L, b);
return 1;
};
const str_reverse = function(L) {
- lapi.lua_pushstring(L, lauxlib.luaL_checkstring(L, 1).reverse());
+ lua.lua_pushstring(L, lauxlib.luaL_checkstring(L, 1).reverse());
return 1;
};
const str_lower = function(L) {
// TODO: will fail on invalid UTF-8
- lapi.lua_pushstring(L, lua.to_luastring(lobject.jsstring(lauxlib.luaL_checkstring(L, 1)).toLowerCase()));
+ lua.lua_pushstring(L, lua.to_luastring(lobject.jsstring(lauxlib.luaL_checkstring(L, 1)).toLowerCase()));
return 1;
};
const str_upper = function(L) {
// TODO: will fail on invalid UTF-8
- lapi.lua_pushstring(L, lua.to_luastring(lobject.jsstring(lauxlib.luaL_checkstring(L, 1)).toUpperCase()));
+ lua.lua_pushstring(L, lua.to_luastring(lobject.jsstring(lauxlib.luaL_checkstring(L, 1)).toUpperCase()));
return 1;
};
@@ -668,7 +668,7 @@ const str_rep = function(L) {
r = r.concat(s.concat(sep));
r = r.concat(s);
- lapi.lua_pushstring(L, n > 0 ? r : []);
+ lua.lua_pushstring(L, n > 0 ? r : []);
return 1;
};
@@ -687,7 +687,7 @@ const str_byte = function(L) {
let n = (pose - posi) + 1;
lauxlib.luaL_checkstack(L, n, lua.to_luastring("string slice too long", true));
for (let i = 0; i < n; i++)
- lapi.lua_pushinteger(L, s[posi + i - 1]);
+ lua.lua_pushinteger(L, s[posi + i - 1]);
return n;
};
@@ -715,7 +715,7 @@ const str_packsize = function(L) {
default: break;
}
}
- lapi.lua_pushinteger(L, totalsize);
+ lua.lua_pushinteger(L, totalsize);
return 1;
};
@@ -786,28 +786,28 @@ const str_unpack = function(L) {
case KOption.Kint:
case KOption.Kuint: {
let res = unpackint(L, data.slice(pos), h.islittle, size, opt === KOption.Kint);
- lapi.lua_pushinteger(L, res);
+ lua.lua_pushinteger(L, res);
break;
}
case KOption.Kfloat: {
let res = unpacknum(L, data.slice(pos), h.islittle, size);
- lapi.lua_pushnumber(L, res);
+ lua.lua_pushnumber(L, res);
break;
}
case KOption.Kchar: {
- lapi.lua_pushstring(L, data.slice(pos, pos + size));
+ lua.lua_pushstring(L, data.slice(pos, pos + size));
break;
}
case KOption.Kstring: {
let len = unpackint(L, data.slice(pos), h.islittle, size, 0);
lauxlib.luaL_argcheck(L, pos + len + size <= ld, 2, lua.to_luastring("data string too short", true));
- lapi.lua_pushstring(L, data.slice(pos + size, pos + size + len));
+ lua.lua_pushstring(L, data.slice(pos + size, pos + size + len));
pos += len; /* skip string */
break;
}
case KOption.Kzstr: {
let len = data.slice(pos).indexOf(0);
- lapi.lua_pushstring(L, data.slice(pos, pos + len));
+ lua.lua_pushstring(L, data.slice(pos, pos + len));
pos += len + 1; /* skip string plus final '\0' */
break;
}
@@ -817,7 +817,7 @@ const str_unpack = function(L) {
}
pos += size;
}
- lapi.lua_pushinteger(L, pos + 1); /* next position */
+ lua.lua_pushinteger(L, pos + 1); /* next position */
return n + 1;
};
@@ -1112,16 +1112,16 @@ const match = function(ms, s, p) {
const push_onecapture = function(ms, i, s, e) {
if (i >= ms.level) {
if (i === 0)
- lapi.lua_pushlstring(ms.L, ms.src.slice(s), e - s); /* add whole match */
+ lua.lua_pushlstring(ms.L, ms.src.slice(s), e - s); /* add whole match */
else
lauxlib.luaL_error(ms.L, lua.to_luastring(`invalid capture index %${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_POSITION)
- lapi.lua_pushinteger(ms.L, ms.src_init + 1);
+ lua.lua_pushinteger(ms.L, ms.src_init + 1);
else
- lapi.lua_pushlstring(ms.L, ms.src.slice(ms.capture[i].init), l);
+ lua.lua_pushlstring(ms.L, ms.src.slice(ms.capture[i].init), l);
}
};
@@ -1189,16 +1189,16 @@ const str_find_aux = function(L, find) {
let init = posrelat(lauxlib.luaL_optinteger(L, 3, 1), ls);
if (init < 1) init = 1;
else if (init > ls + 1) { /* start after string's end? */
- lapi.lua_pushnil(L); /* cannot find anything */
+ lua.lua_pushnil(L); /* cannot find anything */
return 1;
}
/* explicit request or no special characters? */
- if (find && (lapi.lua_toboolean(L, 4) || nospecials(p, lp))) {
+ if (find && (lua.lua_toboolean(L, 4) || nospecials(p, lp))) {
/* do a plain search */
let f = find_subarray(s.slice(init - 1), p, 0);
if (f > -1) {
- lapi.lua_pushinteger(L, init + f);
- lapi.lua_pushinteger(L, init + f + lp - 1);
+ lua.lua_pushinteger(L, init + f);
+ lua.lua_pushinteger(L, init + f + lp - 1);
return 2;
}
} else {
@@ -1214,15 +1214,15 @@ const str_find_aux = function(L, find) {
reprepstate(ms);
if ((res = match(ms, s1, 0)) !== null) {
if (find) {
- lapi.lua_pushinteger(L, s1 + 1); /* start */
- lapi.lua_pushinteger(L, res); /* end */
+ lua.lua_pushinteger(L, s1 + 1); /* start */
+ lua.lua_pushinteger(L, res); /* end */
return push_captures(ms, null, 0) + 2;
} else
return push_captures(ms, s1, res);
}
} while (s1++ < ms.src_end && !anchor);
}
- lapi.lua_pushnil(L); /* not found */
+ lua.lua_pushnil(L); /* not found */
return 1;
};
@@ -1245,7 +1245,7 @@ class GMatchState {
}
const gmatch_aux = function(L) {
- let gm = lapi.lua_touserdata(L, lua.lua_upvalueindex(3));
+ let gm = lua.lua_touserdata(L, lua.lua_upvalueindex(3));
gm.ms.L = L;
for (let src = gm.src; src < gm.ms.src_end; src++) {
reprepstate(gm.ms);
@@ -1263,20 +1263,20 @@ const str_gmatch = function(L) {
let p = lauxlib.luaL_checkstring(L, 2);
let ls = s.length;
let lp = p.length;
- lapi.lua_settop(L, 2); /* keep them on closure to avoid being collected */
+ lua.lua_settop(L, 2); /* keep them on closure to avoid being collected */
let gm = new GMatchState();
- lapi.lua_pushobject(L, gm);
+ lua.lua_pushobject(L, gm);
prepstate(gm.ms, L, s, ls, p, lp);
gm.src = 0;
gm.p = 0;
gm.lastmatch = null;
- lapi.lua_pushcclosure(L, gmatch_aux, 3);
+ lua.lua_pushcclosure(L, gmatch_aux, 3);
return 1;
};
const add_s = function(ms, b, s, e) {
let L = ms.L;
- let news = lapi.lua_tostring(L, 3);
+ let news = lua.lua_tostring(L, 3);
let l = news.length;
for (let i = 0; i < l; i++) {
if (news[i] !== L_ESC)
@@ -1292,7 +1292,7 @@ const add_s = function(ms, b, s, e) {
else {
push_onecapture(ms, news[i] - '1'.charCodeAt(0), s, e);
lauxlib.luaL_tolstring(L, -1);
- lapi.lua_remove(L, -2); /* remove original value */
+ lua.lua_remove(L, -2); /* remove original value */
lauxlib.luaL_addvalue(b); /* add capture to accumulated result */
}
}
@@ -1303,14 +1303,14 @@ const add_value = function(ms, b, s, e, tr) {
let L = ms.L;
switch (tr) {
case lua.LUA_TFUNCTION: {
- lapi.lua_pushvalue(L, 3);
+ lua.lua_pushvalue(L, 3);
let n = push_captures(ms, s, e);
- lapi.lua_call(L, n, 1);
+ lua.lua_call(L, n, 1);
break;
}
case lua.LUA_TTABLE: {
push_onecapture(ms, 0, s, e);
- lapi.lua_gettable(L, 3);
+ lua.lua_gettable(L, 3);
break;
}
default: { /* LUA_TNUMBER or LUA_TSTRING */
@@ -1318,10 +1318,10 @@ const add_value = function(ms, b, s, e, tr) {
return;
}
}
- if (!lapi.lua_toboolean(L, -1)) { /* nil or false? */
- lapi.lua_pop(L, 1);
- lapi.lua_pushlstring(L, s, e - s); /* keep original text */
- } else if (!lapi.lua_isstring(L, -1))
+ if (!lua.lua_toboolean(L, -1)) { /* nil or false? */
+ lua.lua_pop(L, 1);
+ lua.lua_pushlstring(L, s, e - s); /* keep original text */
+ } else if (!lua.lua_isstring(L, -1))
lauxlib.luaL_error(L, lua.to_luastring(`invalid replacement value (a ${lobject.jsstring(lauxlib.luaL_typename(L, -1))})`));
lauxlib.luaL_addvalue(b); /* add result to accumulator */
};
@@ -1332,7 +1332,7 @@ const str_gsub = function(L) {
let p = lauxlib.luaL_checkstring(L, 2); /* pattern */
let lp = p.length;
let lastmatch = null; /* end of last match */
- let tr = lapi.lua_type(L, 3); /* replacement type */
+ let tr = lua.lua_type(L, 3); /* replacement type */
let max_s = lauxlib.luaL_optinteger(L, 4, srcl + 1); /* max replacements */
let anchor = p[0] === '^'.charCodeAt(0);
let n = 0; /* replacement count */
@@ -1360,7 +1360,7 @@ const str_gsub = function(L) {
}
lauxlib.luaL_addlstring(b, ms.src.slice(src), ms.src_end - src);
lauxlib.luaL_pushresult(b);
- lapi.lua_pushinteger(L, n); /* number of substitutions */
+ lua.lua_pushinteger(L, n); /* number of substitutions */
return 2;
};
@@ -1385,14 +1385,14 @@ const strlib = {
};
const createmetatable = function(L) {
- lapi.lua_createtable(L, 0, 1); /* table to be metatable for strings */
- lapi.lua_pushliteral(L, ""); /* dummy string */
- lapi.lua_pushvalue(L, -2); /* copy table */
- lapi.lua_setmetatable(L, -2); /* set table as metatable for strings */
- lapi.lua_pop(L, 1); /* pop dummy string */
- lapi.lua_pushvalue(L, -2); /* get string library */
- lapi.lua_setfield(L, -2, lua.to_luastring("__index", true)); /* lobject.table_index = string */
- lapi.lua_pop(L, 1); /* pop metatable */
+ lua.lua_createtable(L, 0, 1); /* table to be metatable for strings */
+ lua.lua_pushliteral(L, ""); /* dummy string */
+ lua.lua_pushvalue(L, -2); /* copy table */
+ 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)); /* lobject.table_index = string */
+ lua.lua_pop(L, 1); /* pop metatable */
};
const luaopen_string = function(L) {
diff --git a/src/ltablib.js b/src/ltablib.js
index 51f9810..5dc33d1 100644
--- a/src/ltablib.js
+++ b/src/ltablib.js
@@ -22,8 +22,8 @@ const TAB_L = 4; /* length */
const TAB_RW = (TAB_R | TAB_W); /* read/write */
const checkfield = function(L, key, n) {
- lapi.lua_pushstring(L, key);
- return lapi.lua_rawget(L, -n) !== lua.LUA_TNIL;
+ lua.lua_pushstring(L, key);
+ return lua.lua_rawget(L, -n) !== lua.LUA_TNIL;
};
/*
@@ -31,13 +31,13 @@ const checkfield = function(L, key, n) {
** has a metatable with the required metamethods)
*/
const checktab = function(L, arg, what) {
- if (lapi.lua_type(L, arg) !== lua.LUA_TTABLE) { /* is it not a table? */
+ if (lua.lua_type(L, arg) !== lua.LUA_TTABLE) { /* is it not a table? */
let n = 1;
- if (lapi.lua_getmetatable(L, arg) && /* must have metatable */
+ 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))) {
- lapi.lua_pop(L, n); /* pop metatable and tested metamethods */
+ lua.lua_pop(L, n); /* pop metatable and tested metamethods */
}
else
lauxlib.luaL_checktype(L, arg, lua.LUA_TTABLE); /* force an error */
@@ -50,8 +50,8 @@ const aux_getn = function(L, n, w) {
};
const addfield = function(L, b, i) {
- lapi.lua_geti(L, 1, i);
- if (!lapi.lua_isstring(L, -1))
+ lua.lua_geti(L, 1, i);
+ if (!lua.lua_isstring(L, -1))
lauxlib.luaL_error(L, lua.to_luastring(`invalid value (${lobject.jsstring(lauxlib.luaL_typename(L, -1))}) at index ${i} in table for 'concat'`));
lauxlib.luaL_addvalue(b);
@@ -60,7 +60,7 @@ const addfield = function(L, b, i) {
const tinsert = function(L) {
let e = aux_getn(L, 1, TAB_RW) + 1; /* first empty element */
let pos;
- switch (lapi.lua_gettop(L)) {
+ switch (lua.lua_gettop(L)) {
case 2:
pos = e;
break;
@@ -68,8 +68,8 @@ const tinsert = function(L) {
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));
for (let i = e; i > pos; i--) { /* move up elements */
- lapi.lua_geti(L, 1, i - 1);
- lapi.lua_seti(L, 1, i); /* t[i] = t[i - 1] */
+ lua.lua_geti(L, 1, i - 1);
+ lua.lua_seti(L, 1, i); /* t[i] = t[i - 1] */
}
break;
}
@@ -78,7 +78,7 @@ const tinsert = function(L) {
}
}
- lapi.lua_seti(L, 1, pos); /* t[pos] = v */
+ lua.lua_seti(L, 1, pos); /* t[pos] = v */
return 0;
};
@@ -87,13 +87,13 @@ const tremove = function(L) {
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));
- lapi.lua_geti(L, 1, pos); /* result = t[pos] */
+ lua.lua_geti(L, 1, pos); /* result = t[pos] */
for (; pos < size; pos++) {
- lapi.lua_geti(L, 1, pos + 1);
- lapi.lua_seti(L, 1, pos); /* t[pos] = t[pos + 1] */
+ lua.lua_geti(L, 1, pos + 1);
+ lua.lua_seti(L, 1, pos); /* t[pos] = t[pos + 1] */
}
- lapi.lua_pushnil(L);
- lapi.lua_seti(L, 1, pos); /* t[pos] = nil */
+ lua.lua_pushnil(L);
+ lua.lua_seti(L, 1, pos); /* t[pos] = nil */
return 1;
};
@@ -107,7 +107,7 @@ const tmove = function(L) {
let f = lauxlib.luaL_checkinteger(L, 2);
let e = lauxlib.luaL_checkinteger(L, 3);
let t = lauxlib.luaL_checkinteger(L, 4);
- let tt = !lapi.lua_isnoneornil(L, 5) ? 5 : 1; /* destination table */
+ let tt = !lua.lua_isnoneornil(L, 5) ? 5 : 1; /* destination table */
checktab(L, 1, TAB_R);
checktab(L, tt, TAB_W);
if (e >= f) { /* otherwise, nothing to move */
@@ -115,20 +115,20 @@ const tmove = function(L) {
let n = e - f + 1; /* number of elements to move */
lauxlib.luaL_argcheck(L, t <= llimit.LUA_MAXINTEGER - n + 1, 4, lua.to_luastring("destination wrap around", true));
- if (t > e || t <= f || (tt !== 1 && lapi.lua_compare(L, 1, tt, lua.LUA_OPEQ) !== 1)) {
+ if (t > e || t <= f || (tt !== 1 && lua.lua_compare(L, 1, tt, lua.LUA_OPEQ) !== 1)) {
for (let i = 0; i < n; i++) {
- lapi.lua_geti(L, 1, f + i);
- lapi.lua_seti(L, tt, t + i);
+ lua.lua_geti(L, 1, f + i);
+ lua.lua_seti(L, tt, t + i);
}
} else {
for (let i = n - 1; i >= 0; i--) {
- lapi.lua_geti(L, 1, f + i);
- lapi.lua_seti(L, tt, t + i);
+ lua.lua_geti(L, 1, f + i);
+ lua.lua_seti(L, tt, t + i);
}
}
}
- lapi.lua_pushvalue(L, tt); /* return destination table */
+ lua.lua_pushvalue(L, tt); /* return destination table */
return 1;
};
@@ -155,13 +155,13 @@ const tconcat = function(L) {
};
const pack = function(L) {
- let n = lapi.lua_gettop(L); /* number of elements to pack */
- lapi.lua_createtable(L, n, 1); /* create result table */
- lapi.lua_insert(L, 1); /* put it at index 1 */
+ let n = lua.lua_gettop(L); /* number of elements to pack */
+ lua.lua_createtable(L, n, 1); /* create result table */
+ lua.lua_insert(L, 1); /* put it at index 1 */
for (let i = n; i >= 1; i--) /* assign elements */
- lapi.lua_seti(L, 1, i);
- lapi.lua_pushinteger(L, n);
- lapi.lua_setfield(L, 1, ["n".charCodeAt(0)]); /* t.n = number of elements */
+ lua.lua_seti(L, 1, i);
+ lua.lua_pushinteger(L, n);
+ lua.lua_setfield(L, 1, ["n".charCodeAt(0)]); /* t.n = number of elements */
return 1; /* return table */
};
@@ -170,11 +170,11 @@ const unpack = function(L) {
let e = lauxlib.luaL_opt(L, lauxlib.luaL_checkinteger, 3, lauxlib.luaL_len(L, 1));
if (i > e) return 0; /* empty range */
let n = e - i; /* number of elements minus 1 (avoid overflows) */
- if (n >= llimit.MAX_INT || !lapi.lua_checkstack(L, ++n))
+ if (n >= llimit.MAX_INT || !lua.lua_checkstack(L, ++n))
return lauxlib.luaL_error(L, lua.to_luastring("too many results to unpack", true));
for (; i < e; i++) /* push arg[i..e - 1] (to avoid overflows) */
- lapi.lua_geti(L, 1, i);
- lapi.lua_geti(L, 1, e); /* push last element */
+ lua.lua_geti(L, 1, i);
+ lua.lua_geti(L, 1, e); /* push last element */
return n;
};
@@ -183,7 +183,7 @@ const unpack = function(L) {
const auxsort = function(L) {
let t = lapi.index2addr(L, 1);
- if (lapi.lua_type(L, 2) !== lua.LUA_TFUNCTION) { /* no function? */
+ if (lua.lua_type(L, 2) !== lua.LUA_TFUNCTION) { /* no function? */
[...t.value.entries()]
.sort(function (a, b) {
if (typeof a[0] !== 'number') return 1;
@@ -197,12 +197,12 @@ const auxsort = function(L) {
if (typeof a[0] !== 'number') return 1;
else if (typeof b[0] !== 'number') return -1;
- lapi.lua_pushvalue(L, 2); /* push function */
- lapi.lua_pushtvalue(L, a[1]); /* since we use Map.sort, a and b are not on the stack */
- lapi.lua_pushtvalue(L, b[1]);
- lapi.lua_call(L, 2, 1); /* call function */
- let res = lapi.lua_toboolean(L, -1); /* get result */
- lapi.lua_pop(L, 1); /* pop result */
+ lua.lua_pushvalue(L, 2); /* push function */
+ lua.lua_pushtvalue(L, a[1]); /* since we use Map.sort, a and b are not on the stack */
+ lua.lua_pushtvalue(L, b[1]);
+ lua.lua_call(L, 2, 1); /* call function */
+ let res = lua.lua_toboolean(L, -1); /* get result */
+ lua.lua_pop(L, 1); /* pop result */
return res ? -1 : 1;
})
.forEach((e, i) => typeof e[0] === 'number' ? t.value.set(i + 1, e[1]) : true);
@@ -213,9 +213,9 @@ const sort = function(L) {
let n = aux_getn(L, 1, TAB_RW);
if (n > 1) { /* non-trivial interval? */
lauxlib.luaL_argcheck(L, n < llimit.MAX_INT, 1, lua.to_luastring("array too big", true));
- if (!lapi.lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
+ if (!lua.lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
lauxlib.luaL_checktype(L, 2, lua.LUA_TFUNCTION); /* must be a function */
- lapi.lua_settop(L, 2); /* make sure there are two arguments */
+ lua.lua_settop(L, 2); /* make sure there are two arguments */
auxsort(L);
}
return 0;
diff --git a/src/lua.js b/src/lua.js
index 7e22b83..e15654e 100644
--- a/src/lua.js
+++ b/src/lua.js
@@ -2,6 +2,7 @@
"use strict";
const defs = require("./defs.js");
+const lapi = require("./lapi.js");
module.exports.FENGARI_AUTHORS = defs.FENGARI_AUTHORS;
module.exports.FENGARI_COPYRIGHT = defs.FENGARI_COPYRIGHT;
@@ -76,3 +77,101 @@ 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.to_luastring = defs.to_luastring;
+
+module.exports.lua_absindex = lapi.lua_absindex;
+module.exports.lua_atpanic = lapi.lua_atpanic;
+module.exports.lua_call = lapi.lua_call;
+module.exports.lua_callk = lapi.lua_callk;
+module.exports.lua_checkstack = lapi.lua_checkstack;
+module.exports.lua_compare = lapi.lua_compare;
+module.exports.lua_concat = lapi.lua_concat;
+module.exports.lua_copy = lapi.lua_copy;
+module.exports.lua_createtable = lapi.lua_createtable;
+module.exports.lua_dump = lapi.lua_dump;
+module.exports.lua_error = lapi.lua_error;
+module.exports.lua_gc = lapi.lua_gc;
+module.exports.lua_getallocf = lapi.lua_getallocf;
+module.exports.lua_getextraspace = lapi.lua_getextraspace;
+module.exports.lua_getfield = lapi.lua_getfield;
+module.exports.lua_getglobal = lapi.lua_getglobal;
+module.exports.lua_geti = lapi.lua_geti;
+module.exports.lua_getmetatable = lapi.lua_getmetatable;
+module.exports.lua_gettable = lapi.lua_gettable;
+module.exports.lua_gettop = lapi.lua_gettop;
+module.exports.lua_getupvalue = lapi.lua_getupvalue;
+module.exports.lua_getuservalue = lapi.lua_getuservalue;
+module.exports.lua_insert = lapi.lua_insert;
+module.exports.lua_iscfunction = lapi.lua_iscfunction;
+module.exports.lua_isfunction = lapi.lua_isfunction;
+module.exports.lua_isinteger = lapi.lua_isinteger;
+module.exports.lua_isnil = lapi.lua_isnil;
+module.exports.lua_isnone = lapi.lua_isnone;
+module.exports.lua_isnoneornil = lapi.lua_isnoneornil;
+module.exports.lua_isnumber = lapi.lua_isnumber;
+module.exports.lua_isstring = lapi.lua_isstring;
+module.exports.lua_istable = lapi.lua_istable;
+module.exports.lua_isthread = lapi.lua_isthread;
+module.exports.lua_isuserdata = lapi.lua_isuserdata;
+module.exports.lua_len = lapi.lua_len;
+module.exports.lua_load = lapi.lua_load;
+module.exports.lua_newtable = lapi.lua_newtable;
+module.exports.lua_newuserdata = lapi.lua_newuserdata;
+module.exports.lua_next = lapi.lua_next;
+module.exports.lua_pcall = lapi.lua_pcall;
+module.exports.lua_pcallk = lapi.lua_pcallk;
+module.exports.lua_pop = lapi.lua_pop;
+module.exports.lua_pushboolean = lapi.lua_pushboolean;
+module.exports.lua_pushcclosure = lapi.lua_pushcclosure;
+module.exports.lua_pushcfunction = lapi.lua_pushcfunction;
+module.exports.lua_pushglobaltable = lapi.lua_pushglobaltable;
+module.exports.lua_pushinteger = lapi.lua_pushinteger;
+module.exports.lua_pushjsclosure = lapi.lua_pushjsclosure;
+module.exports.lua_pushjsfunction = lapi.lua_pushjsfunction;
+module.exports.lua_pushlightuserdata = lapi.lua_pushlightuserdata;
+module.exports.lua_pushliteral = lapi.lua_pushliteral;
+module.exports.lua_pushlstring = lapi.lua_pushlstring;
+module.exports.lua_pushnil = lapi.lua_pushnil;
+module.exports.lua_pushnumber = lapi.lua_pushnumber;
+module.exports.lua_pushobject = lapi.lua_pushobject;
+module.exports.lua_pushstring = lapi.lua_pushstring;
+module.exports.lua_pushthread = lapi.lua_pushthread;
+module.exports.lua_pushtvalue = lapi.lua_pushtvalue;
+module.exports.lua_pushvalue = lapi.lua_pushvalue;
+module.exports.lua_rawequal = lapi.lua_rawequal;
+module.exports.lua_rawget = lapi.lua_rawget;
+module.exports.lua_rawgeti = lapi.lua_rawgeti;
+module.exports.lua_rawgetp = lapi.lua_rawgetp;
+module.exports.lua_rawlen = lapi.lua_rawlen;
+module.exports.lua_rawset = lapi.lua_rawset;
+module.exports.lua_rawsetp = lapi.lua_rawsetp;
+module.exports.lua_remove = lapi.lua_remove;
+module.exports.lua_replace = lapi.lua_replace;
+module.exports.lua_rotate = lapi.lua_rotate;
+module.exports.lua_setfield = lapi.lua_setfield;
+module.exports.lua_setglobal = lapi.lua_setglobal;
+module.exports.lua_seti = lapi.lua_seti;
+module.exports.lua_setmetatable = lapi.lua_setmetatable;
+module.exports.lua_settable = lapi.lua_settable;
+module.exports.lua_settop = lapi.lua_settop;
+module.exports.lua_setupvalue = lapi.lua_setupvalue;
+module.exports.lua_setuservalue = lapi.lua_setuservalue;
+module.exports.lua_status = lapi.lua_status;
+module.exports.lua_stringtonumber = lapi.lua_stringtonumber;
+module.exports.lua_toboolean = lapi.lua_toboolean;
+module.exports.lua_todataview = lapi.lua_todataview;
+module.exports.lua_tointeger = lapi.lua_tointeger;
+module.exports.lua_tointegerx = lapi.lua_tointegerx;
+module.exports.lua_tojsstring = lapi.lua_tojsstring;
+module.exports.lua_toljsstring = lapi.lua_toljsstring;
+module.exports.lua_tolstring = lapi.lua_tolstring;
+module.exports.lua_tonumber = lapi.lua_tonumber;
+module.exports.lua_topointer = lapi.lua_topointer;
+module.exports.lua_tostring = lapi.lua_tostring;
+module.exports.lua_tothread = lapi.lua_tothread;
+module.exports.lua_touserdata = lapi.lua_touserdata;
+module.exports.lua_type = lapi.lua_type;
+module.exports.lua_typename = lapi.lua_typename;
+module.exports.lua_upvalueid = lapi.lua_upvalueid;
+module.exports.lua_upvaluejoin = lapi.lua_upvaluejoin;
+module.exports.lua_version = lapi.lua_version;
+module.exports.lua_xmove = lapi.lua_xmove;
diff --git a/src/lutf8lib.js b/src/lutf8lib.js
index 9d53a8c..af5f960 100644
--- a/src/lutf8lib.js
+++ b/src/lutf8lib.js
@@ -75,28 +75,28 @@ const utflen = function(L) {
let s1 = dec ? dec.string : null;
if (s1 === null) {
/* conversion error? */
- lapi.lua_pushnil(L); /* return nil ... */
- lapi.lua_pushinteger(L, posi + 1); /* ... and current position */
+ lua.lua_pushnil(L); /* return nil ... */
+ lua.lua_pushinteger(L, posi + 1); /* ... and current position */
return 2;
}
posi = s.length - s1.length;
n++;
}
- lapi.lua_pushinteger(L, n);
+ lua.lua_pushinteger(L, n);
return 1;
};
const pushutfchar = function(L, arg) {
let code = lauxlib.luaL_checkinteger(L, arg);
lauxlib.luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, lua.to_luastring("value out of range", true));
- lapi.lua_pushstring(L, lua.to_luastring(String.fromCharCode(code)));
+ lua.lua_pushstring(L, lua.to_luastring(String.fromCharCode(code)));
};
/*
** utfchar(n1, n2, ...) -> char(n1)..char(n2)...
*/
const utfchar = function(L) {
- let n = lapi.lua_gettop(L); /* number of arguments */
+ let n = lua.lua_gettop(L); /* number of arguments */
if (n === 1) /* optimize common case of single char */
pushutfchar(L, 1);
else {
@@ -150,9 +150,9 @@ const byteoffset = function(L) {
}
if (n === 0) /* did it find given character? */
- lapi.lua_pushinteger(L, posi + 1);
+ lua.lua_pushinteger(L, posi + 1);
else /* no such character */
- lapi.lua_pushnil(L);
+ lua.lua_pushnil(L);
return 1;
};
@@ -182,7 +182,7 @@ const codepoint = function(L) {
return lauxlib.luaL_error(L, lua.to_luastring("invalid UTF-8 code", true));
s = dec.string;
let code = dec.code;
- lapi.lua_pushinteger(L, code);
+ lua.lua_pushinteger(L, code);
n++;
}
return n;
@@ -192,7 +192,7 @@ const iter_aux = function(L) {
let s = lauxlib.luaL_checkstring(L, 1);
s = L.stack[lapi.index2addr_(L, 1)].value;
let len = s.length;
- let n = lapi.lua_tointeger(L, 2) - 1;
+ let n = lua.lua_tointeger(L, 2) - 1;
if (n < 0) /* first iteration? */
n = 0; /* start from here */
@@ -209,17 +209,17 @@ const iter_aux = function(L) {
let next = dec ? dec.string : null;
if (next === null || iscont(next[0]))
return lauxlib.luaL_error(L, lua.to_luastring("invalid UTF-8 code", true));
- lapi.lua_pushinteger(L, n + 1);
- lapi.lua_pushinteger(L, code);
+ lua.lua_pushinteger(L, n + 1);
+ lua.lua_pushinteger(L, code);
return 2;
}
};
const iter_codes = function(L) {
lauxlib.luaL_checkstring(L, 1);
- lapi.lua_pushcfunction(L, iter_aux);
- lapi.lua_pushvalue(L, 1);
- lapi.lua_pushinteger(L, 0);
+ lua.lua_pushcfunction(L, iter_aux);
+ lua.lua_pushvalue(L, 1);
+ lua.lua_pushinteger(L, 0);
return 3;
};
@@ -236,8 +236,8 @@ const UTF8PATT = "[\0-\x7F\xC2-\xF4][\x80-\xBF]*";
const luaopen_utf8 = function(L) {
lauxlib.luaL_newlib(L, funcs);
- lapi.lua_pushstring(L, lua.to_luastring(UTF8PATT));
- lapi.lua_setfield(L, -2, lua.to_luastring("charpattern", true));
+ lua.lua_pushstring(L, lua.to_luastring(UTF8PATT));
+ lua.lua_setfield(L, -2, lua.to_luastring("charpattern", true));
return 1;
};
diff --git a/tests/lapi.js b/tests/lapi.js
index 68e8f7e..1e3624f 100644
--- a/tests/lapi.js
+++ b/tests/lapi.js
@@ -9,7 +9,6 @@ const toByteCode = tests.toByteCode;
const VM = require("../src/lvm.js");
const ldo = require("../src/ldo.js");
-const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const lua = require('../src/lua.js');
const linit = require('../src/linit.js');
@@ -23,7 +22,7 @@ test('luaL_newstate, lua_pushnil, luaL_typename', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushnil(L);
+ lua.lua_pushnil(L);
}, "JS Lua program ran without error");
@@ -44,7 +43,7 @@ test('lua_pushnumber', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushnumber(L, 10.5);
+ lua.lua_pushnumber(L, 10.5);
}, "JS Lua program ran without error");
@@ -55,7 +54,7 @@ test('lua_pushnumber', function (t) {
);
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
10.5,
"top is correct"
);
@@ -71,7 +70,7 @@ test('lua_pushinteger', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushinteger(L, 10);
+ lua.lua_pushinteger(L, 10);
}, "JS Lua program ran without error");
@@ -82,7 +81,7 @@ test('lua_pushinteger', function (t) {
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
10,
"top is correct"
);
@@ -98,7 +97,7 @@ test('lua_pushliteral', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushliteral(L, "hello");
+ lua.lua_pushliteral(L, "hello");
}, "JS Lua program ran without error");
@@ -109,7 +108,7 @@ test('lua_pushliteral', function (t) {
);
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"top is correct"
);
@@ -125,7 +124,7 @@ test('lua_pushboolean', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushboolean(L, true);
+ lua.lua_pushboolean(L, true);
}, "JS Lua program ran without error");
@@ -136,7 +135,7 @@ test('lua_pushboolean', function (t) {
);
t.strictEqual(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
true,
"top is correct"
);
@@ -152,9 +151,9 @@ test('lua_pushvalue', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushliteral(L, "hello");
+ lua.lua_pushliteral(L, "hello");
- lapi.lua_pushvalue(L, -1);
+ lua.lua_pushvalue(L, -1);
}, "JS Lua program ran without error");
@@ -171,13 +170,13 @@ test('lua_pushvalue', function (t) {
);
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"hello",
"Correct element(s) on the stack"
);
@@ -197,8 +196,8 @@ test('lua_pushjsclosure', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushliteral(L, "a value associated to the C closure");
- lapi.lua_pushjsclosure(L, fn, 1);
+ lua.lua_pushliteral(L, "a value associated to the C closure");
+ lua.lua_pushjsclosure(L, fn, 1);
}, "JS Lua program ran without error");
@@ -223,7 +222,7 @@ test('lua_pushjsfunction', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushjsfunction(L, fn);
+ lua.lua_pushjsfunction(L, fn);
}, "JS Lua program ran without error");
@@ -243,20 +242,20 @@ test('lua_call (calling a light JS function)', function (t) {
t.doesNotThrow(function () {
let fn = function(L) {
- lapi.lua_pushliteral(L, "hello");
+ lua.lua_pushliteral(L, "hello");
return 1;
};
L = lauxlib.luaL_newstate();
- lapi.lua_pushjsfunction(L, fn);
+ lua.lua_pushjsfunction(L, fn);
- lapi.lua_call(L, 0, 1);
+ lua.lua_call(L, 0, 1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"top is correct"
);
@@ -271,21 +270,21 @@ test('lua_call (calling a JS closure)', function (t) {
t.doesNotThrow(function () {
let fn = function(L) {
- lapi.lua_pushstring(L, lapi.lua_tostring(L, lua.lua_upvalueindex(1)));
+ lua.lua_pushstring(L, lua.lua_tostring(L, lua.lua_upvalueindex(1)));
return 1;
};
L = lauxlib.luaL_newstate();
- lapi.lua_pushliteral(L, "upvalue hello !");
- lapi.lua_pushjsclosure(L, fn, 1);
+ lua.lua_pushliteral(L, "upvalue hello !");
+ lua.lua_pushjsclosure(L, fn, 1);
- lapi.lua_call(L, 0, 1);
+ lua.lua_call(L, 0, 1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"upvalue hello !",
"top is correct"
);
@@ -300,20 +299,20 @@ test('lua_pcall (calling a light JS function)', function (t) {
t.doesNotThrow(function () {
let fn = function(L) {
- lapi.lua_pushliteral(L, "hello");
+ lua.lua_pushliteral(L, "hello");
return 1;
};
L = lauxlib.luaL_newstate();
- lapi.lua_pushjsfunction(L, fn);
+ lua.lua_pushjsfunction(L, fn);
- lapi.lua_pcall(L, 0, 1, 0);
+ lua.lua_pcall(L, 0, 1, 0);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"top is correct"
);
@@ -333,9 +332,9 @@ test('lua_pcall that breaks', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushjsfunction(L, fn);
+ lua.lua_pushjsfunction(L, fn);
- lapi.lua_pcall(L, 0, 1, 0);
+ lua.lua_pcall(L, 0, 1, 0);
}, "JS Lua program ran without error");
@@ -352,15 +351,15 @@ test('lua_pop', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_pushliteral(L, "hello");
- lapi.lua_pushliteral(L, "world");
+ lua.lua_pushliteral(L, "hello");
+ lua.lua_pushliteral(L, "world");
- lapi.lua_pop(L, 1);
+ lua.lua_pop(L, 1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Correct element(s) on the stack"
);
@@ -381,14 +380,14 @@ test('lua_load and lua_call it', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_load(L, null, bc, lua.to_luastring("test-lua_load"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-lua_load"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, 1);
+ lua.lua_call(L, 0, 1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"JS > Lua > JS \o/",
"Correct element(s) on the stack"
);
@@ -408,17 +407,17 @@ test('lua script reads js upvalues', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_load(L, null, bc, lua.to_luastring("test-lua_load"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-lua_load"), lua.to_luastring("binary"));
- lapi.lua_pushliteral(L, "hello");
- lapi.lua_setglobal(L, lua.to_luastring("js"));
+ lua.lua_pushliteral(L, "hello");
+ lua.lua_setglobal(L, lua.to_luastring("js"));
- lapi.lua_call(L, 0, 1);
+ lua.lua_call(L, 0, 1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -433,12 +432,12 @@ test('lua_createtable', function (t) {
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
- lapi.lua_createtable(L, 3, 3);
+ lua.lua_createtable(L, 3, 3);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_istable(L, -1),
+ lua.lua_istable(L, -1),
"Correct element(s) on the stack"
);
});
@@ -452,12 +451,12 @@ test('lua_newtable', function (t) {
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
- lapi.lua_newtable(L);
+ lua.lua_newtable(L);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_istable(L, -1),
+ lua.lua_istable(L, -1),
"Correct element(s) on the stack"
);
});
@@ -471,20 +470,20 @@ test('lua_settable, lua_gettable', function (t) {
t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
- lapi.lua_newtable(L);
+ lua.lua_newtable(L);
- lapi.lua_pushliteral(L, "key");
- lapi.lua_pushliteral(L, "value");
+ lua.lua_pushliteral(L, "key");
+ lua.lua_pushliteral(L, "value");
- lapi.lua_settable(L, -3);
+ lua.lua_settable(L, -3);
- lapi.lua_pushliteral(L, "key");
- lapi.lua_gettable(L, -2);
+ lua.lua_pushliteral(L, "key");
+ lua.lua_gettable(L, -2);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"value",
"Correct element(s) on the stack"
);
diff --git a/tests/lbaselib.js b/tests/lbaselib.js
index 646f900..abde72c 100644
--- a/tests/lbaselib.js
+++ b/tests/lbaselib.js
@@ -9,7 +9,6 @@ const toByteCode = tests.toByteCode;
const VM = require("../src/lvm.js");
const ldo = require("../src/ldo.js");
-const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const lua = require('../src/lua.js');
const linit = require('../src/linit.js');
@@ -29,9 +28,9 @@ test('print', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-print"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-print"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
});
@@ -63,20 +62,20 @@ test('setmetatable, getmetatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-setmetatable-getmetatable"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-setmetatable-getmetatable"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"hello",
"Correct element(s) on the stack"
);
t.ok(
- lapi.lua_istable(L, -1),
+ lua.lua_istable(L, -1),
"Correct element(s) on the stack"
);
});
@@ -108,19 +107,19 @@ test('rawequal', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-rawequal"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-rawequal"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.notOk(
- lapi.lua_toboolean(L, -2),
+ lua.lua_toboolean(L, -2),
"Correct element(s) on the stack"
);
t.ok(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
"Correct element(s) on the stack"
);
});
@@ -154,32 +153,32 @@ test('rawset, rawget', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-rawequal"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-rawequal"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -4),
+ lua.lua_tojsstring(L, -4),
"hello",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -3),
+ lua.lua_tojsstring(L, -3),
"hello",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"bye",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"bye",
"Correct element(s) on the stack"
);
@@ -201,38 +200,38 @@ test('type', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-type"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-type"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -5),
+ lua.lua_tojsstring(L, -5),
"number",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -4),
+ lua.lua_tojsstring(L, -4),
"boolean",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -3),
+ lua.lua_tojsstring(L, -3),
"string",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"table",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"nil",
"Correct element(s) on the stack"
);
@@ -254,9 +253,9 @@ test('error', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-error"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-error"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
});
@@ -277,14 +276,14 @@ test('error, protected', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-error"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-error"), lua.to_luastring("binary"));
- lapi.lua_pcall(L, 0, -1, 0);
+ lua.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tojsstring(L, -1).endsWith("you fucked up"),
+ lua.lua_tojsstring(L, -1).endsWith("you fucked up"),
"Error is on the stack"
);
});
@@ -309,14 +308,14 @@ test('pcall', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-pcall"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-pcall"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tojsstring(L, -1).endsWith("you fucked up"),
+ lua.lua_tojsstring(L, -1).endsWith("you fucked up"),
"Error is on the stack"
);
});
@@ -345,21 +344,21 @@ test('xpcall', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-pcall"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-pcall"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
- console.log(lapi.lua_tojsstring(L, -1));
+ console.log(lua.lua_tojsstring(L, -1));
t.ok(
- lapi.lua_tojsstring(L, -1).startsWith("Something's wrong:"),
+ lua.lua_tojsstring(L, -1).startsWith("Something's wrong:"),
"msgh was called and modified the error"
);
t.ok(
- lapi.lua_tojsstring(L, -1).endsWith("you fucked up"),
+ lua.lua_tojsstring(L, -1).endsWith("you fucked up"),
"msgh was called and modified the error"
);
});
@@ -387,14 +386,14 @@ test('ipairs', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-ipairs"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-ipairs"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
15,
"Correct element(s) on the stack"
);
@@ -416,26 +415,26 @@ test('select', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-select"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-select"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.deepEqual(
- [...lapi.lua_topointer(L, -3).entries()].map(e => e[1].value),
+ [...lua.lua_topointer(L, -3).entries()].map(e => e[1].value),
[3],
"Correct element(s) on the stack"
);
t.deepEqual(
- [...lapi.lua_topointer(L, -2).entries()].map(e => e[1].value).sort(),
+ [...lua.lua_topointer(L, -2).entries()].map(e => e[1].value).sort(),
[2, 3],
"Correct element(s) on the stack"
);
t.deepEqual(
- [...lapi.lua_topointer(L, -1).entries()].map(e => e[1].value).sort(),
+ [...lua.lua_topointer(L, -1).entries()].map(e => e[1].value).sort(),
[2, 3],
"Correct element(s) on the stack"
);
@@ -457,32 +456,32 @@ test('tonumber', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-tonumber"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-tonumber"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -4),
+ lua.lua_tonumber(L, -4),
123,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -3),
+ lua.lua_tonumber(L, -3),
12.3,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -2),
+ lua.lua_tonumber(L, -2),
395,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
2,
"Correct element(s) on the stack"
);
@@ -504,14 +503,14 @@ test('assert', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-assert"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-assert"), lua.to_luastring("binary"));
- lapi.lua_pcall(L, 0, -1, 0);
+ lua.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tojsstring(L, -1).endsWith("this doesn't makes sense"),
+ lua.lua_tojsstring(L, -1).endsWith("this doesn't makes sense"),
"Error is on the stack"
);
});
@@ -532,20 +531,20 @@ test('rawlen', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-rawlen"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-rawlen"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -2),
+ lua.lua_tonumber(L, -2),
3,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
5,
"Correct element(s) on the stack"
);
@@ -579,14 +578,14 @@ test('next', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-next"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-next"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
10,
"Correct element(s) on the stack"
);
@@ -620,14 +619,14 @@ test('pairs', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-pairs"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-pairs"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
10,
"Correct element(s) on the stack"
);
@@ -670,14 +669,14 @@ test('pairs with __pairs', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-pairs"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-pairs"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
26,
"Correct element(s) on the stack"
);
diff --git a/tests/lcorolib.js b/tests/lcorolib.js
index 3a778d4..29f9b34 100644
--- a/tests/lcorolib.js
+++ b/tests/lcorolib.js
@@ -9,7 +9,6 @@ const toByteCode = tests.toByteCode;
const VM = require("../src/lvm.js");
const ldo = require("../src/ldo.js");
-const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const lua = require('../src/lua.js');
const linit = require('../src/linit.js');
@@ -39,14 +38,14 @@ test('coroutine.create, coroutine.yield, coroutine.resume', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-coroutine"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-coroutine"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
625,
"Correct element(s) on the stack"
);
@@ -82,20 +81,20 @@ test('coroutine.status', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-coroutine.status"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-coroutine.status"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"suspended",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"dead",
"Correct element(s) on the stack"
);
@@ -123,19 +122,19 @@ test('coroutine.isyieldable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-coroutine.isyieldable"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-coroutine.isyieldable"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_toboolean(L, -2),
+ lua.lua_toboolean(L, -2),
"Correct element(s) on the stack"
);
t.notOk(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
"Correct element(s) on the stack"
);
});
@@ -164,19 +163,19 @@ test('coroutine.running', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-coroutine.running"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-coroutine.running"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tothread(L, -2) instanceof lstate.lua_State,
+ lua.lua_tothread(L, -2) instanceof lstate.lua_State,
"Correct element(s) on the stack"
);
t.notOk(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
"Correct element(s) on the stack"
);
});
@@ -205,14 +204,14 @@ test('coroutine.wrap', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-coroutine.wrap"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-coroutine.wrap"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
625,
"Correct element(s) on the stack"
);
diff --git a/tests/ldblib.js b/tests/ldblib.js
index 8913642..06ad4b3 100644
--- a/tests/ldblib.js
+++ b/tests/ldblib.js
@@ -2,7 +2,6 @@
const test = require('tape');
-const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const lua = require('../src/lua.js');
const linit = require('../src/linit.js');
@@ -38,12 +37,12 @@ test('debug.sethook', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"return count line count line count line count return count line count line count return count line count line count return count line ",
"Correct element(s) on the stack"
);
@@ -82,24 +81,24 @@ test('debug.gethook', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.deepEqual(
- lapi.lua_typename(L, lapi.lua_type(L, -3)),
+ lua.lua_typename(L, lua.lua_type(L, -3)),
lua.to_luastring("function"),
"Correct element(s) on the stack"
);
t.deepEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"crl",
"Correct element(s) on the stack"
);
t.deepEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
1,
"Correct element(s) on the stack"
);
@@ -142,12 +141,12 @@ test('debug.getlocal', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"alocal alocalanother anotherinfunction infunctionanotherin anotherin",
"Correct element(s) on the stack"
);
@@ -190,30 +189,30 @@ test('debug.setlocal', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tointeger(L, -4),
+ lua.lua_tointeger(L, -4),
1,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -3),
+ lua.lua_tointeger(L, -3),
2,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -2),
+ lua.lua_tointeger(L, -2),
3,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
4,
"Correct element(s) on the stack"
);
@@ -245,12 +244,12 @@ test('debug.upvalueid', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.ok(
- lapi.lua_touserdata(L, -1),
+ lua.lua_touserdata(L, -1),
"Correct element(s) on the stack"
);
@@ -289,12 +288,12 @@ test('debug.upvaluejoin', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"upvalue2",
"Correct element(s) on the stack"
);
@@ -335,12 +334,12 @@ test('debug.traceback (with a global)', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
`stack traceback:
\t...[string "traceback-test"]9: in function 'rec'
\t...[string "traceback-test"]7: in function 'rec'
@@ -394,12 +393,12 @@ test('debug.traceback (with a upvalue)', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
`stack traceback:
\t...[string "traceback-test"]10: in upvalue 'rec'
\t...[string "traceback-test"]8: in upvalue 'rec'
@@ -448,54 +447,54 @@ test('debug.getinfo', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -8),
+ lua.lua_tojsstring(L, -8),
`[string "getinfo-test"]`,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -7),
+ lua.lua_tointeger(L, -7),
0,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -6),
+ lua.lua_tojsstring(L, -6),
`Lua`,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -5),
+ lua.lua_tointeger(L, -5),
2,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -4),
+ lua.lua_tojsstring(L, -4),
`[string "getinfo-test"]`,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -3),
+ lua.lua_tointeger(L, -3),
1,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
`Lua`,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
0,
"Correct element(s) on the stack"
);
diff --git a/tests/ldebug.js b/tests/ldebug.js
index 0256465..751c9c2 100644
--- a/tests/ldebug.js
+++ b/tests/ldebug.js
@@ -9,7 +9,6 @@ const toByteCode = tests.toByteCode;
const lvm = require("../src/lvm.js");
const ldo = require("../src/ldo.js");
-const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const lua = require('../src/lua.js');
const linit = require('../src/linit.js');
@@ -30,15 +29,15 @@ test('luaG_typeerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
- lapi.lua_pcall(L, 0, -1, 0);
+ lua.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tojsstring(L, -1).endsWith("attempt to get length of a boolean value (local 'a')"),
+ lua.lua_tojsstring(L, -1).endsWith("attempt to get length of a boolean value (local 'a')"),
"Correct error was thrown"
);
});
@@ -49,7 +48,7 @@ test('luaG_typeerror', function (t) {
local a = true
return a.yo
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -60,14 +59,14 @@ test('luaG_typeerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
- lapi.lua_pcall(L, 0, -1, 0);
+ lua.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tojsstring(L, -1).endsWith("attempt to index a boolean value (local 'a')"),
+ lua.lua_tojsstring(L, -1).endsWith("attempt to index a boolean value (local 'a')"),
"Correct error was thrown"
);
});
@@ -89,14 +88,14 @@ test('luaG_typeerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
- lapi.lua_pcall(L, 0, -1, 0);
+ lua.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tojsstring(L, -1).endsWith("attempt to index a boolean value (local 'a')"),
+ lua.lua_tojsstring(L, -1).endsWith("attempt to index a boolean value (local 'a')"),
"Correct error was thrown"
);
});
@@ -107,7 +106,7 @@ test('luaG_typeerror', function (t) {
local a = true
a.yo = 1
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -118,14 +117,14 @@ test('luaG_typeerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
- lapi.lua_pcall(L, 0, -1, 0);
+ lua.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tojsstring(L, -1).endsWith("attempt to index a boolean value (local 'a')"),
+ lua.lua_tojsstring(L, -1).endsWith("attempt to index a boolean value (local 'a')"),
"Correct error was thrown"
);
});
@@ -135,7 +134,7 @@ test('luaG_concaterror', function (t) {
let luaCode = `
return {} .. 'hello'
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -146,14 +145,14 @@ test('luaG_concaterror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
- lapi.lua_pcall(L, 0, -1, 0);
+ lua.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tojsstring(L, -1).endsWith("attempt to concatenate a table value"),
+ lua.lua_tojsstring(L, -1).endsWith("attempt to concatenate a table value"),
"Correct error was thrown"
);
});
@@ -174,14 +173,14 @@ test('luaG_opinterror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
- lapi.lua_pcall(L, 0, -1, 0);
+ lua.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tojsstring(L, -1).endsWith("attempt to perform arithmetic on a string value"),
+ lua.lua_tojsstring(L, -1).endsWith("attempt to perform arithmetic on a string value"),
"Correct error was thrown"
);
});
@@ -202,14 +201,14 @@ test('luaG_tointerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary"));
- lapi.lua_pcall(L, 0, -1, 0);
+ lua.lua_pcall(L, 0, -1, 0);
}, "JS Lua program ran without error");
t.ok(
- lapi.lua_tojsstring(L, -1).endsWith("number has no integer representation"),
+ lua.lua_tojsstring(L, -1).endsWith("number has no integer representation"),
"Correct error was thrown"
);
});
diff --git a/tests/lexparse.js b/tests/lexparse.js
index 68b6667..ddb2dbf 100644
--- a/tests/lexparse.js
+++ b/tests/lexparse.js
@@ -32,19 +32,19 @@ test('LOADK, RETURN', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -72,19 +72,19 @@ test('MOVE', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -112,14 +112,14 @@ test('Binary op', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
@@ -152,14 +152,14 @@ test('Unary op, LOADBOOL', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
@@ -190,14 +190,14 @@ test('NEWTABLE', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
@@ -232,19 +232,19 @@ test('CALL', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
3,
"Program output is correct"
);
@@ -278,14 +278,14 @@ test('Multiple return', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
@@ -319,19 +319,19 @@ test('TAILCALL', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
3,
"Program output is correct"
);
@@ -360,14 +360,14 @@ test('VARARG', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
@@ -399,19 +399,19 @@ test('LE, JMP', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
true,
"Program output is correct"
);
@@ -438,19 +438,19 @@ test('LT', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
false,
"Program output is correct"
);
@@ -477,19 +477,19 @@ test('EQ', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
true,
"Program output is correct"
);
@@ -517,19 +517,19 @@ test('TESTSET (and)', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -557,19 +557,19 @@ test('TESTSET (or)', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -601,19 +601,19 @@ test('TEST (false)', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"goodbye",
"Program output is correct"
);
@@ -644,19 +644,19 @@ test('FORPREP, FORLOOP (int)', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
55,
"Program output is correct"
);
@@ -687,19 +687,19 @@ test('FORPREP, FORLOOP (float)', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
60.5,
"Program output is correct"
);
@@ -729,25 +729,25 @@ test('SETTABLE, GETTABLE', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_topointer(L, -1).get(1).jsstring(),
+ lua.lua_topointer(L, -1).get(1).jsstring(),
"hello",
"Program output is correct"
);
t.strictEqual(
- lapi.lua_topointer(L, -1).get('116|119|111|').jsstring(),
+ lua.lua_topointer(L, -1).get('116|119|111|').jsstring(),
"world",
"Program output is correct"
);
@@ -780,19 +780,19 @@ test('SETUPVAL, GETUPVAL', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"world",
"Program output is correct"
);
@@ -822,25 +822,25 @@ test('SETTABUP, GETTABUP', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_topointer(L, -1).get(1).jsstring(),
+ lua.lua_topointer(L, -1).get(1).jsstring(),
"hello",
"Program output is correct"
);
t.strictEqual(
- lapi.lua_topointer(L, -1).get('116|119|111|').jsstring(),
+ lua.lua_topointer(L, -1).get('116|119|111|').jsstring(),
"world",
"Program output is correct"
);
@@ -872,19 +872,19 @@ test('SELF', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -911,19 +911,19 @@ test('SETLIST', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.deepEqual(
- [...lapi.lua_topointer(L, -1).entries()].map(e => e[1].value).sort(),
+ [...lua.lua_topointer(L, -1).entries()].map(e => e[1].value).sort(),
[1, 2, 3, 4, 5, 6, 7, 8, 9],
"Program output is correct"
);
@@ -954,19 +954,19 @@ test('Variable SETLIST', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.deepEqual(
- [...lapi.lua_topointer(L, -1).entries()].map(e => e[1].value).sort(),
+ [...lua.lua_topointer(L, -1).entries()].map(e => e[1].value).sort(),
[1, 2, 3, 4, 5, 6, 7, 8, 9],
"Program output is correct"
);
@@ -992,19 +992,19 @@ test('Long SETLIST', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.deepEqual(
- [...lapi.lua_topointer(L, -1).entries()].map(e => e[1].value).reverse(),
+ [...lua.lua_topointer(L, -1).entries()].map(e => e[1].value).reverse(),
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],
"Program output is correct"
);
@@ -1047,19 +1047,19 @@ test('TFORCALL, TFORLOOP', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
6,
"Program output is correct"
);
@@ -1088,31 +1088,31 @@ test('LEN', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
5,
"Program output is correct"
);
t.strictEqual(
- lapi.lua_tonumber(L, -2),
+ lua.lua_tonumber(L, -2),
3,
"Program output is correct"
);
t.strictEqual(
- lapi.lua_tonumber(L, -3),
+ lua.lua_tonumber(L, -3),
0,
"Program output is correct"
);
@@ -1137,19 +1137,19 @@ test('CONCAT', function (t) {
luaCode = null;
return code ? lua.to_luastring(code) : null;
};
-
- lapi.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
+
+ lua.lua_load(L, reader, luaCode, lua.to_luastring("test"), lua.to_luastring("text"));
}, "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");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello 2 you",
"Program output is correct"
);
diff --git a/tests/lmathlib.js b/tests/lmathlib.js
index 30c33d8..d39e762 100644
--- a/tests/lmathlib.js
+++ b/tests/lmathlib.js
@@ -9,7 +9,6 @@ const toByteCode = tests.toByteCode;
const VM = require("../src/lvm.js");
const ldo = require("../src/ldo.js");
-const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const lua = require('../src/lua.js');
const linit = require('../src/linit.js');
@@ -32,50 +31,50 @@ test('math.abs, math.sin, math.cos, math.tan, math.asin, math.acos, math.atan',
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tointeger(L, -7),
+ lua.lua_tointeger(L, -7),
10,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -6),
+ lua.lua_tonumber(L, -6),
10.5,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -5),
+ lua.lua_tonumber(L, -5),
-0.8390715290764524,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -4),
+ lua.lua_tonumber(L, -4),
0.6483608274590866,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -3),
+ lua.lua_tonumber(L, -3),
1.5707963267948966,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -2),
+ lua.lua_tonumber(L, -2),
1.0471975511965979,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
1.4711276743037347,
"Correct element(s) on the stack"
);
@@ -97,20 +96,20 @@ test('math.ceil, math.floor', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tointeger(L, -2),
+ lua.lua_tointeger(L, -2),
11,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
10,
"Correct element(s) on the stack"
);
@@ -133,20 +132,20 @@ test('math.deg, math.rad', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -2),
+ lua.lua_tonumber(L, -2),
572.9577951308232,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
0.17453292519943295,
"Correct element(s) on the stack"
);
@@ -169,26 +168,26 @@ test('math.log', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -3),
+ lua.lua_tonumber(L, -3),
2.302585092994046,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -2),
+ lua.lua_tonumber(L, -2),
3.321928094887362,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
1,
"Correct element(s) on the stack"
);
@@ -211,14 +210,14 @@ test('math.exp', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
22026.465794806718,
"Correct element(s) on the stack"
);
@@ -241,20 +240,20 @@ test('math.min, math.max', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -2),
+ lua.lua_tonumber(L, -2),
23,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
5,
"Correct element(s) on the stack"
);
@@ -277,19 +276,19 @@ test('math.random', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.ok(
- 0 <= lapi.lua_tonumber(L, -2) <= 1,
+ 0 <= lua.lua_tonumber(L, -2) <= 1,
"Correct element(s) on the stack"
);
t.ok(
- 10 <= lapi.lua_tonumber(L, -1) <= 15,
+ 10 <= lua.lua_tonumber(L, -1) <= 15,
"Correct element(s) on the stack"
);
@@ -311,14 +310,14 @@ test('math.sqrt', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
3.1622776601683795,
"Correct element(s) on the stack"
);
@@ -341,14 +340,14 @@ test('math.tointeger', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
10,
"Correct element(s) on the stack"
);
@@ -371,26 +370,26 @@ test('math.type', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -3),
+ lua.lua_tojsstring(L, -3),
"integer",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"float",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
null,
"Correct element(s) on the stack"
);
@@ -413,14 +412,14 @@ test('math.ult', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
true,
"Correct element(s) on the stack"
);
@@ -443,14 +442,14 @@ test('math.fmod', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
2,
"Correct element(s) on the stack"
);
@@ -473,20 +472,20 @@ test('math.modf', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tonumber(L, -2),
+ lua.lua_tonumber(L, -2),
3,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
0.3999999999999999,
"Correct element(s) on the stack"
);
diff --git a/tests/load.js b/tests/load.js
index 913fb01..2b346aa 100644
--- a/tests/load.js
+++ b/tests/load.js
@@ -7,7 +7,6 @@ const toByteCode = tests.toByteCode;
const VM = require("../src/lvm.js");
const ldo = require("../src/ldo.js");
-const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const lua = require('../src/lua.js');
const linit = require('../src/linit.js');
@@ -33,12 +32,12 @@ test('luaL_loadstring', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -66,12 +65,12 @@ test('load', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"js running lua running lua",
"Correct element(s) on the stack"
);
@@ -101,12 +100,12 @@ test('luaL_loadbuffer', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -134,12 +133,12 @@ test('loadfile', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -167,12 +166,12 @@ test('loadfile (binary)', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
@@ -199,12 +198,12 @@ test('dofile', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello world",
"Correct element(s) on the stack"
);
diff --git a/tests/loslib.js b/tests/loslib.js
index 1bb217f..00ee019 100644
--- a/tests/loslib.js
+++ b/tests/loslib.js
@@ -2,7 +2,6 @@
const test = require('tape');
-const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const lua = require('../src/lua.js');
const linit = require('../src/linit.js');
@@ -26,12 +25,12 @@ test('os.time', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.ok(
- lapi.lua_isinteger(L, -1),
+ lua.lua_isinteger(L, -1),
"Correct element(s) on the stack"
);
diff --git a/tests/lstrlib.js b/tests/lstrlib.js
index 0fa9115..f4c7ba4 100644
--- a/tests/lstrlib.js
+++ b/tests/lstrlib.js
@@ -7,7 +7,6 @@ const tests = require("./tests.js");
const toByteCode = tests.toByteCode;
const lua = require("../src/lua.js");
-const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const linit = require('../src/linit.js');
@@ -32,18 +31,18 @@ test('string.len', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tointeger(L, -2),
+ lua.lua_tointeger(L, -2),
5,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
5,
"Correct element(s) on the stack"
);
@@ -70,12 +69,12 @@ test('string.char', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Correct element(s) on the stack"
);
@@ -101,18 +100,18 @@ test('string.upper, string.lower', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"HELLO",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Correct element(s) on the stack"
);
@@ -138,12 +137,12 @@ test('string.rep', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello, hello, hello",
"Correct element(s) on the stack"
);
@@ -169,12 +168,12 @@ test('string.reverse', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Correct element(s) on the stack"
);
@@ -200,24 +199,24 @@ test('string.byte', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tointeger(L, -3),
+ lua.lua_tointeger(L, -3),
101,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -2),
+ lua.lua_tointeger(L, -2),
108,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
108,
"Correct element(s) on the stack"
);
@@ -243,12 +242,12 @@ test('string.format', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"%10 0000000023",
"Correct element(s) on the stack"
);
@@ -274,12 +273,12 @@ test('string.format', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"FFFFFFF",
"Correct element(s) on the stack"
);
@@ -305,12 +304,12 @@ test('string.format', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
'"a string with \\"quotes\\" and \\\n new line"',
"Correct element(s) on the stack"
);
@@ -346,72 +345,72 @@ test('string.sub', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -11),
+ lua.lua_tojsstring(L, -11),
"234",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -10),
+ lua.lua_tojsstring(L, -10),
"789",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -9),
+ lua.lua_tojsstring(L, -9),
"",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -8),
+ lua.lua_tojsstring(L, -8),
"7",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -7),
+ lua.lua_tojsstring(L, -7),
"",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -6),
+ lua.lua_tojsstring(L, -6),
"123456789",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -5),
+ lua.lua_tojsstring(L, -5),
"123456789",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -4),
+ lua.lua_tojsstring(L, -4),
"",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -3),
+ lua.lua_tojsstring(L, -3),
"9",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"6789",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"456",
"Correct element(s) on the stack"
);
@@ -445,18 +444,18 @@ test('string.dump', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
- let dv = lapi.lua_todataview(L, -1);
+ let dv = lua.lua_todataview(L, -1);
- lapi.lua_load(L, null, dv, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, dv, lua.to_luastring("test"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello1212.5",
"Correct element(s) on the stack"
);
@@ -485,18 +484,18 @@ test('string.pack/unpack/packsize', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tointeger(L, -2),
+ lua.lua_tointeger(L, -2),
16,
"Correct element(s) on the stack"
);
t.ok(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
"Correct element(s) on the stack"
);
});
@@ -521,18 +520,18 @@ test('string.find without pattern', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tointeger(L, -2),
+ lua.lua_tointeger(L, -2),
6,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
9,
"Correct element(s) on the stack"
);
@@ -558,18 +557,18 @@ test('string.match', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"foo",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"123",
"Correct element(s) on the stack"
);
@@ -595,30 +594,30 @@ test('string.find', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tointeger(L, -4),
+ lua.lua_tointeger(L, -4),
1,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -3),
+ lua.lua_tointeger(L, -3),
8,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"foo",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"123",
"Correct element(s) on the stack"
);
@@ -651,30 +650,30 @@ test('string.gmatch', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -4),
+ lua.lua_tojsstring(L, -4),
"hello",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -3),
+ lua.lua_tojsstring(L, -3),
"world",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"from",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"Lua",
"Correct element(s) on the stack"
);
@@ -700,18 +699,18 @@ test('string.gsub', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"hello hello world world",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
2,
"Correct element(s) on the stack"
);
@@ -737,18 +736,18 @@ test('string.gsub (number)', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"hello hello world",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
1,
"Correct element(s) on the stack"
);
@@ -774,18 +773,18 @@ test('string.gsub (pattern)', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"world hello Lua from",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
2,
"Correct element(s) on the stack"
);
@@ -813,18 +812,18 @@ test('string.gsub (function)', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"4+5 = 9",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
1,
"Correct element(s) on the stack"
);
@@ -852,18 +851,18 @@ test('string.gsub (table)', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"lua-5.3.tar.gz",
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
2,
"Correct element(s) on the stack"
);
diff --git a/tests/ltablib.js b/tests/ltablib.js
index f7de2bf..946742b 100644
--- a/tests/ltablib.js
+++ b/tests/ltablib.js
@@ -9,7 +9,6 @@ const toByteCode = tests.toByteCode;
const VM = require("../src/lvm.js");
const ldo = require("../src/ldo.js");
-const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const lua = require('../src/lua.js');
const linit = require('../src/linit.js');
@@ -41,14 +40,14 @@ test('table.concat', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-table.concat"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-table.concat"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"3,4,5",
"Correct element(s) on the stack"
);
@@ -70,14 +69,14 @@ test('table.pack', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-table.pack"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-table.pack"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.deepEqual(
- [...lapi.lua_topointer(L, -1).entries()]
+ [...lua.lua_topointer(L, -1).entries()]
.filter(e => typeof e[0] === 'number') // Filter out the 'n' field
.map(e => e[1].value).reverse(),
[1, 2, 3],
@@ -101,26 +100,26 @@ test('table.unpack', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-table.unpack"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-table.unpack"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_tointeger(L, -3),
+ lua.lua_tointeger(L, -3),
2,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -2),
+ lua.lua_tointeger(L, -2),
3,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
4,
"Correct element(s) on the stack"
);
@@ -145,14 +144,14 @@ test('table.insert', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-table.insert"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-table.insert"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.deepEqual(
- [...lapi.lua_topointer(L, -1).entries()]
+ [...lua.lua_topointer(L, -1).entries()]
.filter(e => typeof e[0] === 'number')
.map(e => e[1].value).sort(),
[1, 2, 3, 4, 5],
@@ -179,14 +178,14 @@ test('table.remove', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-table.remove"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-table.remove"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.deepEqual(
- [...lapi.lua_topointer(L, -1).entries()]
+ [...lua.lua_topointer(L, -1).entries()]
.filter(e => typeof e[0] === 'number')
.map(e => e[1].value).sort(),
[1, 2, 3, 4, null, null],
@@ -212,14 +211,14 @@ test('table.move', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-table.move"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-table.move"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.deepEqual(
- [...lapi.lua_topointer(L, -1).entries()]
+ [...lua.lua_topointer(L, -1).entries()]
.filter(e => typeof e[0] === 'number')
.map(e => e[1].value).sort(),
[1, 2, 3, 4, 5, 6],
@@ -245,14 +244,14 @@ test('table.sort (<)', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-table.sort"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-table.sort"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.deepEqual(
- inttable2array(lapi.lua_topointer(L, -1)),
+ inttable2array(lua.lua_topointer(L, -1)),
[1, 2, 3, 4, 5],
"Correct element(s) on the stack"
);
@@ -278,14 +277,14 @@ test('table.sort with cmp function', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test-table.sort"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test-table.sort"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
t.deepEqual(
- inttable2array(lapi.lua_topointer(L, -1)),
+ inttable2array(lua.lua_topointer(L, -1)),
[5, 4, 3, 2, 1],
"Correct element(s) on the stack"
);
diff --git a/tests/ltm.js b/tests/ltm.js
index 92be806..64f52aa 100644
--- a/tests/ltm.js
+++ b/tests/ltm.js
@@ -5,7 +5,6 @@ const beautify = require('js-beautify').js_beautify;
const lua = require("../src/lua.js");
const VM = require("../src/lvm.js");
-const lapi = require("../src/lapi.js");
const linit = require("../src/linit.js");
const lauxlib = require("../src/lauxlib.js");
const OC = require('../src/lopcodes.js');
@@ -32,17 +31,17 @@ test('__index, __newindex: with actual table', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
- lapi.lua_call(L, 0, -1);
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.ok(
- lapi.lua_isnil(L, -1),
+ lua.lua_isnil(L, -1),
"Program output is correct"
);
t.strictEqual(
- lapi.lua_tointeger(L, -2),
+ lua.lua_tointeger(L, -2),
1,
"Program output is correct"
);
@@ -66,11 +65,11 @@ test('__newindex: with non table', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.throws(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed with expected error");
});
@@ -101,16 +100,16 @@ test('__index function in metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"__index",
"Program output is correct"
);
@@ -145,15 +144,15 @@ test('__newindex function in metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.ok(
- lapi.lua_isnil(L, -1),
+ lua.lua_isnil(L, -1),
"Program output is correct"
);
});
@@ -187,15 +186,15 @@ test('__index table in metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -232,21 +231,21 @@ test('__newindex table in metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"world",
"Program output is correct"
);
t.ok(
- lapi.lua_isnil(L, -2),
+ lua.lua_isnil(L, -2),
"Program output is correct"
);
});
@@ -288,15 +287,15 @@ test('__index table with own metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -343,21 +342,21 @@ test('__newindex table with own metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
t.ok(
- lapi.lua_isnil(L, -2),
+ lua.lua_isnil(L, -2),
"Program output is correct"
);
});
@@ -446,11 +445,11 @@ test('binary __xxx functions in metatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -500,15 +499,15 @@ test('__eq', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.ok(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
"Program output is correct"
);
});
@@ -540,15 +539,15 @@ test('__lt', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.ok(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
"Program output is correct"
);
});
@@ -580,15 +579,15 @@ test('__le', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.ok(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
"Program output is correct"
);
});
@@ -620,15 +619,15 @@ test('__le that uses __lt', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.ok(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
"Program output is correct"
);
});
@@ -664,21 +663,21 @@ test('__unm, __bnot', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"world",
"Program output is correct"
);
t.strictEqual(
- lapi.lua_tojsstring(L, -2),
+ lua.lua_tojsstring(L, -2),
"hello",
"Program output is correct"
);
@@ -711,15 +710,15 @@ test('__len', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -752,15 +751,15 @@ test('__concat', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -793,11 +792,11 @@ test('__call', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary"));
}, "Bytecode parsed without errors");
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
diff --git a/tests/lutf8lib.js b/tests/lutf8lib.js
index e32409b..4df498c 100644
--- a/tests/lutf8lib.js
+++ b/tests/lutf8lib.js
@@ -4,7 +4,6 @@ const test = require('tape');
const tests = require("./tests.js");
const lua = require("../src/lua.js");
-const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const linit = require('../src/linit.js');
@@ -27,12 +26,12 @@ test('utf8.offset', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
7,
"Correct element(s) on the stack"
);
@@ -59,24 +58,24 @@ test('utf8.codepoint', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tointeger(L, -3),
+ lua.lua_tointeger(L, -3),
176,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -2),
+ lua.lua_tointeger(L, -2),
32,
"Correct element(s) on the stack"
);
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
860,
"Correct element(s) on the stack"
);
@@ -103,12 +102,12 @@ test('utf8.char', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"( ͡° ͜ʖ ͡° )",
"Correct element(s) on the stack"
);
@@ -135,12 +134,12 @@ test('utf8.len', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
12,
"Correct element(s) on the stack"
);
@@ -172,12 +171,12 @@ test('utf8.codes', function (t) {
t.doesNotThrow(function () {
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Lua program ran without error");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"[1,40] [2,32] [3,865] [5,176] [7,32] [8,860] [10,662] [12,32] [13,865] [15,176] [17,32] [18,41] ",
"Correct element(s) on the stack"
);
diff --git a/tests/lvm.js b/tests/lvm.js
index fe463eb..52736fe 100644
--- a/tests/lvm.js
+++ b/tests/lvm.js
@@ -5,7 +5,7 @@ const beautify = require('js-beautify').js_beautify;
const lua_State = require("../src/lstate.js").lua_State;
const VM = require("../src/lvm.js");
-const lapi = require("../src/lapi.js");
+const lua = require("../src/lua.js");
const getState = require("./tests.js").getState;
@@ -21,11 +21,11 @@ test('LOADK, RETURN', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello world",
"Program output is correct"
);
@@ -45,11 +45,11 @@ test('MOVE', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello world",
"Program output is correct"
);
@@ -68,7 +68,7 @@ test('Binary op', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -92,7 +92,7 @@ test('Unary op, LOADBOOL', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -115,7 +115,7 @@ test('NEWTABLE', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.ok(
@@ -142,11 +142,11 @@ test('CALL', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
3,
"Program output is correct"
);
@@ -174,7 +174,7 @@ test('Multiple return', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -200,11 +200,11 @@ test('TAILCALL', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
3,
"Program output is correct"
);
@@ -226,7 +226,7 @@ test('VARARG', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -250,11 +250,11 @@ test('LE, JMP', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
true,
"Program output is correct"
);
@@ -274,11 +274,11 @@ test('LT', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
false,
"Program output is correct"
);
@@ -298,11 +298,11 @@ test('EQ', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_toboolean(L, -1),
+ lua.lua_toboolean(L, -1),
true,
"Program output is correct"
);
@@ -323,11 +323,11 @@ test('TESTSET (and)', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -348,11 +348,11 @@ test('TESTSET (or)', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -377,11 +377,11 @@ test('TEST (true)', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -406,11 +406,11 @@ test('TEST (false)', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"goodbye",
"Program output is correct"
);
@@ -434,11 +434,11 @@ test('FORPREP, FORLOOP (int)', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
55,
"Program output is correct"
);
@@ -462,11 +462,11 @@ test('FORPREP, FORLOOP (float)', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tonumber(L, -1),
+ lua.lua_tonumber(L, -1),
60.5,
"Program output is correct"
);
@@ -489,7 +489,7 @@ test('SETTABLE, GETTABLE', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
console.log(L.stack[L.top - 1]);
@@ -527,11 +527,11 @@ test('SETUPVAL, GETUPVAL', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"world",
"Program output is correct"
);
@@ -554,7 +554,7 @@ test('SETTABUP, GETTABUP', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -589,11 +589,11 @@ test('SELF', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello",
"Program output is correct"
);
@@ -613,7 +613,7 @@ test('SETLIST', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -641,7 +641,7 @@ test('Variable SETLIST', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -665,7 +665,7 @@ test('Long SETLIST', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -689,7 +689,7 @@ test('Long SETLIST', function (t) {
//
// // t.doesNotThrow(function () {
// L = getState(luaCode);
-// lapi.lua_call(L, 0, -1);
+// lua.lua_call(L, 0, -1);
// // }, "Program executed without errors");
//
// t.deepEqual(
@@ -729,11 +729,11 @@ test('TFORCALL, TFORLOOP', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
6,
"Program output is correct"
);
@@ -755,23 +755,23 @@ test('LEN', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tointeger(L, -1),
+ lua.lua_tointeger(L, -1),
5,
"Program output is correct"
);
t.strictEqual(
- lapi.lua_tointeger(L, -2),
+ lua.lua_tointeger(L, -2),
3,
"Program output is correct"
);
t.strictEqual(
- lapi.lua_tointeger(L, -3),
+ lua.lua_tointeger(L, -3),
0,
"Program output is correct"
);
@@ -789,11 +789,11 @@ test('CONCAT', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- lapi.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
- lapi.lua_tojsstring(L, -1),
+ lua.lua_tojsstring(L, -1),
"hello 2 you",
"Program output is correct"
);
diff --git a/tests/manual-tests/debug-cli.js b/tests/manual-tests/debug-cli.js
index 18dee7f..e6e5198 100644
--- a/tests/manual-tests/debug-cli.js
+++ b/tests/manual-tests/debug-cli.js
@@ -1,6 +1,5 @@
"use strict";
-const lapi = require("../../src/lapi.js");
const lauxlib = require("../../src/lauxlib.js");
const lua = require('../../src/lua.js');
const linit = require('../../src/linit.js');
@@ -16,4 +15,4 @@ linit.luaL_openlibs(L);
lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
-lapi.lua_call(L, 0, -1);
+lua.lua_call(L, 0, -1);
diff --git a/tests/manual-tests/lua-cli.js b/tests/manual-tests/lua-cli.js
index 008f39a..468395f 100755
--- a/tests/manual-tests/lua-cli.js
+++ b/tests/manual-tests/lua-cli.js
@@ -2,7 +2,6 @@
"use strict";
const lua = require('../../src/lua.js');
-const lapi = require('../../src/lapi.js');
const lauxlib = require('../../src/lauxlib.js');
const linit = require('../../src/linit.js');
const fs = require('fs');
@@ -14,14 +13,14 @@ const _PROMPT2 = lua.to_luastring("_PROMPT2");
const report = function(L, status) {
if (status !== lua.LUA_OK) {
- lauxlib.lua_writestringerror(`${lapi.lua_tojsstring(L, -1)}\n`);
- lapi.lua_pop(L, 1);
+ lauxlib.lua_writestringerror(`${lua.lua_tojsstring(L, -1)}\n`);
+ lua.lua_pop(L, 1);
}
return status;
};
const docall = function(L, narg, nres) {
- let status = lapi.lua_pcall(L, narg, nres, 0);
+ let status = lua.lua_pcall(L, narg, nres, 0);
return status;
};
@@ -42,11 +41,11 @@ const dostring = function(L, s, name) {
};
const dolibrary = function(L, name) {
- lapi.lua_getglobal(L, lua.to_luastring("require"));
- lapi.lua_pushliteral(L, name);
+ lua.lua_getglobal(L, lua.to_luastring("require"));
+ lua.lua_pushliteral(L, name);
let status = docall(L, 1, 1); /* call 'require(name)' */
if (status === lua.LUA_OK)
- lapi.lua_setglobal(L, lua.to_luastring(name)); /* global[name] = require return */
+ lua.lua_setglobal(L, lua.to_luastring(name)); /* global[name] = require return */
return report(L, status);
};
@@ -137,20 +136,20 @@ if (has_v)
if (has_E) {
/* signal for libraries to ignore env. vars. */
- lapi.lua_pushboolean(L, 1);
- lapi.lua_setfield(L, lua.LUA_REGISTRYINDEX, lua.to_luastring("LUA_NOENV"));
+ lua.lua_pushboolean(L, 1);
+ lua.lua_setfield(L, lua.LUA_REGISTRYINDEX, lua.to_luastring("LUA_NOENV"));
}
/* open standard libraries */
linit.luaL_openlibs(L);
/* create table 'arg' */
-lapi.lua_createtable(L, process.argv.length - (script + 1), script + 1);
+lua.lua_createtable(L, process.argv.length - (script + 1), script + 1);
for (let i = 0; i < process.argv.length; i++) {
- lapi.lua_pushliteral(L, process.argv[i]);
- lapi.lua_seti(L, -2, i - script); /* TODO: rawseti */
+ lua.lua_pushliteral(L, process.argv[i]);
+ lua.lua_seti(L, -2, i - script); /* TODO: rawseti */
}
-lapi.lua_setglobal(L, lua.to_luastring("arg"));
+lua.lua_setglobal(L, lua.to_luastring("arg"));
if (!has_E) {
/* run LUA_INIT */
@@ -193,14 +192,14 @@ for (let i = 1; i < script; i++) {
}
const pushargs = function(L) {
- if (lapi.lua_getglobal(L, lua.to_luastring("arg")) !== lua.LUA_TTABLE)
+ if (lua.lua_getglobal(L, lua.to_luastring("arg")) !== lua.LUA_TTABLE)
lauxlib.luaL_error(L, lua.to_luastring("'arg' is not a table"));
let n = lauxlib.luaL_len(L, -1);
lauxlib.luaL_checkstack(L, n+3, lua.to_luastring("too many arguments to script"));
let i;
for (i=1; i<=n; i++)
- lapi.lua_rawgeti(L, -i, i);
- lapi.lua_remove(L, -i);
+ lua.lua_rawgeti(L, -i, i);
+ lua.lua_remove(L, -i);
return n;
};
@@ -221,11 +220,11 @@ const handle_script = function(L, argv) {
const doREPL = function(L) {
for (;;) {
- lapi.lua_getglobal(L, _PROMPT);
+ lua.lua_getglobal(L, _PROMPT);
let input = readlineSync.prompt({
- prompt: lapi.lua_tojsstring(L, -1) || '> '
+ prompt: lua.lua_tojsstring(L, -1) || '> '
});
- lapi.lua_pop(L, 1);
+ lua.lua_pop(L, 1);
if (input.length === 0)
continue;
@@ -236,20 +235,20 @@ const doREPL = function(L) {
status = lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin);
}
if (status !== lua.LUA_OK) {
- lapi.lua_pop(L, 1);
+ lua.lua_pop(L, 1);
let buffer = lua.to_luastring(input);
if (lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin) === lua.LUA_OK) {
status = lua.LUA_OK;
}
}
- while (status === lua.LUA_ERRSYNTAX && lapi.lua_tojsstring(L, -1).endsWith("<eof>")) {
+ while (status === lua.LUA_ERRSYNTAX && lua.lua_tojsstring(L, -1).endsWith("<eof>")) {
/* continuation */
- lapi.lua_pop(L, 1);
- lapi.lua_getglobal(L, _PROMPT2);
+ lua.lua_pop(L, 1);
+ lua.lua_getglobal(L, _PROMPT2);
input += "\n" + readlineSync.prompt({
- prompt: lapi.lua_tojsstring(L, -1) || '>> '
+ prompt: lua.lua_tojsstring(L, -1) || '>> '
});
- lapi.lua_pop(L, 1);
+ lua.lua_pop(L, 1);
let buffer = lua.to_luastring(input);
status = lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin);
}
@@ -257,18 +256,18 @@ const doREPL = function(L) {
status = docall(L, 0, lua.LUA_MULTRET);
}
if (status === lua.LUA_OK) {
- let n = lapi.lua_gettop(L);
+ let n = lua.lua_gettop(L);
if (n > 0) { /* any result to be printed? */
- lapi.lua_getglobal(L, lua.to_luastring("print"));
- lapi.lua_insert(L, 1);
- if (lapi.lua_pcall(L, n, 0, 0) != lua.LUA_OK) {
- lauxlib.lua_writestringerror(`error calling 'print' (${lapi.lua_tojsstring(L, -1)})\n`);
+ lua.lua_getglobal(L, lua.to_luastring("print"));
+ lua.lua_insert(L, 1);
+ if (lua.lua_pcall(L, n, 0, 0) != lua.LUA_OK) {
+ lauxlib.lua_writestringerror(`error calling 'print' (${lua.lua_tojsstring(L, -1)})\n`);
}
}
} else {
report(L, status);
}
- lapi.lua_settop(L, 0); /* remove eventual returns */
+ lua.lua_settop(L, 0); /* remove eventual returns */
}
};