summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ldblib.js25
-rw-r--r--src/ldebug.js17
2 files changed, 41 insertions, 1 deletions
diff --git a/src/ldblib.js b/src/ldblib.js
index 81f27fb..5c78724 100644
--- a/src/ldblib.js
+++ b/src/ldblib.js
@@ -308,7 +308,6 @@ const unmakemask = function(mask, smask) {
if (mask & lua.LUA_MASKCALL) smask[i++] = char["c"];
if (mask & lua.LUA_MASKRET) smask[i++] = char["r"];
if (mask & lua.LUA_MASKLINE) smask[i++] = char["l"];
- smask[i] = 0;
return smask;
};
@@ -344,6 +343,29 @@ const db_sethook = function(L) {
return 0;
};
+const db_gethook = function(L) {
+ let thread = getthread(L);
+ let L1 = thread.thread;
+ let arg = thread.arg;
+ let buff = [];
+ let mask = ldebug.lua_gethookmask(L1);
+ let hook = ldebug.lua_gethook(L1);
+ if (hook === null) /* no hook? */
+ lapi.lua_pushnil(L);
+ else if (hook !== hookf) /* external hook? */
+ lapi.lua_pushliteral(L, "external hook");
+ else { /* hook table must exist */
+ lapi.lua_rawgetp(L, lua.LUA_REGISTRYINDEX, HOOKKEY);
+ checkstack(L, L1, 1);
+ lapi.lua_pushthread(L1); lapi.lua_xmove(L1, L, 1);
+ lapi.lua_rawget(L, -2); /* 1st result = hooktable[L1] */
+ lapi.lua_remove(L, -2); /* remove hook table */
+ }
+ lapi.lua_pushstring(L, unmakemask(mask, buff)); /* 2nd result = mask */
+ lapi.lua_pushinteger(L, ldebug.lua_gethookcount(L1)); /* 3rd result = count */
+ return 3;
+};
+
const db_traceback = function(L) {
let thread = getthread(L);
let L1 = thread.thread;
@@ -359,6 +381,7 @@ const db_traceback = function(L) {
};
const dblib = {
+ "gethook": db_gethook,
"getinfo": db_getinfo,
"getlocal": db_getlocal,
"getmetatable": db_getmetatable,
diff --git a/src/ldebug.js b/src/ldebug.js
index a73b7f7..0a0e22c 100644
--- a/src/ldebug.js
+++ b/src/ldebug.js
@@ -51,6 +51,20 @@ const lua_sethook = function(L, func, mask, count) {
L.hookmask = mask;
};
+const lua_gethook = function(L) {
+ return L.hook;
+};
+
+
+const lua_gethookmask = function(L) {
+ return L.hookmask;
+};
+
+
+const lua_gethookcount = function(L) {
+ return L.basehookcount;
+};
+
const lua_getstack = function(L, level, ar) {
let ci;
let status;
@@ -633,6 +647,9 @@ module.exports.luaG_runerror = luaG_runerror;
module.exports.luaG_tointerror = luaG_tointerror;
module.exports.luaG_traceexec = luaG_traceexec;
module.exports.luaG_typeerror = luaG_typeerror;
+module.exports.lua_gethook = lua_gethook;
+module.exports.lua_gethookcount = lua_gethookcount;
+module.exports.lua_gethookmask = lua_gethookmask;
module.exports.lua_getinfo = lua_getinfo;
module.exports.lua_getlocal = lua_getlocal;
module.exports.lua_getstack = lua_getstack;