summaryrefslogtreecommitdiff
path: root/src/ldump.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/ldump.js')
-rw-r--r--src/ldump.js43
1 files changed, 25 insertions, 18 deletions
diff --git a/src/ldump.js b/src/ldump.js
index 7e62da3..596a319 100644
--- a/src/ldump.js
+++ b/src/ldump.js
@@ -1,12 +1,24 @@
"use strict";
-const defs = require('./defs.js');
-const CT = defs.constant_types;
-
-const LUAC_DATA = defs.string_of(25, 147, 13, 10, 26, 10);
+const {
+ LUA_SIGNATURE,
+ LUA_VERSION_MAJOR,
+ LUA_VERSION_MINOR,
+ constant_types: {
+ LUA_TBOOLEAN,
+ LUA_TLNGSTR,
+ LUA_TNIL,
+ LUA_TNUMFLT,
+ LUA_TNUMINT,
+ LUA_TSHRSTR
+ },
+ luastring_of
+} = require('./defs.js');
+
+const LUAC_DATA = luastring_of(25, 147, 13, 10, 26, 10);
const LUAC_INT = 0x5678;
const LUAC_NUM = 370.5;
-const LUAC_VERSION = Number.parseInt(defs.LUA_VERSION_MAJOR) * 16 + Number.parseInt(defs.LUA_VERSION_MINOR);
+const LUAC_VERSION = Number(LUA_VERSION_MAJOR) * 16 + Number(LUA_VERSION_MINOR);
const LUAC_FORMAT = 0; /* this is the official format */
class DumpState {
@@ -24,13 +36,8 @@ const DumpBlock = function(b, size, D) {
D.status = D.writer(D.L, b, size, D.data);
};
-const DumpLiteral = function(s, D) {
- s = defs.to_luastring(s);
- DumpBlock(s, s.length, D);
-};
-
const DumpByte = function(y, D) {
- DumpBlock(defs.string_of(y), 1, D);
+ DumpBlock(luastring_of(y), 1, D);
};
const DumpInt = function(x, D) {
@@ -88,19 +95,19 @@ const DumpConstants = function(f, D) {
let o = f.k[i];
DumpByte(o.ttype(), D);
switch (o.ttype()) {
- case CT.LUA_TNIL:
+ case LUA_TNIL:
break;
- case CT.LUA_TBOOLEAN:
+ case LUA_TBOOLEAN:
DumpByte(o.value ? 1 : 0, D);
break;
- case CT.LUA_TNUMFLT:
+ case LUA_TNUMFLT:
DumpNumber(o.value, D);
break;
- case CT.LUA_TNUMINT:
+ case LUA_TNUMINT:
DumpInteger(o.value, D);
break;
- case CT.LUA_TSHRSTR:
- case CT.LUA_TLNGSTR:
+ case LUA_TSHRSTR:
+ case LUA_TLNGSTR:
DumpString(o.tsvalue(), D);
break;
}
@@ -159,7 +166,7 @@ const DumpFunction = function(f, psource, D) {
};
const DumpHeader = function(D) {
- DumpLiteral(defs.LUA_SIGNATURE, D);
+ DumpBlock(LUA_SIGNATURE, LUA_SIGNATURE.length, D);
DumpByte(LUAC_VERSION, D);
DumpByte(LUAC_FORMAT, D);
DumpBlock(LUAC_DATA, LUAC_DATA.length, D);