aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-01-18 08:08:35 +1100
committerdaurnimator <quae@daurnimator.com>2018-01-18 08:08:35 +1100
commit26907ca30bff39eda4eb8fee615ce2a19f8d2fca (patch)
treea0eb096dd336ed6c762eaa0478590e4745ca2ab2
parentbb5c73baee21cec5d2553c46b2dbb4fd35f80019 (diff)
downloadfengari-26907ca30bff39eda4eb8fee615ce2a19f8d2fca.tar.gz
fengari-26907ca30bff39eda4eb8fee615ce2a19f8d2fca.tar.bz2
fengari-26907ca30bff39eda4eb8fee615ce2a19f8d2fca.zip
src/ltm.js: Use destructuring assignment for defs.js
-rw-r--r--src/ltm.js69
1 files changed, 37 insertions, 32 deletions
diff --git a/src/ltm.js b/src/ltm.js
index 4741772..a1aa8e3 100644
--- a/src/ltm.js
+++ b/src/ltm.js
@@ -1,6 +1,12 @@
"use strict";
-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');
@@ -12,7 +18,6 @@ const {
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",
@@ -26,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];
@@ -66,37 +71,37 @@ const TMS = {
};
const luaT_init = function(L) {
- L.l_G.tmname[TMS.TM_INDEX] = new luaS_new(L, defs.to_luastring("__index", true));
- L.l_G.tmname[TMS.TM_NEWINDEX] = new luaS_new(L, defs.to_luastring("__newindex", true));
- L.l_G.tmname[TMS.TM_GC] = new luaS_new(L, defs.to_luastring("__gc", true));
- L.l_G.tmname[TMS.TM_MODE] = new luaS_new(L, defs.to_luastring("__mode", true));
- L.l_G.tmname[TMS.TM_LEN] = new luaS_new(L, defs.to_luastring("__len", true));
- L.l_G.tmname[TMS.TM_EQ] = new luaS_new(L, defs.to_luastring("__eq", true));
- L.l_G.tmname[TMS.TM_ADD] = new luaS_new(L, defs.to_luastring("__add", true));
- L.l_G.tmname[TMS.TM_SUB] = new luaS_new(L, defs.to_luastring("__sub", true));
- L.l_G.tmname[TMS.TM_MUL] = new luaS_new(L, defs.to_luastring("__mul", true));
- L.l_G.tmname[TMS.TM_MOD] = new luaS_new(L, defs.to_luastring("__mod", true));
- L.l_G.tmname[TMS.TM_POW] = new luaS_new(L, defs.to_luastring("__pow", true));
- L.l_G.tmname[TMS.TM_DIV] = new luaS_new(L, defs.to_luastring("__div", true));
- L.l_G.tmname[TMS.TM_IDIV] = new luaS_new(L, defs.to_luastring("__idiv", true));
- L.l_G.tmname[TMS.TM_BAND] = new luaS_new(L, defs.to_luastring("__band", true));
- L.l_G.tmname[TMS.TM_BOR] = new luaS_new(L, defs.to_luastring("__bor", true));
- L.l_G.tmname[TMS.TM_BXOR] = new luaS_new(L, defs.to_luastring("__bxor", true));
- L.l_G.tmname[TMS.TM_SHL] = new luaS_new(L, defs.to_luastring("__shl", true));
- L.l_G.tmname[TMS.TM_SHR] = new luaS_new(L, defs.to_luastring("__shr", true));
- L.l_G.tmname[TMS.TM_UNM] = new luaS_new(L, defs.to_luastring("__unm", true));
- L.l_G.tmname[TMS.TM_BNOT] = new luaS_new(L, defs.to_luastring("__bnot", true));
- L.l_G.tmname[TMS.TM_LT] = new luaS_new(L, defs.to_luastring("__lt", true));
- L.l_G.tmname[TMS.TM_LE] = new luaS_new(L, defs.to_luastring("__le", true));
- L.l_G.tmname[TMS.TM_CONCAT] = new luaS_new(L, defs.to_luastring("__concat", true));
- L.l_G.tmname[TMS.TM_CALL] = new 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) ||
@@ -151,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));
}
}
};
@@ -185,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: