summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lapi.js48
-rw-r--r--tests/tests.js6
2 files changed, 42 insertions, 12 deletions
diff --git a/tests/lapi.js b/tests/lapi.js
index fa1fb59..ff76920 100644
--- a/tests/lapi.js
+++ b/tests/lapi.js
@@ -1,17 +1,19 @@
/*jshint esversion: 6 */
"use strict";
-const test = require('tape');
-const beautify = require('js-beautify').js_beautify;
+const test = require('tape');
+const beautify = require('js-beautify').js_beautify;
-const getState = require("./tests.js").getState;
+const tests = require("./tests.js");
+const getState = tests.getState;
+const toByteCode = tests.toByteCode;
-const VM = require("../src/lvm.js");
-const ldo = require("../src/ldo.js");
-const lapi = require("../src/lapi.js");
-const lauxlib = require("../src/lauxlib.js");
-const lua = require('../src/lua.js');
-const CT = lua.constant_types;
+const VM = require("../src/lvm.js");
+const ldo = require("../src/ldo.js");
+const lapi = require("../src/lapi.js");
+const lauxlib = require("../src/lauxlib.js");
+const lua = require('../src/lua.js');
+const CT = lua.constant_types;
test('luaL_newstate, lua_pushnil, lua_gettop, luaL_typename', function (t) {
let L;
@@ -378,4 +380,32 @@ test('lua_pop', function (t) {
"hello",
"Correct element(s) on the stack"
);
+});
+
+
+test('lua_load and lua_call it', function (t) {
+ let luaCode = `
+ local a = "JS > Lua > JS \o/"
+ return a
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ let bc = toByteCode(luaCode).dataView;
+
+ L = lauxlib.luaL_newstate();
+
+ lapi.lua_load(L, bc, "test-lua_load")
+
+ lapi.lua_call(L, 0, 1);
+
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -1),
+ "JS > Lua > JS \o/",
+ "Correct element(s) on the stack"
+ );
}); \ No newline at end of file
diff --git a/tests/tests.js b/tests/tests.js
index 5a1b023..a9f8730 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -42,6 +42,6 @@ const getState = function(luaCode) {
return L;
};
-module.exports = {
- getState: getState
-} \ No newline at end of file
+
+module.exports.getState = getState;
+module.exports.toByteCode = toByteCode; \ No newline at end of file