1
0
mirror of https://github.com/lua/lua.git synced 2025-01-28 06:03:00 +08:00

better tests (assertions) for debug hooks

This commit is contained in:
Roberto Ierusalimschy 2002-06-18 14:42:52 -03:00
parent a44f37513b
commit eec0905173
3 changed files with 14 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.58 2002/06/18 15:17:58 roberto Exp roberto $
** $Id: ldblib.c,v 1.59 2002/06/18 17:10:43 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@ -126,12 +126,17 @@ static void hookf (lua_State *L, void *key) {
static void callf (lua_State *L, lua_Debug *ar) {
lua_pushstring(L, ar->event);
lua_assert(lua_getinfo(L, "lS", ar) && ar->currentline == -1);
hookf(L, (void *)&KEY_CALLHOOK);
}
static void linef (lua_State *L, lua_Debug *ar) {
lua_pushnumber(L, ar->currentline);
lua_assert((ar->currentline = ar->linedefined = -1,
lua_getinfo(L, "lS", ar) &&
ar->currentline == lua_tonumber(L, -1) &&
ar->linedefined >= 0));
hookf(L, (void *)&KEY_LINEHOOK);
}

5
ldo.c
View File

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 1.180 2002/06/18 15:19:27 roberto Exp roberto $
** $Id: ldo.c,v 1.181 2002/06/18 17:10:43 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -138,6 +138,7 @@ static void luaD_openstack (lua_State *L, StkId pos) {
static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) {
ptrdiff_t top = savestack(L, L->top);
ptrdiff_t ci_top = savestack(L, L->ci->top);
ar->i_ci = L->ci - L->base_ci;
luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
L->ci->top = L->top + LUA_MINSTACK;
L->allowhooks = 0; /* cannot call hooks inside a hook */
@ -155,7 +156,6 @@ void luaD_lineHook (lua_State *L, int line) {
if (L->allowhooks) {
lua_Debug ar;
ar.event = "line";
ar.i_ci = L->ci - L->base_ci;
ar.currentline = line;
dohook(L, &ar, L->linehook);
}
@ -166,7 +166,6 @@ static void luaD_callHook (lua_State *L, lua_Hook callhook, const char *event) {
if (L->allowhooks) {
lua_Debug ar;
ar.event = event;
ar.i_ci = L->ci - L->base_ci;
L->ci->pc = NULL; /* function is not active */
L->ci->top = L->ci->base; /* `top' may not have a valid value yet */
dohook(L, &ar, callhook);

View File

@ -1,5 +1,5 @@
/*
** $Id: lualib.h,v 1.22 2002/04/09 20:19:06 roberto Exp roberto $
** $Id: lualib.h,v 1.23 2002/06/05 17:24:04 roberto Exp roberto $
** Lua standard libraries
** See Copyright Notice in lua.h
*/
@ -38,4 +38,9 @@ LUALIB_API int lua_mathlibopen (lua_State *L);
LUALIB_API int lua_dblibopen (lua_State *L);
/* to help testing the libraries */
#ifndef lua_assert
#define lua_assert(c) /* empty */
#endif
#endif