From a8e82fc01f2558550289f76f55c917039296ec11 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 17 Feb 2017 11:33:23 +0100 Subject: lua_load (bytecode only), lua_call(k) --- tests/lapi.js | 48 +++++++++++++++++++++++++++++++++++++++--------- tests/tests.js | 6 +++--- 2 files changed, 42 insertions(+), 12 deletions(-) (limited to 'tests') 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 -- cgit v1.2.3-70-g09d2