From 9704ff4cb14f34077062447d15196d32ace23e95 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 20 Mar 1996 15:44:02 -0300 Subject: hook variables are global, no more "lua_set...hook" functions. --- luadebug.h | 6 +++--- manual.tex | 17 ++++++++--------- opcode.c | 42 ++++++++++++------------------------------ 3 files changed, 23 insertions(+), 42 deletions(-) diff --git a/luadebug.h b/luadebug.h index 157d1402..0f27d695 100644 --- a/luadebug.h +++ b/luadebug.h @@ -2,7 +2,7 @@ ** LUA - Linguagem para Usuarios de Aplicacao ** Grupo de Tecnologia em Computacao Grafica ** TeCGraf - PUC-Rio -** $Id: luadebug.h,v 1.4 1996/02/07 18:10:27 roberto Exp roberto $ +** $Id: luadebug.h,v 1.5 1996/02/08 17:03:20 roberto Exp roberto $ */ @@ -20,12 +20,12 @@ lua_Function lua_stackedfunction (int level); void lua_funcinfo (lua_Object func, char **filename, int *linedefined); int lua_currentline (lua_Function func); char *lua_getobjname (lua_Object o, char **name); -lua_LHFunction lua_setlinehook (lua_LHFunction hook); -lua_CHFunction lua_setcallhook (lua_CHFunction hook); lua_Object lua_getlocal (lua_Function func, int local_number, char **name); int lua_setlocal (lua_Function func, int local_number); +extern lua_LHFunction lua_linehook; +extern lua_CHFunction lua_callhook; extern int lua_debug; #endif diff --git a/manual.tex b/manual.tex index 4828448a..b99ec2ee 100644 --- a/manual.tex +++ b/manual.tex @@ -1,4 +1,4 @@ -% $Id: manual.tex,v 1.12 1996/03/14 17:45:01 roberto Exp roberto $ +% $Id: manual.tex,v 1.13 1996/03/19 22:39:07 roberto Exp roberto $ \documentstyle[A4,11pt,bnf]{article} @@ -34,7 +34,7 @@ Waldemar Celes Filho \tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio } -\date{\small \verb$Date: 1996/03/14 17:45:01 $} +\date{\small \verb$Date: 1996/03/19 22:39:07 $} \maketitle @@ -810,7 +810,7 @@ int lua_isuserdata (lua_Object object); \end{verbatim} All macros return 1 if the object is compatible with the given type, and 0 otherwise. -\verb'lua_isnumber' accepts numbers and numerical strings, +The function \verb'lua_isnumber' accepts numbers and numerical strings, \verb'lua_isstring' accepts strings and numbers (\see{coercion}), and \verb'lua_isfunction' accepts Lua and C functions. @@ -1587,7 +1587,10 @@ this function fails and returns 0. The Lua interpreter offers two hooks for debug purposes: \begin{verbatim} typedef void (*lua_CHFunction) (lua_Function func, char *file, int line); +extern lua_CHFunction lua_callhook; + typedef void (*lua_LHFunction) (int line); +extern lua_LHFunction lua_linehook; \end{verbatim} The first one is called whenever the interpreter enters or leaves a function. @@ -1606,12 +1609,8 @@ Its only parameter is the line number This second hook is only called if the active function has been pre-compiled with debug information (\see{pragma}). -To set these hooks, there are the functions: -\begin{verbatim} -lua_LHFunction lua_setlinehook (lua_LHFunction hook); -lua_CHFunction lua_setcallhook (lua_CHFunction hook); -\end{verbatim} -Both return the previous hook. +A hook is disabled when its value is NULL (0), +which is the initial value of both hooks. \section{Some Examples} diff --git a/opcode.c b/opcode.c index 1bf1d18b..3b4ce09c 100644 --- a/opcode.c +++ b/opcode.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 3.61 1996/03/19 16:50:24 roberto Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 3.62 1996/03/19 22:28:37 roberto Exp roberto $"; #include #include @@ -54,8 +54,8 @@ static jmp_buf *errorJmp = NULL; /* current error recover point */ /* Hooks */ -static lua_LHFunction line_hook = NULL; -static lua_CHFunction call_hook = NULL; +lua_LHFunction lua_linehook = NULL; +lua_CHFunction lua_callhook = NULL; static StkId lua_execute (Byte *pc, StkId base); @@ -69,24 +69,6 @@ Object *luaI_Address (lua_Object o) } -/* -** Functions to change hook functions. -*/ -lua_LHFunction lua_setlinehook (lua_LHFunction hook) -{ - lua_LHFunction temp = line_hook; - line_hook = hook; - return temp; -} - -lua_CHFunction lua_setcallhook (lua_CHFunction hook) -{ - lua_CHFunction temp = call_hook; - call_hook = hook; - return temp; -} - - /* ** Init stack */ @@ -212,7 +194,7 @@ static void lineHook (int line) int oldCnResults = CnResults; StkId old_top = CBase = top-stack; CnResults = 0; - (*line_hook)(line); + (*lua_linehook)(line); top = stack+old_top; CnResults = oldCnResults; CBase = oldBase; @@ -230,14 +212,14 @@ static void callHook (StkId base, lua_Type type, int isreturn) StkId old_top = CBase = top-stack; CnResults = 0; if (isreturn) - (*call_hook)(LUA_NOOBJECT, "(return)", 0); + (*lua_callhook)(LUA_NOOBJECT, "(return)", 0); else { Object *f = stack+base-1; if (type == LUA_T_MARK) - (*call_hook)(Ref(f), f->value.tf->fileName, f->value.tf->lineDefined); + (*lua_callhook)(Ref(f), f->value.tf->fileName, f->value.tf->lineDefined); else - (*call_hook)(Ref(f), "(C)", -1); + (*lua_callhook)(Ref(f), "(C)", -1); } top = stack+old_top; CnResults = oldCnResults; @@ -258,10 +240,10 @@ static StkId callC (lua_CFunction func, StkId base) CnResults = (top-stack) - base; /* incorporate parameters on the stack */ CBase = base+CnResults; /* == top-stack */ - if (call_hook) + if (lua_callhook) callHook(base, LUA_T_CMARK, 0); (*func)(); - if (call_hook) /* func may have changed call_hook */ + if (lua_callhook) /* func may have changed lua_callhook */ callHook(base, LUA_T_CMARK, 1); firstResult = CBase; CBase = oldBase; @@ -899,7 +881,7 @@ static void comparison (lua_Type tag_less, lua_Type tag_equal, */ static StkId lua_execute (Byte *pc, StkId base) { - if (call_hook) + if (lua_callhook) callHook (base, LUA_T_MARK, 0); while (1) { @@ -1261,7 +1243,7 @@ static StkId lua_execute (Byte *pc, StkId base) case RETCODE0: case RETCODE: - if (call_hook) + if (lua_callhook) callHook (base, LUA_T_MARK, 1); return (base + ((opcode==RETCODE0) ? 0 : *pc)); @@ -1277,7 +1259,7 @@ static StkId lua_execute (Byte *pc, StkId base) (stack+base-1)->tag = LUA_T_LINE; } (stack+base-1)->value.i = code.w; - if (line_hook) + if (lua_linehook) lineHook (code.w); break; } -- cgit v1.2.3-55-g6feb