From 14f5bb167951ad893760cdb526364e9edf1213ef Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 29 Jan 2018 14:59:25 +1100 Subject: src/: Export LUA_SIGNATURE as lua string instead of js string --- src/defs.js | 2 +- src/lauxlib.js | 4 ++-- src/ldo.js | 2 +- src/ldump.js | 10 ++-------- src/lundump.js | 4 ++-- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/defs.js b/src/defs.js index 13d2d1d..9eeea00 100644 --- a/src/defs.js +++ b/src/defs.js @@ -194,7 +194,7 @@ const from_userstring = function(str) { }; /* mark for precompiled code ('Lua') */ -const LUA_SIGNATURE = "\x1bLua"; +const LUA_SIGNATURE = to_luastring("\x1bLua"); const LUA_VERSION_MAJOR = "5"; const LUA_VERSION_MINOR = "3"; diff --git a/src/lauxlib.js b/src/lauxlib.js index 41d00b4..7d46505 100644 --- a/src/lauxlib.js +++ b/src/lauxlib.js @@ -871,7 +871,7 @@ if (typeof process === "undefined") { } let com = skipcomment(lf); /* check for signature first, as we don't want to add line number corrections in binary case */ - if (com.c === LUA_SIGNATURE.charCodeAt(0) && filename) { /* binary file? */ + if (com.c === LUA_SIGNATURE[0] && filename) { /* binary file? */ /* no need to re-open in node.js */ } else if (com.skipped) { /* read initial portion */ lf.buff[lf.n++] = '\n'.charCodeAt(0); /* add line to correct line numbers */ @@ -939,7 +939,7 @@ if (typeof process === "undefined") { } let com = skipcomment(lf); /* check for signature first, as we don't want to add line number corrections in binary case */ - if (com.c === LUA_SIGNATURE.charCodeAt(0) && filename) { /* binary file? */ + if (com.c === LUA_SIGNATURE[0] && filename) { /* binary file? */ /* no need to re-open in node.js */ } else if (com.skipped) { /* read initial portion */ lf.buff[lf.n++] = '\n'.charCodeAt(0); /* add line to correct line numbers */ diff --git a/src/ldo.js b/src/ldo.js index 82af33f..ce8f7bc 100644 --- a/src/ldo.js +++ b/src/ldo.js @@ -710,7 +710,7 @@ const checkmode = function(L, mode, x) { const f_parser = function(L, p) { let cl; let c = p.z.zgetc(); /* read first character */ - if (c === LUA_SIGNATURE.charCodeAt(0)) { + if (c === LUA_SIGNATURE[0]) { checkmode(L, p.mode, to_luastring("binary", true)); cl = lundump.luaU_undump(L, p.z, p.name); } else { diff --git a/src/ldump.js b/src/ldump.js index 09e5866..596a319 100644 --- a/src/ldump.js +++ b/src/ldump.js @@ -12,8 +12,7 @@ const { LUA_TNUMINT, LUA_TSHRSTR }, - luastring_of, - to_luastring + luastring_of } = require('./defs.js'); const LUAC_DATA = luastring_of(25, 147, 13, 10, 26, 10); @@ -37,11 +36,6 @@ const DumpBlock = function(b, size, D) { D.status = D.writer(D.L, b, size, D.data); }; -const DumpLiteral = function(s, D) { - s = to_luastring(s); - DumpBlock(s, s.length, D); -}; - const DumpByte = function(y, D) { DumpBlock(luastring_of(y), 1, D); }; @@ -172,7 +166,7 @@ const DumpFunction = function(f, psource, D) { }; const DumpHeader = function(D) { - DumpLiteral(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); diff --git a/src/lundump.js b/src/lundump.js index 7a9fde1..cf3fafa 100644 --- a/src/lundump.js +++ b/src/lundump.js @@ -56,7 +56,7 @@ class BytecodeParser { if (name[0] === 64 /* ('@').charCodeAt(0) */ || name[0] === 61 /* ('=').charCodeAt(0) */) this.name = name.subarray(1); - else if (name[0] == LUA_SIGNATURE.charCodeAt(0)) + else if (name[0] == LUA_SIGNATURE[0]) this.name = to_luastring("binary string", true); else this.name = name; @@ -248,7 +248,7 @@ class BytecodeParser { } checkHeader() { - this.checkliteral(to_luastring(LUA_SIGNATURE.substring(1)), "not a"); /* 1st char already checked */ + this.checkliteral(LUA_SIGNATURE.subarray(1), "not a"); /* 1st char already checked */ if (this.readByte() !== 0x53) this.error("version mismatch in"); -- cgit v1.2.3-70-g09d2