"lua_debug", "lua_callhook" and "lua_linehook" must be inside "lua_state".

This commit is contained in:
Roberto Ierusalimschy 1999-02-04 15:47:59 -02:00
parent 19de5b2205
commit 5687949560
10 changed files with 53 additions and 56 deletions

14
lapi.c
View File

@ -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 ** Lua API
** See Copyright Notice in lua.h ** 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 lua_setlinehook (lua_LHFunction func) {
lua_LHFunction old = lua_linehook; lua_LHFunction old = L->linehook;
lua_linehook = func; L->linehook = func;
return old; return old;
} }
lua_CHFunction lua_setcallhook (lua_CHFunction func) { lua_CHFunction lua_setcallhook (lua_CHFunction func) {
lua_CHFunction old = lua_callhook; lua_CHFunction old = L->callhook;
lua_callhook = func; L->callhook = func;
return old; return old;
} }
int lua_setdebug (int debug) { int lua_setdebug (int debug) {
int old = lua_debug; int old = L->debug;
lua_debug = debug; L->debug = debug;
return old; return old;
} }

View File

@ -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 ** Interface from Lua to its debug API
** See Copyright Notice in lua.h ** 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) { static void dohook (int ref) {
lua_LHFunction oldlinehook = lua_linehook; /* save old hooks */ lua_LHFunction oldlinehook = lua_setlinehook(NULL);
lua_CHFunction oldcallhook = lua_callhook; lua_CHFunction oldcallhook = lua_setcallhook(NULL);
lua_linehook = NULL; lua_callhook = NULL; /* to avoid recusive calls */
lua_callfunction(lua_getref(ref)); lua_callfunction(lua_getref(ref));
lua_linehook = oldlinehook; /* restore old hooks */ lua_setlinehook(oldlinehook);
lua_callhook = oldcallhook; lua_setcallhook(oldcallhook);
} }
@ -177,12 +176,12 @@ static void setcallhook (void) {
lua_unref(callhook); lua_unref(callhook);
if (f == LUA_NOOBJECT) { if (f == LUA_NOOBJECT) {
callhook = -1; callhook = -1;
lua_callhook = NULL; lua_setcallhook(NULL);
} }
else { else {
lua_pushobject(f); lua_pushobject(f);
callhook = lua_ref(1); callhook = lua_ref(1);
lua_callhook = callf; lua_setcallhook(callf);
} }
} }
@ -192,12 +191,12 @@ static void setlinehook (void) {
lua_unref(linehook); lua_unref(linehook);
if (f == LUA_NOOBJECT) { if (f == LUA_NOOBJECT) {
linehook = -1; linehook = -1;
lua_linehook = NULL; lua_setlinehook(NULL);
} }
else { else {
lua_pushobject(f); lua_pushobject(f);
linehook = lua_ref(1); linehook = lua_ref(1);
lua_linehook = linef; lua_setlinehook(linef);
} }
} }

14
ldo.c
View File

@ -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 ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -94,7 +94,7 @@ void luaD_lineHook (int line)
struct C_Lua_Stack oldCLS = L->Cstack; struct C_Lua_Stack oldCLS = L->Cstack;
StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack; StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack;
L->Cstack.num = 0; L->Cstack.num = 0;
(*lua_linehook)(line); (*L->linehook)(line);
L->stack.top = L->stack.stack+old_top; L->stack.top = L->stack.stack+old_top;
L->Cstack = oldCLS; 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; StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack;
L->Cstack.num = 0; L->Cstack.num = 0;
if (isreturn) if (isreturn)
(*lua_callhook)(LUA_NOOBJECT, "(return)", 0); (*L->callhook)(LUA_NOOBJECT, "(return)", 0);
else { else {
TObject *f = L->stack.stack+base-1; TObject *f = L->stack.stack+base-1;
if (tf) if (tf)
(*lua_callhook)(Ref(f), tf->fileName->str, tf->lineDefined); (*L->callhook)(Ref(f), tf->fileName->str, tf->lineDefined);
else else
(*lua_callhook)(Ref(f), "(C)", -1); (*L->callhook)(Ref(f), "(C)", -1);
} }
L->stack.top = L->stack.stack+old_top; L->stack.top = L->stack.stack+old_top;
L->Cstack = oldCLS; L->Cstack = oldCLS;
@ -133,10 +133,10 @@ static StkId callC (lua_CFunction f, StkId base)
CS->num = numarg; CS->num = numarg;
CS->lua2C = base; CS->lua2C = base;
CS->base = base+numarg; /* == top-stack */ CS->base = base+numarg; /* == top-stack */
if (lua_callhook) if (L->callhook)
luaD_callHook(base, NULL, 0); luaD_callHook(base, NULL, 0);
(*f)(); /* do the actual call */ (*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); luaD_callHook(base, NULL, 1);
firstResult = CS->base; firstResult = CS->base;
*CS = oldCLS; *CS = oldCLS;

9
llex.c
View File

