commit 568794956025183fc9a9b79e0c818a885e3d0aeb
parent 19de5b22054f6da2c3e0eb3138cc7a1195aab4fd
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Thu, 4 Feb 1999 15:47:37 -0200
"lua_debug", "lua_callhook" and "lua_linehook" must be inside "lua_state".
Diffstat:
10 files changed, 53 insertions(+), 56 deletions(-)
diff --git a/lapi.c b/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 1.32 1999/01/26 15:31:17 roberto Exp roberto $
+** $Id: lapi.c,v 1.33 1999/02/03 16:42:42 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -439,20 +439,20 @@ lua_State *lua_setstate (lua_State *st) {
}
lua_LHFunction lua_setlinehook (lua_LHFunction func) {
- lua_LHFunction old = lua_linehook;
- lua_linehook = func;
+ lua_LHFunction old = L->linehook;
+ L->linehook = func;
return old;
}
lua_CHFunction lua_setcallhook (lua_CHFunction func) {
- lua_CHFunction old = lua_callhook;
- lua_callhook = func;
+ lua_CHFunction old = L->callhook;
+ L->callhook = func;
return old;
}
int lua_setdebug (int debug) {
- int old = lua_debug;
- lua_debug = debug;
+ int old = L->debug;
+ L->debug = debug;
return old;
}
diff --git a/ldblib.c b/ldblib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldblib.c,v 1.2 1999/01/11 18:57:35 roberto Exp roberto $
+** $Id: ldblib.c,v 1.3 1999/01/15 11:36:28 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -147,12 +147,11 @@ static int callhook = -1; /* Lua reference to call hook function */
static void dohook (int ref) {
- lua_LHFunction oldlinehook = lua_linehook; /* save old hooks */
- lua_CHFunction oldcallhook = lua_callhook;
- lua_linehook = NULL; lua_callhook = NULL; /* to avoid recusive calls */
+ lua_LHFunction oldlinehook = lua_setlinehook(NULL);
+ lua_CHFunction oldcallhook = lua_setcallhook(NULL);
lua_callfunction(lua_getref(ref));
- lua_linehook = oldlinehook; /* restore old hooks */
- lua_callhook = oldcallhook;
+ lua_setlinehook(oldlinehook);
+ lua_setcallhook(oldcallhook);
}
@@ -177,12 +176,12 @@ static void setcallhook (void) {
lua_unref(callhook);
if (f == LUA_NOOBJECT) {
callhook = -1;
- lua_callhook = NULL;
+ lua_setcallhook(NULL);
}
else {
lua_pushobject(f);
callhook = lua_ref(1);
- lua_callhook = callf;
+ lua_setcallhook(callf);
}
}
@@ -192,12 +191,12 @@ static void setlinehook (void) {
lua_unref(linehook);
if (f == LUA_NOOBJECT) {
linehook = -1;
- lua_linehook = NULL;
+ lua_setlinehook(NULL);
}
else {
lua_pushobject(f);
linehook = lua_ref(1);
- lua_linehook = linef;
+ lua_setlinehook(linef);
}
}
diff --git a/ldo.c b/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 1.29 1998/08/21 17:43:44 roberto Exp $
+** $Id: ldo.c,v 1.30 1999/01/15 11:38:33 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -94,7 +94,7 @@ void luaD_lineHook (int line)
struct C_Lua_Stack oldCLS = L->Cstack;
StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack;
L->Cstack.num = 0;
- (*lua_linehook)(line);
+ (*L->linehook)(line);
L->stack.top = L->stack.stack+old_top;
L->Cstack = oldCLS;
}
@@ -106,13 +106,13 @@ void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn)
StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack;
L->Cstack.num = 0;
if (isreturn)
- (*lua_callhook)(LUA_NOOBJECT, "(return)", 0);
+ (*L->callhook)(LUA_NOOBJECT, "(return)", 0);
else {
TObject *f = L->stack.stack+base-1;
if (tf)
- (*lua_callhook)(Ref(f), tf->fileName->str, tf->lineDefined);
+ (*L->callhook)(Ref(f), tf->fileName->str, tf->lineDefined);
else
- (*lua_callhook)(Ref(f), "(C)", -1);
+ (*L->callhook)(Ref(f), "(C)", -1);
}
L->stack.top = L->stack.stack+old_top;
L->Cstack = oldCLS;
@@ -133,10 +133,10 @@ static StkId callC (lua_CFunction f, StkId base)
CS->num = numarg;
CS->lua2C = base;
CS->base = base+numarg; /* == top-stack */
- if (lua_callhook)
+ if (L->callhook)
luaD_callHook(base, NULL, 0);
(*f)(); /* do the actual call */
- if (lua_callhook) /* func may have changed lua_callhook */
+ if (L->callhook) /* func may have changed lua_callhook */
luaD_callHook(base, NULL, 1);
firstResult = CS->base;
*CS = oldCLS;
diff --git a/llex.c b/llex.c
@@ -1,5 +1,5 @@
/*
-** $Id: llex.c,v 1.26 1998/12/27 20:25:20 roberto Exp roberto $
+** $Id: llex.c,v 1.27 1998/12/28 13:44:54 roberto Exp roberto $
** Lexical Analizer
** See Copyright Notice in lua.h
*/
@@ -20,9 +20,6 @@
-int lua_debug=0;
-
-
#define next(LS) (LS->current = zgetc(LS->lex_z))
@@ -174,10 +171,10 @@ static void inclinenumber (LexState *LS)
readname(LS, buff);
switch (luaL_findstring(buff, pragmas)) {
case 0: /* debug */
- if (!skip) lua_debug = 1;
+ if (!skip) L->debug = 1;
break;
case 1: /* nodebug */
- if (!skip) lua_debug = 0;
+ if (!skip) L->debug = 0;
break;
case 2: /* endinput */
if (!skip) {
diff --git a/lparser.c b/lparser.c
@@ -1,5 +1,5 @@
/*
-** $Id: lparser.c,v 1.14 1999/02/02 19:41:17 roberto Exp roberto $
+** $Id: lparser.c,v 1.15 1999/02/04 16:36:16 roberto Exp roberto $
** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -378,7 +378,7 @@ static void pushupvalue (LexState *ls, TaggedString *n) {
static void check_debugline (LexState *ls) {
- if (lua_debug && ls->linenumber != ls->fs->lastsetline) {
+ if (L->debug && ls->linenumber != ls->fs->lastsetline) {
code_oparg(ls, SETLINE, ls->linenumber, 0);
ls->fs->lastsetline = ls->linenumber;
}
@@ -552,7 +552,7 @@ static void init_state (LexState *ls, FuncState *fs, TaggedString *filename) {
fs->maxcode = 0;
f->code = NULL;
fs->maxconsts = 0;
- if (lua_debug)
+ if (L->debug)
fs->nvars = fs->maxvars = 0;
else
fs->maxvars = -1; /* flag no debug information */
diff --git a/lstate.c b/lstate.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.c,v 1.6 1998/06/02 20:37:04 roberto Exp roberto $
+** $Id: lstate.c,v 1.7 1999/01/15 13:11:22 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@@ -29,6 +29,9 @@ void lua_open (void)
L->Cstack.lua2C = 0;
L->Cstack.num = 0;
L->errorJmp = NULL;
+ L->debug = 0;
+ L->callhook = NULL;
+ L->linehook = NULL;
L->rootproto.next = NULL;
L->rootproto.marked = 0;
L->rootcl.next = NULL;
diff --git a/lstate.h b/lstate.h
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.h,v 1.12 1998/08/21 17:43:44 roberto Exp roberto $
+** $Id: lstate.h,v 1.13 1998/08/30 18:28:58 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@@ -11,6 +11,7 @@
#include "lobject.h"
#include "lua.h"
+#include "luadebug.h"
#define MAX_C_BLOCKS 10
@@ -60,6 +61,9 @@ struct lua_State {
int Mbuffnext; /* next position to fill in Mbuffer */
struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];
int numCblocks; /* number of nested Cblocks */
+ int debug;
+ lua_CHFunction callhook;
+ lua_LHFunction linehook;
/* global state */
GCnode rootproto; /* list of all prototypes */
GCnode rootcl; /* list of all closures */
@@ -80,3 +84,4 @@ struct lua_State {
#endif
+
diff --git a/lua.c b/lua.c
@@ -1,5 +1,5 @@
/*
-** $Id: lua.c,v 1.17 1999/01/08 16:47:44 roberto Exp roberto $
+** $Id: lua.c,v 1.18 1999/01/26 11:50:58 roberto Exp roberto $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@@ -43,18 +43,16 @@ static handler lreset (void) {
static void lstop (void) {
- lua_linehook = old_linehook;
- lua_callhook = old_callhook;
+ lua_setlinehook(old_linehook);
+ lua_setcallhook(old_callhook);
lreset();
lua_error("interrupted!");
}
static void laction (int i) {
- old_linehook = lua_linehook;
- old_callhook = lua_callhook;
- lua_linehook = (lua_LHFunction)lstop;
- lua_callhook = (lua_CHFunction)lstop;
+ old_linehook = lua_setlinehook((lua_LHFunction)lstop);
+ old_callhook = lua_setcallhook((lua_CHFunction)lstop);
}
@@ -156,7 +154,7 @@ int main (int argc, char *argv[])
manual_input(0);
break;
case 'd':
- lua_debug = 1;
+ lua_setdebug(1);
break;
case 'v':
printf("%s %s\n(written by %s)\n\n",
diff --git a/luadebug.h b/luadebug.h
@@ -1,5 +1,5 @@
/*
-** $Id: luadebug.h,v 1.3 1998/09/07 18:59:59 roberto Exp roberto $
+** $Id: luadebug.h,v 1.4 1999/01/15 13:11:22 roberto Exp roberto $
** Debugging API
** See Copyright Notice in lua.h
*/
@@ -26,14 +26,9 @@ int lua_setlocal (lua_Function func, int local_number);
int lua_nups (lua_Function func);
-extern lua_LHFunction lua_linehook;
-extern lua_CHFunction lua_callhook;
-extern int lua_debug;
-
-
-extern lua_LHFunction lua_setlinehook (lua_LHFunction func);
-extern lua_CHFunction lua_setcallhook (lua_CHFunction func);
-extern int lua_setdebug (int debug);
+lua_LHFunction lua_setlinehook (lua_LHFunction func);
+lua_CHFunction lua_setcallhook (lua_CHFunction func);
+int lua_setdebug (int debug);
#endif
diff --git a/lvm.c b/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 1.43 1999/02/02 19:41:17 roberto Exp roberto $
+** $Id: lvm.c,v 1.44 1999/02/04 16:36:16 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -317,7 +317,7 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
struct Stack *S = &L->stack; /* to optimize */
register Byte *pc = tf->code;
TObject *consts = tf->consts;
- if (lua_callhook)
+ if (L->callhook)
luaD_callHook(base, tf, 0);
luaD_checkstack((*pc++)+EXTRA_STACK);
if (*pc < ZEROVARARG)
@@ -335,7 +335,7 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
S->top = S->stack + base;
/* goes through */
case RETCODE:
- if (lua_callhook)
+ if (L->callhook)
luaD_callHook(base, NULL, 1);
return base + (aux ? 0 : *pc);
@@ -615,7 +615,7 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
(S->stack+base-1)->ttype = LUA_T_LINE;
}
(S->stack+base-1)->value.i = aux;
- if (lua_linehook)
+ if (L->linehook)
luaD_lineHook(aux);
break;