commit c2e3cc4c89ccd058c84e1d14499c8b26d99c5b3d
parent 67feed49f189e8e6318a5ef63461e10e2d174a82
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 10 Jan 2011 13:50:55 -0200
using 'luaL_findtable' to manage hook table
Diffstat:
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/ldblib.c b/ldblib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldblib.c,v 1.126 2010/11/16 18:01:28 roberto Exp roberto $
+** $Id: ldblib.c,v 1.127 2010/12/20 17:24:15 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -18,6 +18,9 @@
#include "lualib.h"
+#define HOOKKEY "_HKEY"
+
+
static int db_getregistry (lua_State *L) {
lua_pushvalue(L, LUA_REGISTRYINDEX);
@@ -250,14 +253,13 @@ static int db_upvaluejoin (lua_State *L) {
}
-static const char KEY_HOOK = 'h';
+#define gethooktable(L) luaL_findtable(L, LUA_REGISTRYINDEX, HOOKKEY);
static void hookf (lua_State *L, lua_Debug *ar) {
static const char *const hooknames[] =
{"call", "return", "line", "count", "tail call"};
- lua_pushlightuserdata(L, (void *)&KEY_HOOK);
- lua_rawget(L, LUA_REGISTRYINDEX);
+ gethooktable(L);
lua_pushlightuserdata(L, L);
lua_rawget(L, -2);
if (lua_isfunction(L, -1)) {
@@ -291,19 +293,6 @@ static char *unmakemask (int mask, char *smask) {
}
-static void gethooktable (lua_State *L) {
- lua_pushlightuserdata(L, (void *)&KEY_HOOK);
- lua_rawget(L, LUA_REGISTRYINDEX);
- if (!lua_istable(L, -1)) {
- lua_pop(L, 1);
- lua_createtable(L, 0, 1);
- lua_pushlightuserdata(L, (void *)&KEY_HOOK);
- lua_pushvalue(L, -2);
- lua_rawset(L, LUA_REGISTRYINDEX);
- }
-}
-
-
static int db_sethook (lua_State *L) {
int arg, mask, count;
lua_Hook func;