diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-03-20 15:44:02 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-03-20 15:44:02 -0300 |
commit | 9704ff4cb14f34077062447d15196d32ace23e95 (patch) | |
tree | c0297a49e3f4516eb776c48c4d242edd0874b623 | |
parent | e3c0ce9a6977c750eca72dcf173bcffaf01a11d7 (diff) | |
download | lua-9704ff4cb14f34077062447d15196d32ace23e95.tar.gz lua-9704ff4cb14f34077062447d15196d32ace23e95.tar.bz2 lua-9704ff4cb14f34077062447d15196d32ace23e95.zip |
hook variables are global, no more "lua_set...hook" functions.
-rw-r--r-- | luadebug.h | 6 | ||||
-rw-r--r-- | manual.tex | 17 | ||||
-rw-r--r-- | opcode.c | 42 |
3 files changed, 23 insertions, 42 deletions
@@ -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); | |||
20 | void lua_funcinfo (lua_Object func, char **filename, int *linedefined); | 20 | void lua_funcinfo (lua_Object func, char **filename, int *linedefined); |
21 | int lua_currentline (lua_Function func); | 21 | int lua_currentline (lua_Function func); |
22 | char *lua_getobjname (lua_Object o, char **name); | 22 | char *lua_getobjname (lua_Object o, char **name); |
23 | lua_LHFunction lua_setlinehook (lua_LHFunction hook); | ||
24 | lua_CHFunction lua_setcallhook (lua_CHFunction hook); | ||
25 | 23 | ||
26 | lua_Object lua_getlocal (lua_Function func, int local_number, char **name); | 24 | lua_Object lua_getlocal (lua_Function func, int local_number, char **name); |
27 | int lua_setlocal (lua_Function func, int local_number); | 25 | int lua_setlocal (lua_Function func, int local_number); |
28 | 26 | ||
27 | extern lua_LHFunction lua_linehook; | ||
28 | extern lua_CHFunction lua_callhook; | ||
29 | extern int lua_debug; | 29 | extern int lua_debug; |
30 | 30 | ||
31 | #endif | 31 | #endif |
@@ -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} |
811 | All macros return 1 if the object is compatible with the given type, | 811 | All macros return 1 if the object is compatible with the given type, |
812 | and 0 otherwise. | 812 | and 0 otherwise. |
813 | \verb'lua_isnumber' accepts numbers and numerical strings, | 813 | The 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}), |
815 | and \verb'lua_isfunction' accepts Lua and C functions. | 815 | and \verb'lua_isfunction' accepts Lua and C functions. |
816 | 816 | ||
@@ -1587,7 +1587,10 @@ this function fails and returns 0. | |||
1587 | The Lua interpreter offers two hooks for debug purposes: | 1587 | The Lua interpreter offers two hooks for debug purposes: |
1588 | \begin{verbatim} | 1588 | \begin{verbatim} |
1589 | typedef void (*lua_CHFunction) (lua_Function func, char *file, int line); | 1589 | typedef void (*lua_CHFunction) (lua_Function func, char *file, int line); |
1590 | extern lua_CHFunction lua_callhook; | ||
1591 | |||
1590 | typedef void (*lua_LHFunction) (int line); | 1592 | typedef void (*lua_LHFunction) (int line); |
1593 | extern lua_LHFunction lua_linehook; | ||
1591 | \end{verbatim} | 1594 | \end{verbatim} |
1592 | The first one is called whenever the interpreter enters or leaves a | 1595 | The first one is called whenever the interpreter enters or leaves a |
1593 | function. | 1596 | function. |
@@ -1606,12 +1609,8 @@ Its only parameter is the line number | |||
1606 | This second hook is only called if the active function | 1609 | This second hook is only called if the active function |
1607 | has been pre-compiled with debug information (\see{pragma}). | 1610 | has been pre-compiled with debug information (\see{pragma}). |
1608 | 1611 | ||
1609 | To set these hooks, there are the functions: | 1612 | A hook is disabled when its value is NULL (0), |
1610 | \begin{verbatim} | 1613 | which is the initial value of both hooks. |
1611 | lua_LHFunction lua_setlinehook (lua_LHFunction hook); | ||
1612 | lua_CHFunction lua_setcallhook (lua_CHFunction hook); | ||
1613 | \end{verbatim} | ||
1614 | Both return the previous hook. | ||
1615 | 1614 | ||
1616 | 1615 | ||
1617 | \section{Some Examples} | 1616 | \section{Some Examples} |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.61 1996/03/19 16:50:24 roberto Exp roberto $"; | 6 | char *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 */ |
57 | static lua_LHFunction line_hook = NULL; | 57 | lua_LHFunction lua_linehook = NULL; |
58 | static lua_CHFunction call_hook = NULL; | 58 | lua_CHFunction lua_callhook = NULL; |
59 | 59 | ||
60 | 60 | ||
61 | static StkId lua_execute (Byte *pc, StkId base); | 61 | static 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 | */ | ||
75 | lua_LHFunction lua_setlinehook (lua_LHFunction hook) | ||
76 | { | ||
77 | lua_LHFunction temp = line_hook; | ||
78 | line_hook = hook; | ||
79 | return temp; | ||
80 | } | ||
81 | |||
82 | lua_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 | */ |
93 | static void lua_initstack (void) | 75 | static 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 | */ |
900 | static StkId lua_execute (Byte *pc, StkId base) | 882 | static 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 | } |