summaryrefslogtreecommitdiff
path: root/tests/lapi.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-16 14:49:25 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-16 14:49:25 +0100
commitf556eada483134f5dc433e6bd4510047e4953649 (patch)
treed3e0679859bb19e0694972f8970078f6c58d0fbc /tests/lapi.js
parent8f913dd74957ef18e144f15b78c3e55893744218 (diff)
downloadfengari-f556eada483134f5dc433e6bd4510047e4953649.tar.gz
fengari-f556eada483134f5dc433e6bd4510047e4953649.tar.bz2
fengari-f556eada483134f5dc433e6bd4510047e4953649.zip
lua_pushcclosure, lua_pushcfunction
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