diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-17 11:33:23 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-17 11:34:49 +0100 |
commit | a8e82fc01f2558550289f76f55c917039296ec11 (patch) | |
tree | b226aeca2d8445ee8bcfd644477992a0635e46e0 /tests/lapi.js | |
parent | 4a03542f6ebc8c6d4ed624bc0d30f5a7148a279b (diff) | |
download | fengari-a8e82fc01f2558550289f76f55c917039296ec11.tar.gz fengari-a8e82fc01f2558550289f76f55c917039296ec11.tar.bz2 fengari-a8e82fc01f2558550289f76f55c917039296ec11.zip |
lua_load (bytecode only), lua_call(k)
Diffstat (limited to 'tests/lapi.js')
-rw-r--r-- | tests/lapi.js | 48 |
1 files changed, 39 insertions, 9 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 |