Fix gethook() return values and sethook() behavior when called from hook function.

This commit is contained in:
James Roseborough
2009-09-06 14:49:45 +00:00
parent 1c5e2352f9
commit 9cad7f1001
3 changed files with 19 additions and 13 deletions

View File

@@ -340,6 +340,7 @@ and LuaForge:
Main changes by version: Main changes by version:
<table cellspacing="10"><tr><td><table cellspacing="4"> <table cellspacing="10"><tr><td><table cellspacing="4">
<tr><td>&nbsp;&nbsp;<b>1.0</b></td><td>Initial publicly supported release.</td></tr> <tr valign="top"><td>&nbsp;&nbsp;<b>1.0</b></td><td>Initial publicly supported release.</td></tr>
<tr><td>&nbsp;&nbsp;<b>1.0.1</b></td><td>Fix arg check and behavior of xpcall() to leave stack intact.</td></tr> <tr valign="top"><td>&nbsp;&nbsp;<b>1.0.1</b></td><td>Fix arg check and behavior of xpcall() to leave stack intact.
Fix debug.sethook() to when called from hook function. Fix debug.gethook() return values.</td></tr>
</table></td></tr></table> </table></td></tr></table>

View File

@@ -155,12 +155,16 @@ public class DebugLib extends LFunction {
} }
protected int gethook(LuaState vm) { protected int gethook(LuaState vm) {
LuaState threadVm = vm; LuaState threadVm = optthreadvm(vm, 1);
if ( vm.gettop() >= 2 ) LValue hook = threadVm.gethook();
threadVm = vm.checkthread(1).vm; int mask = threadVm.gethookmask();
vm.pushlvalue(threadVm.gethook()); int count = threadVm.gethookcount();
vm.pushinteger(threadVm.gethookmask()); vm.pushlvalue(hook!=null? hook: LNil.NIL);
vm.pushinteger(threadVm.gethookcount()); vm.pushstring(""
+((mask&LuaState.LUA_MASKCALL)!=0? "c": "")
+((mask&LuaState.LUA_MASKRET) !=0? "r": "")
+((mask&LuaState.LUA_MASKLINE)!=0? "l": ""));
vm.pushinteger(count);
return 3; return 3;
} }

View File

@@ -105,7 +105,7 @@ public class LuaState extends Lua {
// debug hooks - these MUST NOT be initialized, // debug hooks - these MUST NOT be initialized,
// so that a later obfuscation step can decide to remove them. // so that a later obfuscation step can decide to remove them.
private boolean hooksenabled; private boolean hooksenabled,inhook;
private int hookmask; private int hookmask;
private int hookcount; private int hookcount;
private LFunction hookfunc; private LFunction hookfunc;
@@ -2503,14 +2503,15 @@ public class LuaState extends Lua {
} }
private void debugCallHook(int mask, int line) { private void debugCallHook(int mask, int line) {
int oldmask = hookmask; if ( inhook )
return;
int oldtop = top; int oldtop = top;
int oldbase = base; int oldbase = base;
int oldcc = cc; int oldcc = cc;
int oldnresults = nresults; int oldnresults = nresults;
int beyond = (cc>=0? base+calls[cc].closure.p.maxstacksize: top); int beyond = (cc>=0? base+calls[cc].closure.p.maxstacksize: top);
try { try {
hookmask = 0; inhook = true;
// adjust base and top to beyond call frame // adjust base and top to beyond call frame
top = base = beyond; top = base = beyond;
@@ -2541,7 +2542,7 @@ public class LuaState extends Lua {
base = oldbase; base = oldbase;
top = oldtop; top = oldtop;
nresults = oldnresults; nresults = oldnresults;
hookmask = oldmask ; inhook = false;
} }
} }
} }