From 5131a5ab1f471655d6398748b1eaa9abd47c14da Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 17 Feb 2017 14:36:33 +0100 Subject: lua_pcall --- tests/lapi.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'tests') diff --git a/tests/lapi.js b/tests/lapi.js index 298328c..8a1db31 100644 --- a/tests/lapi.js +++ b/tests/lapi.js @@ -353,6 +353,63 @@ test('lua_call (calling a JS closure)', function (t) { }); +test('lua_pcall (calling a light JS function)', function (t) { + let L; + + t.plan(3); + + t.doesNotThrow(function () { + + let fn = function(L) { + lapi.lua_pushstring(L, "hello"); + return 1; + }; + + L = lauxlib.luaL_newstate(); + + lapi.lua_pushjsfunction(L, fn); + + lapi.lua_pcall(L, 0, 1, 0); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_gettop(L), + 1, + "top is correct" + ); + + t.strictEqual( + lapi.lua_tostring(L, -1), + "hello", + "top is correct" + ); +}); + + +test('lua_pcall that breaks', function (t) { + let L; + + t.plan(1); + + t.doesNotThrow(function () { + + let fn = function(L) { + return undefined_value; + }; + + L = lauxlib.luaL_newstate(); + + lapi.lua_pushjsfunction(L, fn); + + lapi.lua_pcall(L, 0, 1, 0); + + }, "JS Lua program ran without error"); + + console.log(L.stack[L.top - 1].value); +}); + + test('lua_pop', function (t) { let L; -- cgit v1.2.3-70-g09d2