mirror of https://github.com/rusefi/lua.git
using 'luaL_findtable' to manage hook table
This commit is contained in:
parent
67feed49f1
commit
c2e3cc4c89
23
ldblib.c
23
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
|
** Interface from Lua to its debug API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -18,6 +18,9 @@
|
||||||
#include "lualib.h"
|
#include "lualib.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define HOOKKEY "_HKEY"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int db_getregistry (lua_State *L) {
|
static int db_getregistry (lua_State *L) {
|
||||||
lua_pushvalue(L, LUA_REGISTRYINDEX);
|
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 void hookf (lua_State *L, lua_Debug *ar) {
|
||||||
static const char *const hooknames[] =
|
static const char *const hooknames[] =
|
||||||
{"call", "return", "line", "count", "tail call"};
|
{"call", "return", "line", "count", "tail call"};
|
||||||
lua_pushlightuserdata(L, (void *)&KEY_HOOK);
|
gethooktable(L);
|
||||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
|
||||||
lua_pushlightuserdata(L, L);
|
lua_pushlightuserdata(L, L);
|
||||||
lua_rawget(L, -2);
|
lua_rawget(L, -2);
|
||||||
if (lua_isfunction(L, -1)) {
|
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) {
|
static int db_sethook (lua_State *L) {
|
||||||
int arg, mask, count;
|
int arg, mask, count;
|
||||||
lua_Hook func;
|
lua_Hook func;
|
||||||
|
|
Loading…
Reference in New Issue