diff options
| author | Lua Team <team@lua.org> | 2006-06-01 12:00:00 +0000 |
|---|---|---|
| committer | repogen <> | 2006-06-01 12:00:00 +0000 |
| commit | 60e37e0252c2758c935c8f382ace44b5100f6f21 (patch) | |
| tree | 4bd1cadadec00aedd818350c0f5c57b968125a85 /src | |
| parent | f6f9af6cbce3516054b6fd2a8e9d3a1b168ce4be (diff) | |
| download | lua-github-60e37e0252c2758c935c8f382ace44b5100f6f21.tar.gz | |
Lua 5.1.1-rc15.1.1-rc1
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 20 | ||||
| -rw-r--r-- | src/lauxlib.c | 18 | ||||
| -rw-r--r-- | src/lauxlib.h | 8 | ||||
| -rw-r--r-- | src/lbaselib.c | 4 | ||||
| -rw-r--r-- | src/lcode.c | 14 | ||||
| -rw-r--r-- | src/lcode.h | 3 | ||||
| -rw-r--r-- | src/lgc.c | 12 | ||||
| -rw-r--r-- | src/liolib.c | 6 | ||||
| -rw-r--r-- | src/llex.c | 3 | ||||
| -rw-r--r-- | src/llex.h | 6 | ||||
| -rw-r--r-- | src/loadlib.c | 6 | ||||
| -rw-r--r-- | src/lopcodes.h | 6 | ||||
| -rw-r--r-- | src/loslib.c | 13 | ||||
| -rw-r--r-- | src/lparser.c | 4 | ||||
| -rw-r--r-- | src/lparser.h | 3 | ||||
| -rw-r--r-- | src/lstate.c | 4 | ||||
| -rw-r--r-- | src/lstrlib.c | 9 | ||||
| -rw-r--r-- | src/lua.c | 29 | ||||
| -rw-r--r-- | src/lua.h | 4 | ||||
| -rw-r--r-- | src/luac.c | 18 | ||||
| -rw-r--r-- | src/luaconf.h | 28 | ||||
| -rw-r--r-- | src/print.c | 21 |
22 files changed, 145 insertions, 94 deletions
diff --git a/src/Makefile b/src/Makefile index 1d46d342..0708ac47 100644 --- a/src/Makefile +++ b/src/Makefile @@ -80,7 +80,7 @@ none: @echo "Please choose a platform: $(PLATS)" aix: - $(MAKE) all CC="xlc" CFLAGS="-O2" MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall" + $(MAKE) all CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall" ansi: $(MAKE) all MYCFLAGS=-DLUA_ANSI @@ -121,15 +121,15 @@ lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \ lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ - lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \ - ldo.h lgc.h + lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \ + ltable.h ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h ldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \ - llex.h lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h \ - ltm.h ldo.h lfunc.h lstring.h lgc.h lvm.h + llex.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \ + lfunc.h lstring.h lgc.h ltable.h lvm.h ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ - lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h \ - lstring.h lundump.h lvm.h + lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h lstring.h \ + ltable.h lundump.h lvm.h ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \ lzio.h lmem.h lundump.h lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \ @@ -139,7 +139,7 @@ lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \ - lzio.h lmem.h llex.h lparser.h ltable.h lstring.h lgc.h + lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ ltm.h lzio.h lmem.h ldo.h @@ -150,8 +150,8 @@ lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \ lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ - lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \ - ldo.h lfunc.h lstring.h lgc.h + lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \ + lfunc.h lstring.h lgc.h ltable.h lstate.o: lstate.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \ diff --git a/src/lauxlib.c b/src/lauxlib.c index 317a48d1..96a6b852 100644 --- a/src/lauxlib.c +++ b/src/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.158 2006/01/16 12:42:21 roberto Exp $ +** $Id: lauxlib.c,v 1.159 2006/03/21 19:31:09 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -123,11 +123,17 @@ LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { void *p = lua_touserdata(L, ud); - lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ - if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2)) - luaL_typerror(L, ud, tname); - lua_pop(L, 2); /* remove both metatables */ - return p; + if (p != NULL) { /* value is a userdata? */ + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ + if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ + lua_pop(L, 2); /* remove both metatables */ + return p; + } + } + } + luaL_typerror(L, ud, tname); /* else error */ + return NULL; /* to avoid warnings */ } diff --git a/src/lauxlib.h b/src/lauxlib.h index 1bba1c04..1f343086 100644 --- a/src/lauxlib.h +++ b/src/lauxlib.h @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.h,v 1.87 2005/12/29 15:32:11 roberto Exp $ +** $Id: lauxlib.h,v 1.88 2006/04/12 20:31:15 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -108,9 +108,11 @@ LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) -#define luaL_dofile(L, fn) (luaL_loadfile(L, fn) || lua_pcall(L, 0, 0, 0)) +#define luaL_dofile(L, fn) \ + (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) -#define luaL_dostring(L, s) (luaL_loadstring(L, s) || lua_pcall(L, 0, 0, 0)) +#define luaL_dostring(L, s) \ + (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) diff --git a/src/lbaselib.c b/src/lbaselib.c index 1d922a81..778e393a 100644 --- a/src/lbaselib.c +++ b/src/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.189 2006/01/18 11:49:12 roberto Exp $ +** $Id: lbaselib.c,v 1.190 2006/05/31 16:50:40 roberto Exp $ ** Basic library ** See Copyright Notice in lua.h */ @@ -619,7 +619,7 @@ static void base_open (lua_State *L) { lua_setglobal(L, "_G"); /* open lib into global table */ luaL_register(L, "_G", base_funcs); - lua_pushliteral(L, LUA_VERSION); + lua_pushlstring(L, LUA_VERSION, 7); lua_setglobal(L, "_VERSION"); /* set global _VERSION */ /* `ipairs' and `pairs' need auxliliary functions as upvalues */ auxopen(L, "ipairs", luaB_ipairs, ipairsaux); diff --git a/src/lcode.c b/src/lcode.c index dd3e37e7..b71acd84 100644 --- a/src/lcode.c +++ b/src/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.24 2005/12/22 16:19:56 roberto Exp $ +** $Id: lcode.c,v 2.25 2006/03/21 19:28:49 roberto Exp $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -731,17 +731,15 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { case OPR_AND: { lua_assert(e1->t == NO_JUMP); /* list must be closed */ luaK_dischargevars(fs, e2); - luaK_concat(fs, &e1->f, e2->f); - e1->k = e2->k; e1->u.s.info = e2->u.s.info; - e1->u.s.aux = e2->u.s.aux; e1->t = e2->t; + luaK_concat(fs, &e2->f, e1->f); + *e1 = *e2; break; } case OPR_OR: { lua_assert(e1->f == NO_JUMP); /* list must be closed */ luaK_dischargevars(fs, e2); - luaK_concat(fs, &e1->t, e2->t); - e1->k = e2->k; e1->u.s.info = e2->u.s.info; - e1->u.s.aux = e2->u.s.aux; e1->f = e2->f; + luaK_concat(fs, &e2->t, e1->t); + *e1 = *e2; break; } case OPR_CONCAT: { @@ -750,7 +748,7 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1); freeexp(fs, e1); SETARG_B(getcode(fs, e2), e1->u.s.info); - e1->k = e2->k; e1->u.s.info = e2->u.s.info; + e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info; } else { luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ diff --git a/src/lcode.h b/src/lcode.h index b5668f22..c02cb2b7 100644 --- a/src/lcode.h +++ b/src/lcode.h @@ -1,5 +1,5 @@ /* -** $Id: lcode.h,v 1.47 2005/11/08 19:44:31 roberto Exp $ +** $Id: lcode.h,v 1.48 2006/03/21 19:28:03 roberto Exp $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -32,7 +32,6 @@ typedef enum BinOpr { OPR_NOBINOPR } BinOpr; -#define binopistest(op) ((op) >= OPR_NE) typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.37 2005/12/22 16:19:56 roberto Exp $ +** $Id: lgc.c,v 2.38 2006/05/24 14:34:06 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -320,8 +320,10 @@ static l_mem propagatemark (global_State *g) { } -static void propagateall (global_State *g) { - while (g->gray) propagatemark(g); +static size_t propagateall (global_State *g) { + size_t m = 0; + while (g->gray) m += propagatemark(g); + return m; } @@ -540,7 +542,7 @@ static void atomic (lua_State *L) { propagateall(g); udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */ marktmu(g); /* mark `preserved' userdata */ - propagateall(g); /* remark, to propagate `preserveness' */ + udsize += propagateall(g); /* remark, to propagate `preserveness' */ cleartable(g->weak); /* remove collected objects from weak tables */ /* flip current white */ g->currentwhite = cast_byte(otherwhite(g)); @@ -590,6 +592,8 @@ static l_mem singlestep (lua_State *L) { case GCSfinalize: { if (g->tmudata) { GCTM(L); + if (g->estimate > GCFINALIZECOST) + g->estimate -= GCFINALIZECOST; return GCFINALIZECOST; } else { diff --git a/src/liolib.c b/src/liolib.c index bb3b5194..be60972c 100644 --- a/src/liolib.c +++ b/src/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 2.72 2006/01/28 12:59:13 roberto Exp $ +** $Id: liolib.c,v 2.73 2006/05/08 20:14:16 roberto Exp $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -99,7 +99,7 @@ static FILE **newfile (lua_State *L) { static int io_pclose (lua_State *L) { FILE **p = topfile(L); int ok = lua_pclose(L, *p); - if (ok) *p = NULL; + *p = NULL; return pushresult(L, ok, NULL); } @@ -107,7 +107,7 @@ static int io_pclose (lua_State *L) { static int io_fclose (lua_State *L) { FILE **p = topfile(L); int ok = (fclose(*p) == 0); - if (ok) *p = NULL; + *p = NULL; return pushresult(L, ok, NULL); } @@ -1,5 +1,5 @@ /* -** $Id: llex.c,v 2.19 2006/02/06 18:28:16 roberto Exp $ +** $Id: llex.c,v 2.20 2006/03/09 18:14:31 roberto Exp $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ @@ -20,6 +20,7 @@ #include "lparser.h" #include "lstate.h" #include "lstring.h" +#include "ltable.h" #include "lzio.h" @@ -1,5 +1,5 @@ /* -** $Id: llex.h,v 1.57 2005/12/07 15:43:05 roberto Exp $ +** $Id: llex.h,v 1.58 2006/03/23 18:23:32 roberto Exp $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ @@ -68,9 +68,9 @@ typedef struct LexState { LUAI_FUNC void luaX_init (lua_State *L); -LUAI_FUNC void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, +LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source); -LUAI_FUNC TString *luaX_newstring (LexState *LS, const char *str, size_t l); +LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); LUAI_FUNC void luaX_next (LexState *ls); LUAI_FUNC void luaX_lookahead (LexState *ls); LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); diff --git a/src/loadlib.c b/src/loadlib.c index 19edaca0..08722e18 100644 --- a/src/loadlib.c +++ b/src/loadlib.c @@ -1,5 +1,5 @@ /* -** $Id: loadlib.c,v 1.51 2005/12/29 15:32:11 roberto Exp $ +** $Id: loadlib.c,v 1.52 2006/04/10 18:27:23 roberto Exp $ ** Dynamic library loader for Lua ** See Copyright Notice in lua.h ** @@ -22,10 +22,6 @@ #include "lualib.h" -/* environment variables that hold the search path for packages */ -#define LUA_PATH "LUA_PATH" -#define LUA_CPATH "LUA_CPATH" - /* prefix for open functions in C libraries */ #define LUA_POF "luaopen_" diff --git a/src/lopcodes.h b/src/lopcodes.h index 2834b1d7..48105f1e 100644 --- a/src/lopcodes.h +++ b/src/lopcodes.h @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.h,v 1.124 2005/12/02 18:42:08 roberto Exp $ +** $Id: lopcodes.h,v 1.125 2006/03/14 19:04:44 roberto Exp $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ @@ -197,8 +197,8 @@ OP_FORLOOP,/* A sBx R(A)+=R(A+2); if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/ OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */ -OP_TFORLOOP,/* A C R(A+3), ... ,R(A+3+C) := R(A)(R(A+1), R(A+2)); - if R(A+3) ~= nil then { pc++; R(A+2)=R(A+3); } */ +OP_TFORLOOP,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); + if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++ */ OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */ OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/ diff --git a/src/loslib.c b/src/loslib.c index 509d7b72..7c6c5d61 100644 --- a/src/loslib.c +++ b/src/loslib.c @@ -1,5 +1,5 @@ /* -** $Id: loslib.c,v 1.17 2006/01/27 13:54:31 roberto Exp $ +** $Id: loslib.c,v 1.19 2006/04/26 18:19:49 roberto Exp $ ** Standard Operating System library ** See Copyright Notice in lua.h */ @@ -28,10 +28,7 @@ static int os_pushresult (lua_State *L, int i, const char *filename) { } else { lua_pushnil(L); - if (filename) - lua_pushfstring(L, "%s: %s", filename, strerror(en)); - else - lua_pushfstring(L, "%s", strerror(en)); + lua_pushfstring(L, "%s: %s", filename, strerror(en)); lua_pushinteger(L, en); return 3; } @@ -126,8 +123,7 @@ static int getfield (lua_State *L, const char *key, int d) { static int os_date (lua_State *L) { const char *s = luaL_optstring(L, 1, "%c"); - time_t t = lua_isnoneornil(L, 2) ? time(NULL) : - (time_t)luaL_checknumber(L, 2); + time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); struct tm *stm; if (*s == '!') { /* UTC? */ stm = gmtime(&t); @@ -199,9 +195,8 @@ static int os_setlocale (lua_State *L) { LC_NUMERIC, LC_TIME}; static const char *const catnames[] = {"all", "collate", "ctype", "monetary", "numeric", "time", NULL}; - const char *l = lua_tostring(L, 1); + const char *l = luaL_optstring(L, 1, NULL); int op = luaL_checkoption(L, 2, "all", catnames); - luaL_argcheck(L, l || lua_isnoneornil(L, 1), 1, "string expected"); lua_pushstring(L, setlocale(cat[op], l)); return 1; } diff --git a/src/lparser.c b/src/lparser.c index b40ee794..6d30ebad 100644 --- a/src/lparser.c +++ b/src/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 2.40 2005/12/22 16:19:56 roberto Exp $ +** $Id: lparser.c,v 2.41 2006/03/09 18:15:48 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -23,7 +23,7 @@ #include "lparser.h" #include "lstate.h" #include "lstring.h" - +#include "ltable.h" diff --git a/src/lparser.h b/src/lparser.h index d5e6e81d..e5b5b57e 100644 --- a/src/lparser.h +++ b/src/lparser.h @@ -1,5 +1,5 @@ /* -** $Id: lparser.h,v 1.56 2005/10/03 14:02:40 roberto Exp $ +** $Id: lparser.h,v 1.57 2006/03/09 18:14:31 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -9,7 +9,6 @@ #include "llimits.h" #include "lobject.h" -#include "ltable.h" #include "lzio.h" diff --git a/src/lstate.c b/src/lstate.c index 77e93fbd..4bcb7594 100644 --- a/src/lstate.c +++ b/src/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.35 2005/10/06 20:46:25 roberto Exp $ +** $Id: lstate.c,v 2.36 2006/05/24 14:15:50 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -198,7 +198,6 @@ static void callallgcTM (lua_State *L, void *ud) { LUA_API void lua_close (lua_State *L) { L = G(L)->mainthread; /* only the main thread can be closed */ - luai_userstateclose(L); lua_lock(L); luaF_close(L, L->stack); /* close all upvalues for this thread */ luaC_separateudata(L, 1); /* separate udata that have GC metamethods */ @@ -209,6 +208,7 @@ LUA_API void lua_close (lua_State *L) { L->nCcalls = 0; } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); lua_assert(G(L)->tmudata == NULL); + luai_userstateclose(L); close_state(L); } diff --git a/src/lstrlib.c b/src/lstrlib.c index 84478fd1..f93a8af0 100644 --- a/src/lstrlib.c +++ b/src/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.130 2005/12/29 15:32:11 roberto Exp $ +** $Id: lstrlib.c,v 1.132 2006/04/26 20:41:19 roberto Exp $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -703,6 +703,10 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { luaL_addchar(b, *s); break; } + case '\r': { + luaL_addlstring(b, "\\r", 2); + break; + } case '\0': { luaL_addlstring(b, "\\000", 4); break; @@ -805,7 +809,8 @@ static int str_format (lua_State *L) { } } default: { /* also treat cases `pnLlh' */ - return luaL_error(L, "invalid option to " LUA_QL("format")); + return luaL_error(L, "invalid option " LUA_QL("%%%c") " to " + LUA_QL("format"), *(strfrmt - 1)); } } luaL_addlstring(&b, buff, strlen(buff)); @@ -1,5 +1,5 @@ /* -** $Id: lua.c,v 1.157 2005/12/29 16:23:32 roberto Exp $ +** $Id: lua.c,v 1.159 2006/05/24 14:16:39 roberto Exp $ ** Lua stand-alone interpreter ** See Copyright Notice in lua.h */ @@ -252,17 +252,30 @@ static int handle_script (lua_State *L, char **argv, int n) { } +/* check that argument has no extra characters at the end */ +#define notail(x) {if ((x)[2] != '\0') return -1;} + + static int collectargs (char **argv, int *pi, int *pv, int *pe) { int i; for (i = 1; argv[i] != NULL; i++) { if (argv[i][0] != '-') /* not an option? */ return i; switch (argv[i][1]) { /* option */ - case '-': return (argv[i+1] != NULL ? i+1 : 0); - case '\0': return i; - case 'i': *pi = 1; /* go through */ - case 'v': *pv = 1; break; - case 'e': *pe = 1; /* go through */ + case '-': + notail(argv[i]); + return (argv[i+1] != NULL ? i+1 : 0); + case '\0': + return i; + case 'i': + notail(argv[i]); + *pi = 1; /* go through */ + case 'v': + notail(argv[i]); + *pv = 1; + break; + case 'e': + *pe = 1; /* go through */ case 'l': if (argv[i][2] == '\0') { i++; @@ -306,12 +319,12 @@ static int runargs (lua_State *L, char **argv, int n) { static int handle_luainit (lua_State *L) { - const char *init = getenv("LUA_INIT"); + const char *init = getenv(LUA_INIT); if (init == NULL) return 0; /* status OK */ else if (init[0] == '@') return dofile(L, init+1); else - return dostring(L, init, "=LUA_INIT"); + return dostring(L, init, "=" LUA_INIT); } @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.216 2006/01/10 12:50:13 roberto Exp $ +** $Id: lua.h,v 1.217 2006/05/31 16:50:40 roberto Exp $ ** Lua - An Extensible Extension Language ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** See Copyright Notice at the end of this file @@ -16,7 +16,7 @@ #include "luaconf.h" -#define LUA_VERSION "Lua 5.1" +#define LUA_VERSION "Lua 5.1.1" #define LUA_VERSION_NUM 501 #define LUA_COPYRIGHT "Copyright (C) 1994-2006 Lua.org, PUC-Rio" #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" @@ -1,5 +1,5 @@ /* -** $Id: luac.c,v 1.52 2005/11/11 14:03:13 lhf Exp $ +** $Id: luac.c,v 1.53 2006/05/31 13:30:05 lhf Exp $ ** Lua compiler (saves bytecodes to files; also list bytecodes) ** See Copyright Notice in lua.h */ @@ -70,6 +70,7 @@ static void usage(const char* message) static int doargs(int argc, char* argv[]) { int i; + int version=0; if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0]; for (i=1; i<argc; i++) { @@ -78,6 +79,7 @@ static int doargs(int argc, char* argv[]) else if (IS("--")) /* end of options; skip it */ { ++i; + if (version) ++version; break; } else if (IS("-")) /* end of options; use stdin */ @@ -95,10 +97,7 @@ static int doargs(int argc, char* argv[]) else if (IS("-s")) /* strip debug information */ stripping=1; else if (IS("-v")) /* show version */ - { - printf("%s %s\n",LUA_VERSION,LUA_COPYRIGHT); - if (argc==2) exit(EXIT_SUCCESS); - } + ++version; else /* unknown option */ usage(argv[i]); } @@ -107,12 +106,17 @@ static int doargs(int argc, char* argv[]) dumping=0; argv[--i]=Output; } + if (version) + { + printf("%s %s\n",LUA_VERSION,LUA_COPYRIGHT); + if (version==argc-1) exit(EXIT_SUCCESS); + } return i; } #define toproto(L,i) (clvalue(L->top+(i))->l.p) -static Proto* combine(lua_State* L, int n) +static const Proto* combine(lua_State* L, int n) { if (n==1) return toproto(L,-1); @@ -156,7 +160,7 @@ static int pmain(lua_State* L) struct Smain* s = (struct Smain*)lua_touserdata(L, 1); int argc=s->argc; char** argv=s->argv; - Proto* f; + const Proto* f; int i; if (!lua_checkstack(L,argc)) fatal("too many input files"); for (i=0; i<argc; i++) diff --git a/src/luaconf.h b/src/luaconf.h index 97a3e30c..f32f1f76 100644 --- a/src/luaconf.h +++ b/src/luaconf.h @@ -1,5 +1,5 @@ /* -** $Id: luaconf.h,v 1.81 2006/02/10 17:44:06 roberto Exp $ +** $Id: luaconf.h,v 1.82 2006/04/10 18:27:23 roberto Exp $ ** Configuration file for Lua ** See Copyright Notice in lua.h */ @@ -60,6 +60,18 @@ /* +@@ LUA_PATH and LUA_CPATH are the names of the environment variables that +@* Lua check to set its paths. +@@ LUA_INIT is the name of the environment variable that Lua +@* checks for initialization code. +** CHANGE them if you want different names. +*/ +#define LUA_PATH "LUA_PATH" +#define LUA_CPATH "LUA_CPATH" +#define LUA_INIT "LUA_INIT" + + +/* @@ LUA_PATH_DEFAULT is the default path that Lua uses to look for @* Lua libraries. @@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for @@ -543,11 +555,25 @@ /* On a Pentium, resort to a trick */ #if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \ (defined(__i386) || defined (_M_IX86) || defined(__i386__)) + +/* On a Microsoft compiler, use assembler */ +#if defined(_MSC_VER) + +#define lua_number2int(i,d) __asm fld d __asm fistp i +#define lua_number2integer(i,n) lua_number2int(i, n) + +/* the next trick should work on any Pentium, but sometimes clashes + with a DirectX idiosyncrasy */ +#else + union luai_Cast { double l_d; long l_l; }; #define lua_number2int(i,d) \ { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; } #define lua_number2integer(i,n) lua_number2int(i, n) +#endif + + /* this option always works, but may be slow */ #else #define lua_number2int(i,d) ((i)=(int)(d)) diff --git a/src/print.c b/src/print.c index 1c3a4457..2a4fb3ed 100644 --- a/src/print.c +++ b/src/print.c @@ -1,5 +1,5 @@ /* -** $Id: print.c,v 1.54 2006/01/11 22:49:27 lhf Exp $ +** $Id: print.c,v 1.55 2006/05/31 13:30:05 lhf Exp $ ** print bytecodes ** See Copyright Notice in lua.h */ @@ -20,13 +20,16 @@ #define Sizeof(x) ((int)sizeof(x)) #define VOID(p) ((const void*)(p)) -static void PrintString(const Proto* f, int n) +static void PrintString(const TString* ts) { - const char* s=svalue(&f->k[n]); + const char* s=getstr(ts); + int n=ts->tsv.len; + int i; putchar('"'); - for (; *s; s++) + for (i=0; i<n; i++) { - switch (*s) + int c=s[i]; + switch (c) { case '"': printf("\\\""); break; case '\a': printf("\\a"); break; @@ -36,10 +39,10 @@ static void PrintString(const Proto* f, int n) case '\r': printf("\\r"); break; case '\t': printf("\\t"); break; case '\v': printf("\\v"); break; - default: if (isprint((unsigned char)*s)) - printf("%c",*s); + default: if (isprint((unsigned char)c)) + putchar(c); else - printf("\\%03u",(unsigned char)*s); + printf("\\%03u",(unsigned char)c); } } putchar('"'); @@ -60,7 +63,7 @@ static void PrintConstant(const Proto* f, int i) printf(LUA_NUMBER_FMT,nvalue(o)); break; case LUA_TSTRING: - PrintString(f,i); + PrintString(rawtsvalue(o)); break; default: /* cannot happen */ printf("? type=%d",ttype(o)); |
