hook variables are global, no more "lua_set...hook" functions.

This commit is contained in:
Roberto Ierusalimschy 1996-03-20 15:44:02 -03:00
parent e3c0ce9a69
commit 9704ff4cb1
3 changed files with 23 additions and 42 deletions

View File

@ -2,7 +2,7 @@
** LUA - Linguagem para Usuarios de Aplicacao ** LUA - Linguagem para Usuarios de Aplicacao
** Grupo de Tecnologia em Computacao Grafica ** Grupo de Tecnologia em Computacao Grafica
** TeCGraf - PUC-Rio ** 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); void lua_funcinfo (lua_Object func, char **filename, int *linedefined);
int lua_currentline (lua_Function func); int lua_currentline (lua_Function func);
char *lua_getobjname (lua_Object o, char **name); 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); lua_Object lua_getlocal (lua_Function func, int local_number, char **name);
int lua_setlocal (lua_Function func, int local_number); int lua_setlocal (lua_Function func, int local_number);
extern lua_LHFunction lua_linehook;
extern lua_CHFunction lua_callhook;
extern int lua_debug; extern int lua_debug;
#endif #endif

View File

@ -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} \documentstyle[A4,11pt,bnf]{article}
@ -34,7 +34,7 @@ Waldemar Celes Filho
\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio \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 \maketitle
@ -810,7 +810,7 @@ int lua_isuserdata (lua_Object object);
\end{verbatim} \end{verbatim}
All macros return 1 if the object is compatible with the given type, All macros return 1 if the object is compatible with the given type,
and 0 otherwise. 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}), \verb'lua_isstring' accepts strings and numbers (\see{coercion}),
and \verb'lua_isfunction' accepts Lua and C functions. 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: The Lua interpreter offers two hooks for debug purposes:
\begin{verbatim} \begin{verbatim}
typedef void (*lua_CHFunction) (lua_Function func, char *file, int line); typedef void (*lua_CHFunction) (lua_Function func, char *file, int line);
extern lua_CHFunction lua_callhook;
typedef void (*lua_LHFunction) (int line); typedef void (*lua_LHFunction) (int line);
extern lua_LHFunction lua_linehook;
\end{verbatim} \end{verbatim}
The first one is called whenever the interpreter enters or leaves a The first one is called whenever the interpreter enters or leaves a
function. function.
@ -1606,12 +1609,8 @@ Its only parameter is the line number
This second hook is only called if the active function This second hook is only called if the active function
has been pre-compiled with debug information (\see{pragma}). has been pre-compiled with debug information (\see{pragma}).
To set these hooks, there are the functions: A hook is disabled when its value is NULL (0),
\begin{verbatim} which is the initial value of both hooks.
lua_LHFunction lua_setlinehook (lua_LHFunction hook);
lua_CHFunction lua_setcallhook (lua_CHFunction hook);
\end{verbatim}
Both return the previous hook.
\section{Some Examples} \section{Some Examples}

View File

@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio ** 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 <setjmp.h> #include <setjmp.h>
#include <stdio.h> #include <stdio.h>
@ -54,8 +54,8 @@ static jmp_buf *errorJmp = NULL; /* current error recover point */
/* Hooks */ /* Hooks */
static lua_LHFunction line_hook = NULL; lua_LHFunction lua_linehook = NULL;
static lua_CHFunction call_hook = NULL; lua_CHFunction lua_callhook = NULL;
static StkId lua_execute (Byte *pc, StkId base); 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 ** Init stack
*/ */
@ -212,7 +194,7 @@ static void lineHook (int line)
int oldCnResults = CnResults; int oldCnResults = CnResults;
StkId old_top = CBase = top-stack; StkId old_top = CBase = top-stack;
CnResults = 0; CnResults = 0;
(*line_hook)(line); (*lua_linehook)(line);
top = stack+old_top; top = stack+old_top;
CnResults = oldCnResults; CnResults = oldCnResults;
CBase = oldBase; CBase = oldBase;
@ -230,14 +212,14 @@ static void callHook (StkId base, lua_Type type, int isreturn)
StkId old_top = CBase = top-stack; StkId old_top = CBase = top-stack;
CnResults = 0; CnResults = 0;
if (isreturn) if (isreturn)
(*call_hook)(LUA_NOOBJECT, "(return)", 0); (*lua_callhook)(LUA_NOOBJECT, "(return)", 0);
else else
{ {
Object *f = stack+base-1; Object *f = stack+base-1;
if (type == LUA_T_MARK) 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 else
(*call_hook)(Ref(f), "(C)", -1); (*lua_callhook)(Ref(f), "(C)", -1);
} }
top = stack+old_top; top = stack+old_top;
CnResults = oldCnResults; CnResults = oldCnResults;
@ -258,10 +240,10 @@ static StkId callC (lua_CFunction func, StkId base)
CnResults = (top-stack) - base; CnResults = (top-stack) - base;
/* incorporate parameters on the stack */ /* incorporate parameters on the stack */
CBase = base+CnResults; /* == top-stack */ CBase = base+CnResults; /* == top-stack */
if (call_hook) if (lua_callhook)
callHook(base, LUA_T_CMARK, 0); callHook(base, LUA_T_CMARK, 0);
(*func)(); (*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); callHook(base, LUA_T_CMARK, 1);
firstResult = CBase; firstResult = CBase;
CBase = oldBase; 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) static StkId lua_execute (Byte *pc, StkId base)
{ {
if (call_hook) if (lua_callhook)
callHook (base, LUA_T_MARK, 0); callHook (base, LUA_T_MARK, 0);
while (1) while (1)
{ {
@ -1261,7 +1243,7 @@ static StkId lua_execute (Byte *pc, StkId base)
case RETCODE0: case RETCODE0:
case RETCODE: case RETCODE:
if (call_hook) if (lua_callhook)
callHook (base, LUA_T_MARK, 1); callHook (base, LUA_T_MARK, 1);
return (base + ((opcode==RETCODE0) ? 0 : *pc)); 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)->tag = LUA_T_LINE;
} }
(stack+base-1)->value.i = code.w; (stack+base-1)->value.i = code.w;
if (line_hook) if (lua_linehook)
lineHook (code.w); lineHook (code.w);
break; break;
} }