diff options
Diffstat (limited to 'etc')
-rw-r--r-- | etc/Makefile | 11 | ||||
l--------- | etc/RCS | 1 | ||||
-rw-r--r-- | etc/README | 38 | ||||
-rw-r--r-- | etc/bin2c.c | 67 | ||||
-rw-r--r-- | etc/compat.lua | 192 | ||||
-rw-r--r-- | etc/doall.lua | 6 | ||||
-rw-r--r-- | etc/lua.magic | 12 | ||||
-rw-r--r-- | etc/lua.xpm | 44 | ||||
-rw-r--r-- | etc/luser_number.h | 34 | ||||
-rw-r--r-- | etc/luser_tests.h | 68 | ||||
-rw-r--r-- | etc/min.c | 47 | ||||
-rw-r--r-- | etc/noparser.c | 16 | ||||
-rw-r--r-- | etc/saconfig.c | 4 | ||||
-rw-r--r-- | etc/trace.c | 55 |
14 files changed, 40 insertions, 555 deletions
diff --git a/etc/Makefile b/etc/Makefile index 1286c640..0fc318cd 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -5,7 +5,7 @@ LUA= .. include $(LUA)/config LIBLUA=$(LIB)/liblua.a -ALL= bin2c min trace noparser luab +ALL= bin2c min noparser luab all: @echo 'choose a target:' $(ALL) @@ -16,14 +16,11 @@ bin2c: bin2c.c min: min.c $(LIBLUA) $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua -trace: trace.c $(LIBLUA) - $(CC) -g $(CFLAGS) -o $@ $@.c -L$(LIB) -llua -llualib $(EXTRA_LIBS) - noparser: noparser.c $(CC) $(CFLAGS) -I$(LUA)/src -o $@.o -c $@.c luab: noparser $(LIBLUA) - cc -o $@ noparser.o $(LUA)/src/lua/lua.o -L$(LIB) -llua -llualib $(EXTRA_LIBS) + $(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' @@ -36,7 +33,3 @@ $(LIBLUA): clean: 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 $@ diff --git a/etc/RCS b/etc/RCS new file mode 120000 index 00000000..1ae38936 --- /dev/null +++ b/etc/RCS @@ -0,0 +1 @@ +../RCS
\ No newline at end of file @@ -1,42 +1,10 @@ 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 - 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 you #include "init.h". - -compat.lua - A compatibility module for Lua 4.0 functions. - -doall.lua - Emulate the command line behaviour of Lua 4.0 - lua.ico - A Lua icon for Windows. + A Lua icon for Windows (and web sites, as favicon.ico). 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>. - -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. @@ -48,7 +16,3 @@ noparser.c saconfig.c Configuration for Lua interpreter. - -trace.c - 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 deleted file mode 100644 index 0993b16d..00000000 --- a/etc/bin2c.c +++ /dev/null @@ -1,67 +0,0 @@ -/* -* bin2c.c -* convert files to byte arrays for automatic loading with lua_dobuffer -* Luiz Henrique de Figueiredo (lhf@tecgraf.puc-rio.br) -* 02 Apr 2003 20:44:31 -*/ - -#include <ctype.h> -#include <stdio.h> -#include <stdlib.h> - -static void dump(FILE* f, int n) -{ - printf("static const unsigned char B%d[]={\n",n); - for (n=1;;n++) - { - int c=getc(f); - if (c==EOF) break; - printf("%3u,",c); - if (n==20) { putchar('\n'); n=0; } - } - printf("\n};\n\n"); -} - -static void fdump(const char* fn, int n) -{ - FILE* f= fopen(fn,"rb"); /* must open in binary mode */ - if (f==NULL) - { - fprintf(stderr,"bin2c: cannot open "); - perror(fn); - exit(1); - } - else - { - printf("/* %s */\n",fn); - dump(f,n); - fclose(f); - } -} - -static void emit(const char* fn, int n) -{ - printf(" lua_dobuffer(L,(const char*)B%d,sizeof(B%d),\"%s\");\n",n,n,fn); -} - -int main(int argc, char* argv[]) -{ - printf("/* code automatically generated by bin2c -- DO NOT EDIT */\n"); - printf("{\n"); - if (argc<2) - { - dump(stdin,0); - emit("=stdin",0); - } - 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(L,\"%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); - } - printf("}\n"); - return 0; -} diff --git a/etc/compat.lua b/etc/compat.lua deleted file mode 100644 index 2a7f3731..00000000 --- a/etc/compat.lua +++ /dev/null @@ -1,192 +0,0 @@ -------------------------------------------------------------------- --- 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/doall.lua b/etc/doall.lua deleted file mode 100644 index fb0fad70..00000000 --- a/etc/doall.lua +++ /dev/null @@ -1,6 +0,0 @@ --- 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 deleted file mode 100644 index c7ae5955..00000000 --- a/etc/lua.magic +++ /dev/null @@ -1,12 +0,0 @@ - -# 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 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/lua.xpm b/etc/lua.xpm deleted file mode 100644 index d3dcd379..00000000 --- a/etc/lua.xpm +++ /dev/null @@ -1,44 +0,0 @@ -/* XPM */ -static char *magick[] = { -/* columns rows colors chars-per-pixel */ -"32 32 6 1", -" c Gray0", -". c #000000008080", -"X c #808080808080", -"o c #c0c0c0c0c0c0", -"O c Gray100", -"+ c None", -/* pixels */ -"++++++++++++++++++++++++++ooo+++", -"++++++++++++++++++++++++oX...Xo+", -"++++++++++++++++++++++++X.....X+", -"+++++++++++++++++++++++o.......o", -"+++++++++XX......XX++++o.......o", -"+++++++X............X++o.......o", -"+++++o................o+X.....X+", -"++++X..................XoX...Xo+", -"+++X..............XXX...X+ooo+++", -"++o.............XoOOOoX..o++++++", -"++..............oOOOOOo...++++++", -"+X.............XOOOOOOOX..X+++++", -"+..............XOOOOOOOX...+++++", -"X..............XOOOOOOOX...X++++", -"X...............oOOOOOo....X++++", -"................XoOOOoX.....++++", -"....XO............XXX.......++++", -"....XO......................++++", -"....XO.....OX..OX.XOOOo.....++++", -"....XO.....OX..OX.OoXXOX....++++", -"....XO.....OX..OX....XOX....++++", -"X...XO.....OX..OX..OOoOX...X++++", -"X...XO.....OX..OX.OX..OX...X++++", -"+...XOXXXX.OoXoOX.OXXXOX...+++++", -"+X..XOOOOO.XOOXOX.XOOOXo..X+++++", -"++........................++++++", -"++o......................o++++++", -"+++X....................X+++++++", -"++++X..................X++++++++", -"+++++o................o+++++++++", -"+++++++X............X+++++++++++", -"+++++++++XX......XX+++++++++++++" -}; diff --git a/etc/luser_number.h b/etc/luser_number.h deleted file mode 100644 index 8cc2678e..00000000 --- a/etc/luser_number.h +++ /dev/null @@ -1,34 +0,0 @@ -/* 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 deleted file mode 100644 index 1ee6e3fd..00000000 --- a/etc/luser_tests.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -** $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,46 +1,37 @@ /* * min.c -- a minimal Lua interpreter -* loads stdin only with minimal error handling. -* no interaction, and no standard library, only a "print" function. +* only dynamic loading is enabled -- all libraries must be dynamically loaded +* no interaction, only batch execution */ #include <stdio.h> #include "lua.h" +#include "lualib.h" +#include "lauxlib.h" -static int print(lua_State *L) +static int run(lua_State *L) { - int n=lua_gettop(L); - int i; - for (i=1; i<=n; i++) + char **argv=lua_touserdata(L,1); + lua_register(L,"error",lua_error); + luaopen_loadlib(L); + while (*++argv) { - 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)); + if (luaL_loadfile(L,*argv)) lua_error(L); else lua_call(L,0,0); } - printf("\n"); 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; -} +#define report(s) fprintf(stderr,"%s\n",s) -int main(void) +int main(int argc, char *argv[]) { lua_State *L=lua_open(); - lua_register(L,"print",print); - if (lua_load(L,getF,stdin,"=stdin") || lua_pcall(L,0,0,0)) - fprintf(stderr,"%s\n",lua_tostring(L,-1)); + if (L==NULL) + { + report("not enough memory for state"); + return 1; + } + if (lua_cpcall(L,run,argv)) report(lua_tostring(L,-1)); + lua_close(L); return 0; } diff --git a/etc/noparser.c b/etc/noparser.c index 00c2b126..9d52f7c0 100644 --- a/etc/noparser.c +++ b/etc/noparser.c @@ -17,10 +17,24 @@ void luaX_init (lua_State *L) { UNUSED(L); } -Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff) { +Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { UNUSED(z); UNUSED(buff); lua_pushstring(L,"parser not loaded"); lua_error(L); return NULL; } + +/* +* If you also want to avoid the dump module, ldump.o, enable the code below. +*/ +#ifdef NODUMP +#include "lundump.h" + +int luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data, int strip) +{ + return 0; + lua_pushstring(L,"dumper not loaded"); + lua_error(L); +} +#endif diff --git a/etc/saconfig.c b/etc/saconfig.c index bf3c64b7..6c07cce1 100644 --- a/etc/saconfig.c +++ b/etc/saconfig.c @@ -1,10 +1,10 @@ -/* sa-config.c -- configuration for stand-alone Lua interpreter +/* saconfig.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: +*** Line editing and history: * #define USE_READLINE to use the GNU readline library. * * To use another library for this, use the code below as a start. diff --git a/etc/trace.c b/etc/trace.c deleted file mode 100644 index c29f1c9d..00000000 --- a/etc/trace.c +++ /dev/null @@ -1,55 +0,0 @@ -/* -* trace.c -- a simple execution tracer for Lua -*/ - -#include <stdio.h> -#include <string.h> -#include "lua.h" -#include "lualib.h" -#include "lauxlib.h" - -static FILE* LOG; /* log file */ -static int I=0; /* indentation level */ - -static void hook(lua_State *L, lua_Debug *ar) -{ - 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; -} - -static void start_trace(lua_State *L, FILE* logfile) -{ - lua_sethook(L,hook,LUA_MASKCALL | LUA_MASKRET | LUA_MASKLINE, 0); - LOG=logfile; -} - -static void stop_trace(lua_State *L) -{ - lua_sethook(L,NULL,0,0); - fclose(LOG); -} - -int main(void) -{ - int rc; - 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(L,stderr); - rc=lua_dofile(L,NULL); - stop_trace(L); - return rc; -} |