summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib-hello.js.mod8
-rw-r--r--tests/loadlib.js32
2 files changed, 40 insertions, 0 deletions
diff --git a/tests/lib-hello.js.mod b/tests/lib-hello.js.mod
new file mode 100644
index 0000000..d4c02e1
--- /dev/null
+++ b/tests/lib-hello.js.mod
@@ -0,0 +1,8 @@
+const lua = require('../src/lua.js');
+
+module.exports = {
+ "hello": function(L) {
+ lua.lua_pushliteral(L, "hello from js lib");
+ return 1;
+ }
+};
diff --git a/tests/loadlib.js b/tests/loadlib.js
index 933991c..b840bf5 100644
--- a/tests/loadlib.js
+++ b/tests/loadlib.js
@@ -66,3 +66,35 @@ test('require a file', function (t) {
);
});
+
+
+test('package.loadlib', function (t) {
+ let luaCode = `
+ return package.loadlib('./tests/lib-hello.js.mod', 'hello')()
+ `, L;
+
+ t.plan(3);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ lauxlib.luaL_openlibs(L);
+
+ lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lua.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+
+ t.strictEqual(
+ lua.lua_tojsstring(L, -1),
+ "hello from js lib",
+ "Correct element(s) on the stack"
+ );
+
+});