From cdf8cf1806ca793c47095b69382b2dd733899af7 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 17 Feb 2017 12:25:28 +0100 Subject: lua can read globals set by js --- tests/lapi.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/lapi.js') diff --git a/tests/lapi.js b/tests/lapi.js index ff76920..419e5c4 100644 --- a/tests/lapi.js +++ b/tests/lapi.js @@ -408,4 +408,34 @@ test('lua_load and lua_call it', function (t) { "JS > Lua > JS \o/", "Correct element(s) on the stack" ); +}); + + +test('lua script reads js upvalues', function (t) { + let luaCode = ` + return js .. " world" + `, 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_pushstring(L, "hello"); + lapi.lua_setglobal(L, "js"); + + lapi.lua_call(L, 0, 1); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_tostring(L, -1), + "hello world", + "Correct element(s) on the stack" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf