aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-02-04 15:47:59 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-02-04 15:47:59 -0200
commit568794956025183fc9a9b79e0c818a885e3d0aeb (patch)
tree02d1a74d7c9a16ca06e94ab4308694ad04f49012
parent19de5b22054f6da2c3e0eb3138cc7a1195aab4fd (diff)
downloadlua-568794956025183fc9a9b79e0c818a885e3d0aeb.tar.gz
lua-568794956025183fc9a9b79e0c818a885e3d0aeb.tar.bz2
lua-568794956025183fc9a9b79e0c818a885e3d0aeb.zip
"lua_debug", "lua_callhook" and "lua_linehook" must be inside "lua_state".
-rw-r--r--lapi.c14
-rw-r--r--ldblib.c19
-rw-r--r--ldo.c14
-rw-r--r--llex.c9
-rw-r--r--lparser.c6
-rw-r--r--lstate.c5
-rw-r--r--lstate.h7
-rw-r--r--lua.c14
-rw-r--r--luadebug.h13
-rw-r--r--lvm.c8
10 files changed, 53 insertions, 56 deletions
diff --git a/lapi.c b/lapi.c
index 6a553422..60eefc80 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.32 1999/01/26 15:31:17 roberto Exp roberto $ 2** $Id: lapi.c,v 1.33 1999/02/03 16:42:42 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -439,20 +439,20 @@ lua_State *lua_setstate (lua_State *st) {
439} 439}
440 440
441lua_LHFunction lua_setlinehook (lua_LHFunction func) { 441lua_LHFunction lua_setlinehook (lua_LHFunction func) {
442 lua_LHFunction old = lua_linehook; 442 lua_LHFunction old = L->linehook;
443 lua_linehook = func; 443 L->linehook = func;
444 return old; 444 return old;
445} 445}
446 446
447lua_CHFunction lua_setcallhook (lua_CHFunction func) { 447lua_CHFunction lua_setcallhook (lua_CHFunction func) {
448 lua_CHFunction old = lua_callhook; 448 lua_CHFunction old = L->callhook;
449 lua_callhook = func; 449 L->callhook = func;
450 return old; 450 return old;
451} 451}
452 452
453int lua_setdebug (int debug) { 453int lua_setdebug (int debug) {
454 int old = lua_debug; 454 int old = L->debug;
455 lua_debug = debug; 455 L->debug = debug;
456 return old; 456 return old;
457} 457}
458 458
diff --git a/ldblib.c b/ldblib.c
index beb7c700..6e8cc5b7 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.2 1999/01/11 18:57:35 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.3 1999/01/15 11:36:28 roberto Exp roberto $
3** Interface from Lua to its debug API 3** Interface from Lua to its debug API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -147,12 +147,11 @@ static int callhook = -1; /* Lua reference to call hook function */
147 147
148 148
149static void dohook (int ref) { 149static void dohook (int ref) {
150 lua_LHFunction oldlinehook = lua_linehook; /* save old hooks */ 150 lua_LHFunction oldlinehook = lua_setlinehook(NULL);
151 lua_CHFunction oldcallhook = lua_callhook; 151 lua_CHFunction oldcallhook = lua_setcallhook(NULL);
152 lua_linehook = NULL; lua_callhook = NULL; /* to avoid recusive calls */
153 lua_callfunction(lua_getref(ref)); 152 lua_callfunction(lua_getref(ref));
154 lua_linehook = oldlinehook; /* restore old hooks */ 153 lua_setlinehook(oldlinehook);
155 lua_callhook = oldcallhook; 154 lua_setcallhook(oldcallhook);
156} 155}
157 156
158 157
@@ -177,12 +176,12 @@ static void setcallhook (void) {
177 lua_unref(callhook); 176 lua_unref(callhook);
178 if (f == LUA_NOOBJECT) { 177 if (f == LUA_NOOBJECT) {
179 callhook = -1; 178 callhook = -1;
180 lua_callhook = NULL; 179 lua_setcallhook(NULL);
181 } 180 }
182 else { 181 else {
183 lua_pushobject(f); 182 lua_pushobject(f);
184 callhook = lua_ref(1); 183 callhook = lua_ref(1);
185 lua_callhook = callf; 184 lua_setcallhook(callf);
186 } 185 }
187} 186}
188 187
@@ -192,12 +191,12 @@ static void setlinehook (void) {
192 lua_unref(linehook); 191 lua_unref(linehook);
193 if (f == LUA_NOOBJECT) { 192 if (f == LUA_NOOBJECT) {
194 linehook = -1; 193 linehook = -1;
195 lua_linehook = NULL; 194 lua_setlinehook(NULL);
196 } 195 }
197 else { 196 else {
198 lua_pushobject(f); 197 lua_pushobject(f);
199 linehook = lua_ref(1); 198 linehook = lua_ref(1);
200 lua_linehook = linef; 199 lua_setlinehook(linef);
201 } 200 }
202} 201}
203 202
diff --git a/ldo.c b/ldo.c
index 4e895c0a..16f79c51 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.29 1998/08/21 17:43:44 roberto Exp $ 2** $Id: ldo.c,v 1.30 1999/01/15 11:38:33 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -94,7 +94,7 @@ void luaD_lineHook (int line)
94 struct C_Lua_Stack oldCLS = L->Cstack; 94 struct C_Lua_Stack oldCLS = L->Cstack;
95 StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack; 95 StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack;
96 L->Cstack.num = 0; 96 L->Cstack.num = 0;
97 (*lua_linehook)(line); 97 (*L->linehook)(line);
98 L->stack.top = L->stack.stack+old_top; 98 L->stack.top = L->stack.stack+old_top;
99 L->Cstack = oldCLS; 99 L->Cstack = oldCLS;
100} 100}
@@ -106,13 +106,13 @@ void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn)
106 StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack; 106 StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack;
107 L->Cstack.num = 0; 107 L->Cstack.num = 0;
108 if (isreturn) 108 if (isreturn)
109 (*lua_callhook)(LUA_NOOBJECT, "(return)", 0); 109 (*L->callhook)(LUA_NOOBJECT, "(return)", 0);
110 else { 110 else {
111 TObject *f = L->stack.stack+base-1; 111 TObject *f = L->stack.stack+base-1;
112 if (tf) 112 if (tf)
113 (*lua_callhook)(Ref(f), tf->fileName->str, tf->lineDefined); 113 (*L->callhook)(Ref(f), tf->fileName->str, tf->lineDefined);
114 else 114 else
115 (*lua_callhook)(Ref(f), "(C)", -1); 115 (*L->callhook)(Ref(f), "(C)", -1);
116 } 116 }
117 L->stack.top = L->stack.stack+old_top; 117 L->stack.top = L->stack.stack+old_top;
118 L->Cstack = oldCLS; 118 L->Cstack = oldCLS;
@@ -133,10 +133,10 @@ static StkId callC (lua_CFunction f, StkId base)
133 CS->num = numarg; 133 CS->num = numarg;
134 CS->lua2C = base; 134 CS->lua2C = base;
135 CS->base = base+numarg; /* == top-stack */ 135 CS->base = base+numarg; /* == top-stack */
136 if (lua_callhook) 136 if (L->callhook)
137 luaD_callHook(base, NULL, 0); 137 luaD_callHook(base, NULL, 0);
138 (*f)(); /* do the actual call */ 138 (*f)(); /* do the actual call */
139 if (lua_callhook) /* func may have changed lua_callhook */ 139 if (L->callhook) /* func may have changed lua_callhook */
140 luaD_callHook(base, NULL, 1); 140 luaD_callHook(base, NULL, 1);
141 firstResult = CS->base; 141 firstResult = CS->base;
142 *CS = oldCLS; 142 *CS = oldCLS;
diff --git a/llex.c b/llex.c
index a0b63fe1..27850864 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 1.26 1998/12/27 20:25:20 roberto Exp roberto $ 2** $Id: llex.c,v 1.27 1998/12/28 13:44:54 roberto Exp roberto $
3** Lexical Analizer 3** Lexical Analizer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -20,9 +20,6 @@
20 20
21 21
22 22
23int lua_debug=0;
24
25
26#define next(LS) (LS->current = zgetc(LS->lex_z)) 23#define next(LS) (LS->current = zgetc(LS->lex_z))
27 24
28 25
@@ -174,10 +171,10 @@ static void inclinenumber (LexState *LS)
174 readname(LS, buff); 171 readname(LS, buff);
175 switch (luaL_findstring(buff, pragmas)) { 172 switch (luaL_findstring(buff, pragmas)) {
176 case 0: /* debug */ 173 case 0: /* debug */
177 if (!skip) lua_debug = 1; 174 if (!skip) L->debug = 1;
178 break; 175 break;
179 case 1: /* nodebug */ 176 case 1: /* nodebug */
180 if (!skip) lua_debug = 0; 177 if (!skip) L->debug = 0;
181 break; 178 break;
182 case 2: /* endinput */ 179 case 2: /* endinput */
183 if (!skip) { 180 if (!skip) {
diff --git a/lparser.c b/lparser.c
index c6fe6547..4dcae7d3 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.14 1999/02/02 19:41:17 roberto Exp roberto $ 2** $Id: lparser.c,v 1.15 1999/02/04 16:36:16 roberto Exp roberto $
3** LL(1) Parser and code generator for Lua 3** LL(1) Parser and code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -378,7 +378,7 @@ static void pushupvalue (LexState *ls, TaggedString *n) {
378 378
379 379
380static void check_debugline (LexState *ls) { 380static void check_debugline (LexState *ls) {
381 if (lua_debug && ls->linenumber != ls->fs->lastsetline) { 381 if (L->debug && ls->linenumber != ls->fs->lastsetline) {
382 code_oparg(ls, SETLINE, ls->linenumber, 0); 382 code_oparg(ls, SETLINE, ls->linenumber, 0);
383 ls->fs->lastsetline = ls->linenumber; 383 ls->fs->lastsetline = ls->linenumber;
384 } 384 }
@@ -552,7 +552,7 @@ static void init_state (LexState *ls, FuncState *fs, TaggedString *filename) {
552 fs->maxcode = 0; 552 fs->maxcode = 0;
553 f->code = NULL; 553 f->code = NULL;
554 fs->maxconsts = 0; 554 fs->maxconsts = 0;
555 if (lua_debug) 555 if (L->debug)
556 fs->nvars = fs->maxvars = 0; 556 fs->nvars = fs->maxvars = 0;
557 else 557 else
558 fs->maxvars = -1; /* flag no debug information */ 558 fs->maxvars = -1; /* flag no debug information */
diff --git a/lstate.c b/lstate.c
index 8547c176..88c7b473 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 1.6 1998/06/02 20:37:04 roberto Exp roberto $ 2** $Id: lstate.c,v 1.7 1999/01/15 13:11:22 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -29,6 +29,9 @@ void lua_open (void)
29 L->Cstack.lua2C = 0; 29 L->Cstack.lua2C = 0;
30 L->Cstack.num = 0; 30 L->Cstack.num = 0;
31 L->errorJmp = NULL; 31 L->errorJmp = NULL;
32 L->debug = 0;
33 L->callhook = NULL;
34 L->linehook = NULL;
32 L->rootproto.next = NULL; 35 L->rootproto.next = NULL;
33 L->rootproto.marked = 0; 36 L->rootproto.marked = 0;
34 L->rootcl.next = NULL; 37 L->rootcl.next = NULL;
diff --git a/lstate.h b/lstate.h
index 16693604..b8d15a6c 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 1.12 1998/08/21 17:43:44 roberto Exp roberto $ 2** $Id: lstate.h,v 1.13 1998/08/30 18:28:58 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,6 +11,7 @@
11 11
12#include "lobject.h" 12#include "lobject.h"
13#include "lua.h" 13#include "lua.h"
14#include "luadebug.h"
14 15
15 16
16#define MAX_C_BLOCKS 10 17#define MAX_C_BLOCKS 10
@@ -60,6 +61,9 @@ struct lua_State {
60 int Mbuffnext; /* next position to fill in Mbuffer */ 61 int Mbuffnext; /* next position to fill in Mbuffer */
61 struct C_Lua_Stack Cblocks[MAX_C_BLOCKS]; 62 struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];
62 int numCblocks; /* number of nested Cblocks */ 63 int numCblocks; /* number of nested Cblocks */
64 int debug;
65 lua_CHFunction callhook;
66 lua_LHFunction linehook;
63 /* global state */ 67 /* global state */
64 GCnode rootproto; /* list of all prototypes */ 68 GCnode rootproto; /* list of all prototypes */
65 GCnode rootcl; /* list of all closures */ 69 GCnode rootcl; /* list of all closures */
@@ -80,3 +84,4 @@ struct lua_State {
80 84
81 85
82#endif 86#endif
87
diff --git a/lua.c b/lua.c
index 6deb6b99..a7ba2a42 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.17 1999/01/08 16:47:44 roberto Exp roberto $ 2** $Id: lua.c,v 1.18 1999/01/26 11:50:58 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -43,18 +43,16 @@ static handler lreset (void) {
43 43
44 44
45static void lstop (void) { 45static void lstop (void) {
46 lua_linehook = old_linehook; 46 lua_setlinehook(old_linehook);
47 lua_callhook = old_callhook; 47 lua_setcallhook(old_callhook);
48 lreset(); 48 lreset();
49 lua_error("interrupted!"); 49 lua_error("interrupted!");
50} 50}
51 51
52 52
53static void laction (int i) { 53static void laction (int i) {
54 old_linehook = lua_linehook; 54 old_linehook = lua_setlinehook((lua_LHFunction)lstop);
55 old_callhook = lua_callhook; 55 old_callhook = lua_setcallhook((lua_CHFunction)lstop);
56 lua_linehook = (lua_LHFunction)lstop;
57 lua_callhook = (lua_CHFunction)lstop;
58} 56}
59 57
60 58
@@ -156,7 +154,7 @@ int main (int argc, char *argv[])
156 manual_input(0); 154 manual_input(0);
157 break; 155 break;
158 case 'd': 156 case 'd':
159 lua_debug = 1; 157 lua_setdebug(1);
160 break; 158 break;
161 case 'v': 159 case 'v':
162 printf("%s %s\n(written by %s)\n\n", 160 printf("%s %s\n(written by %s)\n\n",
diff --git a/luadebug.h b/luadebug.h
index dbc5a1d0..d2e3c862 100644
--- a/luadebug.h
+++ b/luadebug.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luadebug.h,v 1.3 1998/09/07 18:59:59 roberto Exp roberto $ 2** $Id: luadebug.h,v 1.4 1999/01/15 13:11:22 roberto Exp roberto $
3** Debugging API 3** Debugging API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -26,14 +26,9 @@ int lua_setlocal (lua_Function func, int local_number);
26 26
27int lua_nups (lua_Function func); 27int lua_nups (lua_Function func);
28 28
29extern lua_LHFunction lua_linehook; 29lua_LHFunction lua_setlinehook (lua_LHFunction func);
30extern lua_CHFunction lua_callhook; 30lua_CHFunction lua_setcallhook (lua_CHFunction func);
31extern int lua_debug; 31int lua_setdebug (int debug);
32
33
34extern lua_LHFunction lua_setlinehook (lua_LHFunction func);
35extern lua_CHFunction lua_setcallhook (lua_CHFunction func);
36extern int lua_setdebug (int debug);
37 32
38 33
39#endif 34#endif
diff --git a/lvm.c b/lvm.c
index d6befc1a..56f90acf 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.43 1999/02/02 19:41:17 roberto Exp roberto $ 2** $Id: lvm.c,v 1.44 1999/02/04 16:36:16 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -317,7 +317,7 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
317 struct Stack *S = &L->stack; /* to optimize */ 317 struct Stack *S = &L->stack; /* to optimize */
318 register Byte *pc = tf->code; 318 register Byte *pc = tf->code;
319 TObject *consts = tf->consts; 319 TObject *consts = tf->consts;
320 if (lua_callhook) 320 if (L->callhook)
321 luaD_callHook(base, tf, 0); 321 luaD_callHook(base, tf, 0);
322 luaD_checkstack((*pc++)+EXTRA_STACK); 322 luaD_checkstack((*pc++)+EXTRA_STACK);
323 if (*pc < ZEROVARARG) 323 if (*pc < ZEROVARARG)
@@ -335,7 +335,7 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
335 S->top = S->stack + base; 335 S->top = S->stack + base;
336 /* goes through */ 336 /* goes through */
337 case RETCODE: 337 case RETCODE:
338 if (lua_callhook) 338 if (L->callhook)
339 luaD_callHook(base, NULL, 1); 339 luaD_callHook(base, NULL, 1);
340 return base + (aux ? 0 : *pc); 340 return base + (aux ? 0 : *pc);
341 341
@@ -615,7 +615,7 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
615 (S->stack+base-1)->ttype = LUA_T_LINE; 615 (S->stack+base-1)->ttype = LUA_T_LINE;
616 } 616 }
617 (S->stack+base-1)->value.i = aux; 617 (S->stack+base-1)->value.i = aux;
618 if (lua_linehook) 618 if (L->linehook)
619 luaD_lineHook(aux); 619 luaD_lineHook(aux);
620 break; 620 break;
621 621