diff options
Diffstat (limited to 'etc')
-rw-r--r-- | etc/README | 7 | ||||
-rw-r--r-- | etc/bin2c.c | 9 | ||||
-rw-r--r-- | etc/trace.c | 32 |
3 files changed, 25 insertions, 23 deletions
@@ -5,9 +5,9 @@ bin2c.c run with lua_dobuffer. This allows C programs to include all necessary Lua code, even in precompiled form. - Even if code is include in source form, bin2c is useful because it + Even if the code is included in source form, bin2c is useful because it avoids the hassle of having to quote special characters in C strings. - Example of usage: run bin2c file1 file2 ... > init.h. The in your C + Example of usage: Run bin2c file1 file2 ... > init.h. Then, in your C program, just do #include "init.h" anywhere in the *body* of a function. This will be equivalent to calling lua_dofile("file1"); lua_dofile("file2"); ... @@ -17,7 +17,8 @@ min.c setfallback.lua An implementation of fallbacks on top of tag methods. - Useful if you have Lua code written for version 2.5 or earlier. + Useful if you have Lua code written for version 2.5 or earlier, + which uses setfallback. If you have C code that uses lua_setfallback, then define LUA_COMPAT2_5 before building Lua (see config). diff --git a/etc/bin2c.c b/etc/bin2c.c index 349b7eee..fca82a55 100644 --- a/etc/bin2c.c +++ b/etc/bin2c.c @@ -2,15 +2,16 @@ * bin2c.c * convert binary files to byte arrays * Luiz Henrique de Figueiredo (lhf@tecgraf.puc-rio.br) -* 25 Jun 98 10:55:12 +* 24 Nov 98 12:15:27 */ #include <ctype.h> #include <stdio.h> +#include <stdlib.h> void dump(FILE* f, int n) { - printf("static unsigned char B%d[]={\n"); + printf("static unsigned char B%d[]={\n",n); for (n=1;;n++) { int c=getc(f); @@ -49,6 +50,7 @@ void emit(char* fn, int n) int main(int argc, char* argv[]) { + printf("/* code automatically generated by bin2c -- DO NOT EDIT */\n"); printf("{\n"); if (argc<2) { @@ -58,6 +60,9 @@ int main(int argc, char* argv[]) else { int i; + printf("/* #include'ing this file in a C program is equivalent to calling\n"); + for (i=1; i<argc; i++) printf(" lua_dofile(\"%s\");\n",argv[i]); + printf("*/\n"); for (i=1; i<argc; i++) fdump(argv[i],i); for (i=1; i<argc; i++) emit(argv[i],i); } 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; |