diff options
Diffstat (limited to 'etc')
| l--------- | etc/.exrc | 1 | ||||
| -rw-r--r-- | etc/Makefile | 34 | ||||
| -rw-r--r-- | etc/README | 59 | ||||
| -rw-r--r-- | etc/bin2c.c | 24 | ||||
| -rw-r--r-- | etc/compat.lua | 192 | ||||
| -rw-r--r-- | etc/def.lua | 9 | ||||
| -rw-r--r-- | etc/doall.lua | 6 | ||||
| -rw-r--r-- | etc/lua.magic | 6 | ||||
| -rw-r--r-- | etc/luser_number.h | 34 | ||||
| -rw-r--r-- | etc/luser_tests.h | 68 | ||||
| -rw-r--r-- | etc/min.c | 26 | ||||
| -rw-r--r-- | etc/noparser.c | 26 | ||||
| -rw-r--r-- | etc/saconfig.c | 87 | ||||
| -rw-r--r-- | etc/setfallback.lua | 55 | ||||
| -rw-r--r-- | etc/stdcall.lua | 10 | ||||
| -rw-r--r-- | etc/trace.c | 49 |
16 files changed, 526 insertions, 160 deletions
diff --git a/etc/.exrc b/etc/.exrc new file mode 120000 index 00000000..d9067749 --- /dev/null +++ b/etc/.exrc @@ -0,0 +1 @@ +/home/n/lhf/lib/vi/c
\ No newline at end of file diff --git a/etc/Makefile b/etc/Makefile index a7768697..1286c640 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -1,16 +1,14 @@ -# makefile for etc +# makefile for Lua etc LUA= .. include $(LUA)/config LIBLUA=$(LIB)/liblua.a -ALL= bin2c min trace lua.def +ALL= bin2c min trace noparser luab -x: - @echo 'choose a target:' all $(ALL) - -all: $(ALL) +all: + @echo 'choose a target:' $(ALL) bin2c: bin2c.c $(CC) $(CFLAGS) -o $@ $@.c @@ -19,20 +17,26 @@ min: min.c $(LIBLUA) $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua trace: trace.c $(LIBLUA) - $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua -llualib -lm + $(CC) -g $(CFLAGS) -o $@ $@.c -L$(LIB) -llua -llualib $(EXTRA_LIBS) -def: lua.def +noparser: noparser.c + $(CC) $(CFLAGS) -I$(LUA)/src -o $@.o -c $@.c -lua.def: $(INC)/lua.h - $(BIN)/lua def.lua < $(INC)/lua.h > $@ - # cat $(INC)/l*.h | $(BIN)/lua def.lua > $@ +luab: noparser $(LIBLUA) + cc -o $@ noparser.o $(LUA)/src/lua/lua.o -L$(LIB) -llua -llualib $(EXTRA_LIBS) + $(BIN)/luac $(LUA)/test/hello.lua + $@ luac.out + -$@ -e'a=1' -stdcall: - mkdir -p Stdcall - grep -l _API $(LUA)/src/*.[ch] $(LUA)/src/*/*.[ch] | xargs -n1 -i echo $(BIN)/lua stdcall.lua '<{}' '>Stdcall/{}' +flat: + cd ..; mkdir flat; mv include/*.h src/*.[ch] src/*/*.[ch] flat $(LIBLUA): cd ../src; $(MAKE) clean: - rm -f $(ALL) + rm -f $(ALL) a.out core *.o luac.out + +luser_tests.h: RCS/ltests.h,v + co -q -M ltests.h + mv -f ltests.h $@ @@ -1,43 +1,54 @@ -This directory contains some code that might be useful. +This directory contains some useful files and code. +Unlike the code in ../src, everything here is in the public domain. bin2c.c - This program converts files to byte arrays that are automatically - run with lua_dobuffer. This allows C programs to include all necessary - Lua code, even in precompiled form. 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. Then, in your C - program, just do #include "init.h" anywhere in the *body* of a + This program converts files to byte arrays that are automatically run + with lua_dobuffer. This allows C programs to include all necessary Lua + code, even in precompiled form. 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. 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(L,"file1"); lua_dofile(L,"file2"); ... Note that the Lua state is called "L". If you use a different name, - say "mystate", just #define L mystate before #include "init.h". + say "mystate", just #define L mystate before you #include "init.h". -def.lua - A Lua script for creating .DEF for Windows DLLs. - Just do "make def" to create lua.def. +compat.lua + A compatibility module for Lua 4.0 functions. -min.c - A minimal Lua interpreter. +doall.lua + Emulate the command line behaviour of Lua 4.0 lua.ico A Lua icon for Windows. - It was drawn by hand by Markus Gritsch <gritsch@iue.tuwien.ac.at>. + Drawn by hand by Markus Gritsch <gritsch@iue.tuwien.ac.at>. + +lua.magic + Data for teaching file(1) about Lua precompiled chunks. lua.xpm The same icon as lua.ico, but in XPM format. It was converted with ImageMagick by Andy Tai <andy@exp.com>. -lua.magic - Data for teaching file(1) about Lua precompiled chunks. +luser_number.h + Number type configuration for Lua core. + +luser_tests.h + Self-test configuration for Lua core. + +min.c + A minimal Lua interpreter. + Good for learning and for starting your own. -stdcall.lua - A Lua script for changing the calling convention to __stdcall. - Do "make stdcall" and new modules will be created in stdcall/. +noparser.c + Linking with noparser.o avoids loading the parsing modules in lualib.a. + Do "make luab" to build a sample Lua intepreter that does not parse + Lua programs, only loads precompiled programs. -setfallback.lua - A Lua implementation of fallbacks on top of tag methods. - You only need this module if you have Lua code that uses setfallback. +saconfig.c + Configuration for Lua interpreter. trace.c - A simple execution tracer. An example of how to use the debugging hooks. + A simple execution tracer. + An example of how to use the debug hooks in C. diff --git a/etc/bin2c.c b/etc/bin2c.c index ac95a6e8..0993b16d 100644 --- a/etc/bin2c.c +++ b/etc/bin2c.c @@ -1,34 +1,30 @@ /* * bin2c.c -* convert binary files to byte arrays +* convert files to byte arrays for automatic loading with lua_dobuffer * Luiz Henrique de Figueiredo (lhf@tecgraf.puc-rio.br) -* 11 Sep 2000 22:37:14 +* 02 Apr 2003 20:44:31 */ #include <ctype.h> #include <stdio.h> #include <stdlib.h> -void dump(FILE* f, int n) +static void dump(FILE* f, int n) { - printf("static unsigned char B%d[]={\n",n); + printf("static const unsigned char B%d[]={\n",n); for (n=1;;n++) { int c=getc(f); if (c==EOF) break; -#if 0 - printf("0x%02x,",c); -#else printf("%3u,",c); -#endif if (n==20) { putchar('\n'); n=0; } } printf("\n};\n\n"); } -void fdump(char* fn, int n) +static void fdump(const char* fn, int n) { - FILE* f= (fn==NULL) ? stdin : fopen(fn,"rb"); /* must open in binary mode */ + FILE* f= fopen(fn,"rb"); /* must open in binary mode */ if (f==NULL) { fprintf(stderr,"bin2c: cannot open "); @@ -37,15 +33,15 @@ void fdump(char* fn, int n) } else { - if (fn!=NULL) printf("/* %s */\n",fn); + printf("/* %s */\n",fn); dump(f,n); fclose(f); } } -void emit(char* fn, int n) +static void emit(const char* fn, int n) { - printf(" lua_dobuffer(L,B%d,sizeof(B%d),\"%s\");\n",n,n,fn); + printf(" lua_dobuffer(L,(const char*)B%d,sizeof(B%d),\"%s\");\n",n,n,fn); } int main(int argc, char* argv[]) @@ -55,7 +51,7 @@ int main(int argc, char* argv[]) if (argc<2) { dump(stdin,0); - emit("(stdin)",0); + emit("=stdin",0); } else { diff --git a/etc/compat.lua b/etc/compat.lua new file mode 100644 index 00000000..2a7f3731 --- /dev/null +++ b/etc/compat.lua @@ -0,0 +1,192 @@ +------------------------------------------------------------------- +-- Real globals +-- _ALERT +-- _ERRORMESSAGE +-- _VERSION +-- _G +-- assert +-- error +-- metatable +-- next +-- print +-- require +-- tonumber +-- tostring +-- type +-- unpack + +------------------------------------------------------------------- +-- collectgarbage +-- gcinfo + +-- globals + +-- call -> protect(f, err) +-- loadfile +-- loadstring + +-- rawget +-- rawset + +-- getargs = Main.getargs ?? + + +function do_ (f, err) + if not f then print(err); return end + local a,b = pcall(f) + if not a then print(b); return nil + else return b or true + end +end + +function dostring(s) return do_(loadstring(s)) end +-- function dofile(s) return do_(loadfile(s)) end + +------------------------------------------------------------------- +-- Table library +local tab = table +foreach = tab.foreach +foreachi = tab.foreachi +getn = tab.getn +tinsert = tab.insert +tremove = tab.remove +sort = tab.sort + +------------------------------------------------------------------- +-- Debug library +local dbg = debug +getinfo = dbg.getinfo +getlocal = dbg.getlocal +setcallhook = function () error"`setcallhook' is deprecated" end +setlinehook = function () error"`setlinehook' is deprecated" end +setlocal = dbg.setlocal + +------------------------------------------------------------------- +-- math library +local math = math +abs = math.abs +acos = function (x) return math.deg(math.acos(x)) end +asin = function (x) return math.deg(math.asin(x)) end +atan = function (x) return math.deg(math.atan(x)) end +atan2 = function (x,y) return math.deg(math.atan2(x,y)) end +ceil = math.ceil +cos = function (x) return math.cos(math.rad(x)) end +deg = math.deg +exp = math.exp +floor = math.floor +frexp = math.frexp +ldexp = math.ldexp +log = math.log +log10 = math.log10 +max = math.max +min = math.min +mod = math.mod +PI = math.pi +--??? pow = math.pow +rad = math.rad +random = math.random +randomseed = math.randomseed +sin = function (x) return math.sin(math.rad(x)) end +sqrt = math.sqrt +tan = function (x) return math.tan(math.rad(x)) end + +------------------------------------------------------------------- +-- string library +local str = string +strbyte = str.byte +strchar = str.char +strfind = str.find +format = str.format +gsub = str.gsub +strlen = str.len +strlower = str.lower +strrep = str.rep +strsub = str.sub +strupper = str.upper + +------------------------------------------------------------------- +-- os library +clock = os.clock +date = os.date +difftime = os.difftime +execute = os.execute --? +exit = os.exit +getenv = os.getenv +remove = os.remove +rename = os.rename +setlocale = os.setlocale +time = os.time +tmpname = os.tmpname + +------------------------------------------------------------------- +-- compatibility only +getglobal = function (n) return _G[n] end +setglobal = function (n,v) _G[n] = v end + +------------------------------------------------------------------- + +local io, tab = io, table + +-- IO library (files) +_STDIN = io.stdin +_STDERR = io.stderr +_STDOUT = io.stdout +_INPUT = io.stdin +_OUTPUT = io.stdout +seek = io.stdin.seek -- sick ;-) +tmpfile = io.tmpfile +closefile = io.close +openfile = io.open + +function flush (f) + if f then f:flush() + else _OUTPUT:flush() + end +end + +function readfrom (name) + if name == nil then + local f, err, cod = io.close(_INPUT) + _INPUT = io.stdin + return f, err, cod + else + local f, err, cod = io.open(name, "r") + _INPUT = f or _INPUT + return f, err, cod + end +end + +function writeto (name) + if name == nil then + local f, err, cod = io.close(_OUTPUT) + _OUTPUT = io.stdout + return f, err, cod + else + local f, err, cod = io.open(name, "w") + _OUTPUT = f or _OUTPUT + return f, err, cod + end +end + +function appendto (name) + local f, err, cod = io.open(name, "a") + _OUTPUT = f or _OUTPUT + return f, err, cod +end + +function read (...) + local f = _INPUT + if type(arg[1]) == 'userdata' then + f = tab.remove(arg, 1) + end + return f:read(unpack(arg)) +end + +function write (...) + local f = _OUTPUT + if type(arg[1]) == 'userdata' then + f = tab.remove(arg, 1) + end + return f:write(unpack(arg)) +end + diff --git a/etc/def.lua b/etc/def.lua deleted file mode 100644 index 736e32cd..00000000 --- a/etc/def.lua +++ /dev/null @@ -1,9 +0,0 @@ --- def.lua --- make .DEF file from lua.h --- usage: lua def.lua <lua.h >lua.def - -T=read"*a" -write("LIBRARY LUA\nVERSION ") -gsub(T,"LUA_VERSION.-(%d+%.%d+)",write) -write("\nEXPORTS\n") -gsub(T,"(lua_%w+)%s+%(",function (f) write(" ",f,"\n") end) diff --git a/etc/doall.lua b/etc/doall.lua new file mode 100644 index 00000000..fb0fad70 --- /dev/null +++ b/etc/doall.lua @@ -0,0 +1,6 @@ +-- emulate the command line behaviour of Lua 4.0 +-- usage: lua doall.lua f1.lua f2.lua f3.lua ... + +for i=1,table.getn(arg) do + dofile(arg[i]) +end diff --git a/etc/lua.magic b/etc/lua.magic index eb78f8d0..c7ae5955 100644 --- a/etc/lua.magic +++ b/etc/lua.magic @@ -1,10 +1,12 @@ -# Lua precompiled files +# Lua precompiled files. Versions 2.3 and 4.1 were never officially released. 0 string \33Lua precompiled chunk for Lua ->4 byte 0x23 2.3 +>4 byte 0x23 2.3* >4 byte 0x24 2.4 >4 byte 0x25 2.5 >4 byte 0x30 3.0 >4 byte 0x31 3.1 >4 byte 0x32 3.2 >4 byte 0x40 4.0 +>4 byte 0x41 4.1* +>4 byte 0x50 5.0 diff --git a/etc/luser_number.h b/etc/luser_number.h new file mode 100644 index 00000000..8cc2678e --- /dev/null +++ b/etc/luser_number.h @@ -0,0 +1,34 @@ +/* luser_number.h -- number type configuration for Lua core +* +* #define LUA_USER_H to this file and #define one of USE_* below +*/ + +#ifdef USE_DOUBLE +#define LUA_NUMBER double +#define LUA_NUMBER_SCAN "%lf" +#define LUA_NUMBER_FMT "%.14g" +#endif + +#ifdef USE_FLOAT +#define LUA_NUMBER float +#define LUA_NUMBER_SCAN "%f" +#define LUA_NUMBER_FMT "%.5g" +#endif + +#ifdef USE_LONG +#define LUA_NUMBER long +#define LUA_NUMBER_SCAN "%ld" +#define LUA_NUMBER_FMT "%ld" +#define lua_str2number(s,p) strtol((s), (p), 10) +#endif + +#ifdef USE_INT +#define LUA_NUMBER int +#define LUA_NUMBER_SCAN "%d" +#define LUA_NUMBER_FMT "%d" +#define lua_str2number(s,p) ((int) strtol((s), (p), 10)) +#endif + +#ifdef USE_FASTROUND +#define lua_number2int(i,d) __asm__("fldl %1\nfistpl %0":"=m"(i):"m"(d)) +#endif diff --git a/etc/luser_tests.h b/etc/luser_tests.h new file mode 100644 index 00000000..1ee6e3fd --- /dev/null +++ b/etc/luser_tests.h @@ -0,0 +1,68 @@ +/* +** $Id: ltests.h,v 1.20 2002/12/04 17:29:05 roberto Exp $ +** Internal Header for Debugging of the Lua Implementation +** See Copyright Notice in lua.h +*/ + +#ifndef ltests_h +#define ltests_h + + +#include <stdlib.h> + + +#define LUA_DEBUG + +#define LUA_OPNAMES + +#undef NDEBUG +#include <assert.h> +#define lua_assert(c) assert(c) +#define check_exp(c,e) (lua_assert(c), (e)) +#define api_check(L, o) lua_assert(o) + + +/* to avoid warnings, and to make sure value is really unused */ +#define UNUSED(x) (x=0, (void)(x)) + + +/* memory allocator control variables */ +extern unsigned long memdebug_numblocks; +extern unsigned long memdebug_total; +extern unsigned long memdebug_maxmem; +extern unsigned long memdebug_memlimit; + + +#define l_realloc(b, os, s) debug_realloc(b, os, s) +#define l_free(b, os) debug_realloc(b, os, 0) + +void *debug_realloc (void *block, size_t oldsize, size_t size); + + + +/* test for lock/unlock */ +extern int islocked; +#define LUA_USERSTATE int * +#define getlock(l) (*(cast(LUA_USERSTATE *, l) - 1)) +#define lua_userstateopen(l) if (l != NULL) getlock(l) = &islocked; +#define lua_lock(l) lua_assert((*getlock(l))++ == 0) +#define lua_unlock(l) lua_assert(--(*getlock(l)) == 0) + + +int luaB_opentests (lua_State *L); + +#define LUA_EXTRALIBS { "tests", luaB_opentests }, + + +/* real main will be defined at `ltests.c' */ +int l_main (int argc, char *argv[]); +#define main l_main + + + +/* change some sizes to give some bugs a chance */ + +#define LUAL_BUFFERSIZE 27 +#define MINSTRTABSIZE 2 + +#endif @@ -1,13 +1,12 @@ /* -* min.c -* a minimal Lua interpreter. loads stdin only. -* no standard library, only a "print" function. +* min.c -- a minimal Lua interpreter +* loads stdin only with minimal error handling. +* no interaction, and no standard library, only a "print" function. */ #include <stdio.h> #include "lua.h" -/* a simple "print". based on the code in lbaselib.c */ static int print(lua_State *L) { int n=lua_gettop(L); @@ -17,6 +16,10 @@ static int print(lua_State *L) if (i>1) printf("\t"); if (lua_isstring(L,i)) printf("%s",lua_tostring(L,i)); + else if (lua_isnil(L,i)) + printf("%s","nil"); + else if (lua_isboolean(L,i)) + printf("%s",lua_toboolean(L,i) ? "true" : "false"); else printf("%s:%p",lua_typename(L,lua_type(L,i)),lua_topointer(L,i)); } @@ -24,9 +27,20 @@ static int print(lua_State *L) return 0; } +static const char *getF(lua_State *L, void *ud, size_t *size) +{ + FILE *f=(FILE *)ud; + static char buff[512]; + if (feof(f)) return NULL; + *size=fread(buff,1,sizeof(buff),f); + return (*size>0) ? buff : NULL; +} + int main(void) { - lua_State *L=lua_open(0); + lua_State *L=lua_open(); lua_register(L,"print",print); - return lua_dofile(L,NULL); + if (lua_load(L,getF,stdin,"=stdin") || lua_pcall(L,0,0,0)) + fprintf(stderr,"%s\n",lua_tostring(L,-1)); + return 0; } diff --git a/etc/noparser.c b/etc/noparser.c new file mode 100644 index 00000000..00c2b126 --- /dev/null +++ b/etc/noparser.c @@ -0,0 +1,26 @@ +/* +* The code below can be used to make a Lua core that does not contain the +* parsing modules (lcode, llex, lparser), which represent 35% of the total core. +* You'll only be able to load binary files and strings, precompiled with luac. +* (Of course, you'll have to build luac with the original parsing modules!) +* +* To use this module, simply compile it ("make noparser" does that) and +* list its object file before the Lua libraries. The linker should then not +* load the parsing modules. To try it, do "make luab". +*/ + +#include "llex.h" +#include "lparser.h" +#include "lzio.h" + +void luaX_init (lua_State *L) { + UNUSED(L); +} + +Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff) { + UNUSED(z); + UNUSED(buff); + lua_pushstring(L,"parser not loaded"); + lua_error(L); + return NULL; +} diff --git a/etc/saconfig.c b/etc/saconfig.c new file mode 100644 index 00000000..bf3c64b7 --- /dev/null +++ b/etc/saconfig.c @@ -0,0 +1,87 @@ +/* sa-config.c -- configuration for stand-alone Lua interpreter +* +* #define LUA_USERCONFIG to this file +* +* Here are the features that can be customized using #define: +* +*** Line edit and history: +* #define USE_READLINE to use the GNU readline library. +* +* To use another library for this, use the code below as a start. +* Make sure you #define lua_readline and lua_saveline accordingly. +* If you do not #define lua_readline, you'll get a version based on fgets +* that uses a static buffer of size MAXINPUT. +* +* +*** Static Lua libraries to be loaded at startup: +* #define lua_userinit(L) to a Lua function that loads libraries; typically +* #define lua_userinit(L) openstdlibs(L);myinit(L) +* or +* #define lua_userinit(L) myinit(L) +* +* Another way is to add the prototypes of the init functions here and +* #define LUA_EXTRALIBS accordingly. For example, +* #define LUA_EXTRALIBS {"mylib","luaopen_mylib"}, +* Note the ending comma! +* +* +*** Prompts: +* The stand-alone Lua interpreter uses two prompts: PROMPT and PROMPT2. +* PROMPT is the primary prompt, shown when the intepreter is ready to receive +* a new statement. PROMPT2 is the secondary prompt, shown while a statement +* is being entered but is still incomplete. +* +* +*** Program name: +* Error messages usually show argv[0] as a program name. In systems that do +* not give a valid string as argv[0], error messages show PROGNAME instead. +* +* +*/ + +#ifdef USE_READLINE +/* +* This section implements of lua_readline and lua_saveline for lua.c using +* the GNU readline and history libraries. It should also work with drop-in +* replacements such as editline and libedit (you may have to include +* different headers, though). +* +*/ + +#define lua_readline myreadline +#define lua_saveline mysaveline + +#include <ctype.h> +#include <readline/readline.h> +#include <readline/history.h> + +static int myreadline (lua_State *L, const char *prompt) { + char *s=readline(prompt); + if (s==NULL) + return 0; + else { + lua_pushstring(L,s); + lua_pushliteral(L,"\n"); + lua_concat(L,2); + free(s); + return 1; + } +} + +static void mysaveline (lua_State *L, const char *s) { + const char *p; + for (p=s; isspace(*p); p++) + ; + if (*p!=0) { + size_t n=strlen(s)-1; + if (s[n]!='\n') + add_history(s); + else { + lua_pushlstring(L,s,n); + s=lua_tostring(L,-1); + add_history(s); + lua_remove(L,-1); + } + } +} +#endif diff --git a/etc/setfallback.lua b/etc/setfallback.lua deleted file mode 100644 index 783b8667..00000000 --- a/etc/setfallback.lua +++ /dev/null @@ -1,55 +0,0 @@ --------------------------------------------------------------- --- Definition of "setfallback" using tag methods --- (for compatibility with old code) --------------------------------------------------------------- - - --- default fallbacks for each event: -local defaults = { - gettable = function () error('indexed expression not a table') end, - settable = function () error('indexed expression not a table') end, - index = function () return nil end, - getglobal = function () return nil end, - arith = function () error('number expected in arithmetic operation') end, - order = function () error('incompatible types in comparison') end, - concat = function () error('string expected in concatenation') end, - gc = function () return nil end, - ['function'] = function () error('called expression not a function') end, - error = function (s) write(_STDERR, s, '\n') end, -} - - -function setfallback (name, func) - - -- set the given function as the tag method for all "standard" tags - -- (since some combinations may cause errors, use call to avoid messages) - local fillvalids = function (n, func) - call(settagmethod, {0, n, func}, 'x', nil) - call(settagmethod, {tag(0), n, func}, 'x', nil) - call(settagmethod, {tag(''), n, func}, 'x', nil) - call(settagmethod, {tag{}, n, func}, 'x', nil) - call(settagmethod, {tag(function () end), n, func}, 'x', nil) - call(settagmethod, {tag(settagmethod), n, func}, 'x', nil) - call(settagmethod, {tag(nil), n, func}, 'x', nil) - end - - assert(type(func) == 'function') - local oldfunc - if name == 'error' then - oldfunc = seterrormethod(func) - elseif name == 'getglobal' then - oldfunc = settagmethod(tag(nil), 'getglobal', func) - elseif name == 'arith' then - oldfunc = gettagmethod(tag(0), 'pow') - foreach({"add", "sub", "mul", "div", "unm", "pow"}, - function(_, n) %fillvalids(n, %func) end) - elseif name == 'order' then - oldfunc = gettagmethod(tag(nil), 'lt') - foreach({"lt", "gt", "le", "ge"}, - function(_, n) %fillvalids(n, %func) end) - else - oldfunc = gettagmethod(tag(nil), name) - fillvalids(name, func) - end - return oldfunc or rawgettable(%defaults, name) -end diff --git a/etc/stdcall.lua b/etc/stdcall.lua deleted file mode 100644 index 7eac5c2e..00000000 --- a/etc/stdcall.lua +++ /dev/null @@ -1,10 +0,0 @@ --- stdcall.lua --- add __stdcall where appropriate --- usage: lua stdcall.lua <lua.h >s_lua.h --- usage: lua stdcall.lua <lapi.c >s_lapi.c - -T=read"*a" -T=gsub(T,"(lua_%w+%s+%()","__stdcall %1") -T=gsub(T,"(%*lua_CFunction)","__stdcall %1") - -write(T) diff --git a/etc/trace.c b/etc/trace.c index 7c0b86ed..c29f1c9d 100644 --- a/etc/trace.c +++ b/etc/trace.c @@ -1,56 +1,55 @@ /* -* trace.c -* a simple execution tracer for Lua +* trace.c -- a simple execution tracer for Lua */ #include <stdio.h> #include <string.h> #include "lua.h" #include "lualib.h" -#include "luadebug.h" +#include "lauxlib.h" -lua_State *lua_state = NULL; -#define L lua_state /* lazy! */ - -static FILE* LOG; /* output file */ +static FILE* LOG; /* log file */ static int I=0; /* indentation level */ -static void linehook(lua_State *L, lua_Debug *ar) -{ - fprintf(LOG,"%*sdo_line(%d)\t-- %d\n",I,"",ar->currentline,I); -} - -static void callhook(lua_State *L, lua_Debug *ar) +static void hook(lua_State *L, lua_Debug *ar) { - fprintf(LOG,"%*sdo_%s\t-- %p %d\n",I,"",ar->event,ar->_func,I); - if (*ar->event=='r') --I; else ++I; + const char* s=""; + switch (ar->event) + { + case LUA_HOOKTAILRET: ar->event=LUA_HOOKRET; + case LUA_HOOKRET: s="return"; break; + case LUA_HOOKCALL: s="call"; break; + case LUA_HOOKLINE: s="line"; break; + default: break; + } + fprintf(LOG,"[%d]\t%*s%s\t-- %d\n",I,I,"",s,ar->currentline); + if (ar->event==LUA_HOOKCALL) ++I; else if (ar->event==LUA_HOOKRET) --I; } -void start_trace(FILE* logfile) +static void start_trace(lua_State *L, FILE* logfile) { - lua_setlinehook(L,linehook); - lua_setcallhook(L,callhook); + lua_sethook(L,hook,LUA_MASKCALL | LUA_MASKRET | LUA_MASKLINE, 0); LOG=logfile; } -void stop_trace(void) +static void stop_trace(lua_State *L) { - lua_setlinehook(L,NULL); - lua_setcallhook(L,NULL); + lua_sethook(L,NULL,0,0); fclose(LOG); } int main(void) { int rc; - L=lua_open(0); + lua_State *L=lua_open(); lua_baselibopen(L); + lua_tablibopen(L); lua_iolibopen(L); lua_strlibopen(L); lua_mathlibopen(L); lua_dblibopen(L); - start_trace(stderr); - rc=lua_dofile(L,0); - stop_trace(); + start_trace(L,stderr); + rc=lua_dofile(L,NULL); + stop_trace(L); return rc; } |
