This commit is contained in:
Roberto Ierusalimschy
2006-06-22 13:12:59 -03:00
parent 98194db429
commit ee41bc03ab
6 changed files with 29 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lauxlib.c,v 1.158 2006/01/16 12:42:21 roberto Exp roberto $ ** $Id: lauxlib.c,v 1.159 2006/03/21 19:31:09 roberto Exp roberto $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -535,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;
} }

26
lcode.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lcode.c,v 2.24 2005/12/22 16:19:56 roberto Exp roberto $ ** $Id: lcode.c,v 2.25 2006/03/21 19:28:49 roberto Exp roberto $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -221,24 +221,28 @@ static void freeexp (FuncState *fs, expdesc *e) {
} }
static int addk (FuncState *fs, TValue *k, TValue *v) { static int addk (FuncState *fs, TValue *key, TValue *v) {
lua_State *L = fs->L; lua_State *L = fs->L;
TValue *idx = luaH_set(L, fs->h, k); TValue *idx = luaH_set(L, fs->h, key);
Proto *f = fs->f; Proto *f = fs->f;
int oldsize = f->sizek; int k;
if (ttisnumber(idx)) { if (ttisnumber(idx)) {
lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); lua_Number n = nvalue(idx);
return cast_int(nvalue(idx)); lua_number2int(k, n);
lua_assert(luaO_rawequalObj(&f->k[k], v));
} }
else { /* constant not found; create a new entry */ else { /* constant not found; create a new entry */
setnvalue(idx, cast_num(fs->nk)); int oldsize = f->sizek;
luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, k = fs->nk;
MAXARG_Bx, "constant table overflow"); setnvalue(idx, cast_num(k));
luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Bx,
"constant table overflow");
while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
setobj(L, &f->k[fs->nk], v); setobj(L, &f->k[k], v);
fs->nk++;
luaC_barrier(L, f, v); luaC_barrier(L, f, v);
return fs->nk++;
} }
return k;
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: liolib.c,v 2.72 2006/01/28 12:59:13 roberto Exp roberto $ ** $Id: liolib.c,v 2.73 2006/05/08 20:14:16 roberto Exp roberto $
** Standard I/O (and system) library ** Standard I/O (and system) library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -139,7 +139,7 @@ static int io_gc (lua_State *L) {
static int io_tostring (lua_State *L) { static int io_tostring (lua_State *L) {
FILE *f = *topfile(L); FILE *f = *topfile(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;

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: loadlib.c,v 1.51 2005/12/29 15:32:11 roberto Exp roberto $ ** $Id: loadlib.c,v 1.52 2006/04/10 18:27:23 roberto Exp roberto $
** Dynamic library loader for Lua ** Dynamic library loader for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
** **
@@ -356,7 +356,7 @@ 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);
@@ -462,7 +462,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))
@@ -646,8 +646,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: lparser.c,v 2.41 2006/03/09 18:15:48 roberto Exp roberto $ ** $Id: lparser.c,v 2.42 2006/06/05 15:57:59 roberto Exp roberto $
** Lua Parser ** Lua Parser
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -274,8 +274,8 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
static void enterlevel (LexState *ls) { static void enterlevel (LexState *ls) {
if (++ls->L->nCcalls > LUAI_MAXCCALLS) ++ls->L->nCcalls;
luaX_lexerror(ls, "chunk has too many syntax levels", 0); luaY_checklimit(ls->fs, ls->L->nCcalls, LUAI_MAXCCALLS, "syntax levels");
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstrlib.c,v 1.131 2006/04/12 20:13:52 roberto Exp roberto $ ** $Id: lstrlib.c,v 1.132 2006/04/26 20:41:19 roberto Exp roberto $
** 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
*/ */
@@ -185,7 +185,7 @@ typedef struct MatchState {
static int check_capture (MatchState *ms, int l) { static int check_capture (MatchState *ms, int l) {
l -= '1'; l -= '1';
if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED) if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)
return luaL_error(ms->L, "invalid capture index"); return luaL_error(ms->L, "invalid capture index %%%d", l + 1);
return l; return l;
} }