diff options
Diffstat (limited to 'etc/trace.c')
-rw-r--r-- | etc/trace.c | 35 |
1 files changed, 21 insertions, 14 deletions
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 <stdio.h> #include <string.h> #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; } |