summaryrefslogtreecommitdiff
path: root/lib/lua
diff options
context:
space:
mode:
authorpixel <pixel>2008-02-17 00:35:20 +0000
committerpixel <pixel>2008-02-17 00:35:20 +0000
commit658b29261ca0a68f1c5f7f3c3efa20ab56a543b6 (patch)
treee3caffa9a9ed1d80e1f8e23d8e848176d5f08413 /lib/lua
parent546a2ad1f72410fd042625cd44d192804e3ea2d7 (diff)
Upgrading to Lua 5.1.3
Diffstat (limited to 'lib/lua')
-rw-r--r--lib/lua/include/lua.h11
-rw-r--r--lib/lua/include/luaconf.h7
-rw-r--r--lib/lua/includes/lstate.h3
-rw-r--r--lib/lua/src/LuaLib/lauxlib.c13
-rw-r--r--lib/lua/src/LuaLib/lbaselib.c78
-rw-r--r--lib/lua/src/LuaLib/ldblib.c30
-rw-r--r--lib/lua/src/LuaLib/liolib.c69
-rw-r--r--lib/lua/src/LuaLib/loslib.c3
-rw-r--r--lib/lua/src/LuaLib/lstrlib.c10
-rw-r--r--lib/lua/src/LuaLib/ltablib.c5
-rw-r--r--lib/lua/src/lapi.c9
-rw-r--r--lib/lua/src/lcode.c4
-rw-r--r--lib/lua/src/ldebug.c6
-rw-r--r--lib/lua/src/ldo.c24
-rw-r--r--lib/lua/src/lparser.c4
-rw-r--r--lib/lua/src/lstate.c6
-rw-r--r--lib/lua/src/ltable.c6
-rw-r--r--lib/lua/src/lundump.c6
-rw-r--r--lib/lua/src/lvm.c10
19 files changed, 173 insertions, 131 deletions
diff --git a/lib/lua/include/lua.h b/lib/lua/include/lua.h
index ee38746..b91090b 100644
--- a/lib/lua/include/lua.h
+++ b/lib/lua/include/lua.h
@@ -1,5 +1,5 @@
/*
-** $Id: lua.h,v 1.11 2007-07-27 10:05:53 pixel Exp $
+** $Id: lua.h,v 1.12 2008-02-17 00:35:20 pixel Exp $
** Lua - An Extensible Extension Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@@ -20,9 +20,9 @@ extern "C" {
#endif
#define LUA_VERSION "Lua 5.1"
-#define LUA_RELEASE "Lua 5.1.2"
+#define LUA_RELEASE "Lua 5.1.3"
#define LUA_VERSION_NUM 501
-#define LUA_COPYRIGHT "Copyright (C) 1994-2007 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"
@@ -299,6 +299,9 @@ LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
#define lua_Chunkwriter lua_Writer
+/* hack */
+LUA_API void lua_setlevel (lua_State *from, lua_State *to);
+
/*
** {======================================================================
@@ -375,7 +378,7 @@ struct lua_Debug {
/******************************************************************************
-* Copyright (C) 1994-2007 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
* a copy of this software and associated documentation files (the
diff --git a/lib/lua/include/luaconf.h b/lib/lua/include/luaconf.h
index 39677a3..1ada33c 100644
--- a/lib/lua/include/luaconf.h
+++ b/lib/lua/include/luaconf.h
@@ -1,5 +1,5 @@
/*
-** $Id: luaconf.h,v 1.1 2007-07-27 15:47:33 pixel Exp $
+** $Id: luaconf.h,v 1.2 2008-02-17 00:35:20 pixel Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@@ -442,7 +442,8 @@
** functions. This limit is arbitrary; its only purpose is to stop C
** 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)
@@ -666,7 +667,7 @@ union luai_Cast { double l_d; long l_l; };
*/
#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))
#elif defined(LUA_WIN)
diff --git a/lib/lua/includes/lstate.h b/lib/lua/includes/lstate.h
index 1bbacfe..4bb8099 100644
--- a/lib/lua/includes/lstate.h
+++ b/lib/lua/includes/lstate.h
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.h,v 1.8 2007-07-27 10:05:53 pixel Exp $
+** $Id: lstate.h,v 1.9 2008-02-17 00:35:20 pixel Exp $
** Global State
** See Copyright Notice in lua.h
*/
@@ -112,6 +112,7 @@ struct lua_State {
int stacksize;
int size_ci; /* size of array `base_ci' */
unsigned short nCcalls; /* number of nested C calls */
+ unsigned short baseCcalls; /* nested C calls when resuming coroutine */
lu_byte hookmask;
lu_byte allowhook;
int basehookcount;
diff --git a/lib/lua/src/LuaLib/lauxlib.c b/lib/lua/src/LuaLib/lauxlib.c
index 9df860c..9807702 100644
--- a/lib/lua/src/LuaLib/lauxlib.c
+++ b/lib/lua/src/LuaLib/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.5 2007-07-27 10:05:55 pixel Exp $
+** $Id: lauxlib.c,v 1.6 2008-02-17 00:35:21 pixel Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -244,7 +244,7 @@ LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
if (libname) {
int size = libsize(l);
/* 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] */
if (!lua_istable(L, -1)) { /* not found? */
lua_pop(L, 1); /* remove previous result */
@@ -535,7 +535,7 @@ static const char *getF (lua_State *L, void *ud, size_t *size) {
return "\n";
}
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;
}
@@ -570,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 */
if (c == '\n') c = getc(lf.f);
}
- if (c == LUA_SIGNATURE[0] && lf.f != stdin) { /* binary file? */
- fclose(lf.f);
- lf.f = fopen(filename, "rb"); /* reopen in binary mode */
+ if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
+ lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
/* skip eventual `#!...' */
while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
@@ -581,7 +580,7 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
ungetc(c, lf.f);
status = lua_load(L, getF, &lf, lua_tostring(L, -1));
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) {
lua_settop(L, fnameindex); /* ignore results from `lua_load' */
return errfile(L, "read", fnameindex);
diff --git a/lib/lua/src/LuaLib/lbaselib.c b/lib/lua/src/LuaLib/lbaselib.c
index 846f26f..7159a68 100644
--- a/lib/lua/src/LuaLib/lbaselib.c
+++ b/lib/lua/src/LuaLib/lbaselib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbaselib.c,v 1.8 2007-07-27 10:05:55 pixel Exp $
+** $Id: lbaselib.c,v 1.9 2008-02-17 00:35:21 pixel Exp $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -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) {
- int status;
+ int status = costatus(L, co);
if (!lua_checkstack(co, narg))
luaL_error(L, "too many arguments to resume");
- if (lua_status(co) == 0 && lua_gettop(co) == 0) {
- lua_pushliteral(L, "cannot resume dead coroutine");
+ if (status != CO_SUS) {
+ lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]);
return -1; /* error flag */
}
lua_xmove(L, co, narg);
+ lua_setlevel(L, co);
status = lua_resume(co, narg);
if (status == 0 || status == LUA_YIELD) {
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) {
if (lua_pushthread(L))
- return 0; /* main thread is not a coroutine */
- else
- return 1;
+ lua_pushnil(L); /* main thread is not a coroutine */
+ return 1;
}
diff --git a/lib/lua/src/LuaLib/ldblib.c b/lib/lua/src/LuaLib/ldblib.c
index 076ddac..473fd7d 100644
--- a/lib/lua/src/LuaLib/ldblib.c
+++ b/lib/lua/src/LuaLib/ldblib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldblib.c,v 1.5 2007-07-27 10:05:55 pixel Exp $
+** $Id: ldblib.c,v 1.6 2008-02-17 00:35:21 pixel Exp $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -255,24 +255,25 @@ static void gethooktable (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);
if (lua_isnoneornil(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 {
const char *smask = luaL_checkstring(L, arg+2);
- int count = luaL_optint(L, arg+3, 0);
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);
- lua_pushlightuserdata(L1, L1);
+ gethooktable(L);
+ lua_pushlightuserdata(L, L1);
lua_pushvalue(L, arg+1);
- lua_xmove(L, L1, 1);
- lua_rawset(L1, -3); /* set new hook */
- lua_pop(L1, 1); /* remove hook table */
+ lua_rawset(L, -3); /* set new hook */
+ lua_pop(L, 1); /* remove hook table */
+ lua_sethook(L1, func, mask, count); /* set hooks */
return 0;
}
@@ -286,11 +287,10 @@ static int db_gethook (lua_State *L) {
if (hook != NULL && hook != hookf) /* external hook? */
lua_pushliteral(L, "external hook");
else {
- gethooktable(L1);
- lua_pushlightuserdata(L1, L1);
- lua_rawget(L1, -2); /* get hook */
- lua_remove(L1, -2); /* remove hook table */
- lua_xmove(L1, L, 1);
+ gethooktable(L);
+ lua_pushlightuserdata(L, L1);
+ lua_rawget(L, -2); /* get hook */
+ lua_remove(L, -2); /* remove hook table */
}
lua_pushstring(L, unmakemask(mask, buff));
lua_pushinteger(L, lua_gethookcount(L1));
diff --git a/lib/lua/src/LuaLib/liolib.c b/lib/lua/src/LuaLib/liolib.c
index f9866c3..edd42f5 100644
--- a/lib/lua/src/LuaLib/liolib.c
+++ b/lib/lua/src/LuaLib/liolib.c
@@ -1,5 +1,5 @@
/*
-** $Id: liolib.c,v 1.7 2007-07-27 10:05:55 pixel Exp $
+** $Id: liolib.c,v 1.8 2008-02-17 00:35:21 pixel Exp $
** Standard I/O (and system) library
** 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) {
@@ -70,7 +70,7 @@ static int io_type (lua_State *L) {
static FILE *tofile (lua_State *L) {
- FILE **f = topfile(L);
+ FILE **f = tofilep(L);
if (*f == NULL)
luaL_error(L, "attempt to use a closed file");
return *f;
@@ -93,19 +93,31 @@ static FILE **newfile (lua_State *L) {
/*
-** this function has a separated environment, which defines the
-** correct __close for 'popen' files
+** function to (not) close the standard files stdin, stdout, and stderr
+*/
+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) {
- FILE **p = topfile(L);
+ FILE **p = tofilep(L);
int ok = lua_pclose(L, *p);
*p = NULL;
return pushresult(L, ok, NULL);
}
+/*
+** function to close regular files
+*/
static int io_fclose (lua_State *L) {
- FILE **p = topfile(L);
+ FILE **p = tofilep(L);
int ok = (fclose(*p) == 0);
*p = NULL;
return pushresult(L, ok, NULL);
@@ -128,18 +140,18 @@ static int io_close (lua_State *L) {
static int io_gc (lua_State *L) {
- FILE *f = *topfile(L);
- /* ignore closed files and standard files */
- if (f != NULL && f != stdin && f != stdout && f != stderr)
+ FILE *f = *tofilep(L);
+ /* ignore closed files */
+ if (f != NULL)
aux_close(L);
return 0;
}
static int io_tostring (lua_State *L) {
- FILE *f = *topfile(L);
+ FILE *f = *tofilep(L);
if (f == NULL)
- lua_pushstring(L, "file (closed)");
+ lua_pushliteral(L, "file (closed)");
else
lua_pushfstring(L, "file (%p)", f);
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) {
const char *filename = luaL_checkstring(L, 1);
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);
if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
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);
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 */
} while (n > 0 && nr == rlen); /* until end of count or eof */
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_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) {
createmeta(L);
/* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
- lua_createtable(L, 2, 1);
+ newfenv(L, io_fclose);
lua_replace(L, LUA_ENVIRONINDEX);
/* open library */
luaL_register(L, LUA_IOLIBNAME, iolib);
/* create (and set) default files */
+ newfenv(L, io_noclose); /* close function for default files */
createstdfile(L, stdin, IO_INPUT, "stdin");
createstdfile(L, stdout, IO_OUTPUT, "stdout");
createstdfile(L, stderr, 0, "stderr");
- /* create environment for 'popen' */
+ lua_pop(L, 1); /* pop environment for default files */
lua_getfield(L, -1, "popen");
- lua_createtable(L, 0, 1);
- lua_pushcfunction(L, io_pclose);
- lua_setfield(L, -2, "__close");
- lua_setfenv(L, -2);
+ newfenv(L, io_pclose); /* create environment for 'popen' */
+ lua_setfenv(L, -2); /* set fenv for 'popen' */
lua_pop(L, 1); /* pop 'popen' */
- /* set default close function */
- lua_pushcfunction(L, io_fclose);
- lua_setfield(L, LUA_ENVIRONINDEX, "__close");
return 1;
}
diff --git a/lib/lua/src/LuaLib/loslib.c b/lib/lua/src/LuaLib/loslib.c
index 11d665e..4592be1 100644
--- a/lib/lua/src/LuaLib/loslib.c
+++ b/lib/lua/src/LuaLib/loslib.c
@@ -1,5 +1,5 @@
/*
-** $Id: loslib.c,v 1.1 2007-07-27 15:47:33 pixel Exp $
+** $Id: loslib.c,v 1.2 2008-02-17 00:35:21 pixel Exp $
** Standard Operating System library
** See Copyright Notice in lua.h
*/
@@ -215,7 +215,6 @@ static int os_setlocale (lua_State *L) {
static int os_exit (lua_State *L) {
exit(luaL_optint(L, 1, EXIT_SUCCESS));
- return 0; /* to avoid warnings */
}
static const luaL_Reg syslib[] = {
diff --git a/lib/lua/src/LuaLib/lstrlib.c b/lib/lua/src/LuaLib/lstrlib.c
index 8310752..7198464 100644
--- a/lib/lua/src/LuaLib/lstrlib.c
+++ b/lib/lua/src/LuaLib/lstrlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstrlib.c,v 1.5 2007-07-27 10:05:55 pixel Exp $
+** $Id: lstrlib.c,v 1.6 2008-02-17 00:35:21 pixel Exp $
** Standard library for string operations and pattern-matching
** 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);
break;
}
- default: {
- luaL_argerror(L, 3, "string/function/table expected");
- return;
- }
}
if (!lua_toboolean(L, -1)) { /* nil or false? */
lua_pop(L, 1);
@@ -648,11 +644,15 @@ static int str_gsub (lua_State *L) {
size_t srcl;
const char *src = luaL_checklstring(L, 1, &srcl);
const char *p = luaL_checkstring(L, 2);
+ int tr = lua_type(L, 3);
int max_s = luaL_optint(L, 4, srcl+1);
int anchor = (*p == '^') ? (p++, 1) : 0;
int n = 0;
MatchState ms;
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);
ms.L = L;
ms.src_init = src;
diff --git a/lib/lua/src/LuaLib/ltablib.c b/lib/lua/src/LuaLib/ltablib.c
index 6bd11fb..cc6be68 100644
--- a/lib/lua/src/LuaLib/ltablib.c
+++ b/lib/lua/src/LuaLib/ltablib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltablib.c,v 1.5 2007-07-27 10:05:55 pixel Exp $
+** $Id: ltablib.c,v 1.6 2008-02-17 00:35:21 pixel Exp $
** Library for Table Manipulation
** See Copyright Notice in lua.h
*/
@@ -118,7 +118,8 @@ static int tinsert (lua_State *L) {
static int tremove (lua_State *L) {
int e = aux_getn(L, 1);
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 */
lua_rawgeti(L, 1, pos); /* result = t[pos] */
for ( ;pos<e; pos++) {
diff --git a/lib/lua/src/lapi.c b/lib/lua/src/lapi.c
index e456c8f..849c724 100644
--- a/lib/lua/src/lapi.c
+++ b/lib/lua/src/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 1.6 2007-07-27 10:05:53 pixel Exp $
+** $Id: lapi.c,v 1.7 2008-02-17 00:35:20 pixel Exp $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -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_CFunction old;
lua_lock(L);
@@ -749,7 +754,7 @@ LUA_API int lua_setfenv (lua_State *L, int idx) {
res = 0;
break;
}
- luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
+ if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
L->top--;
lua_unlock(L);
return res;
diff --git a/lib/lua/src/lcode.c b/lib/lua/src/lcode.c
index acc7851..981a7fd 100644
--- a/lib/lua/src/lcode.c
+++ b/lib/lua/src/lcode.c
@@ -1,5 +1,5 @@
/*
-** $Id: lcode.c,v 1.6 2007-07-27 10:05:53 pixel Exp $
+** $Id: lcode.c,v 1.7 2008-02-17 00:35:20 pixel Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -699,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;
switch (op) {
case OPR_MINUS: {
- if (e->k == VK)
+ if (!isnumeral(e))
luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */
codearith(fs, OP_UNM, e, &e2);
break;
diff --git a/lib/lua/src/ldebug.c b/lib/lua/src/ldebug.c
index 7d606c6..55d52c8 100644
--- a/lib/lua/src/ldebug.c
+++ b/lib/lua/src/ldebug.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldebug.c,v 1.7 2007-07-27 10:05:53 pixel Exp $
+** $Id: ldebug.c,v 1.8 2008-02-17 00:35:20 pixel Exp $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -593,8 +593,8 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
void luaG_concaterror (lua_State *L, StkId p1, StkId p2) {
- if (ttisstring(p1)) p1 = p2;
- lua_assert(!ttisstring(p1));
+ if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;
+ lua_assert(!ttisstring(p1) && !ttisnumber(p1));
luaG_typeerror(L, p1, "concatenate");
}
diff --git a/lib/lua/src/ldo.c b/lib/lua/src/ldo.c
index 6fc6d3c..71e1084 100644
--- a/lib/lua/src/ldo.c
+++ b/lib/lua/src/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 1.9 2007-07-27 10:05:53 pixel Exp $
+** $Id: ldo.c,v 1.10 2008-02-17 00:35:20 pixel Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -83,7 +83,7 @@ static void resetstack (lua_State *L, int status) {
L->base = L->ci->base;
luaF_close(L, L->base); /* close eventual pending closures */
luaD_seterrorobj(L, status, L->base);
- L->nCcalls = 0;
+ L->nCcalls = L->baseCcalls;
L->allowhook = 1;
restore_stack_limit(L);
L->errfunc = 0;
@@ -336,7 +336,7 @@ static StkId callrethooks (lua_State *L, StkId firstResult) {
ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */
luaD_callhook(L, LUA_HOOKRET, -1);
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);
}
return restorestack(L, fr);
@@ -421,22 +421,24 @@ static int resume_error (lua_State *L, const char *msg) {
LUA_API int lua_resume (lua_State *L, int nargs) {
int status;
lua_lock(L);
- if (L->status != LUA_YIELD) {
- if (L->status != 0)
- return resume_error(L, "cannot resume dead coroutine");
- else if (L->ci != L->base_ci)
+ if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci))
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);
- 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);
if (status != 0) { /* error? */
L->status = cast_byte(status); /* mark thread as `dead' */
luaD_seterrorobj(L, status, L->top);
L->ci->top = L->top;
}
- else
+ else {
+ lua_assert(L->nCcalls == L->baseCcalls);
status = L->status;
+ }
+ --L->nCcalls;
lua_unlock(L);
return status;
}
@@ -445,7 +447,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
LUA_API int lua_yield (lua_State *L, int nresults) {
luai_userstateyield(L, nresults);
lua_lock(L);
- if (L->nCcalls > 0)
+ if (L->nCcalls > L->baseCcalls)
luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
L->base = L->top - nresults; /* protect stack slots below */
L->status = LUA_YIELD;
diff --git a/lib/lua/src/lparser.c b/lib/lua/src/lparser.c
index 206364a..d088722 100644
--- a/lib/lua/src/lparser.c
+++ b/lib/lua/src/lparser.c
@@ -1,5 +1,5 @@
/*
-** $Id: lparser.c,v 1.7 2007-07-27 10:05:54 pixel Exp $
+** $Id: lparser.c,v 1.8 2008-02-17 00:35:20 pixel Exp $
** Lua Parser
** See Copyright Notice in lua.h
*/
@@ -938,6 +938,8 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
primaryexp(ls, &nv.v);
if (nv.v.k == VLOCAL)
check_conflict(ls, lh, &nv.v);
+ luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,
+ "variables in assignment");
assignment(ls, &nv, nvars+1);
}
else { /* assignment -> `=' explist1 */
diff --git a/lib/lua/src/lstate.c b/lib/lua/src/lstate.c
index 8d5f3a6..10e8cda 100644
--- a/lib/lua/src/lstate.c
+++ b/lib/lua/src/lstate.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.c,v 1.7 2007-07-27 10:05:54 pixel Exp $
+** $Id: lstate.c,v 1.8 2008-02-17 00:35:20 pixel Exp $
** Global State
** See Copyright Notice in lua.h
*/
@@ -93,7 +93,7 @@ static void preinit_state (lua_State *L, global_State *g) {
resethookcount(L);
L->openupval = NULL;
L->size_ci = 0;
- L->nCcalls = 0;
+ L->nCcalls = L->baseCcalls = 0;
L->status = 0;
L->base_ci = L->ci = NULL;
L->savedpc = NULL;
@@ -213,7 +213,7 @@ LUA_API void lua_close (lua_State *L) {
do { /* repeat until no more errors */
L->ci = L->base_ci;
L->base = L->top = L->ci->base;
- L->nCcalls = 0;
+ L->nCcalls = L->baseCcalls = 0;
} while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
lua_assert(G(L)->tmudata == NULL);
luai_userstateclose(L);
diff --git a/lib/lua/src/ltable.c b/lib/lua/src/ltable.c
index 62d757a..f9145ed 100644
--- a/lib/lua/src/ltable.c
+++ b/lib/lua/src/ltable.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltable.c,v 1.5 2007-07-27 10:05:54 pixel Exp $
+** $Id: ltable.c,v 1.6 2008-02-17 00:35:20 pixel Exp $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -84,8 +84,8 @@ static const Node dummynode_ = {
static Node *hashnum (const Table *t, lua_Number n) {
unsigned int a[numints];
int i;
- n += 1; /* normalize number (avoid -0) */
- lua_assert(sizeof(a) <= sizeof(n));
+ if (luai_numeq(n, 0)) /* avoid problems with -0 */
+ return gnode(t, 0);
memcpy(a, &n, sizeof(a));
for (i = 1; i < numints; i++) a[0] += a[i];
return hashmod(t, a[0]);
diff --git a/lib/lua/src/lundump.c b/lib/lua/src/lundump.c
index a8692a8..1dd1b01 100644
--- a/lib/lua/src/lundump.c
+++ b/lib/lua/src/lundump.c
@@ -1,5 +1,5 @@
/*
-** $Id: lundump.c,v 1.5 2007-07-27 10:05:54 pixel Exp $
+** $Id: lundump.c,v 1.6 2008-02-17 00:35:20 pixel Exp $
** load precompiled Lua chunks
** See Copyright Notice in lua.h
*/
@@ -29,6 +29,7 @@ typedef struct {
#ifdef LUAC_TRUST_BINARIES
#define IF(c,s)
+#define error(S,s)
#else
#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)
{
size_t r=luaZ_read(S->Z,b,size);
+ UNUSED(r);
IF (r!=0, "unexpected end");
}
@@ -122,7 +124,7 @@ static void LoadConstants(LoadState* S, Proto* f)
setsvalue2n(S->L,o,LoadString(S));
break;
default:
- IF (1, "bad constant");
+ error(S,"bad constant");
break;
}
}
diff --git a/lib/lua/src/lvm.c b/lib/lua/src/lvm.c
index 52f65e6..532e75d 100644
--- a/lib/lua/src/lvm.c
+++ b/lib/lua/src/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 1.11 2007-07-27 10:05:54 pixel Exp $
+** $Id: lvm.c,v 1.12 2008-02-17 00:35:20 pixel Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -61,11 +61,9 @@ static void traceexec (lua_State *L, const Instruction *pc) {
lu_byte mask = L->hookmask;
const Instruction *oldpc = L->savedpc;
L->savedpc = pc;
- if (mask > LUA_MASKLINE) { /* instruction-hook set? */
- if (L->hookcount == 0) {
- resethookcount(L);
- luaD_callhook(L, LUA_HOOKCOUNT, -1);
- }
+ if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) {
+ resethookcount(L);
+ luaD_callhook(L, LUA_HOOKCOUNT, -1);
}
if (mask & LUA_MASKLINE) {
Proto *p = ci_func(L->ci)->l.p;