From 62cb8279094fd137ce2382fe99592ef0aae0f557 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 16 Feb 2017 16:04:03 +0100 Subject: lua_call --- tests/lapi.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests/lapi.js') diff --git a/tests/lapi.js b/tests/lapi.js index ad39fe1..c0f1cdc 100644 --- a/tests/lapi.js +++ b/tests/lapi.js @@ -278,4 +278,38 @@ test('lua_pushcfunction', function (t) { "function", "Correct element(s) on the stack" ); +}); + + +test('lua_call (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_pushcfunction(L, fn); + + lapi.lua_call(L, 0, 1); + + }, "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" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf