From 43c97cbc2904d2bac87c61515bbc16c38a091548 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 14 Apr 2017 08:59:00 +0200 Subject: hooks --- tests/ldblib.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests') diff --git a/tests/ldblib.js b/tests/ldblib.js index 7dd35c3..8d00952 100644 --- a/tests/ldblib.js +++ b/tests/ldblib.js @@ -7,6 +7,50 @@ const lauxlib = require("../src/lauxlib.js"); const lua = require('../src/lua.js'); const linit = require('../src/linit.js'); +test('debug.sethook', function (t) { + let luaCode = ` + result = "" + + debug.sethook(function (event) + result = result .. event .. " " + end, "crl", 1) + + local l = function() end + + l() + l() + 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), + "return count line count line count line count return count line count line count return count line count line count return count line count line ", + "Correct element(s) on the stack" + ); + +}); + + test('debug.getlocal', function (t) { let luaCode = ` local alocal = "alocal" -- cgit v1.2.3-70-g09d2