summaryrefslogtreecommitdiff
path: root/tests/ldblib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-11 12:25:30 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-11 13:28:34 +0200
commitea8b3d63af92085d1563c670968152c7dbbb7642 (patch)
tree1502894844bd04c368bc4c825772d54720db693a /tests/ldblib.js
parent40cb52853ce7a0715761504940b07d77bacf5ec4 (diff)
downloadfengari-ea8b3d63af92085d1563c670968152c7dbbb7642.tar.gz
fengari-ea8b3d63af92085d1563c670968152c7dbbb7642.tar.bz2
fengari-ea8b3d63af92085d1563c670968152c7dbbb7642.zip
debug.getlocal
Diffstat (limited to 'tests/ldblib.js')
-rw-r--r--tests/ldblib.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/ldblib.js b/tests/ldblib.js
index 5e5c298..579912d 100644
--- a/tests/ldblib.js
+++ b/tests/ldblib.js
@@ -1,7 +1,55 @@
"use strict";
+const test = require('tape');
+
const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const lua = require('../src/lua.js');
const linit = require('../src/linit.js');
+test('debug.getlocal', function (t) {
+ let luaCode = `
+ local alocal = "alocal"
+ local another = "another"
+
+ local result = ""
+
+ local l = function()
+ local infunction = "infunction"
+ local anotherin = "anotherin"
+ result = table.concat(table.pack(debug.getlocal(2, 1)), " ")
+ .. table.concat(table.pack(debug.getlocal(2, 2)), " ")
+ .. table.concat(table.pack(debug.getlocal(1, 1)), " ")
+ .. table.concat(table.pack(debug.getlocal(1, 2)), " ")
+ end
+
+ l()
+
+ return result
+ `, L;
+
+ t.plan(3);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tojsstring(L, -1),
+ "alocal alocalanother anotherinfunction infunctionanotherin anotherin",
+ "Correct element(s) on the stack"
+ );
+
+});