diff options
author | Lua Team <team@lua.org> | 2004-09-02 12:00:00 +0000 |
---|---|---|
committer | repogen <> | 2004-09-02 12:00:00 +0000 |
commit | 5d480731503a315eab9d6ab9426e3d4cfd5e52f8 (patch) | |
tree | 5606bf4c36fda4395d2bc1ea226227bcb80114b4 /etc | |
parent | ced7bbbe7a257ce6de94069d5dbf6672aeafd4d9 (diff) | |
download | lua-github-5d480731503a315eab9d6ab9426e3d4cfd5e52f8.tar.gz |
Lua 5.1-work15.1-work1
Diffstat (limited to 'etc')
-rw-r--r-- | etc/Makefile | 19 | ||||
l--------- | etc/RCS | 1 | ||||
-rw-r--r-- | etc/README | 4 | ||||
-rw-r--r-- | etc/all.c | 41 | ||||
-rw-r--r-- | etc/min.c | 46 | ||||
-rw-r--r-- | etc/noparser.c | 3 |
6 files changed, 84 insertions, 30 deletions
diff --git a/etc/Makefile b/etc/Makefile index 0fc318cd..805df1d2 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -4,32 +4,29 @@ LUA= .. include $(LUA)/config -LIBLUA=$(LIB)/liblua.a -ALL= bin2c min noparser luab +ALL= min noparser luab 1 all: @echo 'choose a target:' $(ALL) -bin2c: bin2c.c - $(CC) $(CFLAGS) -o $@ $@.c - min: min.c $(LIBLUA) - $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua + $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua -llualib 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) +luab: noparser + $(CC) -o $@ noparser.o $(LUA)/src/lua/lua.o -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB) $(BIN)/luac $(LUA)/test/hello.lua $@ luac.out -$@ -e'a=1' +1: + $(CC) $(CFLAGS) -I../src -I../src/lib -I../src/lua all.c $(EXTRA_LIBS) $(DLLIB) + ./a.out $(LUA)/test/hello.lua + flat: cd ..; mkdir flat; mv include/*.h src/*.[ch] src/*/*.[ch] flat -$(LIBLUA): - cd ../src; $(MAKE) - clean: rm -f $(ALL) a.out core *.o luac.out diff --git a/etc/RCS b/etc/RCS deleted file mode 120000 index 1ae38936..00000000 --- a/etc/RCS +++ /dev/null @@ -1 +0,0 @@ -../RCS
\ No newline at end of file @@ -1,6 +1,10 @@ This directory contains some useful files and code. Unlike the code in ../src, everything here is in the public domain. +all.c + Full Lua interpreter in a single file. + Do "make 1". + lua.ico A Lua icon for Windows (and web sites, as favicon.ico). Drawn by hand by Markus Gritsch <gritsch@iue.tuwien.ac.at>. diff --git a/etc/all.c b/etc/all.c new file mode 100644 index 00000000..fc4b045a --- /dev/null +++ b/etc/all.c @@ -0,0 +1,41 @@ +/* +* all.c -- Lua core, libraries and interpreter in a single file +*/ + +#define LUA_CORE +#define LUA_LIB +#define lua_c + +#include "lapi.c" +#include "lcode.c" +#include "ldebug.c" +#include "ldo.c" +#include "ldump.c" +#include "lfunc.c" +#include "lgc.c" +#include "llex.c" +#include "lmem.c" +#include "lobject.c" +#include "lopcodes.c" +#include "lparser.c" +#include "lstate.c" +#include "lstring.c" +#include "ltable.c" +#include "ltm.c" +#include "lundump.c" +#include "lvm.c" +#include "lzio.c" + +#include "lauxlib.c" +#include "lbaselib.c" +#include "ldblib.c" +#include "liolib.c" +#include "linit.c" +#include "lmathlib.c" +#include "loadlib.c" +#define pushresult pushresult2 +#include "loslib.c" +#include "lstrlib.c" +#include "ltablib.c" + +#include "lua.c" @@ -1,37 +1,47 @@ /* * min.c -- a minimal Lua interpreter -* only dynamic loading is enabled -- all libraries must be dynamically loaded -* no interaction, only batch execution +* loads stdin only with minimal error handling. +* no interaction, and no standard library, only a "print" function. */ #include <stdio.h> #include "lua.h" -#include "lualib.h" #include "lauxlib.h" -static int run(lua_State *L) +static int print(lua_State *L) { - char **argv=lua_touserdata(L,1); - lua_register(L,"error",lua_error); - luaopen_loadlib(L); - while (*++argv) + int n=lua_gettop(L); + int i; + for (i=1; i<=n; i++) { - if (luaL_loadfile(L,*argv)) lua_error(L); else lua_call(L,0,0); + 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)); } + printf("\n"); return 0; } -#define report(s) fprintf(stderr,"%s\n",s) +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(int argc, char *argv[]) +int main(void) { lua_State *L=lua_open(); - 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); + 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)); return 0; } diff --git a/etc/noparser.c b/etc/noparser.c index 9d52f7c0..dc58faff 100644 --- a/etc/noparser.c +++ b/etc/noparser.c @@ -9,6 +9,8 @@ * load the parsing modules. To try it, do "make luab". */ +#define LUA_CORE + #include "llex.h" #include "lparser.h" #include "lzio.h" @@ -28,6 +30,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { /* * If you also want to avoid the dump module, ldump.o, enable the code below. */ +#define NODUMP #ifdef NODUMP #include "lundump.h" |