From f556eada483134f5dc433e6bd4510047e4953649 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 16 Feb 2017 14:49:25 +0100 Subject: lua_pushcclosure, lua_pushcfunction --- tests/lapi.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'tests/lapi.js') diff --git a/tests/lapi.js b/tests/lapi.js index 875a89c..ad39fe1 100644 --- a/tests/lapi.js +++ b/tests/lapi.js @@ -215,4 +215,67 @@ test('lua_pushvalue', function (t) { "hello", "top is correct" ); +}); + + +test('lua_pushcclosure', function (t) { + let L; + + t.plan(3); + + t.doesNotThrow(function () { + + let fn = function(L) { + return 0; + }; + + L = lauxlib.luaL_newstate(); + + lapi.lua_pushstring(L, "a value associated to the C closure"); + lapi.lua_pushcclosure(L, fn, 1); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_gettop(L), + 1, + "top is correct" + ); + + t.strictEqual( + lauxlib.luaL_typename(L, lapi.lua_gettop(L)), + "function", + "Correct element(s) on the stack" + ); +}); + + +test('lua_pushcfunction', function (t) { + let L; + + t.plan(3); + + t.doesNotThrow(function () { + + let fn = function(L) { + return 0; + }; + + L = lauxlib.luaL_newstate(); + + lapi.lua_pushcfunction(L, fn); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_gettop(L), + 1, + "top is correct" + ); + + t.strictEqual( + lauxlib.luaL_typename(L, lapi.lua_gettop(L)), + "function", + "Correct element(s) on the stack" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf