summaryrefslogtreecommitdiff
path: root/etc/trace.c
diff options
context:
space:
mode:
authorLua Team <team@lua.org>1999-07-08 12:00:00 +0000
committerrepogen <>1999-07-08 12:00:00 +0000
commitafb67002d94ef22c14741910ba83da262a6e9338 (patch)
treeb51ab3502813f590a4b115997f6fe41da43b6586 /etc/trace.c
parent377347776f1f3d820f92151f70bec667f96d5e6b (diff)
downloadlua-github-3.2.tar.gz
Lua 3.23.2
Diffstat (limited to 'etc/trace.c')
-rw-r--r--etc/trace.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/etc/trace.c b/etc/trace.c
index 1da38a1c..2c92850f 100644
--- a/etc/trace.c
+++ b/etc/trace.c
@@ -1,6 +1,6 @@
/*
* trace.c
-* a simple execution tracer
+* a simple execution tracer for Lua
*/
#include <stdio.h>
@@ -8,45 +8,41 @@
#include "lua.h"
#include "luadebug.h"
-static FILE* P; /* output file */
+static FILE* LOG; /* output file */
static int L=0; /* indentation level */
static void linehook(int line)
{
- fprintf(P,"%*sLINE(%d)\t-- %d\n",L,"",line,L);
+ fprintf(LOG,"%*sLINE(%d)\t-- %d\n",L,"",line,L);
}
static void callhook(lua_Function func, char* file, int line)
{
- fprintf(P,"%*sCALL('%s',%d)\t-- %d\n",L,"",file,line,L);
+ fprintf(LOG,"%*sCALL('%s',%d)\t-- %d\n",L,"",file,line,L);
if (line==0 && strcmp(file,"(return)")==0) --L; else ++L;
}
-void start_trace(void)
+void start_trace(FILE* logfile)
{
- lua_linehook=linehook;
- lua_callhook=callhook;
- lua_debug=1;
-#if 0
- P=fopen("trace.out","w");
-#else
- P=stderr;
-#endif
+ lua_setlinehook(linehook);
+ lua_setcallhook(callhook);
+ lua_setdebug(1);
+ LOG=logfile;
}
void stop_trace(void)
{
- lua_linehook=NULL;
- lua_callhook=NULL;
- lua_debug=0;
- fclose(P);
+ lua_setlinehook(NULL);
+ lua_setcallhook(NULL);
+ lua_setdebug(0);
+ fclose(LOG);
}
int main(void)
{
int rc;
lua_open();
- start_trace();
+ start_trace(stderr);
rc=lua_dofile(0);
stop_trace();
return rc;