aboutsummaryrefslogtreecommitdiff
path: root/tests/lapi.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lapi.js')
-rw-r--r--tests/lapi.js63
1 files changed, 63 insertions, 0 deletions
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