aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lauxlib.js35
-rw-r--r--src/lbaselib.js33
-rw-r--r--src/lcorolib.js5
-rw-r--r--src/ldblib.js18
-rw-r--r--src/lmathlib.js3
-rw-r--r--src/loslib.js4
-rw-r--r--src/lstrlib.js17
-rw-r--r--src/ltablib.js11
-rw-r--r--src/lua.js12
9 files changed, 70 insertions, 68 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js
index 3d75282..1ee8900 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -9,7 +9,6 @@ const lua = require('./lua.js');
const char = lua.char;
const ldebug = require('./ldebug.js');
const lobject = require('./lobject.js');
-const CT = lua.constant_types;
const LUA_LOADED_TABLE = "_LOADED";
@@ -35,7 +34,7 @@ const findfield = function(L, objidx, level) {
lapi.lua_pushnil(L); /* start 'next' loop */
while (lapi.lua_next(L, -2)) { /* for each pair in table */
- if (lapi.lua_type(L, -2) === CT.LUA_TSTRING) { /* ignore non-string keys */
+ 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) */
return 1;
@@ -161,9 +160,9 @@ 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)) === CT.LUA_TSTRING)
+ 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) === CT.LUA_TLIGHTUSERDATA)
+ else if (lapi.lua_type(L, arg) === lua.LUA_TLIGHTUSERDATA)
typearg = lua.to_luastring("light userdata", true);
else
typearg = luaL_typename(L, arg);
@@ -219,7 +218,7 @@ const luaL_argcheck = function(L, cond, arg, extramsg) {
};
const luaL_checkany = function(L, arg) {
- if (lapi.lua_type(L, arg) === CT.LUA_TNONE)
+ if (lapi.lua_type(L, arg) === lua.LUA_TNONE)
luaL_argerror(L, arg, lua.to_luastring("value expected", true));
};
@@ -234,7 +233,7 @@ const luaL_checkstring = function(L, n) {
const luaL_checklstring = function(L, arg) {
let s = lapi.lua_tolstring(L, arg);
- if (s === null || s === undefined) tag_error(L, arg, CT.LUA_TSTRING);
+ if (s === null || s === undefined) tag_error(L, arg, lua.LUA_TSTRING);
return s;
};
@@ -250,13 +249,13 @@ const interror = function(L, arg) {
if (lapi.lua_isnumber(L, arg))
luaL_argerror(L, arg, lua.to_luastring("number has no integer representation", true));
else
- tag_error(L, arg, CT.LUA_TNUMBER);
+ tag_error(L, arg, lua.LUA_TNUMBER);
};
const luaL_checknumber = function(L, arg) {
let d = lapi.lua_tonumber(L, arg);
if (d === false)
- tag_error(L, arg, CT.LUA_TNUMBER);
+ tag_error(L, arg, lua.LUA_TNUMBER);
return d;
};
@@ -332,11 +331,11 @@ const luaL_loadstring = function(L, s) {
const luaL_getmetafield = function(L, obj, event) {
if (!lapi.lua_getmetatable(L, obj))
- return CT.LUA_TNIL;
+ return lua.LUA_TNIL;
else {
lapi.lua_pushstring(L, event);
let tt = lapi.lua_rawget(L, -2);
- if (tt === CT.LUA_TNIL)
+ if (tt === lua.LUA_TNIL)
lapi.lua_pop(L, 2);
return tt;
}
@@ -344,7 +343,7 @@ const luaL_getmetafield = function(L, obj, event) {
const luaL_callmeta = function(L, obj, event) {
obj = lapi.lua_absindex(L, obj);
- if (luaL_getmetafield(L, obj, event) === CT.LUA_TNIL)
+ if (luaL_getmetafield(L, obj, event) === lua.LUA_TNIL)
return false;
lapi.lua_pushvalue(L, obj);
@@ -368,21 +367,21 @@ const luaL_tolstring = function(L, idx) {
luaL_error(L, lua.to_luastring("'__tostring' must return a string", true));
} else {
switch(lapi.lua_type(L, idx)) {
- case CT.LUA_TNUMBER:
- case CT.LUA_TBOOLEAN:
+ case lua.LUA_TNUMBER:
+ case lua.LUA_TBOOLEAN:
lapi.lua_pushstring(L, lua.to_luastring(`${lapi.index2addr(L, idx).value}`));
break;
- case CT.LUA_TSTRING:
+ case lua.LUA_TSTRING:
lapi.lua_pushstring(L, lapi.index2addr(L, idx).value);
break;
- case CT.LUA_TNIL:
+ case lua.LUA_TNIL:
lapi.lua_pushstring(L, lua.to_luastring(`nil`));
break;
default:
let tt = luaL_getmetafield(L, idx, lua.to_luastring("__name", true));
- let kind = tt === CT.LUA_TSTRING ? lapi.lua_tostring(L, -1) : luaL_typename(L, idx);
+ 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)}`));
- if (tt !== CT.LUA_TNIL)
+ if (tt !== lua.LUA_TNIL)
lapi.lua_remove(L, -2);
break;
}
@@ -420,7 +419,7 @@ 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) === CT.LUA_TTABLE)
+ if (lapi.lua_getfield(L, idx, fname) === lua.LUA_TTABLE)
return true; /* table already there */
else {
lapi.lua_pop(L, 1); /* remove previous result */
diff --git a/src/lbaselib.js b/src/lbaselib.js
index 02b9fc6..8b4e6a5 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -6,7 +6,6 @@ const lua = require('./lua.js');
const lapi = require('./lapi.js');
const lauxlib = require('./lauxlib.js');
const lobject = require('./lobject.js');
-const CT = lua.constant_types;
const TS = lua.thread_status;
const luaB_print = function(L) {
@@ -51,9 +50,9 @@ const luaB_getmetatable = function(L) {
const luaB_setmetatable = function(L) {
let t = lapi.lua_type(L, 2);
- lauxlib.luaL_checktype(L, 1, CT.LUA_TTABLE);
- lauxlib.luaL_argcheck(L, t === CT.LUA_TNIL || t === CT.LUA_TTABLE, 2, lua.to_luastring("nil or table expected", true));
- if (lauxlib.luaL_getmetafield(L, 1, lua.to_luastring("__metatable", true)) !== CT.LUA_TNIL)
+ 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);
@@ -69,13 +68,13 @@ const luaB_rawequal = function(L) {
const luaB_rawlen = function(L) {
let t = lapi.lua_type(L, 1);
- lauxlib.luaL_argcheck(L, t === CT.LUA_TTABLE || t === CT.LUA_TSTRING, 1, lua.to_luastring("table or string expected", true));
+ 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));
return 1;
};
const luaB_rawget = function(L) {
- lauxlib.luaL_checktype(L, 1, CT.LUA_TTABLE);
+ lauxlib.luaL_checktype(L, 1, lua.LUA_TTABLE);
lauxlib.luaL_checkany(L, 2);
lapi.lua_settop(L, 2);
lapi.lua_rawget(L, 1);
@@ -83,7 +82,7 @@ const luaB_rawget = function(L) {
};
const luaB_rawset = function(L) {
- lauxlib.luaL_checktype(L, 1, CT.LUA_TTABLE);
+ lauxlib.luaL_checktype(L, 1, lua.LUA_TTABLE);
lauxlib.luaL_checkany(L, 2);
lauxlib.luaL_checkany(L, 3);
lapi.lua_settop(L, 3);
@@ -93,14 +92,14 @@ const luaB_rawset = function(L) {
const luaB_type = function(L) {
let t = lapi.lua_type(L, 1);
- lauxlib.luaL_argcheck(L, t !== CT.LUA_TNONE, 1, lua.to_luastring("value expected", true));
+ lauxlib.luaL_argcheck(L, t !== lua.LUA_TNONE, 1, lua.to_luastring("value expected", true));
lapi.lua_pushstring(L, lapi.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) === CT.LUA_TNIL) { /* no metamethod? */
+ 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 */
@@ -113,7 +112,7 @@ const pairsmeta = function(L, method, iszero, iter) {
};
const luaB_next = function(L) {
- lauxlib.luaL_checktype(L, 1, CT.LUA_TTABLE);
+ 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))
return 2;
@@ -133,7 +132,7 @@ 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) === CT.LUA_TNIL ? 1 : 2;
+ return lapi.lua_geti(L, 1, i) === lua.LUA_TNIL ? 1 : 2;
};
/*
@@ -154,7 +153,7 @@ const luaB_ipairs = function(L) {
const luaB_tonumber = function(L) {
if (lapi.lua_type(L, 2) <= 0) { /* standard conversion? */
lauxlib.luaL_checkany(L, 1);
- if (lapi.lua_type(L, 1) === CT.LUA_TNUMBER) { /* already a number? */
+ if (lapi.lua_type(L, 1) === lua.LUA_TNUMBER) { /* already a number? */
lapi.lua_settop(L, 1);
return 1;
} else {
@@ -164,7 +163,7 @@ const luaB_tonumber = function(L) {
}
} else {
let base = lauxlib.luaL_checkinteger(L, 2);
- lauxlib.luaL_checktype(L, 1, CT.LUA_TSTRING); /* no numbers as strings */
+ lauxlib.luaL_checktype(L, 1, lua.LUA_TSTRING); /* no numbers as strings */
let s = lapi.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);
@@ -181,7 +180,7 @@ const luaB_tonumber = function(L) {
const luaB_error = function(L) {
let level = lauxlib.luaL_optinteger(L, 2, 1);
lapi.lua_settop(L, 1);
- if (lapi.lua_type(L, 1) === CT.LUA_TSTRING && level > 0) {
+ if (lapi.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);
@@ -203,7 +202,7 @@ const luaB_assert = function(L) {
const luaB_select = function(L) {
let n = lapi.lua_gettop(L);
- if (lapi.lua_type(L, 1) === CT.LUA_TSTRING && lapi.lua_tostring(L, 1)[0] === "#".charCodeAt(0)) {
+ if (lapi.lua_type(L, 1) === lua.LUA_TSTRING && lapi.lua_tostring(L, 1)[0] === "#".charCodeAt(0)) {
lapi.lua_pushinteger(L, n - 1);
return 1;
} else {
@@ -246,7 +245,7 @@ const luaB_pcall = function(L) {
*/
const luaB_xpcall = function(L) {
let n = lapi.lua_gettop(L);
- lauxlib.luaL_checktype(L, 2, CT.LUA_TFUNCTION); /* check error function */
+ 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 */
@@ -306,7 +305,7 @@ const luaB_load = function(L) {
status = lauxlib.luaL_loadbufferx(L, s, chunkname, mode);
} else { /* loading from a reader function */
let chunkname = lauxlib.luaL_optstring(L, 2, lua.to_luastring("=(load)", true));
- lauxlib.luaL_checktype(L, 1, CT.LUA_TFUNCTION);
+ 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);
}
diff --git a/src/lcorolib.js b/src/lcorolib.js
index b7c4555..a46df98 100644
--- a/src/lcorolib.js
+++ b/src/lcorolib.js
@@ -9,7 +9,6 @@ const lstate = require('./lstate.js');
const ldo = require('./ldo.js');
const ldebug = require('./ldebug.js');
const lobject = require('./lobject.js');
-const CT = lua.constant_types;
const TS = lua.thread_status;
const getco = function(L) {
@@ -65,7 +64,7 @@ const luaB_auxwrap = function(L) {
let co = lapi.lua_tothread(L, lua.lua_upvalueindex(1));
let r = auxresume(L, co, lapi.lua_gettop(L));
if (r < 0) {
- if (lapi.lua_type(L, -1) === CT.LUA_TSTRING) { /* error object is a string? */
+ if (lapi.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);
@@ -78,7 +77,7 @@ const luaB_auxwrap = function(L) {
};
const luaB_cocreate = function(L) {
- lauxlib.luaL_checktype(L, 1, CT.LUA_TFUNCTION);
+ 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 */
diff --git a/src/ldblib.js b/src/ldblib.js
index a4de832..fb2b8a2 100644
--- a/src/ldblib.js
+++ b/src/ldblib.js
@@ -33,14 +33,14 @@ const db_getmetatable = function(L) {
const db_setmetatable = function(L) {
const t = lapi.lua_type(L, 2);
- lauxlib.luaL_argcheck(L, t == lua.CT.LUA_TNIL || t == lua.CT.LUA_TTABLE, 2, lua.to_luastring("nil or table expected", true));
+ 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);
return 1; /* return 1st argument */
};
const db_getuservalue = function(L) {
- if (lapi.lua_type(L, 1) !== lua.CT.LUA_TUSERDATA)
+ if (lapi.lua_type(L, 1) !== lua.LUA_TUSERDATA)
lapi.lua_pushnil(L);
else
lapi.lua_getuservalue(L, 1);
@@ -49,7 +49,7 @@ const db_getuservalue = function(L) {
const db_setuservalue = function(L) {
- lauxlib.luaL_checktype(L, 1, lua.CT.LUA_TUSERDATA);
+ lauxlib.luaL_checktype(L, 1, lua.LUA_TUSERDATA);
lauxlib.luaL_checkany(L, 2);
lapi.lua_settop(L, 2);
lapi.lua_setuservalue(L, 1);
@@ -219,7 +219,7 @@ 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.CT.LUA_TFUNCTION); /* closure */
+ lauxlib.luaL_checktype(L, 1, lua.LUA_TFUNCTION); /* closure */
let name = get ? lapi.lua_getupvalue(L, 1, n) : lapi.lua_setupvalue(L, 1, n);
if (name === null) return 0;
lapi.lua_pushstring(L, name);
@@ -243,7 +243,7 @@ const db_setupvalue = function(L) {
*/
const checkupval = function(L, argf, argnup) {
let nup = lauxlib.luaL_checkinteger(L, argnup); /* upvalue index */
- lauxlib.luaL_checktype(L, argf, lua.CT.LUA_TFUNCTION); /* closure */
+ 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));
return nup;
};
@@ -278,7 +278,7 @@ const hooknames = ["call", "return", "line", "count", "tail call"].map(e => lua.
const hookf = function(L, ar) {
lapi.lua_rawgetp(L, lua.LUA_REGISTRYINDEX, HOOKKEY);
lapi.lua_pushthread(L);
- if (lapi.lua_rawget(L, -2) === lua.CT.LUA_TFUNCTION) { /* is there a hook function? */
+ if (lapi.lua_rawget(L, -2) === lua.LUA_TFUNCTION) { /* is there a hook function? */
lapi.lua_pushstring(L, hooknames[ar.event]); /* push event name */
if (ar.currentline >= 0)
lapi.lua_pushinteger(L, ar.currentline); /* push current line */
@@ -322,11 +322,11 @@ const db_sethook = function(L) {
}
else {
const smask = lauxlib.luaL_checkstring(L, arg + 2);
- lauxlib.luaL_checktype(L, arg+1, lua.CT.LUA_TFUNCTION);
+ lauxlib.luaL_checktype(L, arg+1, lua.LUA_TFUNCTION);
count = lauxlib.luaL_optinteger(L, arg + 3, 0);
func = hookf; mask = makemask(smask, count);
}
- if (lapi.lua_rawgetp(L, lua.LUA_REGISTRYINDEX, HOOKKEY) === lua.CT.LUA_TNIL) {
+ 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 */
@@ -411,7 +411,7 @@ if (typeof require === "function") {
prompt: 'lua_debug> '
});
- // TODO: if in browser, use a designated input in the DOM ?
+ // TODO: if in browser, use a designated input in the DOM ?
const db_debug = function(L) {
for (;;) {
let input = readlineSync.prompt();
diff --git a/src/lmathlib.js b/src/lmathlib.js
index fd18711..149bebd 100644
--- a/src/lmathlib.js
+++ b/src/lmathlib.js
@@ -11,7 +11,6 @@ const ldo = require('./ldo.js');
const ldebug = require('./ldebug.js');
const llimit = require('./llimit.js');
const luaconf = require('./luaconf.js');
-const CT = lua.constant_types;
const TS = lua.thread_status;
var RNG = seedrandom();
@@ -195,7 +194,7 @@ const math_max = function(L) {
};
const math_type = function(L) {
- if (lapi.lua_type(L, 1) === CT.LUA_TNUMBER) {
+ if (lapi.lua_type(L, 1) === lua.LUA_TNUMBER) {
if (lapi.lua_isinteger(L, 1))
lapi.lua_pushliteral(L, "integer");
else
diff --git a/src/loslib.js b/src/loslib.js
index 781dec9..4eea581 100644
--- a/src/loslib.js
+++ b/src/loslib.js
@@ -33,7 +33,7 @@ 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);
if (res !== false) { /* field is not an integer? */
- if (t != lua.CT.LUA_TNIL) /* some other value? */
+ if (t != lua.LUA_TNIL) /* some other value? */
return lauxlib.luaL_error(L, lua.to_luastring(`field '${key}' is not an integer`), true);
else if (d < 0) /* absent field; no default? */
return lauxlib.luaL_error(L, lua.to_luastring(`field '${key}' missing in date table`), true);
@@ -51,7 +51,7 @@ const getfield = function(L, key, d, delta) {
const os_time = function(L) {
let t = new Date();
if (!lapi.lua_isnoneornil(L, 1)) /* called with arg */{
- lauxlib.luaL_checktype(L, 1, lua.CT.LUA_TTABLE); /* make sure table is at the top */
+ lauxlib.luaL_checktype(L, 1, lua.LUA_TTABLE); /* make sure table is at the top */
lapi.lua_settop(L, 1);
t.setSeconds(getfield(L, "sec", 0, 0));
t.setSeconds(getfield(L, "min", 0, 0));
diff --git a/src/lstrlib.js b/src/lstrlib.js
index f26400e..1935de3 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -9,7 +9,6 @@ const lobject = require('./lobject.js');
const lua = require('./lua.js');
const luaconf = require('./luaconf.js');
const llimit = require('./llimit.js');
-const CT = lua.constant_types;
const char = lua.char;
const sL_ESC = '%';
@@ -79,7 +78,7 @@ const writer = function(L, b, size, B) {
const str_dump = function(L) {
let b = [];
let strip = lapi.lua_toboolean(L, 2);
- lauxlib.luaL_checktype(L, 1, CT.LUA_TFUNCTION);
+ lauxlib.luaL_checktype(L, 1, lua.LUA_TFUNCTION);
lapi.lua_settop(L, 1);
if (lapi.lua_dump(L, writer, b, strip) !== 0)
return lauxlib.luaL_error(L, lua.to_luastring("unable to dump given function"));
@@ -219,12 +218,12 @@ const checkdp = function(buff) {
const addliteral = function(L, b, arg) {
switch(lapi.lua_type(L, arg)) {
- case CT.LUA_TSTRING: {
+ case lua.LUA_TSTRING: {
let s = lapi.lua_tostring(L, arg);
addquoted(b, s, s.length);
break;
}
- case CT.LUA_TNUMBER: {
+ case lua.LUA_TNUMBER: {
if (!lapi.lua_isinteger(L, arg)) { /* float? */
let n = lapi.lua_tonumber(L, arg); /* write as hexa ('%a') */
concat(b, lua_number2strx(L, lua.to_luastring(`%${luaconf.LUA_INTEGER_FRMLEN}a`), n));
@@ -235,7 +234,7 @@ const addliteral = function(L, b, arg) {
}
break;
}
- case CT.LUA_TNIL: case CT.LUA_TBOOLEAN: {
+ case lua.LUA_TNIL: case lua.LUA_TBOOLEAN: {
concat(b, lauxlib.luaL_tolstring(L, arg));
break;
}
@@ -1304,13 +1303,13 @@ const add_s = function(ms, b, s, e) {
const add_value = function(ms, b, s, e, tr) {
let L = ms.L;
switch (tr) {
- case CT.LUA_TFUNCTION: {
+ case lua.LUA_TFUNCTION: {
lapi.lua_pushvalue(L, 3);
let n = push_captures(ms, s, e);
lapi.lua_call(L, n, 1);
break;
}
- case CT.LUA_TTABLE: {
+ case lua.LUA_TTABLE: {
push_onecapture(ms, 0, s, e);
lapi.lua_gettable(L, 3);
break;
@@ -1340,7 +1339,7 @@ const str_gsub = function(L) {
let n = 0; /* replacement count */
let ms = new MatchState(L);
let b = new lauxlib.luaL_Buffer(L);
- lauxlib.luaL_argcheck(L, tr === CT.LUA_TNUMBER || tr === CT.LUA_TSTRING || tr === CT.LUA_TFUNCTION || tr === CT.LUA_TTABLE, 3,
+ lauxlib.luaL_argcheck(L, tr === lua.LUA_TNUMBER || tr === lua.LUA_TSTRING || tr === lua.LUA_TFUNCTION || tr === lua.LUA_TTABLE, 3,
lua.to_luastring("string/function/table expected", true));
lauxlib.luaL_buffinit(L, b);
if (anchor) {
@@ -1394,7 +1393,7 @@ const createmetatable = function(L) {
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 */
+ lapi.lua_pop(L, 1); /* pop metatable */
};
const luaopen_string = function(L) {
diff --git a/src/ltablib.js b/src/ltablib.js
index bc51836..60b1554 100644
--- a/src/ltablib.js
+++ b/src/ltablib.js
@@ -10,7 +10,6 @@ const ldo = require('./ldo.js');
const ldebug = require('./ldebug.js');
const llimit = require('./llimit.js');
const lobject = require('./lobject.js');
-const CT = lua.constant_types;
const TS = lua.thread_status;
@@ -25,7 +24,7 @@ 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) !== CT.LUA_TNIL;
+ return lapi.lua_rawget(L, -n) !== lua.LUA_TNIL;
};
/*
@@ -33,7 +32,7 @@ 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) !== CT.LUA_TTABLE) { /* is it not a table? */
+ if (lapi.lua_type(L, arg) !== lua.LUA_TTABLE) { /* is it not a table? */
let n = 1;
if (lapi.lua_getmetatable(L, arg) && /* must have metatable */
(!(what & TAB_R) || checkfield(L, lua.to_luastring("__index", true), ++n)) &&
@@ -42,7 +41,7 @@ const checktab = function(L, arg, what) {
lapi.lua_pop(L, n); /* pop metatable and tested metamethods */
}
else
- lauxlib.luaL_checktype(L, arg, CT.LUA_TTABLE); /* force an error */
+ lauxlib.luaL_checktype(L, arg, lua.LUA_TTABLE); /* force an error */
}
};
@@ -185,7 +184,7 @@ const unpack = function(L) {
const auxsort = function(L) {
let t = lapi.index2addr(L, 1);
- if (lapi.lua_type(L, 2) !== CT.LUA_TFUNCTION) { /* no function? */
+ if (lapi.lua_type(L, 2) !== lua.LUA_TFUNCTION) { /* no function? */
[...t.value.entries()]
.sort(function (a, b) {
if (typeof a[0] !== 'number') return 1;
@@ -216,7 +215,7 @@ const sort = function(L) {
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? */
- lauxlib.luaL_checktype(L, 2, CT.LUA_TFUNCTION); /* must be a function */
+ lauxlib.luaL_checktype(L, 2, lua.LUA_TFUNCTION); /* must be a function */
lapi.lua_settop(L, 2); /* make sure there are two arguments */
auxsort(L);
}
diff --git a/src/lua.js b/src/lua.js
index f54f679..37ecadd 100644
--- a/src/lua.js
+++ b/src/lua.js
@@ -4,7 +4,6 @@
const defs = require("./defs.js");
module.exports.char = defs.char;
-module.exports.CT = defs.CT;
module.exports.FENGARI_AUTHORS = defs.FENGARI_AUTHORS;
module.exports.FENGARI_COPYRIGHT = defs.FENGARI_COPYRIGHT;
module.exports.FENGARI_RELEASE = defs.FENGARI_RELEASE;
@@ -52,13 +51,22 @@ module.exports.LUA_RIDX_GLOBALS = defs.LUA_RIDX_GLOBALS;
module.exports.LUA_RIDX_LAST = defs.LUA_RIDX_LAST;
module.exports.LUA_RIDX_MAINTHREAD = defs.LUA_RIDX_MAINTHREAD;
module.exports.LUA_SIGNATURE = defs.LUA_SIGNATURE;
+module.exports.LUA_TNONE = defs.CT.LUA_TNONE;
+module.exports.LUA_TNIL = defs.CT.LUA_TNIL;
+module.exports.LUA_TBOOLEAN = defs.CT.LUA_TBOOLEAN;
+module.exports.LUA_TLIGHTUSERDATA = defs.CT.LUA_TLIGHTUSERDATA;
+module.exports.LUA_TNUMBER = defs.CT.LUA_TNUMBER;
+module.exports.LUA_TSTRING = defs.CT.LUA_TSTRING;
+module.exports.LUA_TTABLE = defs.CT.LUA_TTABLE;
+module.exports.LUA_TFUNCTION = defs.CT.LUA_TFUNCTION;
+module.exports.LUA_TUSERDATA = defs.CT.LUA_TUSERDATA;
+module.exports.LUA_TTHREAD = defs.CT.LUA_TTHREAD;
module.exports.LUA_VERSION = defs.LUA_VERSION;
module.exports.LUA_VERSION_MAJOR = defs.LUA_VERSION_MAJOR;
module.exports.LUA_VERSION_MINOR = defs.LUA_VERSION_MINOR;
module.exports.LUA_VERSION_NUM = defs.LUA_VERSION_NUM;
module.exports.LUA_VERSION_RELEASE = defs.LUA_VERSION_RELEASE;
module.exports.LUA_VERSUFFIX = defs.LUA_VERSUFFIX;
-module.exports.constant_types = defs.constant_types;
module.exports.lua_Debug = defs.lua_Debug;
module.exports.lua_upvalueindex = defs.lua_upvalueindex;
module.exports.print_version = defs.print_version;