git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8211 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Brian West 2008-04-28 17:33:58 +00:00
parent 53f2c134a3
commit a4f4228b2d
57 changed files with 5210 additions and 301 deletions

View File

@ -20,7 +20,7 @@ MYLIBS=
# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
PLATS= aix ansi bsd generic linux macosx mingw posix solaris PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
LUA_A= liblua.a LUA_A= liblua.a
CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \ CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
@ -77,10 +77,11 @@ echo:
# convenience targets for popular platforms # convenience targets for popular platforms
none: none:
@echo "Please choose a platform: $(PLATS)" @echo "Please choose a platform:"
@echo " $(PLATS)"
aix: 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: ansi:
$(MAKE) all MYCFLAGS=-DLUA_ANSI $(MAKE) all MYCFLAGS=-DLUA_ANSI
@ -88,6 +89,9 @@ ansi:
bsd: bsd:
$(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E" $(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
freebsd:
$(MAKE) all MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"
generic: generic:
$(MAKE) all MYCFLAGS= $(MAKE) all MYCFLAGS=
@ -95,14 +99,15 @@ linux:
$(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses" $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
macosx: macosx:
$(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"
# use this on Mac OS X 10.4 # use this on Mac OS X 10.3-
# $(MAKE) all MYCFLAGS="-DLUA_USE_MACOSX -DLUA_USE_READLINE" MYLIBS="-lreadline" # $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX
mingw: mingw:
$(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \ $(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \
"AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \ "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \
"MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe
$(MAKE) "LUAC_T=luac.exe" luac.exe
posix: posix:
$(MAKE) all MYCFLAGS=-DLUA_USE_POSIX $(MAKE) all MYCFLAGS=-DLUA_USE_POSIX
@ -121,15 +126,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 lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h
lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.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 \ 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 \ lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \
ldo.h lgc.h ltable.h
ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.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 \ 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 \ llex.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \
ltm.h ldo.h lfunc.h lstring.h lgc.h lvm.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 \ 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 \ lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h lstring.h \
lstring.h lundump.h lvm.h ltable.h lundump.h lvm.h
ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \ ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \
lzio.h lmem.h lundump.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 \ lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \
@ -139,19 +144,18 @@ 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 linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h
liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.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 \ 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 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 \ lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
ltm.h lzio.h lmem.h ldo.h ltm.h lzio.h lmem.h ldo.h
loadlib.o: loadlib.c lauxlib.h lua.h luaconf.h lobject.h llimits.h \ loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h
lualib.h
lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \ lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \
ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h
lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.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 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 \ 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 \ lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \
ldo.h lfunc.h lstring.h lgc.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 \ 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 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 \ lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lapi.c,v 2.53 2006/01/10 12:50:00 roberto Exp $ ** $Id: lapi.c,v 2.55.1.3 2008/01/03 15:20:39 roberto Exp $
** Lua API ** Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -32,7 +32,7 @@
const char lua_ident[] = const char lua_ident[] =
"$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" "$Lua: " LUA_RELEASE " " LUA_COPYRIGHT " $\n"
"$Authors: " LUA_AUTHORS " $\n" "$Authors: " LUA_AUTHORS " $\n"
"$URL: www.lua.org $\n"; "$URL: www.lua.org $\n";
@ -123,6 +123,11 @@ LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {
} }
LUA_API void lua_setlevel (lua_State *from, lua_State *to) {
to->nCcalls = from->nCcalls;
}
LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {
lua_CFunction old; lua_CFunction old;
lua_lock(L); lua_lock(L);
@ -199,6 +204,9 @@ LUA_API void lua_insert (lua_State *L, int idx) {
LUA_API void lua_replace (lua_State *L, int idx) { LUA_API void lua_replace (lua_State *L, int idx) {
StkId o; StkId o;
lua_lock(L); lua_lock(L);
/* explicit test for incompatible code */
if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci)
luaG_runerror(L, "no calling environment");
api_checknelems(L, 1); api_checknelems(L, 1);
o = index2adr(L, idx); o = index2adr(L, idx);
api_checkvalidindex(L, o); api_checkvalidindex(L, o);
@ -746,7 +754,7 @@ LUA_API int lua_setfenv (lua_State *L, int idx) {
res = 0; res = 0;
break; break;
} }
luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
L->top--; L->top--;
lua_unlock(L); lua_unlock(L);
return res; return res;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lapi.h,v 2.2 2005/04/25 19:24:10 roberto Exp $ ** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $
** Auxiliary functions from Lua API ** Auxiliary functions from Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lauxlib.c,v 1.158 2006/01/16 12:42:21 roberto Exp $ ** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** 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) { LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
void *p = lua_touserdata(L, ud); void *p = lua_touserdata(L, ud);
lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ if (p != NULL) { /* value is a userdata? */
if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2)) if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
luaL_typerror(L, ud, tname); lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
lua_pop(L, 2); /* remove both metatables */ if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */
return p; lua_pop(L, 2); /* remove both metatables */
return p;
}
}
}
luaL_typerror(L, ud, tname); /* else error */
return NULL; /* to avoid warnings */
} }
@ -238,7 +244,7 @@ LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
if (libname) { if (libname) {
int size = libsize(l); int size = libsize(l);
/* check whether lib already exists */ /* check whether lib already exists */
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", size); luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
lua_getfield(L, -1, libname); /* get _LOADED[libname] */ lua_getfield(L, -1, libname); /* get _LOADED[libname] */
if (!lua_istable(L, -1)) { /* not found? */ if (!lua_istable(L, -1)) { /* not found? */
lua_pop(L, 1); /* remove previous result */ lua_pop(L, 1); /* remove previous result */
@ -529,7 +535,7 @@ static const char *getF (lua_State *L, void *ud, size_t *size) {
return "\n"; return "\n";
} }
if (feof(lf->f)) return NULL; if (feof(lf->f)) return NULL;
*size = fread(lf->buff, 1, LUAL_BUFFERSIZE, lf->f); *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);
return (*size > 0) ? lf->buff : NULL; return (*size > 0) ? lf->buff : NULL;
} }
@ -564,9 +570,8 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */
if (c == '\n') c = getc(lf.f); if (c == '\n') c = getc(lf.f);
} }
if (c == LUA_SIGNATURE[0] && lf.f != stdin) { /* binary file? */ if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
fclose(lf.f); lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
lf.f = fopen(filename, "rb"); /* reopen in binary mode */
if (lf.f == NULL) return errfile(L, "reopen", fnameindex); if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
/* skip eventual `#!...' */ /* skip eventual `#!...' */
while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
@ -575,7 +580,7 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
ungetc(c, lf.f); ungetc(c, lf.f);
status = lua_load(L, getF, &lf, lua_tostring(L, -1)); status = lua_load(L, getF, &lf, lua_tostring(L, -1));
readstatus = ferror(lf.f); readstatus = ferror(lf.f);
if (lf.f != stdin) fclose(lf.f); /* close file (even in case of errors) */ if (filename) fclose(lf.f); /* close file (even in case of errors) */
if (readstatus) { if (readstatus) {
lua_settop(L, fnameindex); /* ignore results from `lua_load' */ lua_settop(L, fnameindex); /* ignore results from `lua_load' */
return errfile(L, "read", fnameindex); return errfile(L, "read", fnameindex);

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lauxlib.h,v 1.87 2005/12/29 15:32:11 roberto Exp $ ** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** 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_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))) #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lbaselib.c,v 1.189 2006/01/18 11:49:12 roberto Exp $ ** $Id: lbaselib.c,v 1.191.1.4 2008/01/20 13:53:22 roberto Exp $
** Basic library ** Basic library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -114,11 +114,11 @@ static int luaB_setmetatable (lua_State *L) {
} }
static void getfunc (lua_State *L) { static void getfunc (lua_State *L, int opt) {
if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
else { else {
lua_Debug ar; lua_Debug ar;
int level = luaL_optint(L, 1, 1); int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1);
luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
if (lua_getstack(L, level, &ar) == 0) if (lua_getstack(L, level, &ar) == 0)
luaL_argerror(L, 1, "invalid level"); luaL_argerror(L, 1, "invalid level");
@ -131,7 +131,7 @@ static void getfunc (lua_State *L) {
static int luaB_getfenv (lua_State *L) { static int luaB_getfenv (lua_State *L) {
getfunc(L); getfunc(L, 1);
if (lua_iscfunction(L, -1)) /* is a C function? */ if (lua_iscfunction(L, -1)) /* is a C function? */
lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */
else else
@ -142,7 +142,7 @@ static int luaB_getfenv (lua_State *L) {
static int luaB_setfenv (lua_State *L) { static int luaB_setfenv (lua_State *L) {
luaL_checktype(L, 2, LUA_TTABLE); luaL_checktype(L, 2, LUA_TTABLE);
getfunc(L); getfunc(L, 0);
lua_pushvalue(L, 2); lua_pushvalue(L, 2);
if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {
/* change environment of current thread */ /* change environment of current thread */
@ -477,15 +477,52 @@ static const luaL_Reg base_funcs[] = {
** ======================================================= ** =======================================================
*/ */
#define CO_RUN 0 /* running */
#define CO_SUS 1 /* suspended */
#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */
#define CO_DEAD 3
static const char *const statnames[] =
{"running", "suspended", "normal", "dead"};
static int costatus (lua_State *L, lua_State *co) {
if (L == co) return CO_RUN;
switch (lua_status(co)) {
case LUA_YIELD:
return CO_SUS;
case 0: {
lua_Debug ar;
if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */
return CO_NOR; /* it is running */
else if (lua_gettop(co) == 0)
return CO_DEAD;
else
return CO_SUS; /* initial state */
}
default: /* some error occured */
return CO_DEAD;
}
}
static int luaB_costatus (lua_State *L) {
lua_State *co = lua_tothread(L, 1);
luaL_argcheck(L, co, 1, "coroutine expected");
lua_pushstring(L, statnames[costatus(L, co)]);
return 1;
}
static int auxresume (lua_State *L, lua_State *co, int narg) { static int auxresume (lua_State *L, lua_State *co, int narg) {
int status; int status = costatus(L, co);
if (!lua_checkstack(co, narg)) if (!lua_checkstack(co, narg))
luaL_error(L, "too many arguments to resume"); luaL_error(L, "too many arguments to resume");
if (lua_status(co) == 0 && lua_gettop(co) == 0) { if (status != CO_SUS) {
lua_pushliteral(L, "cannot resume dead coroutine"); lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]);
return -1; /* error flag */ return -1; /* error flag */
} }
lua_xmove(L, co, narg); lua_xmove(L, co, narg);
lua_setlevel(L, co);
status = lua_resume(co, narg); status = lua_resume(co, narg);
if (status == 0 || status == LUA_YIELD) { if (status == 0 || status == LUA_YIELD) {
int nres = lua_gettop(co); int nres = lua_gettop(co);
@ -556,39 +593,10 @@ static int luaB_yield (lua_State *L) {
} }
static int luaB_costatus (lua_State *L) {
lua_State *co = lua_tothread(L, 1);
luaL_argcheck(L, co, 1, "coroutine expected");
if (L == co) lua_pushliteral(L, "running");
else {
switch (lua_status(co)) {
case LUA_YIELD:
lua_pushliteral(L, "suspended");
break;
case 0: {
lua_Debug ar;
if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */
lua_pushliteral(L, "normal"); /* it is running */
else if (lua_gettop(co) == 0)
lua_pushliteral(L, "dead");
else
lua_pushliteral(L, "suspended"); /* initial state */
break;
}
default: /* some error occured */
lua_pushliteral(L, "dead");
break;
}
}
return 1;
}
static int luaB_corunning (lua_State *L) { static int luaB_corunning (lua_State *L) {
if (lua_pushthread(L)) if (lua_pushthread(L))
return 0; /* main thread is not a coroutine */ lua_pushnil(L); /* main thread is not a coroutine */
else return 1;
return 1;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lcode.c,v 2.24 2005/12/22 16:19:56 roberto Exp $ ** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -35,15 +35,20 @@ static int isnumeral(expdesc *e) {
void luaK_nil (FuncState *fs, int from, int n) { void luaK_nil (FuncState *fs, int from, int n) {
Instruction *previous; Instruction *previous;
if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
if (fs->pc == 0) /* function start? */ if (fs->pc == 0) { /* function start? */
return; /* positions are already clean */ if (from >= fs->nactvar)
if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) { return; /* positions are already clean */
int pfrom = GETARG_A(*previous); }
int pto = GETARG_B(*previous); else {
if (pfrom <= from && from <= pto+1) { /* can connect both? */ previous = &fs->f->code[fs->pc-1];
if (from+n-1 > pto) if (GET_OPCODE(*previous) == OP_LOADNIL) {
SETARG_B(*previous, from+n-1); int pfrom = GETARG_A(*previous);
return; int pto = GETARG_B(*previous);
if (pfrom <= from && from <= pto+1) { /* can connect both? */
if (from+n-1 > pto)
SETARG_B(*previous, from+n-1);
return;
}
} }
} }
} }
@ -657,10 +662,16 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {
if (constfolding(op, e1, e2)) if (constfolding(op, e1, e2))
return; return;
else { else {
int o1 = luaK_exp2RK(fs, e1);
int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
freeexp(fs, e2); int o1 = luaK_exp2RK(fs, e1);
freeexp(fs, e1); if (o1 > o2) {
freeexp(fs, e1);
freeexp(fs, e2);
}
else {
freeexp(fs, e2);
freeexp(fs, e1);
}
e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
e1->k = VRELOCABLE; e1->k = VRELOCABLE;
} }
@ -688,7 +699,7 @@ void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {
e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
switch (op) { switch (op) {
case OPR_MINUS: { case OPR_MINUS: {
if (e->k == VK) if (!isnumeral(e))
luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */ luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */
codearith(fs, OP_UNM, e, &e2); codearith(fs, OP_UNM, e, &e2);
break; break;
@ -718,10 +729,15 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
break; break;
} }
default: { case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
case OPR_MOD: case OPR_POW: {
if (!isnumeral(v)) luaK_exp2RK(fs, v); if (!isnumeral(v)) luaK_exp2RK(fs, v);
break; break;
} }
default: {
luaK_exp2RK(fs, v);
break;
}
} }
} }
@ -731,17 +747,15 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
case OPR_AND: { case OPR_AND: {
lua_assert(e1->t == NO_JUMP); /* list must be closed */ lua_assert(e1->t == NO_JUMP); /* list must be closed */
luaK_dischargevars(fs, e2); luaK_dischargevars(fs, e2);
luaK_concat(fs, &e1->f, e2->f); luaK_concat(fs, &e2->f, e1->f);
e1->k = e2->k; e1->u.s.info = e2->u.s.info; *e1 = *e2;
e1->u.s.aux = e2->u.s.aux; e1->t = e2->t;
break; break;
} }
case OPR_OR: { case OPR_OR: {
lua_assert(e1->f == NO_JUMP); /* list must be closed */ lua_assert(e1->f == NO_JUMP); /* list must be closed */
luaK_dischargevars(fs, e2); luaK_dischargevars(fs, e2);
luaK_concat(fs, &e1->t, e2->t); luaK_concat(fs, &e2->t, e1->t);
e1->k = e2->k; e1->u.s.info = e2->u.s.info; *e1 = *e2;
e1->u.s.aux = e2->u.s.aux; e1->f = e2->f;
break; break;
} }
case OPR_CONCAT: { case OPR_CONCAT: {
@ -750,7 +764,7 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1); lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1);
freeexp(fs, e1); freeexp(fs, e1);
SETARG_B(getcode(fs, e2), e1->u.s.info); 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 { else {
luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lcode.h,v 1.47 2005/11/08 19:44:31 roberto Exp $ ** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -32,7 +32,6 @@ typedef enum BinOpr {
OPR_NOBINOPR OPR_NOBINOPR
} BinOpr; } BinOpr;
#define binopistest(op) ((op) >= OPR_NE)
typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldblib.c,v 1.104 2005/12/29 15:32:11 roberto Exp $ ** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $
** Interface from Lua to its debug API ** Interface from Lua to its debug API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -255,24 +255,25 @@ static void gethooktable (lua_State *L) {
static int db_sethook (lua_State *L) { static int db_sethook (lua_State *L) {
int arg; int arg, mask, count;
lua_Hook func;
lua_State *L1 = getthread(L, &arg); lua_State *L1 = getthread(L, &arg);
if (lua_isnoneornil(L, arg+1)) { if (lua_isnoneornil(L, arg+1)) {
lua_settop(L, arg+1); lua_settop(L, arg+1);
lua_sethook(L1, NULL, 0, 0); /* turn off hooks */ func = NULL; mask = 0; count = 0; /* turn off hooks */
} }
else { else {
const char *smask = luaL_checkstring(L, arg+2); const char *smask = luaL_checkstring(L, arg+2);
int count = luaL_optint(L, arg+3, 0);
luaL_checktype(L, arg+1, LUA_TFUNCTION); luaL_checktype(L, arg+1, LUA_TFUNCTION);
lua_sethook(L1, hookf, makemask(smask, count), count); count = luaL_optint(L, arg+3, 0);
func = hookf; mask = makemask(smask, count);
} }
gethooktable(L1); gethooktable(L);
lua_pushlightuserdata(L1, L1); lua_pushlightuserdata(L, L1);
lua_pushvalue(L, arg+1); lua_pushvalue(L, arg+1);
lua_xmove(L, L1, 1); lua_rawset(L, -3); /* set new hook */
lua_rawset(L1, -3); /* set new hook */ lua_pop(L, 1); /* remove hook table */
lua_pop(L1, 1); /* remove hook table */ lua_sethook(L1, func, mask, count); /* set hooks */
return 0; return 0;
} }
@ -286,11 +287,10 @@ static int db_gethook (lua_State *L) {
if (hook != NULL && hook != hookf) /* external hook? */ if (hook != NULL && hook != hookf) /* external hook? */
lua_pushliteral(L, "external hook"); lua_pushliteral(L, "external hook");
else { else {
gethooktable(L1); gethooktable(L);
lua_pushlightuserdata(L1, L1); lua_pushlightuserdata(L, L1);
lua_rawget(L1, -2); /* get hook */ lua_rawget(L, -2); /* get hook */
lua_remove(L1, -2); /* remove hook table */ lua_remove(L, -2); /* remove hook table */
lua_xmove(L1, L, 1);
} }
lua_pushstring(L, unmakemask(mask, buff)); lua_pushstring(L, unmakemask(mask, buff));
lua_pushinteger(L, lua_gethookcount(L1)); lua_pushinteger(L, lua_gethookcount(L1));

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldebug.c,v 2.29 2005/12/22 16:19:56 roberto Exp $ ** $Id: ldebug.c,v 2.29.1.3 2007/12/28 15:32:23 roberto Exp $
** Debug Interface ** Debug Interface
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -432,14 +432,16 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) {
break; break;
} }
case OP_CLOSURE: { case OP_CLOSURE: {
int nup; int nup, j;
check(b < pt->sizep); check(b < pt->sizep);
nup = pt->p[b]->nups; nup = pt->p[b]->nups;
check(pc + nup < pt->sizecode); check(pc + nup < pt->sizecode);
for (; nup>0; nup--) { for (j = 1; j <= nup; j++) {
OpCode op1 = GET_OPCODE(pt->code[pc+nup]); OpCode op1 = GET_OPCODE(pt->code[pc + j]);
check(op1 == OP_GETUPVAL || op1 == OP_MOVE); check(op1 == OP_GETUPVAL || op1 == OP_MOVE);
} }
if (reg != NO_REG) /* tracing? */
pc += nup; /* do not 'execute' these pseudo-instructions */
break; break;
} }
case OP_VARARG: { case OP_VARARG: {
@ -561,8 +563,8 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { void luaG_concaterror (lua_State *L, StkId p1, StkId p2) {
if (ttisstring(p1)) p1 = p2; if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;
lua_assert(!ttisstring(p1)); lua_assert(!ttisstring(p1) && !ttisnumber(p1));
luaG_typeerror(L, p1, "concatenate"); luaG_typeerror(L, p1, "concatenate");
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldebug.h,v 2.3 2005/04/25 19:24:10 roberto Exp $ ** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $
** Auxiliary functions from Debug Interface module ** Auxiliary functions from Debug Interface module
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldo.c,v 2.37 2005/12/22 16:19:56 roberto Exp $ ** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $
** Stack and Call structure of Lua ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -83,7 +83,7 @@ static void resetstack (lua_State *L, int status) {
L->base = L->ci->base; L->base = L->ci->base;
luaF_close(L, L->base); /* close eventual pending closures */ luaF_close(L, L->base); /* close eventual pending closures */
luaD_seterrorobj(L, status, L->base); luaD_seterrorobj(L, status, L->base);
L->nCcalls = 0; L->nCcalls = L->baseCcalls;
L->allowhook = 1; L->allowhook = 1;
restore_stack_limit(L); restore_stack_limit(L);
L->errfunc = 0; L->errfunc = 0;
@ -332,7 +332,7 @@ static StkId callrethooks (lua_State *L, StkId firstResult) {
ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */
luaD_callhook(L, LUA_HOOKRET, -1); luaD_callhook(L, LUA_HOOKRET, -1);
if (f_isLua(L->ci)) { /* Lua function? */ if (f_isLua(L->ci)) { /* Lua function? */
while (L->ci->tailcalls--) /* call hook for eventual tail calls */ while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */
luaD_callhook(L, LUA_HOOKTAILRET, -1); luaD_callhook(L, LUA_HOOKTAILRET, -1);
} }
return restorestack(L, fr); return restorestack(L, fr);
@ -383,12 +383,14 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
static void resume (lua_State *L, void *ud) { static void resume (lua_State *L, void *ud) {
StkId firstArg = cast(StkId, ud); StkId firstArg = cast(StkId, ud);
CallInfo *ci = L->ci; CallInfo *ci = L->ci;
if (L->status != LUA_YIELD) { /* start coroutine */ if (L->status == 0) { /* start coroutine? */
lua_assert(ci == L->base_ci && firstArg > L->base); lua_assert(ci == L->base_ci && firstArg > L->base);
if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA)
return; return;
} }
else { /* resuming from previous yield */ else { /* resuming from previous yield */
lua_assert(L->status == LUA_YIELD);
L->status = 0;
if (!f_isLua(ci)) { /* `common' yield? */ if (!f_isLua(ci)) { /* `common' yield? */
/* finish interrupted execution of `OP_CALL' */ /* finish interrupted execution of `OP_CALL' */
lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL ||
@ -399,7 +401,6 @@ static void resume (lua_State *L, void *ud) {
else /* yielded inside a hook: just continue its execution */ else /* yielded inside a hook: just continue its execution */
L->base = L->ci->base; L->base = L->ci->base;
} }
L->status = 0;
luaV_execute(L, cast_int(L->ci - L->base_ci)); luaV_execute(L, cast_int(L->ci - L->base_ci));
} }
@ -416,22 +417,24 @@ static int resume_error (lua_State *L, const char *msg) {
LUA_API int lua_resume (lua_State *L, int nargs) { LUA_API int lua_resume (lua_State *L, int nargs) {
int status; int status;
lua_lock(L); lua_lock(L);
if (L->status != LUA_YIELD) { if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci))
if (L->status != 0)
return resume_error(L, "cannot resume dead coroutine");
else if (L->ci != L->base_ci)
return resume_error(L, "cannot resume non-suspended coroutine"); return resume_error(L, "cannot resume non-suspended coroutine");
} if (L->nCcalls >= LUAI_MAXCCALLS)
return resume_error(L, "C stack overflow");
luai_userstateresume(L, nargs); luai_userstateresume(L, nargs);
lua_assert(L->errfunc == 0 && L->nCcalls == 0); lua_assert(L->errfunc == 0);
L->baseCcalls = ++L->nCcalls;
status = luaD_rawrunprotected(L, resume, L->top - nargs); status = luaD_rawrunprotected(L, resume, L->top - nargs);
if (status != 0) { /* error? */ if (status != 0) { /* error? */
L->status = cast_byte(status); /* mark thread as `dead' */ L->status = cast_byte(status); /* mark thread as `dead' */
luaD_seterrorobj(L, status, L->top); luaD_seterrorobj(L, status, L->top);
L->ci->top = L->top; L->ci->top = L->top;
} }
else else {
lua_assert(L->nCcalls == L->baseCcalls);
status = L->status; status = L->status;
}
--L->nCcalls;
lua_unlock(L); lua_unlock(L);
return status; return status;
} }
@ -440,7 +443,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
LUA_API int lua_yield (lua_State *L, int nresults) { LUA_API int lua_yield (lua_State *L, int nresults) {
luai_userstateyield(L, nresults); luai_userstateyield(L, nresults);
lua_lock(L); lua_lock(L);
if (L->nCcalls > 0) if (L->nCcalls > L->baseCcalls)
luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
L->base = L->top - nresults; /* protect stack slots below */ L->base = L->top - nresults; /* protect stack slots below */
L->status = LUA_YIELD; L->status = LUA_YIELD;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldo.h,v 2.7 2005/08/24 16:15:49 roberto Exp $ ** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $
** Stack and Call structure of Lua ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldump.c,v 1.15 2006/02/16 15:53:49 lhf Exp $ ** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
** save precompiled Lua chunks ** save precompiled Lua chunks
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lfunc.c,v 2.12 2005/12/22 16:19:56 roberto Exp $ ** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures ** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -55,7 +55,7 @@ UpVal *luaF_findupval (lua_State *L, StkId level) {
GCObject **pp = &L->openupval; GCObject **pp = &L->openupval;
UpVal *p; UpVal *p;
UpVal *uv; UpVal *uv;
while ((p = ngcotouv(*pp)) != NULL && p->v >= level) { while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) {
lua_assert(p->v != &p->u.value); lua_assert(p->v != &p->u.value);
if (p->v == level) { /* found a corresponding upvalue? */ if (p->v == level) { /* found a corresponding upvalue? */
if (isdead(g, obj2gco(p))) /* is it dead? */ if (isdead(g, obj2gco(p))) /* is it dead? */
@ -96,7 +96,7 @@ void luaF_freeupval (lua_State *L, UpVal *uv) {
void luaF_close (lua_State *L, StkId level) { void luaF_close (lua_State *L, StkId level) {
UpVal *uv; UpVal *uv;
global_State *g = G(L); global_State *g = G(L);
while ((uv = ngcotouv(L->openupval)) != NULL && uv->v >= level) { while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) {
GCObject *o = obj2gco(uv); GCObject *o = obj2gco(uv);
lua_assert(!isblack(o) && uv->v != &uv->u.value); lua_assert(!isblack(o) && uv->v != &uv->u.value);
L->openupval = uv->next; /* remove from `open' list */ L->openupval = uv->next; /* remove from `open' list */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lfunc.h,v 2.4 2005/04/25 19:24:10 roberto Exp $ ** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures ** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lgc.c,v 2.37 2005/12/22 16:19:56 roberto Exp $ ** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -320,8 +320,10 @@ static l_mem propagatemark (global_State *g) {
} }
static void propagateall (global_State *g) { static size_t propagateall (global_State *g) {
while (g->gray) propagatemark(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); propagateall(g);
udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */ udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */
marktmu(g); /* mark `preserved' userdata */ 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 */ cleartable(g->weak); /* remove collected objects from weak tables */
/* flip current white */ /* flip current white */
g->currentwhite = cast_byte(otherwhite(g)); g->currentwhite = cast_byte(otherwhite(g));
@ -590,6 +592,8 @@ static l_mem singlestep (lua_State *L) {
case GCSfinalize: { case GCSfinalize: {
if (g->tmudata) { if (g->tmudata) {
GCTM(L); GCTM(L);
if (g->estimate > GCFINALIZECOST)
g->estimate -= GCFINALIZECOST;
return GCFINALIZECOST; return GCFINALIZECOST;
} }
else { else {

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lgc.h,v 2.15 2005/08/24 16:15:49 roberto Exp $ ** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: linit.c,v 1.14 2005/12/29 15:32:11 roberto Exp $ ** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $
** Initialization of libraries for lua.c ** Initialization of libraries for lua.c
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: liolib.c,v 2.72 2006/01/28 12:59:13 roberto Exp $ ** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $
** Standard I/O (and system) library ** Standard I/O (and system) library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -51,7 +51,7 @@ static void fileerror (lua_State *L, int arg, const char *filename) {
} }
#define topfile(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) #define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE))
static int io_type (lua_State *L) { static int io_type (lua_State *L) {
@ -70,7 +70,7 @@ static int io_type (lua_State *L) {
static FILE *tofile (lua_State *L) { static FILE *tofile (lua_State *L) {
FILE **f = topfile(L); FILE **f = tofilep(L);
if (*f == NULL) if (*f == NULL)
luaL_error(L, "attempt to use a closed file"); luaL_error(L, "attempt to use a closed file");
return *f; return *f;
@ -93,21 +93,33 @@ static FILE **newfile (lua_State *L) {
/* /*
** this function has a separated environment, which defines the ** function to (not) close the standard files stdin, stdout, and stderr
** correct __close for 'popen' files */
static int io_noclose (lua_State *L) {
lua_pushnil(L);
lua_pushliteral(L, "cannot close standard file");
return 2;
}
/*
** function to close 'popen' files
*/ */
static int io_pclose (lua_State *L) { static int io_pclose (lua_State *L) {
FILE **p = topfile(L); FILE **p = tofilep(L);
int ok = lua_pclose(L, *p); int ok = lua_pclose(L, *p);
if (ok) *p = NULL; *p = NULL;
return pushresult(L, ok, NULL); return pushresult(L, ok, NULL);
} }
/*
** function to close regular files
*/
static int io_fclose (lua_State *L) { static int io_fclose (lua_State *L) {
FILE **p = topfile(L); FILE **p = tofilep(L);
int ok = (fclose(*p) == 0); int ok = (fclose(*p) == 0);
if (ok) *p = NULL; *p = NULL;
return pushresult(L, ok, NULL); return pushresult(L, ok, NULL);
} }
@ -128,18 +140,18 @@ static int io_close (lua_State *L) {
static int io_gc (lua_State *L) { static int io_gc (lua_State *L) {
FILE *f = *topfile(L); FILE *f = *tofilep(L);
/* ignore closed files and standard files */ /* ignore closed files */
if (f != NULL && f != stdin && f != stdout && f != stderr) if (f != NULL)
aux_close(L); aux_close(L);
return 0; return 0;
} }
static int io_tostring (lua_State *L) { static int io_tostring (lua_State *L) {
FILE *f = *topfile(L); FILE *f = *tofilep(L);
if (f == NULL) if (f == NULL)
lua_pushstring(L, "file (closed)"); lua_pushliteral(L, "file (closed)");
else else
lua_pushfstring(L, "file (%p)", f); lua_pushfstring(L, "file (%p)", f);
return 1; return 1;
@ -155,6 +167,10 @@ static int io_open (lua_State *L) {
} }
/*
** this function has a separated environment, which defines the
** correct __close for 'popen' files
*/
static int io_popen (lua_State *L) { static int io_popen (lua_State *L) {
const char *filename = luaL_checkstring(L, 1); const char *filename = luaL_checkstring(L, 1);
const char *mode = luaL_optstring(L, 2, "r"); const char *mode = luaL_optstring(L, 2, "r");
@ -280,7 +296,7 @@ static int read_line (lua_State *L, FILE *f) {
char *p = luaL_prepbuffer(&b); char *p = luaL_prepbuffer(&b);
if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */ if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
luaL_pushresult(&b); /* close buffer */ luaL_pushresult(&b); /* close buffer */
return (lua_strlen(L, -1) > 0); /* check whether read something */ return (lua_objlen(L, -1) > 0); /* check whether read something */
} }
l = strlen(p); l = strlen(p);
if (l == 0 || p[l-1] != '\n') if (l == 0 || p[l-1] != '\n')
@ -308,7 +324,7 @@ static int read_chars (lua_State *L, FILE *f, size_t n) {
n -= nr; /* still have to read `n' chars */ n -= nr; /* still have to read `n' chars */
} while (n > 0 && nr == rlen); /* until end of count or eof */ } while (n > 0 && nr == rlen); /* until end of count or eof */
luaL_pushresult(&b); /* close buffer */ luaL_pushresult(&b); /* close buffer */
return (n == 0 || lua_strlen(L, -1) > 0); return (n == 0 || lua_objlen(L, -1) > 0);
} }
@ -502,31 +518,36 @@ static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {
lua_pushvalue(L, -1); lua_pushvalue(L, -1);
lua_rawseti(L, LUA_ENVIRONINDEX, k); lua_rawseti(L, LUA_ENVIRONINDEX, k);
} }
lua_setfield(L, -2, fname); lua_pushvalue(L, -2); /* copy environment */
lua_setfenv(L, -2); /* set it */
lua_setfield(L, -3, fname);
}
static void newfenv (lua_State *L, lua_CFunction cls) {
lua_createtable(L, 0, 1);
lua_pushcfunction(L, cls);
lua_setfield(L, -2, "__close");
} }
LUALIB_API int luaopen_io (lua_State *L) { LUALIB_API int luaopen_io (lua_State *L) {
createmeta(L); createmeta(L);
/* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
lua_createtable(L, 2, 1); newfenv(L, io_fclose);
lua_replace(L, LUA_ENVIRONINDEX); lua_replace(L, LUA_ENVIRONINDEX);
/* open library */ /* open library */
luaL_register(L, LUA_IOLIBNAME, iolib); luaL_register(L, LUA_IOLIBNAME, iolib);
/* create (and set) default files */ /* create (and set) default files */
newfenv(L, io_noclose); /* close function for default files */
createstdfile(L, stdin, IO_INPUT, "stdin"); createstdfile(L, stdin, IO_INPUT, "stdin");
createstdfile(L, stdout, IO_OUTPUT, "stdout"); createstdfile(L, stdout, IO_OUTPUT, "stdout");
createstdfile(L, stderr, 0, "stderr"); createstdfile(L, stderr, 0, "stderr");
/* create environment for 'popen' */ lua_pop(L, 1); /* pop environment for default files */
lua_getfield(L, -1, "popen"); lua_getfield(L, -1, "popen");
lua_createtable(L, 0, 1); newfenv(L, io_pclose); /* create environment for 'popen' */
lua_pushcfunction(L, io_pclose); lua_setfenv(L, -2); /* set fenv for 'popen' */
lua_setfield(L, -2, "__close");
lua_setfenv(L, -2);
lua_pop(L, 1); /* pop 'popen' */ lua_pop(L, 1); /* pop 'popen' */
/* set default close function */
lua_pushcfunction(L, io_fclose);
lua_setfield(L, LUA_ENVIRONINDEX, "__close");
return 1; return 1;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: llex.c,v 2.19 2006/02/06 18:28:16 roberto Exp $ ** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -20,6 +20,7 @@
#include "lparser.h" #include "lparser.h"
#include "lstate.h" #include "lstate.h"
#include "lstring.h" #include "lstring.h"
#include "ltable.h"
#include "lzio.h" #include "lzio.h"

View File

@ -1,5 +1,5 @@
/* /*
** $Id: llex.h,v 1.57 2005/12/07 15:43:05 roberto Exp $ ** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** 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_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); 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_next (LexState *ls);
LUAI_FUNC void luaX_lookahead (LexState *ls); LUAI_FUNC void luaX_lookahead (LexState *ls);
LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);

View File

@ -1,5 +1,5 @@
/* /*
** $Id: llimits.h,v 1.69 2005/12/27 17:12:00 roberto Exp $ ** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $
** Limits, basic types, and some other `installation-dependent' definitions ** Limits, basic types, and some other `installation-dependent' definitions
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lmathlib.c,v 1.67 2005/08/26 17:36:32 roberto Exp $ ** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $
** Standard mathematical library ** Standard mathematical library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lmem.c,v 1.70 2005/12/26 13:35:47 roberto Exp $ ** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $
** Interface to Memory Manager ** Interface to Memory Manager
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lmem.h,v 1.31 2005/04/25 19:24:10 roberto Exp $ ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $
** Interface to Memory Manager ** Interface to Memory Manager
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: loadlib.c,v 1.51 2005/12/29 15:32:11 roberto Exp $ ** $Id: loadlib.c,v 1.52.1.2 2007/12/28 14:58:43 roberto Exp $
** Dynamic library loader for Lua ** Dynamic library loader for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
** **
@ -16,16 +16,12 @@
#define loadlib_c #define loadlib_c
#define LUA_LIB #define LUA_LIB
#include "lauxlib.h"
#include "lobject.h"
#include "lua.h" #include "lua.h"
#include "lauxlib.h"
#include "lualib.h" #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 */ /* prefix for open functions in C libraries */
#define LUA_POF "luaopen_" #define LUA_POF "luaopen_"
@ -102,7 +98,7 @@ static void setprogdir (lua_State *L) {
char buff[MAX_PATH + 1]; char buff[MAX_PATH + 1];
char *lb; char *lb;
DWORD nsize = sizeof(buff)/sizeof(char); DWORD nsize = sizeof(buff)/sizeof(char);
DWORD n = GetModuleFileName(NULL, buff, nsize); DWORD n = GetModuleFileNameA(NULL, buff, nsize);
if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
luaL_error(L, "unable to get ModuleFileName"); luaL_error(L, "unable to get ModuleFileName");
else { else {
@ -116,7 +112,7 @@ static void setprogdir (lua_State *L) {
static void pusherror (lua_State *L) { static void pusherror (lua_State *L) {
int error = GetLastError(); int error = GetLastError();
char buffer[128]; char buffer[128];
if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, error, 0, buffer, sizeof(buffer), NULL)) NULL, error, 0, buffer, sizeof(buffer), NULL))
lua_pushstring(L, buffer); lua_pushstring(L, buffer);
else else
@ -129,7 +125,7 @@ static void ll_unloadlib (void *lib) {
static void *ll_load (lua_State *L, const char *path) { static void *ll_load (lua_State *L, const char *path) {
HINSTANCE lib = LoadLibrary(path); HINSTANCE lib = LoadLibraryA(path);
if (lib == NULL) pusherror(L); if (lib == NULL) pusherror(L);
return lib; return lib;
} }
@ -360,15 +356,16 @@ static const char *findfile (lua_State *L, const char *name,
path = lua_tostring(L, -1); path = lua_tostring(L, -1);
if (path == NULL) if (path == NULL)
luaL_error(L, LUA_QL("package.%s") " must be a string", pname); luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
lua_pushstring(L, ""); /* error accumulator */ lua_pushliteral(L, ""); /* error accumulator */
while ((path = pushnexttemplate(L, path)) != NULL) { while ((path = pushnexttemplate(L, path)) != NULL) {
const char *filename; const char *filename;
filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);
lua_remove(L, -2); /* remove path template */
if (readable(filename)) /* does file exist and is readable? */ if (readable(filename)) /* does file exist and is readable? */
return filename; /* return that file name */ return filename; /* return that file name */
lua_pop(L, 2); /* remove path template and file name */ lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
luaO_pushfstring(L, "\n\tno file " LUA_QS, filename); lua_remove(L, -2); /* remove file name */
lua_concat(L, 2); lua_concat(L, 2); /* add entry to possible error message */
} }
return NULL; /* not found */ return NULL; /* not found */
} }
@ -427,8 +424,8 @@ static int loader_Croot (lua_State *L) {
funcname = mkfuncname(L, name); funcname = mkfuncname(L, name);
if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { if ((stat = ll_loadfunc(L, filename, funcname)) != 0) {
if (stat != ERRFUNC) loaderror(L, filename); /* real error */ if (stat != ERRFUNC) loaderror(L, filename); /* real error */
luaO_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
name, filename); name, filename);
return 1; /* function not found */ return 1; /* function not found */
} }
return 1; return 1;
@ -442,7 +439,7 @@ static int loader_preload (lua_State *L) {
luaL_error(L, LUA_QL("package.preload") " must be a table"); luaL_error(L, LUA_QL("package.preload") " must be a table");
lua_getfield(L, -1, name); lua_getfield(L, -1, name);
if (lua_isnil(L, -1)) /* not found? */ if (lua_isnil(L, -1)) /* not found? */
luaO_pushfstring(L, "\n\tno field package.preload['%s']", name); lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
return 1; return 1;
} }
@ -466,7 +463,7 @@ static int ll_require (lua_State *L) {
lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
if (!lua_istable(L, -1)) if (!lua_istable(L, -1))
luaL_error(L, LUA_QL("package.loaders") " must be a table"); luaL_error(L, LUA_QL("package.loaders") " must be a table");
lua_pushstring(L, ""); /* error message accumulator */ lua_pushliteral(L, ""); /* error message accumulator */
for (i=1; ; i++) { for (i=1; ; i++) {
lua_rawgeti(L, -2, i); /* get a loader */ lua_rawgeti(L, -2, i); /* get a loader */
if (lua_isnil(L, -1)) if (lua_isnil(L, -1))
@ -650,8 +647,8 @@ LUALIB_API int luaopen_package (lua_State *L) {
setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */ setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */
setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */ setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */
/* store config information */ /* store config information */
lua_pushstring(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n"
LUA_EXECDIR "\n" LUA_IGMARK); LUA_EXECDIR "\n" LUA_IGMARK);
lua_setfield(L, -2, "config"); lua_setfield(L, -2, "config");
/* set field `loaded' */ /* set field `loaded' */
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2);

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lobject.c,v 2.22 2006/02/10 17:43:52 roberto Exp $ ** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $
** Some generic functions over Lua objects ** Some generic functions over Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lobject.h,v 2.20 2006/01/18 11:37:34 roberto Exp $ ** $Id: lobject.h,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $
** Type definitions for Lua objects ** Type definitions for Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lopcodes.c,v 1.37 2005/11/08 19:45:36 roberto Exp $ ** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lopcodes.h,v 1.124 2005/12/02 18:42:08 roberto Exp $ ** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $
** Opcodes for Lua virtual machine ** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h ** 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) }*/ 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_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)); 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 { pc++; R(A+2)=R(A+3); } */ 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_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)*/ OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/

View File

@ -1,5 +1,5 @@
/* /*
** $Id: loslib.c,v 1.17 2006/01/27 13:54:31 roberto Exp $ ** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $
** Standard Operating System library ** Standard Operating System library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -28,10 +28,7 @@ static int os_pushresult (lua_State *L, int i, const char *filename) {
} }
else { else {
lua_pushnil(L); lua_pushnil(L);
if (filename) lua_pushfstring(L, "%s: %s", filename, strerror(en));
lua_pushfstring(L, "%s: %s", filename, strerror(en));
else
lua_pushfstring(L, "%s", strerror(en));
lua_pushinteger(L, en); lua_pushinteger(L, en);
return 3; return 3;
} }
@ -126,8 +123,7 @@ static int getfield (lua_State *L, const char *key, int d) {
static int os_date (lua_State *L) { static int os_date (lua_State *L) {
const char *s = luaL_optstring(L, 1, "%c"); const char *s = luaL_optstring(L, 1, "%c");
time_t t = lua_isnoneornil(L, 2) ? time(NULL) : time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));
(time_t)luaL_checknumber(L, 2);
struct tm *stm; struct tm *stm;
if (*s == '!') { /* UTC? */ if (*s == '!') { /* UTC? */
stm = gmtime(&t); stm = gmtime(&t);
@ -150,11 +146,22 @@ static int os_date (lua_State *L) {
setboolfield(L, "isdst", stm->tm_isdst); setboolfield(L, "isdst", stm->tm_isdst);
} }
else { else {
char b[256]; char cc[3];
if (strftime(b, sizeof(b), s, stm)) luaL_Buffer b;
lua_pushstring(L, b); cc[0] = '%'; cc[2] = '\0';
else luaL_buffinit(L, &b);
return luaL_error(L, LUA_QL("date") " format too long"); for (; *s; s++) {
if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */
luaL_addchar(&b, *s);
else {
size_t reslen;
char buff[200]; /* should be big enough for any conversion result */
cc[1] = *(++s);
reslen = strftime(buff, sizeof(buff), cc, stm);
luaL_addlstring(&b, buff, reslen);
}
}
luaL_pushresult(&b);
} }
return 1; return 1;
} }
@ -199,9 +206,8 @@ static int os_setlocale (lua_State *L) {
LC_NUMERIC, LC_TIME}; LC_NUMERIC, LC_TIME};
static const char *const catnames[] = {"all", "collate", "ctype", "monetary", static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
"numeric", "time", NULL}; "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); 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)); lua_pushstring(L, setlocale(cat[op], l));
return 1; return 1;
} }
@ -209,7 +215,6 @@ static int os_setlocale (lua_State *L) {
static int os_exit (lua_State *L) { static int os_exit (lua_State *L) {
exit(luaL_optint(L, 1, EXIT_SUCCESS)); exit(luaL_optint(L, 1, EXIT_SUCCESS));
return 0; /* to avoid warnings */
} }
static const luaL_Reg syslib[] = { static const luaL_Reg syslib[] = {

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lparser.c,v 2.40 2005/12/22 16:19:56 roberto Exp $ ** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $
** Lua Parser ** Lua Parser
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -23,7 +23,7 @@
#include "lparser.h" #include "lparser.h"
#include "lstate.h" #include "lstate.h"
#include "lstring.h" #include "lstring.h"
#include "ltable.h"
@ -299,7 +299,8 @@ static void leaveblock (FuncState *fs) {
removevars(fs->ls, bl->nactvar); removevars(fs->ls, bl->nactvar);
if (bl->upval) if (bl->upval)
luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);
lua_assert(!bl->isbreakable || !bl->upval); /* loops have no body */ /* a block either controls scope or breaks (never both) */
lua_assert(!bl->isbreakable || !bl->upval);
lua_assert(bl->nactvar == fs->nactvar); lua_assert(bl->nactvar == fs->nactvar);
fs->freereg = fs->nactvar; /* free registers */ fs->freereg = fs->nactvar; /* free registers */
luaK_patchtohere(fs, bl->breaklist); luaK_patchtohere(fs, bl->breaklist);
@ -444,6 +445,7 @@ static void recfield (LexState *ls, struct ConsControl *cc) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
int reg = ls->fs->freereg; int reg = ls->fs->freereg;
expdesc key, val; expdesc key, val;
int rkkey;
if (ls->t.token == TK_NAME) { if (ls->t.token == TK_NAME) {
luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
checkname(ls, &key); checkname(ls, &key);
@ -452,10 +454,9 @@ static void recfield (LexState *ls, struct ConsControl *cc) {
yindex(ls, &key); yindex(ls, &key);
cc->nh++; cc->nh++;
checknext(ls, '='); checknext(ls, '=');
luaK_exp2RK(fs, &key); rkkey = luaK_exp2RK(fs, &key);
expr(ls, &val); expr(ls, &val);
luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, luaK_exp2RK(fs, &key), luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val));
luaK_exp2RK(fs, &val));
fs->freereg = reg; /* free registers */ fs->freereg = reg; /* free registers */
} }
@ -488,7 +489,7 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) {
static void listfield (LexState *ls, struct ConsControl *cc) { static void listfield (LexState *ls, struct ConsControl *cc) {
expr(ls, &cc->v); expr(ls, &cc->v);
luaY_checklimit(ls->fs, cc->na, MAXARG_Bx, "items in a constructor"); luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
cc->na++; cc->na++;
cc->tostore++; cc->tostore++;
} }
@ -937,6 +938,8 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
primaryexp(ls, &nv.v); primaryexp(ls, &nv.v);
if (nv.v.k == VLOCAL) if (nv.v.k == VLOCAL)
check_conflict(ls, lh, &nv.v); check_conflict(ls, lh, &nv.v);
luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,
"variables in assignment");
assignment(ls, &nv, nvars+1); assignment(ls, &nv, nvars+1);
} }
else { /* assignment -> `=' explist1 */ else { /* assignment -> `=' explist1 */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lparser.h,v 1.56 2005/10/03 14:02:40 roberto Exp $ ** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $
** Lua Parser ** Lua Parser
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -9,7 +9,6 @@
#include "llimits.h" #include "llimits.h"
#include "lobject.h" #include "lobject.h"
#include "ltable.h"
#include "lzio.h" #include "lzio.h"

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstate.c,v 2.35 2005/10/06 20:46:25 roberto Exp $ ** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -93,7 +93,7 @@ static void preinit_state (lua_State *L, global_State *g) {
resethookcount(L); resethookcount(L);
L->openupval = NULL; L->openupval = NULL;
L->size_ci = 0; L->size_ci = 0;
L->nCcalls = 0; L->nCcalls = L->baseCcalls = 0;
L->status = 0; L->status = 0;
L->base_ci = L->ci = NULL; L->base_ci = L->ci = NULL;
L->savedpc = NULL; L->savedpc = NULL;
@ -198,7 +198,6 @@ static void callallgcTM (lua_State *L, void *ud) {
LUA_API void lua_close (lua_State *L) { LUA_API void lua_close (lua_State *L) {
L = G(L)->mainthread; /* only the main thread can be closed */ L = G(L)->mainthread; /* only the main thread can be closed */
luai_userstateclose(L);
lua_lock(L); lua_lock(L);
luaF_close(L, L->stack); /* close all upvalues for this thread */ luaF_close(L, L->stack); /* close all upvalues for this thread */
luaC_separateudata(L, 1); /* separate udata that have GC metamethods */ luaC_separateudata(L, 1); /* separate udata that have GC metamethods */
@ -206,9 +205,10 @@ LUA_API void lua_close (lua_State *L) {
do { /* repeat until no more errors */ do { /* repeat until no more errors */
L->ci = L->base_ci; L->ci = L->base_ci;
L->base = L->top = L->ci->base; L->base = L->top = L->ci->base;
L->nCcalls = 0; L->nCcalls = L->baseCcalls = 0;
} while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
lua_assert(G(L)->tmudata == NULL); lua_assert(G(L)->tmudata == NULL);
luai_userstateclose(L);
close_state(L); close_state(L);
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstate.h,v 2.24 2006/02/06 18:27:59 roberto Exp $ ** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -112,6 +112,7 @@ struct lua_State {
int stacksize; int stacksize;
int size_ci; /* size of array `base_ci' */ int size_ci; /* size of array `base_ci' */
unsigned short nCcalls; /* number of nested C calls */ unsigned short nCcalls; /* number of nested C calls */
unsigned short baseCcalls; /* nested C calls when resuming coroutine */
lu_byte hookmask; lu_byte hookmask;
lu_byte allowhook; lu_byte allowhook;
int basehookcount; int basehookcount;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstring.c,v 2.8 2005/12/22 16:19:56 roberto Exp $ ** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
** String table (keeps all strings handled by Lua) ** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstring.h,v 1.43 2005/04/25 19:24:10 roberto Exp $ ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $
** String table (keep all strings handled by Lua) ** String table (keep all strings handled by Lua)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstrlib.c,v 1.130 2005/12/29 15:32:11 roberto Exp $ ** $Id: lstrlib.c,v 1.132.1.3 2007/12/28 15:32:23 roberto Exp $
** Standard library for string operations and pattern-matching ** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -629,10 +629,6 @@ static void add_value (MatchState *ms, luaL_Buffer *b, const char *s,
lua_gettable(L, 3); lua_gettable(L, 3);
break; break;
} }
default: {
luaL_argerror(L, 3, "string/function/table expected");
return;
}
} }
if (!lua_toboolean(L, -1)) { /* nil or false? */ if (!lua_toboolean(L, -1)) { /* nil or false? */
lua_pop(L, 1); lua_pop(L, 1);
@ -648,11 +644,15 @@ static int str_gsub (lua_State *L) {
size_t srcl; size_t srcl;
const char *src = luaL_checklstring(L, 1, &srcl); const char *src = luaL_checklstring(L, 1, &srcl);
const char *p = luaL_checkstring(L, 2); const char *p = luaL_checkstring(L, 2);
int tr = lua_type(L, 3);
int max_s = luaL_optint(L, 4, srcl+1); int max_s = luaL_optint(L, 4, srcl+1);
int anchor = (*p == '^') ? (p++, 1) : 0; int anchor = (*p == '^') ? (p++, 1) : 0;
int n = 0; int n = 0;
MatchState ms; MatchState ms;
luaL_Buffer b; luaL_Buffer b;
luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,
"string/function/table expected");
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
ms.L = L; ms.L = L;
ms.src_init = src; ms.src_init = src;
@ -703,6 +703,10 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
luaL_addchar(b, *s); luaL_addchar(b, *s);
break; break;
} }
case '\r': {
luaL_addlstring(b, "\\r", 2);
break;
}
case '\0': { case '\0': {
luaL_addlstring(b, "\\000", 4); luaL_addlstring(b, "\\000", 4);
break; break;
@ -719,7 +723,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
const char *p = strfrmt; const char *p = strfrmt;
while (strchr(FLAGS, *p)) p++; /* skip flags */ while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
luaL_error(L, "invalid format (repeated flags)"); luaL_error(L, "invalid format (repeated flags)");
if (isdigit(uchar(*p))) p++; /* skip width */ if (isdigit(uchar(*p))) p++; /* skip width */
@ -805,7 +809,8 @@ static int str_format (lua_State *L) {
} }
} }
default: { /* also treat cases `pnLlh' */ 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)); luaL_addlstring(&b, buff, strlen(buff));

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltable.c,v 2.32 2006/01/18 11:49:02 roberto Exp $ ** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $
** Lua tables (hash) ** Lua tables (hash)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -84,8 +84,8 @@ static const Node dummynode_ = {
static Node *hashnum (const Table *t, lua_Number n) { static Node *hashnum (const Table *t, lua_Number n) {
unsigned int a[numints]; unsigned int a[numints];
int i; int i;
n += 1; /* normalize number (avoid -0) */ if (luai_numeq(n, 0)) /* avoid problems with -0 */
lua_assert(sizeof(a) <= sizeof(n)); return gnode(t, 0);
memcpy(a, &n, sizeof(a)); memcpy(a, &n, sizeof(a));
for (i = 1; i < numints; i++) a[0] += a[i]; for (i = 1; i < numints; i++) a[0] += a[i];
return hashmod(t, a[0]); return hashmod(t, a[0]);

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltable.h,v 2.10 2006/01/10 13:13:06 roberto Exp $ ** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $
** Lua tables (hash) ** Lua tables (hash)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltablib.c,v 1.38 2005/10/23 17:38:15 roberto Exp $ ** $Id: ltablib.c,v 1.38.1.2 2007/12/28 15:32:23 roberto Exp $
** Library for Table Manipulation ** Library for Table Manipulation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -118,7 +118,8 @@ static int tinsert (lua_State *L) {
static int tremove (lua_State *L) { static int tremove (lua_State *L) {
int e = aux_getn(L, 1); int e = aux_getn(L, 1);
int pos = luaL_optint(L, 2, e); int pos = luaL_optint(L, 2, e);
if (e == 0) return 0; /* table is `empty' */ if (!(1 <= pos && pos <= e)) /* position is outside bounds? */
return 0; /* nothing to remove */
luaL_setn(L, 1, e - 1); /* t.n = n-1 */ luaL_setn(L, 1, e - 1); /* t.n = n-1 */
lua_rawgeti(L, 1, pos); /* result = t[pos] */ lua_rawgeti(L, 1, pos); /* result = t[pos] */
for ( ;pos<e; pos++) { for ( ;pos<e; pos++) {

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltm.c,v 2.8 2006/01/10 12:50:00 roberto Exp $ ** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
** Tag methods ** Tag methods
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltm.h,v 2.6 2005/06/06 13:30:25 roberto Exp $ ** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $
** Tag methods ** Tag methods
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lua.c,v 1.157 2005/12/29 16:23:32 roberto Exp $ ** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $
** Lua stand-alone interpreter ** Lua stand-alone interpreter
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -74,6 +74,8 @@ static int report (lua_State *L, int status) {
static int traceback (lua_State *L) { static int traceback (lua_State *L) {
if (!lua_isstring(L, 1)) /* 'message' not a string? */
return 1; /* keep it intact */
lua_getfield(L, LUA_GLOBALSINDEX, "debug"); lua_getfield(L, LUA_GLOBALSINDEX, "debug");
if (!lua_istable(L, -1)) { if (!lua_istable(L, -1)) {
lua_pop(L, 1); lua_pop(L, 1);
@ -107,7 +109,7 @@ static int docall (lua_State *L, int narg, int clear) {
static void print_version (void) { static void print_version (void) {
l_message(NULL, LUA_VERSION " " LUA_COPYRIGHT); l_message(NULL, LUA_RELEASE " " LUA_COPYRIGHT);
} }
@ -144,7 +146,7 @@ static int dostring (lua_State *L, const char *s, const char *name) {
static int dolibrary (lua_State *L, const char *name) { static int dolibrary (lua_State *L, const char *name) {
lua_getglobal(L, "require"); lua_getglobal(L, "require");
lua_pushstring(L, name); lua_pushstring(L, name);
return report(L, lua_pcall(L, 1, 0, 0)); return report(L, docall(L, 1, 1));
} }
@ -252,17 +254,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) { static int collectargs (char **argv, int *pi, int *pv, int *pe) {
int i; int i;
for (i = 1; argv[i] != NULL; i++) { for (i = 1; argv[i] != NULL; i++) {
if (argv[i][0] != '-') /* not an option? */ if (argv[i][0] != '-') /* not an option? */
return i; return i;
switch (argv[i][1]) { /* option */ switch (argv[i][1]) { /* option */
case '-': return (argv[i+1] != NULL ? i+1 : 0); case '-':
case '\0': return i; notail(argv[i]);
case 'i': *pi = 1; /* go through */ return (argv[i+1] != NULL ? i+1 : 0);
case 'v': *pv = 1; break; case '\0':
case 'e': *pe = 1; /* go through */ 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': case 'l':
if (argv[i][2] == '\0') { if (argv[i][2] == '\0') {
i++; i++;
@ -306,12 +321,12 @@ static int runargs (lua_State *L, char **argv, int n) {
static int handle_luainit (lua_State *L) { 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 */ if (init == NULL) return 0; /* status OK */
else if (init[0] == '@') else if (init[0] == '@')
return dofile(L, init+1); return dofile(L, init+1);
else else
return dostring(L, init, "=LUA_INIT"); return dostring(L, init, "=" LUA_INIT);
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lua.h,v 1.216 2006/01/10 12:50:13 roberto Exp $ ** $Id: lua.h,v 1.218.1.4 2008/01/03 15:41:15 roberto Exp $
** Lua - An Extensible Extension Language ** Lua - An Extensible Extension Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file ** See Copyright Notice at the end of this file
@ -17,8 +17,9 @@
#define LUA_VERSION "Lua 5.1" #define LUA_VERSION "Lua 5.1"
#define LUA_RELEASE "Lua 5.1.3"
#define LUA_VERSION_NUM 501 #define LUA_VERSION_NUM 501
#define LUA_COPYRIGHT "Copyright (C) 1994-2006 Lua.org, PUC-Rio" #define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
@ -293,6 +294,9 @@ LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
#define lua_Chunkwriter lua_Writer #define lua_Chunkwriter lua_Writer
/* hack */
LUA_API void lua_setlevel (lua_State *from, lua_State *to);
/* /*
** {====================================================================== ** {======================================================================
@ -358,7 +362,7 @@ struct lua_Debug {
/****************************************************************************** /******************************************************************************
* Copyright (C) 1994-2006 Lua.org, PUC-Rio. All rights reserved. * Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the

View File

@ -1,5 +1,5 @@
/* /*
** $Id: luac.c,v 1.52 2005/11/11 14:03:13 lhf Exp $ ** $Id: luac.c,v 1.54 2006/06/02 17:37:11 lhf Exp $
** Lua compiler (saves bytecodes to files; also list bytecodes) ** Lua compiler (saves bytecodes to files; also list bytecodes)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -70,6 +70,7 @@ static void usage(const char* message)
static int doargs(int argc, char* argv[]) static int doargs(int argc, char* argv[])
{ {
int i; int i;
int version=0;
if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0]; if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];
for (i=1; i<argc; i++) 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 */ else if (IS("--")) /* end of options; skip it */
{ {
++i; ++i;
if (version) ++version;
break; break;
} }
else if (IS("-")) /* end of options; use stdin */ 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 */ else if (IS("-s")) /* strip debug information */
stripping=1; stripping=1;
else if (IS("-v")) /* show version */ else if (IS("-v")) /* show version */
{ ++version;
printf("%s %s\n",LUA_VERSION,LUA_COPYRIGHT);
if (argc==2) exit(EXIT_SUCCESS);
}
else /* unknown option */ else /* unknown option */
usage(argv[i]); usage(argv[i]);
} }
@ -107,12 +106,17 @@ static int doargs(int argc, char* argv[])
dumping=0; dumping=0;
argv[--i]=Output; argv[--i]=Output;
} }
if (version)
{
printf("%s %s\n",LUA_RELEASE,LUA_COPYRIGHT);
if (version==argc-1) exit(EXIT_SUCCESS);
}
return i; return i;
} }
#define toproto(L,i) (clvalue(L->top+(i))->l.p) #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) if (n==1)
return toproto(L,-1); return toproto(L,-1);
@ -156,7 +160,7 @@ static int pmain(lua_State* L)
struct Smain* s = (struct Smain*)lua_touserdata(L, 1); struct Smain* s = (struct Smain*)lua_touserdata(L, 1);
int argc=s->argc; int argc=s->argc;
char** argv=s->argv; char** argv=s->argv;
Proto* f; const Proto* f;
int i; int i;
if (!lua_checkstack(L,argc)) fatal("too many input files"); if (!lua_checkstack(L,argc)) fatal("too many input files");
for (i=0; i<argc; i++) for (i=0; i<argc; i++)

View File

@ -1,5 +1,5 @@
/* /*
** $Id: luaconf.h,v 1.81 2006/02/10 17:44:06 roberto Exp $ ** $Id: luaconf.h,v 1.82.1.6 2008/01/18 17:07:48 roberto Exp $
** Configuration file for Lua ** Configuration file for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -59,6 +59,18 @@
#endif #endif
/*
@@ 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_PATH_DEFAULT is the default path that Lua uses to look for
@* Lua libraries. @* Lua libraries.
@ -348,7 +360,7 @@
/* /*
@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib' @@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
@* behavior. @* behavior.
** CHANGE it to undefined as soon as you replace to 'luaL_registry' ** CHANGE it to undefined as soon as you replace to 'luaL_register'
** your uses of 'luaL_openlib' ** your uses of 'luaL_openlib'
*/ */
#define LUA_COMPAT_OPENLIB #define LUA_COMPAT_OPENLIB
@ -430,7 +442,8 @@
** functions. This limit is arbitrary; its only purpose is to stop C ** functions. This limit is arbitrary; its only purpose is to stop C
** functions to consume unlimited stack space. ** functions to consume unlimited stack space.
*/ */
#define LUAI_MAXCSTACK 2048 #define LUAI_MCS_AUX ((int)(INT_MAX / (4*sizeof(LUA_NUMBER))))
#define LUAI_MAXCSTACK (LUAI_MCS_AUX > SHRT_MAX ? SHRT_MAX : LUAI_MCS_AUX)
@ -543,11 +556,25 @@
/* On a Pentium, resort to a trick */ /* On a Pentium, resort to a trick */
#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \ #if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
(defined(__i386) || defined (_M_IX86) || defined(__i386__)) (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; }; union luai_Cast { double l_d; long l_l; };
#define lua_number2int(i,d) \ #define lua_number2int(i,d) \
{ volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; } { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
#define lua_number2integer(i,n) lua_number2int(i, n) #define lua_number2integer(i,n) lua_number2int(i, n)
#endif
/* this option always works, but may be slow */ /* this option always works, but may be slow */
#else #else
#define lua_number2int(i,d) ((i)=(int)(d)) #define lua_number2int(i,d) ((i)=(int)(d))
@ -640,7 +667,7 @@ union luai_Cast { double l_d; long l_l; };
*/ */
#if defined(LUA_USE_POPEN) #if defined(LUA_USE_POPEN)
#define lua_popen(L,c,m) ((void)L, popen(c,m)) #define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
#define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) #define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
#elif defined(LUA_WIN) #elif defined(LUA_WIN)

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lualib.h,v 1.36 2005/12/27 17:12:00 roberto Exp $ ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $
** Lua standard libraries ** Lua standard libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lundump.c,v 1.60 2006/02/16 15:53:49 lhf Exp $ ** $Id: lundump.c,v 2.7.1.2 2008/01/18 16:39:11 roberto Exp $
** load precompiled Lua chunks ** load precompiled Lua chunks
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -29,6 +29,7 @@ typedef struct {
#ifdef LUAC_TRUST_BINARIES #ifdef LUAC_TRUST_BINARIES
#define IF(c,s) #define IF(c,s)
#define error(S,s)
#else #else
#define IF(c,s) if (c) error(S,s) #define IF(c,s) if (c) error(S,s)
@ -47,6 +48,7 @@ static void error(LoadState* S, const char* why)
static void LoadBlock(LoadState* S, void* b, size_t size) static void LoadBlock(LoadState* S, void* b, size_t size)
{ {
size_t r=luaZ_read(S->Z,b,size); size_t r=luaZ_read(S->Z,b,size);
UNUSED(r);
IF (r!=0, "unexpected end"); IF (r!=0, "unexpected end");
} }
@ -122,7 +124,7 @@ static void LoadConstants(LoadState* S, Proto* f)
setsvalue2n(S->L,o,LoadString(S)); setsvalue2n(S->L,o,LoadString(S));
break; break;
default: default:
IF (1, "bad constant"); error(S,"bad constant");
break; break;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lundump.h,v 1.40 2005/11/11 14:03:13 lhf Exp $ ** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
** load precompiled Lua chunks ** load precompiled Lua chunks
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lvm.c,v 2.62 2006/01/23 19:51:43 roberto Exp $ ** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $
** Lua virtual machine ** Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -61,11 +61,9 @@ static void traceexec (lua_State *L, const Instruction *pc) {
lu_byte mask = L->hookmask; lu_byte mask = L->hookmask;
const Instruction *oldpc = L->savedpc; const Instruction *oldpc = L->savedpc;
L->savedpc = pc; L->savedpc = pc;
if (mask > LUA_MASKLINE) { /* instruction-hook set? */ if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) {
if (L->hookcount == 0) { resethookcount(L);
resethookcount(L); luaD_callhook(L, LUA_HOOKCOUNT, -1);
luaD_callhook(L, LUA_HOOKCOUNT, -1);
}
} }
if (mask & LUA_MASKLINE) { if (mask & LUA_MASKLINE) {
Proto *p = ci_func(L->ci)->l.p; Proto *p = ci_func(L->ci)->l.p;
@ -165,7 +163,7 @@ static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2,
const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */
if (ttisnil(tm)) if (ttisnil(tm))
tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ tm = luaT_gettmbyobj(L, p2, event); /* try second operand */
if (!ttisfunction(tm)) return 0; if (ttisnil(tm)) return 0;
callTMres(L, res, tm, p1, p2); callTMres(L, res, tm, p1, p2);
return 1; return 1;
} }
@ -281,10 +279,12 @@ void luaV_concat (lua_State *L, int total, int last) {
do { do {
StkId top = L->base + last + 1; StkId top = L->base + last + 1;
int n = 2; /* number of elements handled in this pass (at least 2) */ int n = 2; /* number of elements handled in this pass (at least 2) */
if (!tostring(L, top-2) || !tostring(L, top-1)) { if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
luaG_concaterror(L, top-2, top-1); luaG_concaterror(L, top-2, top-1);
} else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ } else if (tsvalue(top-1)->len == 0) /* second op is empty? */
(void)tostring(L, top - 2); /* result is first op (as string) */
else {
/* at least two string values; get as many as possible */ /* at least two string values; get as many as possible */
size_t tl = tsvalue(top-1)->len; size_t tl = tsvalue(top-1)->len;
char *buffer; char *buffer;
@ -376,6 +376,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
TValue *k; TValue *k;
const Instruction *pc; const Instruction *pc;
reentry: /* entry point */ reentry: /* entry point */
lua_assert(isLua(L->ci));
pc = L->savedpc; pc = L->savedpc;
cl = &clvalue(L->ci->func)->l; cl = &clvalue(L->ci->func)->l;
base = L->base; base = L->base;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lvm.h,v 2.5 2005/08/22 18:54:49 roberto Exp $ ** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $
** Lua virtual machine ** Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lzio.c,v 1.31 2005/06/03 20:15:29 roberto Exp $ ** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $
** a generic input stream interface ** a generic input stream interface
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lzio.h,v 1.21 2005/05/17 19:49:15 roberto Exp $ ** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $
** Buffered streams ** Buffered streams
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: print.c,v 1.54 2006/01/11 22:49:27 lhf Exp $ ** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $
** print bytecodes ** print bytecodes
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -20,15 +20,18 @@
#define Sizeof(x) ((int)sizeof(x)) #define Sizeof(x) ((int)sizeof(x))
#define VOID(p) ((const void*)(p)) #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);
size_t i,n=ts->tsv.len;
putchar('"'); putchar('"');
for (; *s; s++) for (i=0; i<n; i++)
{ {
switch (*s) int c=s[i];
switch (c)
{ {
case '"': printf("\\\""); break; case '"': printf("\\\""); break;
case '\\': printf("\\\\"); break;
case '\a': printf("\\a"); break; case '\a': printf("\\a"); break;
case '\b': printf("\\b"); break; case '\b': printf("\\b"); break;
case '\f': printf("\\f"); break; case '\f': printf("\\f"); break;
@ -36,10 +39,10 @@ static void PrintString(const Proto* f, int n)
case '\r': printf("\\r"); break; case '\r': printf("\\r"); break;
case '\t': printf("\\t"); break; case '\t': printf("\\t"); break;
case '\v': printf("\\v"); break; case '\v': printf("\\v"); break;
default: if (isprint((unsigned char)*s)) default: if (isprint((unsigned char)c))
printf("%c",*s); putchar(c);
else else
printf("\\%03u",(unsigned char)*s); printf("\\%03u",(unsigned char)c);
} }
} }
putchar('"'); putchar('"');
@ -60,7 +63,7 @@ static void PrintConstant(const Proto* f, int i)
printf(LUA_NUMBER_FMT,nvalue(o)); printf(LUA_NUMBER_FMT,nvalue(o));
break; break;
case LUA_TSTRING: case LUA_TSTRING:
PrintString(f,i); PrintString(rawtsvalue(o));
break; break;
default: /* cannot happen */ default: /* cannot happen */
printf("? type=%d",ttype(o)); printf("? type=%d",ttype(o));

File diff suppressed because it is too large Load Diff