aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-03-20 15:44:02 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-03-20 15:44:02 -0300
commit9704ff4cb14f34077062447d15196d32ace23e95 (patch)
treec0297a49e3f4516eb776c48c4d242edd0874b623
parente3c0ce9a6977c750eca72dcf173bcffaf01a11d7 (diff)
downloadlua-9704ff4cb14f34077062447d15196d32ace23e95.tar.gz
lua-9704ff4cb14f34077062447d15196d32ace23e95.tar.bz2
lua-9704ff4cb14f34077062447d15196d32ace23e95.zip
hook variables are global, no more "lua_set...hook" functions.
-rw-r--r--luadebug.h6
-rw-r--r--manual.tex17
-rw-r--r--opcode.c42
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 @@
2** LUA - Linguagem para Usuarios de Aplicacao 2** LUA - Linguagem para Usuarios de Aplicacao
3** Grupo de Tecnologia em Computacao Grafica 3** Grupo de Tecnologia em Computacao Grafica
4** TeCGraf - PUC-Rio 4** TeCGraf - PUC-Rio
5** $Id: luadebug.h,v 1.4 1996/02/07 18:10:27 roberto Exp roberto $ 5** $Id: luadebug.h,v 1.5 1996/02/08 17:03:20 roberto Exp roberto $
6*/ 6*/
7 7
8 8
@@ -20,12 +20,12 @@ lua_Function lua_stackedfunction (int level);
20void lua_funcinfo (lua_Object func, char **filename, int *linedefined); 20void lua_funcinfo (lua_Object func, char **filename, int *linedefined);
21int lua_currentline (lua_Function func); 21int lua_currentline (lua_Function func);
22char *lua_getobjname (lua_Object o, char **name); 22char *lua_getobjname (lua_Object o, char **name);
23lua_LHFunction lua_setlinehook (lua_LHFunction hook);
24lua_CHFunction lua_setcallhook (lua_CHFunction hook);
25 23
26lua_Object lua_getlocal (lua_Function func, int local_number, char **name); 24lua_Object lua_getlocal (lua_Function func, int local_number, char **name);
27int lua_setlocal (lua_Function func, int local_number); 25int lua_setlocal (lua_Function func, int local_number);
28 26
27extern lua_LHFunction lua_linehook;
28extern lua_CHFunction lua_callhook;
29extern int lua_debug; 29extern int lua_debug;
30 30
31#endif 31#endif
diff --git a/manual.tex b/manual.tex
index 4828448a..b99ec2ee 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.12 1996/03/14 17:45:01 roberto Exp roberto $ 1% $Id: manual.tex,v 1.13 1996/03/19 22:39:07 roberto Exp roberto $
2 2
3\documentstyle[A4,11pt,bnf]{article} 3\documentstyle[A4,11pt,bnf]{article}
4 4
@@ -34,7 +34,7 @@ Waldemar Celes Filho
34\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio 34\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio
35} 35}
36 36
37\date{\small \verb$Date: 1996/03/14 17:45:01 $} 37\date{\small \verb$Date: 1996/03/19 22:39:07 $}
38 38
39\maketitle 39\maketitle
40 40
@@ -810,7 +810,7 @@ int lua_isuserdata (lua_Object object);
810\end{verbatim} 810\end{verbatim}
811All macros return 1 if the object is compatible with the given type, 811All macros return 1 if the object is compatible with the given type,
812and 0 otherwise. 812and 0 otherwise.
813\verb'lua_isnumber' accepts numbers and numerical strings, 813The function \verb'lua_isnumber' accepts numbers and numerical strings,
814\verb'lua_isstring' accepts strings and numbers (\see{coercion}), 814\verb'lua_isstring' accepts strings and numbers (\see{coercion}),
815and \verb'lua_isfunction' accepts Lua and C functions. 815and \verb'lua_isfunction' accepts Lua and C functions.
816 816
@@ -1587,7 +1587,10 @@ this function fails and returns 0.
1587The Lua interpreter offers two hooks for debug purposes: 1587The Lua interpreter offers two hooks for debug purposes:
1588\begin{verbatim} 1588\begin{verbatim}
1589typedef void (*lua_CHFunction) (lua_Function func, char *file, int line); 1589typedef void (*lua_CHFunction) (lua_Function func, char *file, int line);
1590extern lua_CHFunction lua_callhook;
1591
1590typedef void (*lua_LHFunction) (int line); 1592typedef void (*lua_LHFunction) (int line);
1593extern lua_LHFunction lua_linehook;
1591\end{verbatim} 1594\end{verbatim}
1592The first one is called whenever the interpreter enters or leaves a 1595The first one is called whenever the interpreter enters or leaves a
1593function. 1596function.
@@ -1606,12 +1609,8 @@ Its only parameter is the line number
1606This second hook is only called if the active function 1609This second hook is only called if the active function
1607has been pre-compiled with debug information (\see{pragma}). 1610has been pre-compiled with debug information (\see{pragma}).
1608 1611
1609To set these hooks, there are the functions: 1612A hook is disabled when its value is NULL (0),
1610\begin{verbatim} 1613which is the initial value of both hooks.
1611lua_LHFunction lua_setlinehook (lua_LHFunction hook);
1612lua_CHFunction lua_setcallhook (lua_CHFunction hook);
1613\end{verbatim}
1614Both return the previous hook.
1615 1614
1616 1615
1617\section{Some Examples} 1616\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 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 3.61 1996/03/19 16:50:24 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 3.62 1996/03/19 22:28:37 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -54,8 +54,8 @@ static jmp_buf *errorJmp = NULL; /* current error recover point */
54 54
55 55
56/* Hooks */ 56/* Hooks */
57static lua_LHFunction line_hook = NULL; 57lua_LHFunction lua_linehook = NULL;
58static lua_CHFunction call_hook = NULL; 58lua_CHFunction lua_callhook = NULL;
59 59
60 60
61static StkId lua_execute (Byte *pc, StkId base); 61static StkId lua_execute (Byte *pc, StkId base);
@@ -70,24 +70,6 @@ Object *luaI_Address (lua_Object o)
70 70
71 71
72/* 72/*
73** Functions to change hook functions.
74*/
75lua_LHFunction lua_setlinehook (lua_LHFunction hook)
76{
77 lua_LHFunction temp = line_hook;
78 line_hook = hook;
79 return temp;
80}
81
82lua_CHFunction lua_setcallhook (lua_CHFunction hook)
83{
84 lua_CHFunction temp = call_hook;
85 call_hook = hook;
86 return temp;
87}
88
89
90/*
91** Init stack 73** Init stack
92*/ 74*/
93static void lua_initstack (void) 75static void lua_initstack (void)
@@ -212,7 +194,7 @@ static void lineHook (int line)
212 int oldCnResults = CnResults; 194 int oldCnResults = CnResults;
213 StkId old_top = CBase = top-stack; 195 StkId old_top = CBase = top-stack;
214 CnResults = 0; 196 CnResults = 0;
215 (*line_hook)(line); 197 (*lua_linehook)(line);
216 top = stack+old_top; 198 top = stack+old_top;
217 CnResults = oldCnResults; 199 CnResults = oldCnResults;
218 CBase = oldBase; 200 CBase = oldBase;
@@ -230,14 +212,14 @@ static void callHook (StkId base, lua_Type type, int isreturn)
230 StkId old_top = CBase = top-stack; 212 StkId old_top = CBase = top-stack;
231 CnResults = 0; 213 CnResults = 0;
232 if (isreturn) 214 if (isreturn)
233 (*call_hook)(LUA_NOOBJECT, "(return)", 0); 215 (*lua_callhook)(LUA_NOOBJECT, "(return)", 0);
234 else 216 else
235 { 217 {
236 Object *f = stack+base-1; 218 Object *f = stack+base-1;
237 if (type == LUA_T_MARK) 219 if (type == LUA_T_MARK)
238 (*call_hook)(Ref(f), f->value.tf->fileName, f->value.tf->lineDefined); 220 (*lua_callhook)(Ref(f), f->value.tf->fileName, f->value.tf->lineDefined);
239 else 221 else
240 (*call_hook)(Ref(f), "(C)", -1); 222 (*lua_callhook)(Ref(f), "(C)", -1);
241 } 223 }
242 top = stack+old_top; 224 top = stack+old_top;
243 CnResults = oldCnResults; 225 CnResults = oldCnResults;
@@ -258,10 +240,10 @@ static StkId callC (lua_CFunction func, StkId base)
258 CnResults = (top-stack) - base; 240 CnResults = (top-stack) - base;
259 /* incorporate parameters on the stack */ 241 /* incorporate parameters on the stack */
260 CBase = base+CnResults; /* == top-stack */ 242 CBase = base+CnResults; /* == top-stack */
261 if (call_hook) 243 if (lua_callhook)
262 callHook(base, LUA_T_CMARK, 0); 244 callHook(base, LUA_T_CMARK, 0);
263 (*func)(); 245 (*func)();
264 if (call_hook) /* func may have changed call_hook */ 246 if (lua_callhook) /* func may have changed lua_callhook */
265 callHook(base, LUA_T_CMARK, 1); 247 callHook(base, LUA_T_CMARK, 1);
266 firstResult = CBase; 248 firstResult = CBase;
267 CBase = oldBase; 249 CBase = oldBase;
@@ -899,7 +881,7 @@ static void comparison (lua_Type tag_less, lua_Type tag_equal,
899*/ 881*/
900static StkId lua_execute (Byte *pc, StkId base) 882static StkId lua_execute (Byte *pc, StkId base)
901{ 883{
902 if (call_hook) 884 if (lua_callhook)
903 callHook (base, LUA_T_MARK, 0); 885 callHook (base, LUA_T_MARK, 0);
904 while (1) 886 while (1)
905 { 887 {
@@ -1261,7 +1243,7 @@ static StkId lua_execute (Byte *pc, StkId base)
1261 1243
1262 case RETCODE0: 1244 case RETCODE0:
1263 case RETCODE: 1245 case RETCODE:
1264 if (call_hook) 1246 if (lua_callhook)
1265 callHook (base, LUA_T_MARK, 1); 1247 callHook (base, LUA_T_MARK, 1);
1266 return (base + ((opcode==RETCODE0) ? 0 : *pc)); 1248 return (base + ((opcode==RETCODE0) ? 0 : *pc));
1267 1249
@@ -1277,7 +1259,7 @@ static StkId lua_execute (Byte *pc, StkId base)
1277 (stack+base-1)->tag = LUA_T_LINE; 1259 (stack+base-1)->tag = LUA_T_LINE;
1278 } 1260 }
1279 (stack+base-1)->value.i = code.w; 1261 (stack+base-1)->value.i = code.w;
1280 if (line_hook) 1262 if (lua_linehook)
1281 lineHook (code.w); 1263 lineHook (code.w);
1282 break; 1264 break;
1283 } 1265 }