From 8cb71cb5548e3138e5d4e4744f52c79d9fafb116 Mon Sep 17 00:00:00 2001 From: Lua Team Date: Mon, 6 Nov 2000 12:00:00 +0000 Subject: Lua 4.0 --- etc/trace.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'etc/trace.c') diff --git a/etc/trace.c b/etc/trace.c index 2c92850f..7c0b86ed 100644 --- a/etc/trace.c +++ b/etc/trace.c @@ -6,44 +6,51 @@ #include #include #include "lua.h" +#include "lualib.h" #include "luadebug.h" +lua_State *lua_state = NULL; +#define L lua_state /* lazy! */ + static FILE* LOG; /* output file */ -static int L=0; /* indentation level */ +static int I=0; /* indentation level */ -static void linehook(int line) +static void linehook(lua_State *L, lua_Debug *ar) { - fprintf(LOG,"%*sLINE(%d)\t-- %d\n",L,"",line,L); + fprintf(LOG,"%*sdo_line(%d)\t-- %d\n",I,"",ar->currentline,I); } -static void callhook(lua_Function func, char* file, int line) +static void callhook(lua_State *L, lua_Debug *ar) { - fprintf(LOG,"%*sCALL('%s',%d)\t-- %d\n",L,"",file,line,L); - if (line==0 && strcmp(file,"(return)")==0) --L; else ++L; + fprintf(LOG,"%*sdo_%s\t-- %p %d\n",I,"",ar->event,ar->_func,I); + if (*ar->event=='r') --I; else ++I; } void start_trace(FILE* logfile) { - lua_setlinehook(linehook); - lua_setcallhook(callhook); - lua_setdebug(1); + lua_setlinehook(L,linehook); + lua_setcallhook(L,callhook); LOG=logfile; } void stop_trace(void) { - lua_setlinehook(NULL); - lua_setcallhook(NULL); - lua_setdebug(0); + lua_setlinehook(L,NULL); + lua_setcallhook(L,NULL); fclose(LOG); } int main(void) { int rc; - lua_open(); + L=lua_open(0); + lua_baselibopen(L); + lua_iolibopen(L); + lua_strlibopen(L); + lua_mathlibopen(L); + lua_dblibopen(L); start_trace(stderr); - rc=lua_dofile(0); + rc=lua_dofile(L,0); stop_trace(); return rc; } -- cgit v1.2.1