summaryrefslogtreecommitdiff
path: root/src/ltm.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/ltm.js')
-rw-r--r--src/ltm.js81
1 files changed, 44 insertions, 37 deletions
diff --git a/src/ltm.js b/src/ltm.js
index 79a483e..a1aa8e3 100644
--- a/src/ltm.js
+++ b/src/ltm.js
@@ -1,16 +1,23 @@
"use strict";
-const assert = require('assert');
-
-const defs = require('./defs.js');
+const {
+ constant_types: {
+ LUA_TTABLE,
+ LUA_TUSERDATA
+ },
+ to_luastring
+} = require('./defs.js');
+const { lua_assert } = require('./llimits.js');
const lobject = require('./lobject.js');
const ldo = require('./ldo.js');
const lstate = require('./lstate.js');
-const lstring = require('./lstring.js');
+const {
+ luaS_bless,
+ luaS_new
+} = require('./lstring.js');
const ltable = require('./ltable.js');
const ldebug = require('./ldebug.js');
const lvm = require('./lvm.js');
-const CT = defs.constant_types;
const luaT_typenames_ = [
"no value",
@@ -24,7 +31,7 @@ const luaT_typenames_ = [
"userdata",
"thread",
"proto" /* this last case is used for tests only */
-].map(e => defs.to_luastring(e));
+].map(e => to_luastring(e));
const ttypename = function(t) {
return luaT_typenames_[t + 1];
@@ -64,42 +71,42 @@ const TMS = {
};
const luaT_init = function(L) {
- L.l_G.tmname[TMS.TM_INDEX] = new lstring.luaS_new(L, defs.to_luastring("__index", true));
- L.l_G.tmname[TMS.TM_NEWINDEX] = new lstring.luaS_new(L, defs.to_luastring("__newindex", true));
- L.l_G.tmname[TMS.TM_GC] = new lstring.luaS_new(L, defs.to_luastring("__gc", true));
- L.l_G.tmname[TMS.TM_MODE] = new lstring.luaS_new(L, defs.to_luastring("__mode", true));
- L.l_G.tmname[TMS.TM_LEN] = new lstring.luaS_new(L, defs.to_luastring("__len", true));
- L.l_G.tmname[TMS.TM_EQ] = new lstring.luaS_new(L, defs.to_luastring("__eq", true));
- L.l_G.tmname[TMS.TM_ADD] = new lstring.luaS_new(L, defs.to_luastring("__add", true));
- L.l_G.tmname[TMS.TM_SUB] = new lstring.luaS_new(L, defs.to_luastring("__sub", true));
- L.l_G.tmname[TMS.TM_MUL] = new lstring.luaS_new(L, defs.to_luastring("__mul", true));
- L.l_G.tmname[TMS.TM_MOD] = new lstring.luaS_new(L, defs.to_luastring("__mod", true));
- L.l_G.tmname[TMS.TM_POW] = new lstring.luaS_new(L, defs.to_luastring("__pow", true));
- L.l_G.tmname[TMS.TM_DIV] = new lstring.luaS_new(L, defs.to_luastring("__div", true));
- L.l_G.tmname[TMS.TM_IDIV] = new lstring.luaS_new(L, defs.to_luastring("__idiv", true));
- L.l_G.tmname[TMS.TM_BAND] = new lstring.luaS_new(L, defs.to_luastring("__band", true));
- L.l_G.tmname[TMS.TM_BOR] = new lstring.luaS_new(L, defs.to_luastring("__bor", true));
- L.l_G.tmname[TMS.TM_BXOR] = new lstring.luaS_new(L, defs.to_luastring("__bxor", true));
- L.l_G.tmname[TMS.TM_SHL] = new lstring.luaS_new(L, defs.to_luastring("__shl", true));
- L.l_G.tmname[TMS.TM_SHR] = new lstring.luaS_new(L, defs.to_luastring("__shr", true));
- L.l_G.tmname[TMS.TM_UNM] = new lstring.luaS_new(L, defs.to_luastring("__unm", true));
- L.l_G.tmname[TMS.TM_BNOT] = new lstring.luaS_new(L, defs.to_luastring("__bnot", true));
- L.l_G.tmname[TMS.TM_LT] = new lstring.luaS_new(L, defs.to_luastring("__lt", true));
- L.l_G.tmname[TMS.TM_LE] = new lstring.luaS_new(L, defs.to_luastring("__le", true));
- L.l_G.tmname[TMS.TM_CONCAT] = new lstring.luaS_new(L, defs.to_luastring("__concat", true));
- L.l_G.tmname[TMS.TM_CALL] = new lstring.luaS_new(L, defs.to_luastring("__call", true));
+ L.l_G.tmname[TMS.TM_INDEX] = new luaS_new(L, to_luastring("__index", true));
+ L.l_G.tmname[TMS.TM_NEWINDEX] = new luaS_new(L, to_luastring("__newindex", true));
+ L.l_G.tmname[TMS.TM_GC] = new luaS_new(L, to_luastring("__gc", true));
+ L.l_G.tmname[TMS.TM_MODE] = new luaS_new(L, to_luastring("__mode", true));
+ L.l_G.tmname[TMS.TM_LEN] = new luaS_new(L, to_luastring("__len", true));
+ L.l_G.tmname[TMS.TM_EQ] = new luaS_new(L, to_luastring("__eq", true));
+ L.l_G.tmname[TMS.TM_ADD] = new luaS_new(L, to_luastring("__add", true));
+ L.l_G.tmname[TMS.TM_SUB] = new luaS_new(L, to_luastring("__sub", true));
+ L.l_G.tmname[TMS.TM_MUL] = new luaS_new(L, to_luastring("__mul", true));
+ L.l_G.tmname[TMS.TM_MOD] = new luaS_new(L, to_luastring("__mod", true));
+ L.l_G.tmname[TMS.TM_POW] = new luaS_new(L, to_luastring("__pow", true));
+ L.l_G.tmname[TMS.TM_DIV] = new luaS_new(L, to_luastring("__div", true));
+ L.l_G.tmname[TMS.TM_IDIV] = new luaS_new(L, to_luastring("__idiv", true));
+ L.l_G.tmname[TMS.TM_BAND] = new luaS_new(L, to_luastring("__band", true));
+ L.l_G.tmname[TMS.TM_BOR] = new luaS_new(L, to_luastring("__bor", true));
+ L.l_G.tmname[TMS.TM_BXOR] = new luaS_new(L, to_luastring("__bxor", true));
+ L.l_G.tmname[TMS.TM_SHL] = new luaS_new(L, to_luastring("__shl", true));
+ L.l_G.tmname[TMS.TM_SHR] = new luaS_new(L, to_luastring("__shr", true));
+ L.l_G.tmname[TMS.TM_UNM] = new luaS_new(L, to_luastring("__unm", true));
+ L.l_G.tmname[TMS.TM_BNOT] = new luaS_new(L, to_luastring("__bnot", true));
+ L.l_G.tmname[TMS.TM_LT] = new luaS_new(L, to_luastring("__lt", true));
+ L.l_G.tmname[TMS.TM_LE] = new luaS_new(L, to_luastring("__le", true));
+ L.l_G.tmname[TMS.TM_CONCAT] = new luaS_new(L, to_luastring("__concat", true));
+ L.l_G.tmname[TMS.TM_CALL] = new luaS_new(L, to_luastring("__call", true));
};
/*
** Return the name of the type of an object. For tables and userdata
** with metatable, use their '__name' metafield, if present.
*/
-const __name = defs.to_luastring('__name', true);
+const __name = to_luastring('__name', true);
const luaT_objtypename = function(L, o) {
let mt;
if ((o.ttistable() && (mt = o.value.metatable) !== null) ||
(o.ttisfulluserdata() && (mt = o.value.metatable) !== null)) {
- let name = ltable.luaH_getstr(mt, lstring.luaS_bless(L, __name));
+ let name = ltable.luaH_getstr(mt, luaS_bless(L, __name));
if (name.ttisstring())
return name.svalue();
}
@@ -149,10 +156,10 @@ const luaT_trybinTM = function(L, p1, p2, res, event) {
if (n1 !== false && n2 !== false)
return ldebug.luaG_tointerror(L, p1, p2);
else
- return ldebug.luaG_opinterror(L, p1, p2, defs.to_luastring("perform bitwise operation on", true));
+ return ldebug.luaG_opinterror(L, p1, p2, to_luastring("perform bitwise operation on", true));
}
default:
- return ldebug.luaG_opinterror(L, p1, p2, defs.to_luastring("perform arithmetic on", true));
+ return ldebug.luaG_opinterror(L, p1, p2, to_luastring("perform arithmetic on", true));
}
}
};
@@ -172,7 +179,7 @@ const fasttm = function(l, et, e) {
const luaT_gettm = function(events, event, ename) {
const tm = ltable.luaH_getstr(events, ename);
- assert(event <= TMS.TM_EQ);
+ lua_assert(event <= TMS.TM_EQ);
if (tm.ttisnil()) { /* no tag method? */
events.flags |= 1<<event; /* cache this fact */
return null;
@@ -183,8 +190,8 @@ const luaT_gettm = function(events, event, ename) {
const luaT_gettmbyobj = function(L, o, event) {
let mt;
switch(o.ttnov()) {
- case CT.LUA_TTABLE:
- case CT.LUA_TUSERDATA:
+ case LUA_TTABLE:
+ case LUA_TUSERDATA:
mt = o.value.metatable;
break;
default: