aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ldo.js16
-rw-r--r--tests/ldblib.js2
2 files changed, 16 insertions, 2 deletions
diff --git a/src/ldo.js b/src/ldo.js
index ed1213e..426422a 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -9,6 +9,7 @@ const ldebug = require('./ldebug.js');
const lfunc = require('./lfunc.js');
const llimit = require('./llimit.js');
const lobject = require('./lobject.js');
+const lopcodes= require('./lopcodes.js');
const lparser = require('./lparser.js');
const lstate = require('./lstate.js');
const lstring = require('./lstring.js');
@@ -173,7 +174,8 @@ const luaD_precall = function(L, off, nresults) {
ci.l_code = p.code;
ci.l_savedpc = 0;
ci.callstatus = lstate.CIST_LUA;
-
+ if (L.hookmask & defs.LUA_MASKCALL)
+ callhook(L, ci);
return false;
}
default:
@@ -272,6 +274,18 @@ const luaD_hook = function(L, event, line) {
}
};
+const callhook = function(L, ci) {
+ let hook = defs.LUA_HOOKCALL;
+ ci.l_savedpc++; /* hooks assume 'pc' is already incremented */
+ if ((ci.previous.callstatus & lstate.CIST_LUA) &&
+ ci.previous.l_code[ci.previous.l_savedpc - 1].opcode == lopcodes.OpCodesI.OP_TAILCALL) {
+ ci.callstatus |= lstate.CIST_TAIL;
+ hook = defs.LUA_HOOKTAILCALL;
+ }
+ luaD_hook(L, hook, -1);
+ ci.l_savedpc--; /* correct 'pc' */
+};
+
const adjust_varargs = function(L, p, actual) {
let nfixargs = p.numparams;
/* move fixed parameters to final position */
diff --git a/tests/ldblib.js b/tests/ldblib.js
index 82d40c2..7f39c09 100644
--- a/tests/ldblib.js
+++ b/tests/ldblib.js
@@ -44,7 +44,7 @@ test('debug.sethook', function (t) {
t.strictEqual(
lua.lua_tojsstring(L, -1),
- "return count line count line count line count line return count line count line count line return count line count line count line return count line ",
+ "return count line count line count line call count line return count line count line call count line return count line count line call count line return count line ",
"Correct element(s) on the stack"
);