From 3d667b50989e31d18af0c235e28b68055adf62ff Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 14 Apr 2017 11:48:23 +0200 Subject: debug.gethook --- tests/ldblib.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'tests') diff --git a/tests/ldblib.js b/tests/ldblib.js index 8c3ad7f..6587228 100644 --- a/tests/ldblib.js +++ b/tests/ldblib.js @@ -51,6 +51,62 @@ test('debug.sethook', function (t) { }); +test('debug.gethook', function (t) { + let luaCode = ` + local result = "" + + debug.sethook(function (event) + result = result .. event .. " " + end, "crl", 1) + + local l = function() end + + l() + l() + l() + + return debug.gethook() + `, L; + + t.plan(5); + + 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.deepEqual( + lapi.lua_typename(L, lapi.lua_type(L, -3)), + lua.to_luastring("function"), + "Correct element(s) on the stack" + ); + + t.deepEqual( + lapi.lua_tojsstring(L, -2), + "crl", + "Correct element(s) on the stack" + ); + + t.deepEqual( + lapi.lua_tointeger(L, -1), + 1, + "Correct element(s) on the stack" + ); + +}); + + test('debug.getlocal', function (t) { let luaCode = ` local alocal = "alocal" -- cgit v1.2.3-54-g00ecf