aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-17 14:36:33 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-17 14:53:03 +0100
commit5131a5ab1f471655d6398748b1eaa9abd47c14da (patch)
treebf8d1b5102a59898ed520d1afa023301f6483607 /tests
parent78b48979b8dbd367043c39fb21007ab4f54cd0a4 (diff)
downloadfengari-5131a5ab1f471655d6398748b1eaa9abd47c14da.tar.gz
fengari-5131a5ab1f471655d6398748b1eaa9abd47c14da.tar.bz2
fengari-5131a5ab1f471655d6398748b1eaa9abd47c14da.zip
lua_pcall
Diffstat (limited to 'tests')
-rw-r--r--tests/lapi.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/lapi.js b/tests/lapi.js
index 298328c..8a1db31 100644
--- a/tests/lapi.js
+++ b/tests/lapi.js
@@ -353,6 +353,63 @@ test('lua_call (calling a JS closure)', function (t) {
});
+test('lua_pcall (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_pushjsfunction(L, fn);
+
+ lapi.lua_pcall(L, 0, 1, 0);
+
+ }, "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"
+ );
+});
+
+
+test('lua_pcall that breaks', function (t) {
+ let L;
+
+ t.plan(1);
+
+ t.doesNotThrow(function () {
+
+ let fn = function(L) {
+ return undefined_value;
+ };
+
+ L = lauxlib.luaL_newstate();
+
+ lapi.lua_pushjsfunction(L, fn);
+
+ lapi.lua_pcall(L, 0, 1, 0);
+
+ }, "JS Lua program ran without error");
+
+ console.log(L.stack[L.top - 1].value);
+});
+
+
test('lua_pop', function (t) {
let L;