@ -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 ** Lexical Analizer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -20,9 +20,6 @@
int lua_debug=0;
#define next(LS) (LS->current = zgetc(LS->lex_z)) #define next(LS) (LS->current = zgetc(LS->lex_z))
@ -174,10 +171,10 @@ static void inclinenumber (LexState *LS)
readname(LS, buff); readname(LS, buff);
switch (luaL_findstring(buff, pragmas)) { switch (luaL_findstring(buff, pragmas)) {
case 0: /* debug */ case 0: /* debug */
if (!skip) lua_debug = 1; if (!skip) L->debug = 1;
break; break;
case 1: /* nodebug */ case 1: /* nodebug */
if (!skip) lua_debug = 0; if (!skip) L->debug = 0;
break; break;
case 2: /* endinput */ case 2: /* endinput */
if (!skip) { if (!skip) {

View File

@ -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 ** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -378,7 +378,7 @@ static void pushupvalue (LexState *ls, TaggedString *n) {
static void check_debugline (LexState *ls) { 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); code_oparg(ls, SETLINE, ls->linenumber, 0);
ls->fs->lastsetline = ls->linenumber; ls->fs->lastsetline = ls->linenumber;
} }
@ -552,7 +552,7 @@ static void init_state (LexState *ls, FuncState *fs, TaggedString *filename) {
fs->maxcode = 0; fs->maxcode = 0;
f->code = NULL; f->code = NULL;
fs->maxconsts = 0; fs->maxconsts = 0;
if (lua_debug) if (L->debug)
fs->nvars = fs->maxvars = 0; fs->nvars = fs->maxvars = 0;
else else
fs->maxvars = -1; /* flag no debug information */ fs->maxvars = -1; /* flag no debug information */

View File

@ -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 ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -29,6 +29,9 @@ void lua_open (void)
L->Cstack.lua2C = 0; L->Cstack.lua2C = 0;
L->Cstack.num = 0; L->Cstack.num = 0;
L->errorJmp = NULL; L->errorJmp = NULL;
L->debug = 0;
L->callhook = NULL;
L->linehook = NULL;
L->rootproto.next = NULL; L->rootproto.next = NULL;
L->rootproto.marked = 0; L->rootproto.marked = 0;
L->rootcl.next = NULL; L->rootcl.next = NULL;

View File

@ -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 ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -11,6 +11,7 @@
#include "lobject.h" #include "lobject.h"
#include "lua.h" #include "lua.h"
#include "luadebug.h"
#define MAX_C_BLOCKS 10 #define MAX_C_BLOCKS 10
@ -60,6 +61,9 @@ struct lua_State {
int Mbuffnext; /* next position to fill in Mbuffer */ int Mbuffnext; /* next position to fill in Mbuffer */
struct C_Lua_Stack Cblocks[MAX_C_BLOCKS]; struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];
int numCblocks; /* number of nested Cblocks */ int numCblocks; /* number of nested Cblocks */
int debug;
lua_CHFunction callhook;
lua_LHFunction linehook;
/* global state */ /* global state */
GCnode rootproto; /* list of all prototypes */ GCnode rootproto; /* list of all prototypes */
GCnode rootcl; /* list of all closures */ GCnode rootcl; /* list of all closures */
@ -80,3 +84,4 @@ struct lua_State {
#endif #endif

14
lua.c
View File

@ -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 ** Lua stand-alone interpreter
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -43,18 +43,16 @@ static handler lreset (void) {
static void lstop (void) { static void lstop (void) {
lua_linehook = old_linehook; lua_setlinehook(old_linehook);
lua_callhook = old_callhook; lua_setcallhook(old_callhook);
lreset(); lreset();
lua_error("interrupted!"); lua_error("interrupted!");
} }
static void laction (int i) { static void laction (int i) {
old_linehook = lua_linehook; old_linehook = lua_setlinehook((lua_LHFunction)lstop);
old_callhook = lua_callhook; old_callhook = lua_setcallhook((lua_CHFunction)lstop);
lua_linehook = (lua_LHFunction)lstop;
lua_callhook = (lua_CHFunction)lstop;
} }
@ -156,7 +154,7 @@ int main (int argc, char *argv[])
manual_input(0); manual_input(0);
break; break;
case 'd': case 'd':
lua_debug = 1; lua_setdebug(1);
break; break;
case 'v': case 'v':
printf("%s %s\n(written by %s)\n\n", printf("%s %s\n(written by %s)\n\n",

View File

@ -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 ** Debugging API
** See Copyright Notice in lua.h ** 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); int lua_nups (lua_Function func);
extern lua_LHFunction lua_linehook; lua_LHFunction lua_setlinehook (lua_LHFunction func);
extern lua_CHFunction lua_callhook; lua_CHFunction lua_setcallhook (lua_CHFunction func);
extern int lua_debug; int lua_setdebug (int debug);
extern lua_LHFunction lua_setlinehook (lua_LHFunction func);
extern lua_CHFunction lua_setcallhook (lua_CHFunction func);
extern int lua_setdebug (int debug);
#endif #endif

8
lvm.c
View File

@ -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 ** Lua virtual machine
** See Copyright Notice in lua.h ** 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 */ struct Stack *S = &L->stack; /* to optimize */
register Byte *pc = tf->code; register Byte *pc = tf->code;
TObject *consts = tf->consts; TObject *consts = tf->consts;
if (lua_callhook) if (L->callhook)
luaD_callHook(base, tf, 0); luaD_callHook(base, tf, 0);
luaD_checkstack((*pc++)+EXTRA_STACK); luaD_checkstack((*pc++)+EXTRA_STACK);
if (*pc < ZEROVARARG) if (*pc < ZEROVARARG)
@ -335,7 +335,7 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
S->top = S->stack + base; S->top = S->stack + base;
/* goes through */ /* goes through */
case RETCODE: case RETCODE:
if (lua_callhook) if (L->callhook)
luaD_callHook(base, NULL, 1); luaD_callHook(base, NULL, 1);
return base + (aux ? 0 : *pc); 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)->ttype = LUA_T_LINE;
} }
(S->stack+base-1)->value.i = aux; (S->stack+base-1)->value.i = aux;
if (lua_linehook) if (L->linehook)
luaD_lineHook(aux); luaD_lineHook(aux);
break; break;