aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lapi.js1
-rw-r--r--src/ldo.js22
-rw-r--r--src/lfunc.js20
-rw-r--r--src/lstate.js21
-rw-r--r--src/lundump.js6
-rw-r--r--tests/ltm.js192
-rw-r--r--tests/lvm.js60
-rw-r--r--tests/tests.js8
8 files changed, 179 insertions, 151 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 0e3c3bd..976841d 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -10,6 +10,7 @@ const lfunc = require('./lfunc.js');
const lua = require('./lua.js');
const lstate = require('./lstate.js');
const lvm = require('./lvm.js');
+const lundump = require('./lundump.js');
const MAXUPVAL = lfunc.MAXUPVAL;
const CT = lua.constant_types;
const TS = lua.thread_status;
diff --git a/src/ldo.js b/src/ldo.js
index f965a47..3686f7d 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -261,6 +261,28 @@ const luaD_callnoyield = function(L, off, nResults) {
L.nny--;
};
+// TODO: since we only handle binary, no need for a reader or mode
+const f_parser = function(L, data) {
+ assert(data instanceof DataView, "data must be a DataView");
+
+ let p = new lundump.BytecodeParser(data);
+ let cl = p.luaU_undump();
+
+ assert(cl.nupvalues == cl.p.sizeupvalues);
+
+ lfunc.luaF_initupvals(L, cl);
+};
+
+const luaD_protectedparser = function(L, data, name) {
+ L.nny++;
+
+ let status = luaD_pcall(L, f_parser, data, L.top, L.errfunc);
+
+ L.nny--;
+
+ return status;
+};
+
module.exports.nil = nil;
module.exports.luaD_precall = luaD_precall;
module.exports.luaD_poscall = luaD_poscall;
diff --git a/src/lfunc.js b/src/lfunc.js
index f3e11d3..39ad049 100644
--- a/src/lfunc.js
+++ b/src/lfunc.js
@@ -88,8 +88,18 @@ const luaF_close = function(L, level) {
}
};
-module.exports.Proto = Proto;
-module.exports.UpVal = UpVal;
-module.exports.findupval = findupval;
-module.exports.luaF_close = luaF_close;
-module.exports.MAXUPVAL = 255; \ No newline at end of file
+const luaF_initupvals = function(L, cl) {
+ for (let i = 0; i < cl.nupvalues; i++) {
+ let uv = new UpVal();
+ uv.refcount = 1;
+ uv.u.value = null;
+ uv.v = uv.u.value;
+ }
+};
+
+module.exports.Proto = Proto;
+module.exports.UpVal = UpVal;
+module.exports.findupval = findupval;
+module.exports.luaF_close = luaF_close;
+module.exports.MAXUPVAL = 255;
+module.exports.luaF_initupvals = luaF_initupvals; \ No newline at end of file
diff --git a/src/lstate.js b/src/lstate.js
index 4d71be7..54e7ac7 100644
--- a/src/lstate.js
+++ b/src/lstate.js
@@ -44,22 +44,11 @@ class CallInfo {
class lua_State {
constructor(cl) {
- if (cl) { // TODO: remove
- this.top = 1;
- this.ci = new CallInfo(0, cl, 1, 1, null, null);
- this.ci.u.l.savedpc = cl.p.code;
- this.ci.nresults = LUA_MULTRET;
- this.ciOff = 0;
- this.stack = [
- cl
- ];
- } else {
- this.base_ci = new CallInfo(); // Will be populated later
- this.top = 0;
- this.ci = null;
- this.ciOff = null;
- this.stack = [];
- }
+ this.base_ci = new CallInfo(); // Will be populated later
+ this.top = 0;
+ this.ci = null;
+ this.ciOff = null;
+ this.stack = [];
this.openupval = [];
this.status = TS.LUA_OK;
this.next = null;
diff --git a/src/lundump.js b/src/lundump.js
index 0ff3143..ab1dd6f 100644
--- a/src/lundump.js
+++ b/src/lundump.js
@@ -290,10 +290,14 @@ class BytecodeParser {
}
- luaU_undump() {
+ luaU_undump(L) {
this.checkHeader();
let cl = new LClosure(this.readByte());
+
+ L.stack[L.top] = cl;
+ L.top++;
+
cl.p = new Proto();
this.readFunction(cl.p);
diff --git a/tests/ltm.js b/tests/ltm.js
index e365a2a..9a3dee5 100644
--- a/tests/ltm.js
+++ b/tests/ltm.js
@@ -5,7 +5,7 @@ const test = require('tape');
const beautify = require('js-beautify').js_beautify;
const VM = require("../src/lvm.js");
-const ldo = require("../src/ldo.js");
+const lapi = require("../src/lapi.js");
const OC = require('../src/lopcodes.js');
const getState = require("./tests.js").getState;
@@ -23,7 +23,7 @@ test('__index, __newindex: with actual table', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -55,7 +55,7 @@ test('__index: with non table', function (t) {
}, "Bytecode parsed without errors");
t.throws(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed with expected error");
});
@@ -75,7 +75,7 @@ test('__newindex: with non table', function (t) {
}, "Bytecode parsed without errors");
t.throws(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed with expected error");
});
@@ -121,16 +121,16 @@ test('__index function in metatable', function (t) {
// 3 [4] RETURN 0 1
t.strictEqual(
- OC.OpCodes[L.stack[0].p.code[4].opcode],
+ OC.OpCodes[L.stack[1].p.code[4].opcode],
"OP_GETTABLE",
"Correct opcode marked as breakpoint"
);
t.comment("We set a breakpoint")
- L.stack[0].p.code[4].breakpoint = true;
+ L.stack[1].p.code[4].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
t.strictEqual(
@@ -141,20 +141,20 @@ test('__index function in metatable', function (t) {
t.comment("We unset the breakpoint and correct pcOff");
L.ci.pcOff--;
- L.stack[0].p.code[4].breakpoint = false;
+ L.stack[1].p.code[4].breakpoint = false;
t.ok(
- L.stack[2].ttistable() && !L.stack[2].value.hash.get("__index"),
- "t is on stack at 2"
+ L.stack[3].ttistable() && !L.stack[3].value.hash.get("__index"),
+ "t is on stack at 3"
);
t.ok(
- L.stack[1].ttistable() && L.stack[1].value.hash.get("__index"),
- "mt is on stack at 1"
+ L.stack[2].ttistable() && L.stack[2].value.hash.get("__index"),
+ "mt is on stack at 2"
);
t.comment("We manually set t's metatable to mt");
- L.stack[2].metatable = L.stack[1];
+ L.stack[3].metatable = L.stack[2];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -212,16 +212,16 @@ test('__newindex function in metatable', function (t) {
// 3 [4] RETURN 0 1
t.strictEqual(
- OC.OpCodes[L.stack[0].p.code[4].opcode],
+ OC.OpCodes[L.stack[1].p.code[4].opcode],
"OP_SETTABLE",
"Correct opcode marked as breakpoint"
);
t.comment("We set a breakpoint")
- L.stack[0].p.code[4].breakpoint = true;
+ L.stack[1].p.code[4].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
t.strictEqual(
@@ -232,20 +232,20 @@ test('__newindex function in metatable', function (t) {
t.comment("We unset the breakpoint and correct pcOff");
L.ci.pcOff--;
- L.stack[0].p.code[4].breakpoint = false;
+ L.stack[1].p.code[4].breakpoint = false;
t.ok(
- L.stack[2].ttistable() && !L.stack[2].value.hash.get("__newindex"),
- "t is on stack at 2"
+ L.stack[3].ttistable() && !L.stack[3].value.hash.get("__newindex"),
+ "t is on stack at 3"
);
t.ok(
- L.stack[1].ttistable() && L.stack[1].value.hash.get("__newindex"),
- "mt is on stack at 1"
+ L.stack[2].ttistable() && L.stack[2].value.hash.get("__newindex"),
+ "mt is on stack at 2"
);
t.comment("We manually set t's metatable to mt");
- L.stack[2].metatable = L.stack[1];
+ L.stack[3].metatable = L.stack[2];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -297,16 +297,16 @@ test('__index table in metatable', function (t) {
// 8 [9] RETURN 0 1
t.strictEqual(
- OC.OpCodes[L.stack[0].p.code[5].opcode],
+ OC.OpCodes[L.stack[1].p.code[5].opcode],
"OP_GETTABLE",
"Correct opcode marked as breakpoint"
);
t.comment("We set a breakpoint")
- L.stack[0].p.code[5].breakpoint = true;
+ L.stack[1].p.code[5].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
t.strictEqual(
@@ -317,20 +317,20 @@ test('__index table in metatable', function (t) {
t.comment("We unset the breakpoint and correct pcOff");
L.ci.pcOff--;
- L.stack[0].p.code[5].breakpoint = false;
+ L.stack[1].p.code[5].breakpoint = false;
t.ok(
- L.stack[3].ttistable() && !L.stack[3].value.hash.get("__index"),
- "t is on stack at 3"
+ L.stack[4].ttistable() && !L.stack[4].value.hash.get("__index"),
+ "t is on stack at 4"
);
t.ok(
- L.stack[2].ttistable() && L.stack[2].value.hash.get("__index"),
- "mt is on stack at 2"
+ L.stack[3].ttistable() && L.stack[3].value.hash.get("__index"),
+ "mt is on stack at 3"
);
t.comment("We manually set t's metatable to mt");
- L.stack[3].metatable = L.stack[2];
+ L.stack[4].metatable = L.stack[3];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -386,16 +386,16 @@ test('__newindex table in metatable', function (t) {
// 10 [15] RETURN 0 1
t.strictEqual(
- OC.OpCodes[L.stack[0].p.code[5].opcode],
+ OC.OpCodes[L.stack[1].p.code[5].opcode],
"OP_SETTABLE",
"Correct opcode marked as breakpoint"
);
t.comment("We set a breakpoint")
- L.stack[0].p.code[5].breakpoint = true;
+ L.stack[1].p.code[5].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
t.strictEqual(
@@ -406,20 +406,20 @@ test('__newindex table in metatable', function (t) {
t.comment("We unset the breakpoint and correct pcOff");
L.ci.pcOff--;
- L.stack[0].p.code[5].breakpoint = false;
+ L.stack[1].p.code[5].breakpoint = false;
t.ok(
- L.stack[3].ttistable() && !L.stack[3].value.hash.get("__newindex"),
- "t is on stack at 3"
+ L.stack[4].ttistable() && !L.stack[4].value.hash.get("__newindex"),
+ "t is on stack at 4"
);
t.ok(
- L.stack[2].ttistable() && L.stack[2].value.hash.get("__newindex"),
- "mt is on stack at 2"
+ L.stack[3].ttistable() && L.stack[3].value.hash.get("__newindex"),
+ "mt is on stack at 3"
);
t.comment("We manually set t's metatable to mt");
- L.stack[3].metatable = L.stack[2];
+ L.stack[4].metatable = L.stack[3];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -495,39 +495,39 @@ test('__index table with own metatable', function (t) {
// 2 [3] RETURN 2 2
// 3 [4] RETURN 0 1
- L.stack[0].p.code[5].breakpoint = true;
- L.stack[0].p.code[7].breakpoint = true;
- L.stack[0].p.code[8].breakpoint = true;
+ L.stack[1].p.code[5].breakpoint = true;
+ L.stack[1].p.code[7].breakpoint = true;
+ L.stack[1].p.code[8].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[5].breakpoint = false;
+ L.stack[1].p.code[5].breakpoint = false;
t.comment("We manually set mmt's metatable to mmmt");
- L.stack[2].metatable = L.stack[1];
+ L.stack[3].metatable = L.stack[2];
t.doesNotThrow(function () {
VM.luaV_execute(L);
}, "Second part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[7].breakpoint = false;
+ L.stack[1].p.code[7].breakpoint = false;
t.comment("We manually set mt's metatable to mmt");
- L.stack[3].metatable = L.stack[2];
+ L.stack[4].metatable = L.stack[3];
t.doesNotThrow(function () {
VM.luaV_execute(L);
}, "Third part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[8].breakpoint = false;
+ L.stack[1].p.code[8].breakpoint = false;
t.comment("We manually set t's metatable to mt");
- L.stack[4].metatable = L.stack[3];
+ L.stack[4].metatable = L.stack[4];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -600,39 +600,39 @@ test('__newindex table with own metatable', function (t) {
// 1 [5] SETUPVAL 2 0 ; up
// 2 [6] RETURN 0 1
- L.stack[0].p.code[5].breakpoint = true;
- L.stack[0].p.code[7].breakpoint = true;
- L.stack[0].p.code[8].breakpoint = true;
+ L.stack[1].p.code[5].breakpoint = true;
+ L.stack[1].p.code[7].breakpoint = true;
+ L.stack[1].p.code[8].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[5].breakpoint = false;
+ L.stack[1].p.code[5].breakpoint = false;
t.comment("We manually set mmt's metatable to mmmt");
- L.stack[2].metatable = L.stack[1];
+ L.stack[4].metatable = L.stack[3];
t.doesNotThrow(function () {
VM.luaV_execute(L);
}, "Second part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[7].breakpoint = false;
+ L.stack[1].p.code[7].breakpoint = false;
t.comment("We manually set mt's metatable to mmt");
- L.stack[3].metatable = L.stack[2];
+ L.stack[5].metatable = L.stack[4];
t.doesNotThrow(function () {
VM.luaV_execute(L);
}, "Third part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[8].breakpoint = false;
+ L.stack[1].p.code[8].breakpoint = false;
t.comment("We manually set t's metatable to mt");
- L.stack[4].metatable = L.stack[3];
+ L.stack[6].metatable = L.stack[5];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -779,17 +779,17 @@ test('binary __xxx functions in metatable', function (t) {
//
// ...
- L.stack[0].p.code[26].breakpoint = true;
+ L.stack[1].p.code[26].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[26].breakpoint = false;
+ L.stack[1].p.code[26].breakpoint = false;
t.comment("We manually set t's metatable to mt");
- L.stack[2].metatable = L.stack[1];
+ L.stack[3].metatable = L.stack[2];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -855,17 +855,17 @@ test('__eq', function (t) {
L = getState(luaCode);
}, "Bytecode parsed without errors");
- L.stack[0].p.code[5].breakpoint = true;
+ L.stack[1].p.code[5].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[5].breakpoint = false;
+ L.stack[1].p.code[5].breakpoint = false;
t.comment("We manually set t's metatable to mt");
- L.stack[2].metatable = L.stack[1];
+ L.stack[3].metatable = L.stack[2];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -918,17 +918,17 @@ test('__lt', function (t) {
L = getState(luaCode);
}, "Bytecode parsed without errors");
- L.stack[0].p.code[5].breakpoint = true;
+ L.stack[1].p.code[5].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[5].breakpoint = false;
+ L.stack[1].p.code[5].breakpoint = false;
t.comment("We manually set t's metatable to mt");
- L.stack[2].metatable = L.stack[1];
+ L.stack[3].metatable = L.stack[2];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -981,17 +981,17 @@ test('__le', function (t) {
L = getState(luaCode);
}, "Bytecode parsed without errors");
- L.stack[0].p.code[5].breakpoint = true;
+ L.stack[1].p.code[5].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[5].breakpoint = false;
+ L.stack[1].p.code[5].breakpoint = false;
t.comment("We manually set t's metatable to mt");
- L.stack[2].metatable = L.stack[1];
+ L.stack[3].metatable = L.stack[2];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -1044,17 +1044,17 @@ test('__le that uses __lt', function (t) {
L = getState(luaCode);
}, "Bytecode parsed without errors");
- L.stack[0].p.code[5].breakpoint = true;
+ L.stack[1].p.code[5].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[5].breakpoint = false;
+ L.stack[1].p.code[5].breakpoint = false;
t.comment("We manually set t's metatable to mt");
- L.stack[2].metatable = L.stack[1];
+ L.stack[3].metatable = L.stack[2];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -1110,17 +1110,17 @@ test('__unm, __bnot', function (t) {
L = getState(luaCode);
}, "Bytecode parsed without errors");
- L.stack[0].p.code[6].breakpoint = true;
+ L.stack[1].p.code[6].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[6].breakpoint = false;
+ L.stack[1].p.code[6].breakpoint = false;
t.comment("We manually set t's metatable to mt");
- L.stack[2].metatable = L.stack[1];
+ L.stack[3].metatable = L.stack[2];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -1175,17 +1175,17 @@ test('__len', function (t) {
L = getState(luaCode);
}, "Bytecode parsed without errors");
- L.stack[0].p.code[4].breakpoint = true;
+ L.stack[1].p.code[4].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[4].breakpoint = false;
+ L.stack[1].p.code[4].breakpoint = false;
t.comment("We manually set t's metatable to mt");
- L.stack[2].metatable = L.stack[1];
+ L.stack[3].metatable = L.stack[2];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -1236,17 +1236,17 @@ test('__concat', function (t) {
L = getState(luaCode);
}, "Bytecode parsed without errors");
- L.stack[0].p.code[6].breakpoint = true;
+ L.stack[1].p.code[6].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[6].breakpoint = false;
+ L.stack[1].p.code[6].breakpoint = false;
t.comment("We manually set t's metatable to mt");
- L.stack[2].metatable = L.stack[1];
+ L.stack[3].metatable = L.stack[2];
t.doesNotThrow(function () {
VM.luaV_execute(L);
@@ -1296,17 +1296,17 @@ test('__call', function (t) {
L = getState(luaCode);
}, "Bytecode parsed without errors");
- L.stack[0].p.code[7].breakpoint = true;
+ L.stack[1].p.code[7].breakpoint = true;
t.doesNotThrow(function () {
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "First part of the program executed without errors");
L.ci.pcOff--;
- L.stack[0].p.code[7].breakpoint = false;
+ L.stack[1].p.code[7].breakpoint = false;
t.comment("We manually set t's metatable to mt");
- L.stack[2].metatable = L.stack[1];
+ L.stack[3].metatable = L.stack[2];
t.doesNotThrow(function () {
VM.luaV_execute(L);
diff --git a/tests/lvm.js b/tests/lvm.js
index ac62f20..273002a 100644
--- a/tests/lvm.js
+++ b/tests/lvm.js
@@ -6,7 +6,7 @@ const beautify = require('js-beautify').js_beautify;
const lua_State = require("../src/lstate.js").lua_State;
const VM = require("../src/lvm.js");
-const ldo = require("../src/ldo.js");
+const lapi = require("../src/lapi.js");
const Table = require("../src/lobject.js").Table;;
const getState = require("./tests.js").getState;
@@ -23,7 +23,7 @@ test('LOADK, RETURN', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -47,7 +47,7 @@ test('MOV', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -70,7 +70,7 @@ test('Binary op', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -94,7 +94,7 @@ test('Unary op, LOADBOOL', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -117,7 +117,7 @@ test('NEWTABLE', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.ok(
@@ -144,7 +144,7 @@ test('CALL', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -176,7 +176,7 @@ test('Multiple return', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -202,7 +202,7 @@ test('TAILCALL', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -228,7 +228,7 @@ test('VARARG', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -252,7 +252,7 @@ test('LE, JMP', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -276,7 +276,7 @@ test('LT', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -300,7 +300,7 @@ test('EQ', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -325,7 +325,7 @@ test('TESTSET (and)', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -350,7 +350,7 @@ test('TESTSET (or)', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -379,7 +379,7 @@ test('TEST (true)', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -408,7 +408,7 @@ test('TEST (false)', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -436,7 +436,7 @@ test('FORPREP, FORLOOP (int)', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -463,7 +463,7 @@ test('FORPREP, FORLOOP (float)', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -490,7 +490,7 @@ test('SETTABLE, GETTABLE', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -526,7 +526,7 @@ test('SETUPVAL, GETUPVAL', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -553,7 +553,7 @@ test('SETTABUP, GETTABUP', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -588,7 +588,7 @@ test('SELF', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -612,7 +612,7 @@ test('SETLIST', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -640,7 +640,7 @@ test('Variable SETLIST', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -664,7 +664,7 @@ test('Long SETLIST', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.deepEqual(
@@ -688,7 +688,7 @@ test('Long SETLIST', function (t) {
//
// // t.doesNotThrow(function () {
// L = getState(luaCode);
-// ldo.luaD_call(L, 0, -1);
+// lapi.lua_call(L, 0, -1);
// // }, "Program executed without errors");
//
// t.deepEqual(
@@ -728,7 +728,7 @@ test('TFORCALL, TFORLOOP', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -754,7 +754,7 @@ test('LEN', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
@@ -788,7 +788,7 @@ test('CONCAT', function (t) {
t.doesNotThrow(function () {
L = getState(luaCode);
- ldo.luaD_call(L, 0, -1);
+ lapi.lua_call(L, 0, -1);
}, "Program executed without errors");
t.strictEqual(
diff --git a/tests/tests.js b/tests/tests.js
index 02dac80..5a1b023 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -7,7 +7,7 @@ const tmp = require('tmp');
const DataView = require('buffer-dataview');
const BytecodeParser = require("../src/lundump.js");
-const lua_State = require("../src/lstate.js").lua_State;
+const lauxlib = require("../src/lauxlib.js");
const VM = require("../src/lvm.js");
const toByteCode = function (luaCode) {
@@ -34,10 +34,12 @@ const getState = function(luaCode) {
dv = bc.dataView,
bcl = bc.bclist;
+ let L = lauxlib.luaL_newstate();
+
let p = new BytecodeParser(dv);
- let cl = p.luaU_undump();
+ let cl = p.luaU_undump(L);
- return new lua_State(cl);
+ return L;
};
module.exports = {