Compare commits

..

36 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
69ea087dff small change to strip file names when stripping debug information 2006-02-17 13:51:03 -02:00
Roberto Ierusalimschy
c05aaf3bf0 avoid warning in OS X - ansi 2006-02-10 15:44:06 -02:00
Roberto Ierusalimschy
298ae7e230 complete support for hexadecimal constants 2006-02-10 15:43:52 -02:00
Roberto Ierusalimschy
6316a866a3 compiler warning 2006-02-06 16:28:16 -02:00
Roberto Ierusalimschy
ea2cc2bc47 small improvements for allignments 2006-02-06 16:27:59 -02:00
Roberto Ierusalimschy
64205e91a3 empty string may cause out-of-bound access 2006-01-28 10:59:13 -02:00
Roberto Ierusalimschy
8173688542 detail 2006-01-27 11:54:39 -02:00
Roberto Ierusalimschy
3ef5a6797f detail 2006-01-23 18:06:19 -02:00
Roberto Ierusalimschy
9e6e43984d details 2006-01-23 17:51:43 -02:00
Roberto Ierusalimschy
baffc37f5c detail 2006-01-18 09:49:12 -02:00
Roberto Ierusalimschy
440113bbe8 unused macro removed 2006-01-18 09:37:34 -02:00
Roberto Ierusalimschy
73ebc5d8f6 compat code should keep compatibility 2006-01-16 10:42:21 -02:00
Roberto Ierusalimschy
a666752b1d detail 2006-01-13 17:36:28 -02:00
Roberto Ierusalimschy
f8b7a5581e avoid unnecessary exports 2006-01-10 11:13:06 -02:00
Roberto Ierusalimschy
ffb798e1e2 avoids type punning for table keys 2006-01-10 10:51:53 -02:00
Roberto Ierusalimschy
fa936f8fa9 detail 2006-01-10 10:50:13 -02:00
Roberto Ierusalimschy
dd1221582b details 2006-01-10 10:50:00 -02:00
Roberto Ierusalimschy
bfdcbbcd76 small optimizations (lua_newtable -> lua_createtable) 2005-12-29 14:23:32 -02:00
Roberto Ierusalimschy
30eebb2d1c detail (stop collector while openning libraries) 2005-12-29 10:30:16 -02:00
Roberto Ierusalimschy
0fd6466957 lua_assert is an internal matter, not to be configured 2005-12-27 15:12:00 -02:00
Roberto Ierusalimschy
6a516878e9 collectgarbage"count" returns kilobytes (where K = 1024) 2005-12-27 15:10:11 -02:00
Roberto Ierusalimschy
a486090a5c copyright will be 2006 2005-12-27 15:09:50 -02:00
Roberto Ierusalimschy
0160591998 removal of dead code 2005-12-26 11:35:47 -02:00
Roberto Ierusalimschy
c505f341d6 small changes in casts 2005-12-22 14:19:56 -02:00
Roberto Ierusalimschy
428325baec detail 2005-12-21 10:59:43 -02:00
Roberto Ierusalimschy
0561f71f0f (much) better error messages for 'require' 2005-12-19 18:56:39 -02:00
Roberto Ierusalimschy
9fbefdf69c integer formats in 'string.format' may need to operate with larger-than-int
types
2005-12-15 16:53:34 -02:00
Roberto Ierusalimschy
43c61fc113 details 2005-12-15 16:17:49 -02:00
Roberto Ierusalimschy
ea6b1b42c7 more robust way to test for decimal point separator 2005-12-08 13:50:54 -02:00
Roberto Ierusalimschy
87024e257d details 2005-12-07 13:43:05 -02:00
Roberto Ierusalimschy
6cd461633d clearer error message for uninstalled loadlib 2005-12-07 13:42:32 -02:00
Roberto Ierusalimschy
16fd4abaf6 corrects decimal point to follow current locale 2005-12-07 13:33:27 -02:00
Roberto Ierusalimschy
f26b85c5b7 small detail 2005-12-02 16:42:08 -02:00
Roberto Ierusalimschy
3592c08a2c avoid printing two copyright messages with '-v -i' options 2005-11-28 12:44:48 -02:00
Roberto Ierusalimschy
db724e14e0 new macro luai_numisnan 2005-11-25 11:29:32 -02:00
Roberto Ierusalimschy
1702953293 new macro LUA_WIN + new macro luai_numisnan 2005-11-25 11:29:11 -02:00
37 changed files with 465 additions and 353 deletions

27
lapi.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 2.50 2005/09/20 17:55:10 roberto Exp roberto $
** $Id: lapi.c,v 2.52 2005/12/22 16:19:56 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -40,7 +40,7 @@ const char lua_ident[] =
#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base))
#define api_checkvalidindex(L, i) api_check(L, (i) != &luaO_nilobject)
#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject)
#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;}
@@ -50,7 +50,7 @@ static TValue *index2adr (lua_State *L, int idx) {
if (idx > 0) {
TValue *o = L->base + (idx - 1);
api_check(L, idx <= L->ci->top - L->base);
if (o >= L->top) return cast(TValue *, &luaO_nilobject);
if (o >= L->top) return cast(TValue *, luaO_nilobject);
else return o;
}
else if (idx > LUA_REGISTRYINDEX) {
@@ -70,7 +70,7 @@ static TValue *index2adr (lua_State *L, int idx) {
idx = LUA_GLOBALSINDEX - idx;
return (idx <= func->c.nupvalues)
? &func->c.upvalue[idx-1]
: cast(TValue *, &luaO_nilobject);
: cast(TValue *, luaO_nilobject);
}
}
}
@@ -153,7 +153,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
LUA_API int lua_gettop (lua_State *L) {
return cast(int, L->top - L->base);
return cast_int(L->top - L->base);
}
@@ -234,7 +234,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) {
LUA_API int lua_type (lua_State *L, int idx) {
StkId o = index2adr(L, idx);
return (o == &luaO_nilobject) ? LUA_TNONE : ttype(o);
return (o == luaO_nilobject) ? LUA_TNONE : ttype(o);
}
@@ -272,7 +272,7 @@ LUA_API int lua_isuserdata (lua_State *L, int idx) {
LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
StkId o1 = index2adr(L, index1);
StkId o2 = index2adr(L, index2);
return (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
: luaO_rawequalObj(o1, o2);
}
@@ -283,8 +283,7 @@ LUA_API int lua_equal (lua_State *L, int index1, int index2) {
lua_lock(L); /* may call tag method */
o1 = index2adr(L, index1);
o2 = index2adr(L, index2);
i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
: equalobj(L, o1, o2);
i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2);
lua_unlock(L);
return i;
}
@@ -296,7 +295,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
lua_lock(L); /* may call tag method */
o1 = index2adr(L, index1);
o2 = index2adr(L, index2);
i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
: luaV_lessthan(L, o1, o2);
lua_unlock(L);
return i;
@@ -430,7 +429,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
lua_lock(L);
setnvalue(L->top, cast(lua_Number, n));
setnvalue(L->top, cast_num(n));
api_incr_top(L);
lua_unlock(L);
}
@@ -910,11 +909,11 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
}
case LUA_GCCOUNT: {
/* GC values are expressed in Kbytes: #bytes/2^10 */
res = cast(int, g->totalbytes >> 10);
res = cast_int(g->totalbytes >> 10);
break;
}
case LUA_GCCOUNTB: {
res = cast(int, g->totalbytes & 0x3ff);
res = cast_int(g->totalbytes & 0x3ff);
break;
}
case LUA_GCSTEP: {
@@ -983,7 +982,7 @@ LUA_API void lua_concat (lua_State *L, int n) {
api_checknelems(L, n);
if (n >= 2) {
luaC_checkGC(L);
luaV_concat(L, n, cast(int, L->top - L->base) - 1);
luaV_concat(L, n, cast_int(L->top - L->base) - 1);
L->top -= (n-1);
}
else if (n == 0) { /* push empty string */

View File

@@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.155 2005/10/20 11:35:25 roberto Exp roberto $
** $Id: lauxlib.c,v 1.157 2005/12/29 15:32:11 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -226,16 +226,24 @@ LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
}
static int libsize (const luaL_Reg *l) {
int size = 0;
for (; l->name; l++) size++;
return size;
}
LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
const luaL_Reg *l, int nup) {
if (libname) {
int size = libsize(l);
/* check whether lib already exists */
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", size);
lua_getfield(L, -1, libname); /* get _LOADED[libname] */
if (!lua_istable(L, -1)) { /* not found? */
lua_pop(L, 1); /* remove previous result */
/* try global variable (and create one if it does not exist) */
if (luaL_findtable(L, LUA_GLOBALSINDEX, libname) != NULL)
if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
luaL_error(L, "name conflict for module " LUA_QS, libname);
lua_pushvalue(L, -1);
lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
@@ -287,23 +295,33 @@ static void getsizes (lua_State *L) {
LUALIB_API void luaL_setn (lua_State *L, int t, int n) {
t = abs_index(L, t);
getsizes(L);
lua_pushvalue(L, t);
lua_pushinteger(L, n);
lua_rawset(L, -3); /* sizes[t] = n */
lua_pop(L, 1); /* remove `sizes' */
lua_pushliteral(L, "n");
lua_rawget(L, t);
if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */
lua_pushliteral(L, "n"); /* use it */
lua_pushinteger(L, n);
lua_rawset(L, t);
}
else { /* use `sizes' */
getsizes(L);
lua_pushvalue(L, t);
lua_pushinteger(L, n);
lua_rawset(L, -3); /* sizes[t] = n */
lua_pop(L, 1); /* remove `sizes' */
}
}
LUALIB_API int luaL_getn (lua_State *L, int t) {
int n;
t = abs_index(L, t);
getsizes(L); /* try sizes[t] */
lua_pushliteral(L, "n"); /* try t.n */
lua_rawget(L, t);
if ((n = checkint(L, 1)) >= 0) return n;
getsizes(L); /* else try sizes[t] */
lua_pushvalue(L, t);
lua_rawget(L, -2);
if ((n = checkint(L, 2)) >= 0) return n;
lua_getfield(L, t, "n"); /* else try t.n */
if ((n = checkint(L, 1)) >= 0) return n;
return (int)lua_objlen(L, t);
}
@@ -331,7 +349,7 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
const char *fname) {
const char *fname, int szhint) {
const char *e;
lua_pushvalue(L, idx);
do {
@@ -341,7 +359,7 @@ LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
lua_rawget(L, -2);
if (lua_isnil(L, -1)) { /* no such field? */
lua_pop(L, 1); /* remove this nil */
lua_newtable(L); /* create a new table for field */
lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
lua_pushlstring(L, fname, e - fname);
lua_pushvalue(L, -2);
lua_settable(L, -4); /* set new table into field */

View File

@@ -1,5 +1,5 @@
/*
** $Id: lauxlib.h,v 1.85 2005/09/06 17:19:51 roberto Exp roberto $
** $Id: lauxlib.h,v 1.86 2005/10/21 13:47:42 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -86,7 +86,7 @@ LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
const char *r);
LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
const char *fname);
const char *fname, int szhint);

View File

@@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.185 2005/10/20 11:35:50 roberto Exp roberto $
** $Id: lbaselib.c,v 1.188 2005/12/29 15:32:11 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -201,7 +201,7 @@ static int luaB_collectgarbage (lua_State *L) {
switch (optsnum[o]) {
case LUA_GCCOUNT: {
int b = lua_gc(L, LUA_GCCOUNTB, 0);
lua_pushnumber(L, ((lua_Number)res*1024 + b)/1000);
lua_pushnumber(L, res + ((lua_Number)b/1024));
return 1;
}
case LUA_GCSTEP: {
@@ -625,7 +625,7 @@ static void base_open (lua_State *L) {
auxopen(L, "ipairs", luaB_ipairs, ipairsaux);
auxopen(L, "pairs", luaB_pairs, luaB_next);
/* `newproxy' needs a weaktable as upvalue */
lua_newtable(L); /* new table `w' */
lua_createtable(L, 0, 1); /* new table `w' */
lua_pushvalue(L, -1); /* `w' will be its own metatable */
lua_setmetatable(L, -2);
lua_pushliteral(L, "kv");

12
lcode.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lcode.c,v 2.21 2005/11/08 19:44:31 roberto Exp roberto $
** $Id: lcode.c,v 2.23 2005/11/25 13:29:32 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -196,7 +196,7 @@ void luaK_checkstack (FuncState *fs, int n) {
if (newstack > fs->f->maxstacksize) {
if (newstack >= MAXSTACK)
luaX_syntaxerror(fs->ls, "function or expression too complex");
fs->f->maxstacksize = cast(lu_byte, newstack);
fs->f->maxstacksize = cast_byte(newstack);
}
}
@@ -227,11 +227,11 @@ static int addk (FuncState *fs, TValue *k, TValue *v) {
Proto *f = fs->f;
int oldsize = f->sizek;
if (ttisnumber(idx)) {
lua_assert(luaO_rawequalObj(&fs->f->k[cast(int, nvalue(idx))], v));
return cast(int, nvalue(idx));
lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v));
return cast_int(nvalue(idx));
}
else { /* constant not found; create a new entry */
setnvalue(idx, cast(lua_Number, fs->nk));
setnvalue(idx, cast_num(fs->nk));
luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
MAXARG_Bx, "constant table overflow");
while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
@@ -647,7 +647,7 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
case OP_LEN: return 0; /* no constant folding for 'len' */
default: lua_assert(0); r = 0; break;
}
if (r != r) return 0; /* do not attempt to produce NaN */
if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */
e1->u.nval = r;
return 1;
}

View File

@@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.102 2005/10/19 13:05:11 roberto Exp roberto $
** $Id: ldblib.c,v 1.103 2005/11/01 16:08:32 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -116,7 +116,7 @@ static int db_getinfo (lua_State *L) {
return luaL_argerror(L, arg+1, "function or level expected");
if (!lua_getinfo(L1, options, &ar))
return luaL_argerror(L, arg+2, "invalid option");
lua_newtable(L);
lua_createtable(L, 0, 2);
if (strchr(options, 'S')) {
settabss(L, "source", ar.source);
settabss(L, "short_src", ar.short_src);
@@ -246,7 +246,7 @@ static void gethooktable (lua_State *L) {
lua_rawget(L, LUA_REGISTRYINDEX);
if (!lua_istable(L, -1)) {
lua_pop(L, 1);
lua_newtable(L);
lua_createtable(L, 0, 1);
lua_pushlightuserdata(L, (void *)&KEY_HOOK);
lua_pushvalue(L, -2);
lua_rawset(L, LUA_REGISTRYINDEX);

View File

@@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 2.27 2005/10/06 20:43:44 roberto Exp roberto $
** $Id: ldebug.c,v 2.28 2005/11/01 16:08:52 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -61,7 +61,7 @@ LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {
L->hook = func;
L->basehookcount = count;
resethookcount(L);
L->hookmask = cast(lu_byte, mask);
L->hookmask = cast_byte(mask);
return 1;
}
@@ -92,7 +92,7 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
}
if (level == 0 && ci > L->base_ci) { /* level found? */
status = 1;
ar->i_ci = cast(int, ci - L->base_ci);
ar->i_ci = cast_int(ci - L->base_ci);
}
else if (level < 0) { /* level is of a lost tail call? */
status = 1;
@@ -550,7 +550,7 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
const char *name = NULL;
const char *t = luaT_typenames[ttype(o)];
const char *kind = (isinstack(L->ci, o)) ?
getobjname(L, L->ci, cast(int, o - L->base), &name) :
getobjname(L, L->ci, cast_int(o - L->base), &name) :
NULL;
if (kind)
luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",

17
ldo.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 2.35 2005/10/14 16:23:33 roberto Exp roberto $
** $Id: ldo.c,v 2.36 2005/10/23 17:52:42 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -71,7 +71,7 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
static void restore_stack_limit (lua_State *L) {
lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);
if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */
int inuse = cast(int, L->ci - L->base_ci);
int inuse = cast_int(L->ci - L->base_ci);
if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */
luaD_reallocCI(L, LUAI_MAXCALLS);
}
@@ -97,7 +97,7 @@ void luaD_throw (lua_State *L, int errcode) {
LUAI_THROW(L, L->errorJmp);
}
else {
L->status = cast(lu_byte, errcode);
L->status = cast_byte(errcode);
if (G(L)->panic) {
resetstack(L, errcode);
lua_unlock(L);
@@ -189,7 +189,7 @@ void luaD_callhook (lua_State *L, int event, int line) {
if (event == LUA_HOOKTAILRET)
ar.i_ci = 0; /* tail call; no debug information about it */
else
ar.i_ci = cast(int, L->ci - L->base_ci);
ar.i_ci = cast_int(L->ci - L->base_ci);
luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
L->ci->top = L->top + LUA_MINSTACK;
lua_assert(L->ci->top <= L->stack_last);
@@ -221,8 +221,7 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) {
for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */
setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i);
/* store counter in field `n' */
setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")),
cast(lua_Number, nvar));
setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar));
}
#endif
/* move fixed parameters to final position */
@@ -282,7 +281,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
L->top = base + p->numparams;
}
else { /* vararg function */
int nargs = cast(int, L->top - func) - 1;
int nargs = cast_int(L->top - func) - 1;
base = adjust_varargs(L, p, nargs);
func = restorestack(L, funcr); /* previous call may change the stack */
}
@@ -401,7 +400,7 @@ static void resume (lua_State *L, void *ud) {
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));
}
@@ -427,7 +426,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
lua_assert(L->errfunc == 0 && L->nCcalls == 0);
status = luaD_rawrunprotected(L, resume, L->top - nargs);
if (status != 0) { /* error? */
L->status = cast(lu_byte, status); /* mark thread as `dead' */
L->status = cast_byte(status); /* mark thread as `dead' */
luaD_seterrorobj(L, status, L->top);
L->ci->top = L->top;
}

View File

@@ -1,5 +1,5 @@
/*
** $Id: ldump.c,v 1.13 2005/11/01 17:04:55 lhf Exp lhf $
** $Id: ldump.c,v 1.15 2006/02/16 15:53:49 lhf Exp $
** save precompiled Lua chunks
** See Copyright Notice in lua.h
*/
@@ -128,7 +128,7 @@ static void DumpDebug(const Proto* f, DumpState* D)
static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
{
DumpString((f->source==p) ? NULL : f->source,D);
DumpString((f->source==p || D->strip) ? NULL : f->source,D);
DumpInt(f->linedefined,D);
DumpInt(f->lastlinedefined,D);
DumpChar(f->nups,D);

View File

@@ -1,5 +1,5 @@
/*
** $Id: lfunc.c,v 2.10 2005/04/29 13:54:05 roberto Exp roberto $
** $Id: lfunc.c,v 2.11 2005/05/05 20:47:02 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
@@ -25,7 +25,7 @@ Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) {
luaC_link(L, obj2gco(c), LUA_TFUNCTION);
c->c.isC = 1;
c->c.env = e;
c->c.nupvalues = cast(lu_byte, nelems);
c->c.nupvalues = cast_byte(nelems);
return c;
}
@@ -35,7 +35,7 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) {
luaC_link(L, obj2gco(c), LUA_TFUNCTION);
c->l.isC = 0;
c->l.env = e;
c->l.nupvalues = cast(lu_byte, nelems);
c->l.nupvalues = cast_byte(nelems);
while (nelems--) c->l.upvals[nelems] = NULL;
return c;
}

17
lgc.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lgc.c,v 2.35 2005/08/04 13:37:38 roberto Exp roberto $
** $Id: lgc.c,v 2.36 2005/08/24 17:06:36 roberto Exp roberto $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@@ -29,11 +29,10 @@
#define GCFINALIZECOST 100
#define maskmarks \
cast(lu_byte, ~(bitmask(BLACKBIT)|WHITEBITS))
#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS))
#define makewhite(g,x) \
((x)->gch.marked = ((x)->gch.marked & maskmarks) | luaC_white(g))
((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g)))
#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT)
@@ -169,8 +168,8 @@ static int traversetable (global_State *g, Table *h) {
weakvalue = (strchr(svalue(mode), 'v') != NULL);
if (weakkey || weakvalue) { /* is really weak? */
h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */
h->marked |= cast(lu_byte, (weakkey << KEYWEAKBIT) |
(weakvalue << VALUEWEAKBIT));
h->marked |= cast_byte((weakkey << KEYWEAKBIT) |
(weakvalue << VALUEWEAKBIT));
h->gclist = g->weak; /* must be cleared after GC, ... */
g->weak = obj2gco(h); /* ... so put in the appropriate list */
}
@@ -240,8 +239,8 @@ static void traverseclosure (global_State *g, Closure *cl) {
static void checkstacksizes (lua_State *L, StkId max) {
int ci_used = cast(int, L->ci - L->base_ci); /* number of `ci' in use */
int s_used = cast(int, max - L->stack); /* part of stack in use */
int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */
int s_used = cast_int(max - L->stack); /* part of stack in use */
if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */
return; /* do not touch the stacks */
if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
@@ -544,7 +543,7 @@ static void atomic (lua_State *L) {
propagateall(g); /* remark, to propagate `preserveness' */
cleartable(g->weak); /* remove collected objects from weak tables */
/* flip current white */
g->currentwhite = cast(lu_byte, otherwhite(g));
g->currentwhite = cast_byte(otherwhite(g));
g->sweepstrgc = 0;
g->sweepgc = &g->rootgc;
g->gcstate = GCSsweepstring;

View File

@@ -1,5 +1,5 @@
/*
** $Id: linit.c,v 1.12 2005/08/10 18:06:58 roberto Exp roberto $
** $Id: linit.c,v 1.13 2005/08/26 17:36:32 roberto Exp roberto $
** Initialization of libraries for lua.c
** See Copyright Notice in lua.h
*/
@@ -16,13 +16,13 @@
static const luaL_Reg lualibs[] = {
{"", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
{LUA_TABLIBNAME, luaopen_table},
{LUA_IOLIBNAME, luaopen_io},
{LUA_OSLIBNAME, luaopen_os},
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{LUA_DBLIBNAME, luaopen_debug},
{LUA_LOADLIBNAME, luaopen_package},
{NULL, NULL}
};

View File

@@ -1,5 +1,5 @@
/*
** $Id: liolib.c,v 2.68 2005/10/14 16:24:11 roberto Exp roberto $
** $Id: liolib.c,v 2.71 2006/01/17 13:54:02 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@@ -28,6 +28,7 @@ static const char *const fnames[] = {"input", "output"};
static int pushresult (lua_State *L, int i, const char *filename) {
int en = errno; /* calls to Lua API may change this value */
if (i) {
lua_pushboolean(L, 1);
return 1;
@@ -35,10 +36,10 @@ static int pushresult (lua_State *L, int i, const char *filename) {
else {
lua_pushnil(L);
if (filename)
lua_pushfstring(L, "%s: %s", filename, strerror(errno));
lua_pushfstring(L, "%s: %s", filename, strerror(en));
else
lua_pushfstring(L, "%s", strerror(errno));
lua_pushinteger(L, errno);
lua_pushfstring(L, "%s", strerror(en));
lua_pushinteger(L, en);
return 3;
}
}
@@ -282,7 +283,7 @@ static int read_line (lua_State *L, FILE *f) {
return (lua_strlen(L, -1) > 0); /* check whether read something */
}
l = strlen(p);
if (p[l-1] != '\n')
if (l == 0 || p[l-1] != '\n')
luaL_addsize(&b, l);
else {
luaL_addsize(&b, l - 1); /* do not include `eol' */
@@ -507,8 +508,8 @@ static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {
LUALIB_API int luaopen_io (lua_State *L) {
createmeta(L);
/* create new (private) environment */
lua_newtable(L);
/* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
lua_createtable(L, 2, 1);
lua_replace(L, LUA_ENVIRONINDEX);
/* open library */
luaL_register(L, LUA_IOLIBNAME, iolib);
@@ -518,7 +519,7 @@ LUALIB_API int luaopen_io (lua_State *L) {
createstdfile(L, stderr, 0, "stderr");
/* create environment for 'popen' */
lua_getfield(L, -1, "popen");
lua_newtable(L);
lua_createtable(L, 0, 1);
lua_pushcfunction(L, io_pclose);
lua_setfield(L, -2, "__close");
lua_setfenv(L, -2);

60
llex.c
View File

@@ -1,11 +1,12 @@
/*
** $Id: llex.c,v 2.12 2005/05/17 19:49:15 roberto Exp roberto $
** $Id: llex.c,v 2.18 2006/01/23 20:06:19 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
#include <ctype.h>
#include <locale.h>
#include <string.h>
#define llex_c
@@ -65,7 +66,7 @@ void luaX_init (lua_State *L) {
TString *ts = luaS_new(L, luaX_tokens[i]);
luaS_fix(ts); /* reserved words are never collected */
lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN);
ts->tsv.reserved = cast(lu_byte, i+1); /* reserved word */
ts->tsv.reserved = cast_byte(i+1); /* reserved word */
}
}
@@ -134,6 +135,7 @@ static void inclinenumber (LexState *ls) {
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
ls->decpoint = '.';
ls->L = L;
ls->lookahead.token = TK_EOS; /* no look-ahead token */
ls->z = z;
@@ -163,6 +165,27 @@ static int check_next (LexState *ls, const char *set) {
}
static void buffreplace (LexState *ls, char from, char to) {
size_t n = luaZ_bufflen(ls->buff);
char *p = luaZ_buffer(ls->buff);
while (n--)
if (p[n] == from) p[n] = to;
}
static void trydecpoint (LexState *ls, SemInfo *seminfo) {
/* format error: try to update decimal point separator */
struct lconv *cv = localeconv();
char old = ls->decpoint;
ls->decpoint = (cv ? cv->decimal_point[0] : '.');
buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */
if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {
/* format error with correct decimal point: no more options */
buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */
luaX_lexerror(ls, "malformed number", TK_NUMBER);
}
}
/* LUA_NUMBER */
static void read_numeral (LexState *ls, SemInfo *seminfo) {
@@ -170,15 +193,14 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) {
do {
save_and_next(ls);
} while (isdigit(ls->current) || ls->current == '.');
if (check_next(ls, "Ee")) { /* `E'? */
if (check_next(ls, "Ee")) /* `E'? */
check_next(ls, "+-"); /* optional exponent sign */
while (isdigit(ls->current)) {
save_and_next(ls);
}
}
while (isalnum(ls->current) || ls->current == '_')
save_and_next(ls);
save(ls, '\0');
if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r))
luaX_lexerror(ls, "malformed number", TK_NUMBER);
buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */
trydecpoint(ls, seminfo); /* try to update decimal point separator */
}
@@ -306,7 +328,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) {
}
int luaX_lex (LexState *ls, SemInfo *seminfo) {
static int llex (LexState *ls, SemInfo *seminfo) {
luaZ_resetbuffer(ls->buff);
for (;;) {
switch (ls->current) {
@@ -419,4 +441,20 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) {
}
}
#undef next
void luaX_next (LexState *ls) {
ls->lastline = ls->linenumber;
if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
ls->t = ls->lookahead; /* use this one */
ls->lookahead.token = TK_EOS; /* and discharge it */
}
else
ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */
}
void luaX_lookahead (LexState *ls) {
lua_assert(ls->lookahead.token == TK_EOS);
ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
}

6
llex.h
View File

@@ -1,5 +1,5 @@
/*
** $Id: llex.h,v 1.54 2005/04/25 19:24:10 roberto Exp roberto $
** $Id: llex.h,v 1.56 2005/12/07 15:33:27 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@@ -63,6 +63,7 @@ typedef struct LexState {
ZIO *z; /* input stream */
Mbuffer *buff; /* buffer for tokens */
TString *source; /* current source name */
char decpoint; /* locale decimal point */
} LexState;
@@ -70,7 +71,8 @@ LUAI_FUNC void luaX_init (lua_State *L);
LUAI_FUNC void luaX_setinput (lua_State *L, LexState *LS, ZIO *z,
TString *source);
LUAI_FUNC TString *luaX_newstring (LexState *LS, const char *str, size_t l);
LUAI_FUNC int luaX_lex (LexState *LS, SemInfo *seminfo);
LUAI_FUNC void luaX_next (LexState *ls);
LUAI_FUNC void luaX_lookahead (LexState *ls);
LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);
LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);
LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);

View File

@@ -1,5 +1,5 @@
/*
** $Id: llimits.h,v 1.66 2005/08/04 13:37:10 roberto Exp roberto $
** $Id: llimits.h,v 1.68 2005/12/22 16:19:56 roberto Exp roberto $
** Limits, basic types, and some other `installation-dependent' definitions
** See Copyright Notice in lua.h
*/
@@ -15,9 +15,6 @@
#include "lua.h"
#define api_check luai_apicheck
typedef LUAI_UINT32 lu_int32;
typedef LUAI_UMEM lu_mem;
@@ -54,7 +51,19 @@ typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
typedef LUAI_UACNUMBER l_uacNumber;
#define check_exp(c,e) (lua_assert(c), (e))
/* internal assertions for in-house debugging */
#ifdef lua_assert
#define check_exp(c,e) (lua_assert(c), (e))
#define api_check(l,e) lua_assert(e)
#else
#define lua_assert(c) ((void)0)
#define check_exp(c,e) (e)
#define api_check luai_apicheck
#endif
#ifndef UNUSED
@@ -66,6 +75,10 @@ typedef LUAI_UACNUMBER l_uacNumber;
#define cast(t, exp) ((t)(exp))
#endif
#define cast_byte(i) cast(lu_byte, (i))
#define cast_num(i) cast(lua_Number, (i))
#define cast_int(i) cast(int, (i))
/*

18
lmem.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lmem.c,v 1.68 2005/01/14 14:21:16 roberto Exp roberto $
** $Id: lmem.c,v 1.69 2005/02/23 17:30:22 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@@ -81,22 +81,6 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
luaD_throw(L, LUA_ERRMEM);
lua_assert((nsize == 0) == (block == NULL));
g->totalbytes = (g->totalbytes - osize) + nsize;
#if 0
{ /* auxiliar patch to monitor garbage collection */
static unsigned long total = 0; /* our "time" */
static lu_mem last = 0; /* last totalmem that generated an output */
static FILE *f = NULL; /* output file */
if (nsize <= osize) total += 1; /* "time" always grow */
else total += (nsize - osize);
if ((int)g->totalbytes - (int)last > 1000 ||
(int)g->totalbytes - (int)last < -1000) {
last = g->totalbytes;
if (f == NULL) f = fopen("trace", "w");
fprintf(f, "%lu %u %u %u %d\n", total, g->totalbytes, g->GCthreshold,
g->estimate, g->gcstate);
}
}
#endif
return block;
}

View File

@@ -1,5 +1,5 @@
/*
** $Id: loadlib.c,v 1.47 2005/10/06 20:46:10 roberto Exp roberto $
** $Id: loadlib.c,v 1.50 2005/12/19 20:56:39 roberto Exp roberto $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
**
@@ -16,8 +16,9 @@
#define loadlib_c
#define LUA_LIB
#include "lua.h"
#include "lauxlib.h"
#include "lobject.h"
#include "lua.h"
#include "lualib.h"
@@ -236,11 +237,8 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
#define LIB_FAIL "absent"
#if defined(__ELF__) || defined(__sun) || defined(sgi) || defined(__hpux)
#define DLMSG LUA_QL("loadlib") " not enabled; check your Lua installation"
#else
#define DLMSG LUA_QL("loadlib") " not supported"
#endif
#define DLMSG "dynamic libraries not enabled; check your Lua installation"
static void ll_unloadlib (void *lib) {
(void)lib; /* to avoid warnings */
@@ -362,20 +360,23 @@ static const char *findfile (lua_State *L, const char *name,
path = lua_tostring(L, -1);
if (path == NULL)
luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
lua_pushstring(L, ""); /* error accumulator */
while ((path = pushnexttemplate(L, path)) != NULL) {
const char *filename;
filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);
if (readable(filename)) /* does file exist and is readable? */
return filename; /* return that file name */
lua_pop(L, 2); /* remove path template and file name */
luaO_pushfstring(L, "\n\tno file " LUA_QS, filename);
lua_concat(L, 2);
}
return NULL; /* not found */
}
static void loaderror (lua_State *L) {
luaL_error(L, "error loading module " LUA_QS " (%s)",
lua_tostring(L, 1), lua_tostring(L, -1));
static void loaderror (lua_State *L, const char *filename) {
luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s",
lua_tostring(L, 1), filename, lua_tostring(L, -1));
}
@@ -383,9 +384,9 @@ static int loader_Lua (lua_State *L) {
const char *filename;
const char *name = luaL_checkstring(L, 1);
filename = findfile(L, name, "path");
if (filename == NULL) return 0; /* library not found in this path */
if (filename == NULL) return 1; /* library not found in this path */
if (luaL_loadfile(L, filename) != 0)
loaderror(L);
loaderror(L, filename);
return 1; /* library loaded successfully */
}
@@ -405,10 +406,10 @@ static int loader_C (lua_State *L) {
const char *funcname;
const char *name = luaL_checkstring(L, 1);
const char *filename = findfile(L, name, "cpath");
if (filename == NULL) return 0; /* library not found in this path */
if (filename == NULL) return 1; /* library not found in this path */
funcname = mkfuncname(L, name);
if (ll_loadfunc(L, filename, funcname) != 0)
loaderror(L);
loaderror(L, filename);
return 1; /* library loaded successfully */
}
@@ -422,22 +423,26 @@ static int loader_Croot (lua_State *L) {
if (p == NULL) return 0; /* is root */
lua_pushlstring(L, name, p - name);
filename = findfile(L, lua_tostring(L, -1), "cpath");
if (filename == NULL) return 0; /* root not found */
if (filename == NULL) return 1; /* root not found */
funcname = mkfuncname(L, name);
if ((stat = ll_loadfunc(L, filename, funcname)) != 0) {
if (stat == ERRFUNC) return 0; /* function not found */
else
loaderror(L); /* real error */
if (stat != ERRFUNC) loaderror(L, filename); /* real error */
luaO_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
name, filename);
return 1; /* function not found */
}
return 1;
}
static int loader_preload (lua_State *L) {
const char *name = luaL_checkstring(L, 1);
lua_getfield(L, LUA_ENVIRONINDEX, "preload");
if (!lua_istable(L, -1))
luaL_error(L, LUA_QL("package.preload") " must be a table");
lua_getfield(L, -1, luaL_checkstring(L, 1));
lua_getfield(L, -1, name);
if (lua_isnil(L, -1)) /* not found? */
luaO_pushfstring(L, "\n\tno field package.preload['%s']", name);
return 1;
}
@@ -461,14 +466,20 @@ static int ll_require (lua_State *L) {
lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
if (!lua_istable(L, -1))
luaL_error(L, LUA_QL("package.loaders") " must be a table");
lua_pushstring(L, ""); /* error message accumulator */
for (i=1; ; i++) {
lua_rawgeti(L, -1, i); /* get a loader */
lua_rawgeti(L, -2, i); /* get a loader */
if (lua_isnil(L, -1))
luaL_error(L, "module " LUA_QS " not found", name);
luaL_error(L, "module " LUA_QS " not found:%s",
name, lua_tostring(L, -2));
lua_pushstring(L, name);
lua_call(L, 1, 1); /* call it */
if (lua_isnil(L, -1)) lua_pop(L, 1); /* did not found module */
else break; /* module loaded successfully */
if (lua_isfunction(L, -1)) /* did it find module? */
break; /* module loaded successfully */
else if (lua_isstring(L, -1)) /* loader returned error message? */
lua_concat(L, 2); /* accumulate it */
else
lua_pop(L, 1);
}
lua_pushlightuserdata(L, sentinel);
lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
@@ -539,7 +550,7 @@ static int ll_module (lua_State *L) {
if (!lua_istable(L, -1)) { /* not found? */
lua_pop(L, 1); /* remove previous result */
/* try global variable (and create one if it does not exist) */
if (luaL_findtable(L, LUA_GLOBALSINDEX, modname) != NULL)
if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL)
return luaL_error(L, "name conflict for module " LUA_QS, modname);
lua_pushvalue(L, -1);
lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */
@@ -562,7 +573,7 @@ static int ll_module (lua_State *L) {
static int ll_seeall (lua_State *L) {
luaL_checktype(L, 1, LUA_TTABLE);
if (!lua_getmetatable(L, 1)) {
lua_newtable(L); /* create new metatable */
lua_createtable(L, 0, 1); /* create new metatable */
lua_pushvalue(L, -1);
lua_setmetatable(L, 1);
}
@@ -629,7 +640,7 @@ LUALIB_API int luaopen_package (lua_State *L) {
lua_pushvalue(L, -1);
lua_replace(L, LUA_ENVIRONINDEX);
/* create `loaders' table */
lua_newtable(L);
lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1);
/* fill it with pre-defined loaders */
for (i=0; loaders[i] != NULL; i++) {
lua_pushcfunction(L, loaders[i]);
@@ -643,7 +654,7 @@ LUALIB_API int luaopen_package (lua_State *L) {
LUA_EXECDIR "\n" LUA_IGMARK);
lua_setfield(L, -2, "config");
/* set field `loaded' */
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2);
lua_setfield(L, -2, "loaded");
/* set field `preload' */
lua_newtable(L);

View File

@@ -1,5 +1,5 @@
/*
** $Id: lobject.c,v 2.18 2005/08/01 04:22:23 roberto Exp roberto $
** $Id: lobject.c,v 2.21 2006/01/10 12:50:00 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@@ -24,7 +24,7 @@
const TValue luaO_nilobject = {{NULL}, LUA_TNIL};
const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL};
/*
@@ -39,7 +39,7 @@ int luaO_int2fb (unsigned int x) {
e++;
}
if (x < 8) return x;
else return ((e+1) << 3) | (cast(int, x) - 8);
else return ((e+1) << 3) | (cast_int(x) - 8);
}
@@ -91,6 +91,8 @@ int luaO_str2d (const char *s, lua_Number *result) {
char *endptr;
*result = lua_str2number(s, &endptr);
if (endptr == s) return 0; /* conversion failed */
if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */
*result = cast_num(strtoul(s, &endptr, 16));
if (*endptr == '\0') return 1; /* most common case */
while (isspace(cast(unsigned char, *endptr))) endptr++;
if (*endptr != '\0') return 0; /* invalid trailing characters? */
@@ -129,12 +131,12 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
break;
}
case 'd': {
setnvalue(L->top, cast(lua_Number, va_arg(argp, int)));
setnvalue(L->top, cast_num(va_arg(argp, int)));
incr_top(L);
break;
}
case 'f': {
setnvalue(L->top, cast(lua_Number, va_arg(argp, l_uacNumber)));
setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
incr_top(L);
break;
}
@@ -161,7 +163,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
fmt = e+2;
}
pushstr(L, fmt);
luaV_concat(L, n+1, cast(int, L->top - L->base) - 1);
luaV_concat(L, n+1, cast_int(L->top - L->base) - 1);
L->top -= n;
return svalue(L->top - 1);
}

View File

@@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 2.17 2005/06/13 14:19:00 roberto Exp roberto $
** $Id: lobject.h,v 2.19 2006/01/10 12:51:53 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@@ -119,9 +119,6 @@ typedef struct lua_TValue {
#define setnvalue(obj,x) \
{ TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; }
#define chgnvalue(obj,x) \
check_exp(ttype(obj)==LUA_TNUMBER, (obj)->value.n=(x))
#define setpvalue(obj,x) \
{ TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; }
@@ -323,9 +320,12 @@ typedef union Closure {
** Tables
*/
typedef struct TKey {
TValuefields;
struct Node *next; /* for chaining */
typedef union TKey {
struct {
TValuefields;
struct Node *next; /* for chaining */
} nk;
TValue tvk;
} TKey;
@@ -360,8 +360,9 @@ typedef struct Table {
#define sizenode(t) (twoto((t)->lsizenode))
#define luaO_nilobject (&luaO_nilobject_)
LUAI_DATA const TValue luaO_nilobject;
LUAI_DATA const TValue luaO_nilobject_;
#define ceillog2(x) (luaO_log2((x)-1) + 1)

View File

@@ -1,5 +1,5 @@
/*
** $Id: lopcodes.h,v 1.122 2005/08/29 20:49:21 roberto Exp roberto $
** $Id: lopcodes.h,v 1.123 2005/10/23 17:37:55 roberto Exp roberto $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -208,7 +208,7 @@ OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */
} OpCode;
#define NUM_OPCODES (cast(int, OP_VARARG+1))
#define NUM_OPCODES (cast(int, OP_VARARG) + 1)

View File

@@ -1,5 +1,5 @@
/*
** $Id: loslib.c,v 1.13 2005/09/09 18:22:46 roberto Exp roberto $
** $Id: loslib.c,v 1.16 2005/12/22 16:19:56 roberto Exp roberto $
** Standard Operating System library
** See Copyright Notice in lua.h
*/
@@ -21,6 +21,7 @@
static int os_pushresult (lua_State *L, int i, const char *filename) {
int en = errno; /* calls to Lua API may change this value */
if (i) {
lua_pushboolean(L, 1);
return 1;
@@ -28,35 +29,35 @@ static int os_pushresult (lua_State *L, int i, const char *filename) {
else {
lua_pushnil(L);
if (filename)
lua_pushfstring(L, "%s: %s", filename, strerror(errno));
lua_pushfstring(L, "%s: %s", filename, strerror(en));
else
lua_pushfstring(L, "%s", strerror(errno));
lua_pushinteger(L, errno);
lua_pushfstring(L, "%s", strerror(en));
lua_pushinteger(L, en);
return 3;
}
}
static int io_execute (lua_State *L) {
static int os_execute (lua_State *L) {
lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
return 1;
}
static int io_remove (lua_State *L) {
static int os_remove (lua_State *L) {
const char *filename = luaL_checkstring(L, 1);
return os_pushresult(L, remove(filename) == 0, filename);
}
static int io_rename (lua_State *L) {
static int os_rename (lua_State *L) {
const char *fromname = luaL_checkstring(L, 1);
const char *toname = luaL_checkstring(L, 2);
return os_pushresult(L, rename(fromname, toname) == 0, fromname);
}
static int io_tmpname (lua_State *L) {
static int os_tmpname (lua_State *L) {
char buff[LUA_TMPNAMBUFSIZE];
int err;
lua_tmpnam(buff, err);
@@ -67,13 +68,13 @@ static int io_tmpname (lua_State *L) {
}
static int io_getenv (lua_State *L) {
static int os_getenv (lua_State *L) {
lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */
return 1;
}
static int io_clock (lua_State *L) {
static int os_clock (lua_State *L) {
lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);
return 1;
}
@@ -123,7 +124,7 @@ static int getfield (lua_State *L, const char *key, int d) {
}
static int io_date (lua_State *L) {
static int os_date (lua_State *L) {
const char *s = luaL_optstring(L, 1, "%c");
time_t t = lua_isnoneornil(L, 2) ? time(NULL) :
(time_t)luaL_checknumber(L, 2);
@@ -159,7 +160,7 @@ static int io_date (lua_State *L) {
}
static int io_time (lua_State *L) {
static int os_time (lua_State *L) {
time_t t;
if (lua_isnoneornil(L, 1)) /* called without args? */
t = time(NULL); /* get current time */
@@ -179,12 +180,12 @@ static int io_time (lua_State *L) {
if (t == (time_t)(-1))
lua_pushnil(L);
else
lua_pushnumber(L, t);
lua_pushnumber(L, (lua_Number)t);
return 1;
}
static int io_difftime (lua_State *L) {
static int os_difftime (lua_State *L) {
lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),
(time_t)(luaL_optnumber(L, 2, 0))));
return 1;
@@ -193,7 +194,7 @@ static int io_difftime (lua_State *L) {
/* }====================================================== */
static int io_setloc (lua_State *L) {
static int os_setlocale (lua_State *L) {
static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
LC_NUMERIC, LC_TIME};
static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
@@ -206,23 +207,23 @@ static int io_setloc (lua_State *L) {
}
static int io_exit (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[] = {
{"clock", io_clock},
{"date", io_date},
{"difftime", io_difftime},
{"execute", io_execute},
{"exit", io_exit},
{"getenv", io_getenv},
{"remove", io_remove},
{"rename", io_rename},
{"setlocale", io_setloc},
{"time", io_time},
{"tmpname", io_tmpname},
{"clock", os_clock},
{"date", os_date},
{"difftime", os_difftime},
{"execute", os_execute},
{"exit", os_exit},
{"getenv", os_getenv},
{"remove", os_remove},
{"rename", os_rename},
{"setlocale", os_setlocale},
{"time", os_time},
{"tmpname", os_tmpname},
{NULL, NULL}
};

View File

@@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 2.37 2005/10/03 14:02:40 roberto Exp roberto $
** $Id: lparser.c,v 2.39 2005/12/07 15:43:05 roberto Exp roberto $
** Lua Parser
** See Copyright Notice in lua.h
*/
@@ -54,24 +54,6 @@ static void chunk (LexState *ls);
static void expr (LexState *ls, expdesc *v);
static void next (LexState *ls) {
ls->lastline = ls->linenumber;
if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
ls->t = ls->lookahead; /* use this one */
ls->lookahead.token = TK_EOS; /* and discharge it */
}
else
ls->t.token = luaX_lex(ls, &ls->t.seminfo); /* read next token */
}
static void lookahead (LexState *ls) {
lua_assert(ls->lookahead.token == TK_EOS);
ls->lookahead.token = luaX_lex(ls, &ls->lookahead.seminfo);
}
static void anchor_token (LexState *ls) {
if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {
TString *ts = ls->t.seminfo.ts;
@@ -97,7 +79,7 @@ static void errorlimit (FuncState *fs, int limit, const char *what) {
static int testnext (LexState *ls, int c) {
if (ls->t.token == c) {
next(ls);
luaX_next(ls);
return 1;
}
else return 0;
@@ -111,7 +93,7 @@ static void check (LexState *ls, int c) {
static void checknext (LexState *ls, int c) {
check(ls, c);
next(ls);
luaX_next(ls);
}
@@ -136,7 +118,7 @@ static TString *str_checkname (LexState *ls) {
TString *ts;
check(ls, TK_NAME);
ts = ls->t.seminfo.ts;
next(ls);
luaX_next(ls);
return ts;
}
@@ -184,7 +166,7 @@ static void new_localvar (LexState *ls, TString *name, int n) {
static void adjustlocalvars (LexState *ls, int nvars) {
FuncState *fs = ls->fs;
fs->nactvar = cast(lu_byte, fs->nactvar + nvars);
fs->nactvar = cast_byte(fs->nactvar + nvars);
for (; nvars; nvars--) {
getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;
}
@@ -216,8 +198,8 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) {
f->upvalues[f->nups] = name;
luaC_objbarrier(fs->L, f, name);
lua_assert(v->k == VLOCAL || v->k == VUPVAL);
fs->upvalues[f->nups].k = cast(lu_byte, v->k);
fs->upvalues[f->nups].info = cast(lu_byte, v->u.s.info);
fs->upvalues[f->nups].k = cast_byte(v->k);
fs->upvalues[f->nups].info = cast_byte(v->u.s.info);
return f->nups++;
}
@@ -404,7 +386,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
luaX_setinput(L, &lexstate, z, luaS_new(L, name));
open_func(&lexstate, &funcstate);
funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */
next(&lexstate); /* read first token */
luaX_next(&lexstate); /* read first token */
chunk(&lexstate);
check(&lexstate, TK_EOS);
close_func(&lexstate);
@@ -426,7 +408,7 @@ static void field (LexState *ls, expdesc *v) {
FuncState *fs = ls->fs;
expdesc key;
luaK_exp2anyreg(fs, v);
next(ls); /* skip the dot or colon */
luaX_next(ls); /* skip the dot or colon */
checkname(ls, &key);
luaK_indexed(fs, v, &key);
}
@@ -434,7 +416,7 @@ static void field (LexState *ls, expdesc *v) {
static void yindex (LexState *ls, expdesc *v) {
/* index -> '[' expr ']' */
next(ls); /* skip the '[' */
luaX_next(ls); /* skip the '[' */
expr(ls, v);
luaK_exp2val(ls->fs, v);
checknext(ls, ']');
@@ -530,7 +512,7 @@ static void constructor (LexState *ls, expdesc *t) {
closelistfield(fs, &cc);
switch(ls->t.token) {
case TK_NAME: { /* may be listfields or recfields */
lookahead(ls);
luaX_lookahead(ls);
if (ls->lookahead.token != '=') /* expression? */
listfield(ls, &cc);
else
@@ -571,7 +553,7 @@ static void parlist (LexState *ls) {
break;
}
case TK_DOTS: { /* param -> `...' */
next(ls);
luaX_next(ls);
#if defined(LUA_COMPAT_VARARG)
/* use `arg' as default name */
new_localvarliteral(ls, "arg", nparams++);
@@ -585,7 +567,7 @@ static void parlist (LexState *ls) {
} while (!f->is_vararg && testnext(ls, ','));
}
adjustlocalvars(ls, nparams);
f->numparams = fs->nactvar - (f->is_vararg & VARARG_HASARG);
f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG));
luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
}
@@ -632,7 +614,7 @@ static void funcargs (LexState *ls, expdesc *f) {
case '(': { /* funcargs -> `(' [ explist1 ] `)' */
if (line != ls->lastline)
luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)");
next(ls);
luaX_next(ls);
if (ls->t.token == ')') /* arg list is empty? */
args.k = VVOID;
else {
@@ -648,7 +630,7 @@ static void funcargs (LexState *ls, expdesc *f) {
}
case TK_STRING: { /* funcargs -> STRING */
codestring(ls, &args, ls->t.seminfo.ts);
next(ls); /* must use `seminfo' before `next' */
luaX_next(ls); /* must use `seminfo' before `next' */
break;
}
default: {
@@ -686,7 +668,7 @@ static void prefixexp (LexState *ls, expdesc *v) {
switch (ls->t.token) {
case '(': {
int line = ls->linenumber;
next(ls);
luaX_next(ls);
expr(ls, v);
check_match(ls, ')', '(', line);
luaK_dischargevars(ls->fs, v);
@@ -724,7 +706,7 @@ static void primaryexp (LexState *ls, expdesc *v) {
}
case ':': { /* `:' NAME funcargs */
expdesc key;
next(ls);
luaX_next(ls);
checkname(ls, &key);
luaK_self(fs, v, &key);
funcargs(ls, v);
@@ -779,7 +761,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
return;
}
case TK_FUNCTION: {
next(ls);
luaX_next(ls);
body(ls, v, 0, ls->linenumber);
return;
}
@@ -788,7 +770,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
return;
}
}
next(ls);
luaX_next(ls);
}
@@ -848,7 +830,7 @@ static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) {
enterlevel(ls);
uop = getunopr(ls->t.token);
if (uop != OPR_NOUNOPR) {
next(ls);
luaX_next(ls);
subexpr(ls, v, UNARY_PRIORITY);
luaK_prefix(ls->fs, uop, v);
}
@@ -858,7 +840,7 @@ static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) {
while (op != OPR_NOBINOPR && priority[op].left > limit) {
expdesc v2;
BinOpr nextop;
next(ls);
luaX_next(ls);
luaK_infix(ls->fs, op, v);
/* read sub-expression with higher priority */
nextop = subexpr(ls, &v2, priority[op].right);
@@ -1009,7 +991,7 @@ static void whilestat (LexState *ls, int line) {
int whileinit;
int condexit;
BlockCnt bl;
next(ls); /* skip WHILE */
luaX_next(ls); /* skip WHILE */
whileinit = luaK_getlabel(fs);
condexit = cond(ls);
enterblock(fs, &bl, 1);
@@ -1030,7 +1012,7 @@ static void repeatstat (LexState *ls, int line) {
BlockCnt bl1, bl2;
enterblock(fs, &bl1, 1); /* loop block */
enterblock(fs, &bl2, 0); /* scope block */
next(ls); /* skip REPEAT */
luaX_next(ls); /* skip REPEAT */
chunk(ls);
check_match(ls, TK_UNTIL, TK_REPEAT, line);
condexit = cond(ls); /* read condition (inside scope block) */
@@ -1130,7 +1112,7 @@ static void forstat (LexState *ls, int line) {
TString *varname;
BlockCnt bl;
enterblock(fs, &bl, 1); /* scope for loop and control variables */
next(ls); /* skip `for' */
luaX_next(ls); /* skip `for' */
varname = str_checkname(ls); /* first variable name */
switch (ls->t.token) {
case '=': fornum(ls, varname, line); break;
@@ -1145,7 +1127,7 @@ static void forstat (LexState *ls, int line) {
static int test_then_block (LexState *ls) {
/* test_then_block -> [IF | ELSEIF] cond THEN block */
int condexit;
next(ls); /* skip IF or ELSEIF */
luaX_next(ls); /* skip IF or ELSEIF */
condexit = cond(ls);
checknext(ls, TK_THEN);
block(ls); /* `then' part */
@@ -1167,7 +1149,7 @@ static void ifstat (LexState *ls, int line) {
if (ls->t.token == TK_ELSE) {
luaK_concat(fs, &escapelist, luaK_jump(fs));
luaK_patchtohere(fs, flist);
next(ls); /* skip ELSE (after patch, for correct line info) */
luaX_next(ls); /* skip ELSE (after patch, for correct line info) */
block(ls); /* `else' part */
}
else
@@ -1228,7 +1210,7 @@ static void funcstat (LexState *ls, int line) {
/* funcstat -> FUNCTION funcname body */
int needself;
expdesc v, b;
next(ls); /* skip FUNCTION */
luaX_next(ls); /* skip FUNCTION */
needself = funcname(ls, &v);
body(ls, &b, needself, line);
luaK_storevar(ls->fs, &v, &b);
@@ -1255,7 +1237,7 @@ static void retstat (LexState *ls) {
FuncState *fs = ls->fs;
expdesc e;
int first, nret; /* registers with returned values */
next(ls); /* skip RETURN */
luaX_next(ls); /* skip RETURN */
if (block_follow(ls->t.token) || ls->t.token == ';')
first = nret = 0; /* return no values */
else {
@@ -1295,7 +1277,7 @@ static int statement (LexState *ls) {
return 0;
}
case TK_DO: { /* stat -> DO block END */
next(ls); /* skip DO */
luaX_next(ls); /* skip DO */
block(ls);
check_match(ls, TK_END, TK_DO, line);
return 0;
@@ -1313,7 +1295,7 @@ static int statement (LexState *ls) {
return 0;
}
case TK_LOCAL: { /* stat -> localstat */
next(ls); /* skip LOCAL */
luaX_next(ls); /* skip LOCAL */
if (testnext(ls, TK_FUNCTION)) /* local function? */
localfunc(ls);
else
@@ -1325,7 +1307,7 @@ static int statement (LexState *ls) {
return 1; /* must be last statement */
}
case TK_BREAK: { /* stat -> breakstat */
next(ls); /* skip BREAK */
luaX_next(ls); /* skip BREAK */
breakstat(ls);
return 1; /* must be last statement */
}

View File

@@ -1,5 +1,5 @@
/*
** $Id: lstate.h,v 2.22 2005/06/03 20:15:58 roberto Exp roberto $
** $Id: lstate.h,v 2.23 2005/07/09 13:22:34 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@@ -49,8 +49,8 @@ typedef struct CallInfo {
StkId base; /* base for this function */
StkId func; /* function index in the stack */
StkId top; /* top for this function */
int nresults; /* expected number of results from this function */
const Instruction *savedpc;
int nresults; /* expected number of results from this function */
int tailcalls; /* number of tail calls lost under this entry */
} CallInfo;
@@ -71,9 +71,9 @@ typedef struct global_State {
void *ud; /* auxiliary data to `frealloc' */
lu_byte currentwhite;
lu_byte gcstate; /* state of garbage collector */
int sweepstrgc; /* position of sweep in `strt' */
GCObject *rootgc; /* list of all collectable objects */
GCObject **sweepgc; /* position of sweep in `rootgc' */
int sweepstrgc; /* position of sweep in `strt' */
GCObject *gray; /* list of gray objects */
GCObject *grayagain; /* list of objects to be traversed atomically */
GCObject *weak; /* list of weak tables (to be cleared) */
@@ -99,6 +99,7 @@ typedef struct global_State {
*/
struct lua_State {
CommonHeader;
lu_byte status;
StkId top; /* first free slot in the stack */
StkId base; /* base of current function */
global_State *l_G;
@@ -106,14 +107,13 @@ struct lua_State {
const Instruction *savedpc; /* `savedpc' of current function */
StkId stack_last; /* last free slot in the stack */
StkId stack; /* stack base */
int stacksize;
CallInfo *end_ci; /* points after end of ci array*/
CallInfo *base_ci; /* array of CallInfo's */
int stacksize;
int size_ci; /* size of array `base_ci' */
unsigned short nCcalls; /* number of nested C calls */
lu_byte hookmask;
lu_byte allowhook;
lu_byte status;
int basehookcount;
int hookcount;
lua_Hook hook;

View File

@@ -1,5 +1,5 @@
/*
** $Id: lstring.c,v 2.6 2005/01/18 17:18:09 roberto Exp roberto $
** $Id: lstring.c,v 2.7 2005/02/18 12:40:02 roberto Exp roberto $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@@ -35,7 +35,7 @@ void luaS_resize (lua_State *L, int newsize) {
GCObject *next = p->gch.next; /* save next */
unsigned int h = gco2ts(p)->hash;
int h1 = lmod(h, newsize); /* new position */
lua_assert(cast(int, h%newsize) == lmod(h, newsize));
lua_assert(cast_int(h%newsize) == lmod(h, newsize));
p->gch.next = newhash[h1]; /* chain it */
newhash[h1] = p;
p = next;

View File

@@ -1,5 +1,5 @@
/*
** $Id: lstrlib.c,v 1.126 2005/10/23 17:46:30 roberto Exp roberto $
** $Id: lstrlib.c,v 1.129 2005/12/21 12:59:43 roberto Exp roberto $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@@ -683,8 +683,13 @@ static int str_gsub (lua_State *L) {
/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
#define MAX_ITEM 512
/* maximum size of each format specification (such as '%-099.99d') */
#define MAX_FORMAT 20
/* valid flags in a format specification */
#define FLAGS "-+ #0"
/*
** maximum size of each format specification (such as '%-099.99d')
** (+10 accounts for %99.99x plus margin of error)
*/
#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
@@ -712,30 +717,37 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
luaL_addchar(b, '"');
}
static const char *scanformat (lua_State *L, const char *strfrmt,
char *form, int *hasprecision) {
static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
const char *p = strfrmt;
while (strchr("-+ #0", *p)) p++; /* skip flags */
while (strchr(FLAGS, *p)) p++; /* skip flags */
if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
luaL_error(L, "invalid format (repeated flags)");
if (isdigit(uchar(*p))) p++; /* skip width */
if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
if (*p == '.') {
p++;
*hasprecision = 1;
if (isdigit(uchar(*p))) p++; /* skip precision */
if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
}
if (isdigit(uchar(*p)))
luaL_error(L, "invalid format (width or precision too long)");
if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */
luaL_error(L, "invalid format (too long)");
form[0] = L_ESC;
strncpy(form+1, strfrmt, p-strfrmt+1);
form[p-strfrmt+2] = 0;
*(form++) = '%';
strncpy(form, strfrmt, p - strfrmt + 1);
form += p - strfrmt + 1;
*form = '\0';
return p;
}
static void addintlen (char *form) {
size_t l = strlen(form);
char spec = form[l - 1];
strcpy(form + l - 1, LUA_INTFRMLEN);
form[l + sizeof(LUA_INTFRMLEN) - 2] = spec;
form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0';
}
static int str_format (lua_State *L) {
int arg = 1;
size_t sfl;
@@ -751,21 +763,26 @@ static int str_format (lua_State *L) {
else { /* format item */
char form[MAX_FORMAT]; /* to store the format (`%...') */
char buff[MAX_ITEM]; /* to store the formatted item */
int hasprecision = 0;
arg++;
strfrmt = scanformat(L, strfrmt, form, &hasprecision);
strfrmt = scanformat(L, strfrmt, form);
switch (*strfrmt++) {
case 'c': case 'd': case 'i': {
sprintf(buff, form, luaL_checkint(L, arg));
case 'c': {
sprintf(buff, form, (int)luaL_checknumber(L, arg));
break;
}
case 'd': case 'i': {
addintlen(form);
sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
break;
}
case 'o': case 'u': case 'x': case 'X': {
sprintf(buff, form, (unsigned int)(luaL_checknumber(L, arg)));
addintlen(form);
sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
break;
}
case 'e': case 'E': case 'f':
case 'g': case 'G': {
sprintf(buff, form, luaL_checknumber(L, arg));
sprintf(buff, form, (double)luaL_checknumber(L, arg));
break;
}
case 'q': {
@@ -775,7 +792,7 @@ static int str_format (lua_State *L) {
case 's': {
size_t l;
const char *s = luaL_checklstring(L, arg, &l);
if (!hasprecision && l >= 100) {
if (!strchr(form, '.') && l >= 100) {
/* no precision and string is too long to be formatted;
keep original string */
lua_pushvalue(L, arg);
@@ -820,7 +837,7 @@ static const luaL_Reg strlib[] = {
static void createmetatable (lua_State *L) {
lua_newtable(L); /* create metatable for strings */
lua_createtable(L, 0, 1); /* create metatable for strings */
lua_pushliteral(L, ""); /* dummy string */
lua_pushvalue(L, -2);
lua_setmetatable(L, -2); /* set string metatable */

View File

@@ -1,5 +1,5 @@
/*
** $Id: ltable.c,v 2.26 2005/07/11 14:01:37 roberto Exp roberto $
** $Id: ltable.c,v 2.31 2006/01/10 13:13:06 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -66,13 +66,15 @@
/*
** number of ints inside a lua_Number
*/
#define numints cast(int, sizeof(lua_Number)/sizeof(int))
#define numints cast_int(sizeof(lua_Number)/sizeof(int))
const Node luaH_dummynode = {
#define dummynode (&dummynode_)
static const Node dummynode_ = {
{{NULL}, LUA_TNIL}, /* value */
{{NULL}, LUA_TNIL, NULL} /* key */
{{{NULL}, LUA_TNIL, NULL}} /* key */
};
@@ -95,7 +97,7 @@ static Node *hashnum (const Table *t, lua_Number n) {
** returns the `main' position of an element in a table (that is, the index
** of its hash value)
*/
Node *luaH_mainposition (const Table *t, const TValue *key) {
static Node *mainposition (const Table *t, const TValue *key) {
switch (ttype(key)) {
case LUA_TNUMBER:
return hashnum(t, nvalue(key));
@@ -120,7 +122,7 @@ static int arrayindex (const TValue *key) {
lua_Number n = nvalue(key);
int k;
lua_number2int(k, n);
if (luai_numeq(cast(lua_Number, k), nvalue(key)))
if (luai_numeq(cast_num(k), n))
return k;
}
return -1; /* `key' did not match some condition */
@@ -139,13 +141,13 @@ static int findindex (lua_State *L, Table *t, StkId key) {
if (0 < i && i <= t->sizearray) /* is `key' inside array part? */
return i-1; /* yes; that's the index (corrected to C) */
else {
Node *n = luaH_mainposition(t, key);
Node *n = mainposition(t, key);
do { /* check whether `key' is somewhere in the chain */
/* key may be dead already, but it is ok to use it in `next' */
if (luaO_rawequalObj(key2tval(n), key) ||
(ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&
gcvalue(gkey(n)) == gcvalue(key))) {
i = cast(int, n - gnode(t, 0)); /* key index in hash table */
i = cast_int(n - gnode(t, 0)); /* key index in hash table */
/* hash elements are numbered after array ones */
return i + t->sizearray;
}
@@ -161,7 +163,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) {
int i = findindex(L, t, key); /* find original element */
for (i++; i < t->sizearray; i++) { /* try first array part */
if (!ttisnil(&t->array[i])) { /* a non-nil value? */
setnvalue(key, cast(lua_Number, i+1));
setnvalue(key, cast_num(i+1));
setobj2s(L, key+1, &t->array[i]);
return 1;
}
@@ -270,7 +272,7 @@ static void setarrayvector (lua_State *L, Table *t, int size) {
static void setnodevector (lua_State *L, Table *t, int size) {
int lsize;
if (size == 0) { /* no elements to hash part? */
t->node = cast(Node *, &luaH_dummynode); /* use common `dummynode' */
t->node = cast(Node *, dummynode); /* use common `dummynode' */
lsize = 0;
}
else {
@@ -281,12 +283,13 @@ static void setnodevector (lua_State *L, Table *t, int size) {
size = twoto(lsize);
t->node = luaM_newvector(L, size, Node);
for (i=0; i<size; i++) {
gnext(&t->node[i]) = NULL;
setnilvalue(gkey(gnode(t, i)));
setnilvalue(gval(gnode(t, i)));
Node *n = gnode(t, i);
gnext(n) = NULL;
setnilvalue(gkey(n));
setnilvalue(gval(n));
}
}
t->lsizenode = cast(lu_byte, lsize);
t->lsizenode = cast_byte(lsize);
t->lastfree = gnode(t, size); /* all positions are free */
}
@@ -316,13 +319,13 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
if (!ttisnil(gval(old)))
setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old));
}
if (nold != &luaH_dummynode)
if (nold != dummynode)
luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */
}
void luaH_resizearray (lua_State *L, Table *t, int nasize) {
int nsize = (t->node == &luaH_dummynode) ? 0 : sizenode(t);
int nsize = (t->node == dummynode) ? 0 : sizenode(t);
resize(L, t, nasize, nsize);
}
@@ -356,12 +359,12 @@ Table *luaH_new (lua_State *L, int narray, int nhash) {
Table *t = luaM_new(L, Table);
luaC_link(L, obj2gco(t), LUA_TTABLE);
t->metatable = NULL;
t->flags = cast(lu_byte, ~0);
t->flags = cast_byte(~0);
/* temporary values (kept only if some malloc fails) */
t->array = NULL;
t->sizearray = 0;
t->lsizenode = 0;
t->node = cast(Node *, &luaH_dummynode);
t->node = cast(Node *, dummynode);
setarrayvector(L, t, narray);
setnodevector(L, t, nhash);
return t;
@@ -369,7 +372,7 @@ Table *luaH_new (lua_State *L, int narray, int nhash) {
void luaH_free (lua_State *L, Table *t) {
if (t->node != &luaH_dummynode)
if (t->node != dummynode)
luaM_freearray(L, t->node, sizenode(t), Node);
luaM_freearray(L, t->array, t->sizearray, TValue);
luaM_free(L, t);
@@ -394,16 +397,16 @@ static Node *getfreepos (Table *t) {
** position), new key goes to an empty position.
*/
static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
Node *mp = luaH_mainposition(t, key);
if (!ttisnil(gval(mp)) || mp == &luaH_dummynode) {
Node *mp = mainposition(t, key);
if (!ttisnil(gval(mp)) || mp == dummynode) {
Node *othern;
Node *n = getfreepos(t); /* get a free place */
if (n == NULL) { /* cannot find a free place? */
rehash(L, t, key); /* grow table */
return luaH_set(L, t, key); /* re-insert key into grown table */
}
lua_assert(n != &luaH_dummynode);
othern = luaH_mainposition(t, key2tval(mp));
lua_assert(n != dummynode);
othern = mainposition(t, key2tval(mp));
if (othern != mp) { /* is colliding node out of its main position? */
/* yes; move colliding node into free position */
while (gnext(othern) != mp) othern = gnext(othern); /* find previous */
@@ -434,14 +437,14 @@ const TValue *luaH_getnum (Table *t, int key) {
if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
return &t->array[key-1];
else {
lua_Number nk = cast(lua_Number, key);
lua_Number nk = cast_num(key);
Node *n = hashnum(t, nk);
do { /* check whether `key' is somewhere in the chain */
if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
return gval(n); /* that's it */
else n = gnext(n);
} while (n);
return &luaO_nilobject;
return luaO_nilobject;
}
}
@@ -456,7 +459,7 @@ const TValue *luaH_getstr (Table *t, TString *key) {
return gval(n); /* that's it */
else n = gnext(n);
} while (n);
return &luaO_nilobject;
return luaO_nilobject;
}
@@ -465,24 +468,24 @@ const TValue *luaH_getstr (Table *t, TString *key) {
*/
const TValue *luaH_get (Table *t, const TValue *key) {
switch (ttype(key)) {
case LUA_TNIL: return &luaO_nilobject;
case LUA_TNIL: return luaO_nilobject;
case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));
case LUA_TNUMBER: {
int k;
lua_Number n = nvalue(key);
lua_number2int(k, n);
if (luai_numeq(cast(lua_Number, k), nvalue(key))) /* index is int? */
if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */
return luaH_getnum(t, k); /* use specialized version */
/* else go through */
}
default: {
Node *n = luaH_mainposition(t, key);
Node *n = mainposition(t, key);
do { /* check whether `key' is somewhere in the chain */
if (luaO_rawequalObj(key2tval(n), key))
return gval(n); /* that's it */
else n = gnext(n);
} while (n);
return &luaO_nilobject;
return luaO_nilobject;
}
}
}
@@ -491,11 +494,11 @@ const TValue *luaH_get (Table *t, const TValue *key) {
TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
const TValue *p = luaH_get(t, key);
t->flags = 0;
if (p != &luaO_nilobject)
if (p != luaO_nilobject)
return cast(TValue *, p);
else {
if (ttisnil(key)) luaG_runerror(L, "table index is nil");
else if (ttisnumber(key) && !luai_numeq(nvalue(key), nvalue(key)))
else if (ttisnumber(key) && luai_numisnan(nvalue(key)))
luaG_runerror(L, "table index is NaN");
return newkey(L, t, key);
}
@@ -504,11 +507,11 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
TValue *luaH_setnum (lua_State *L, Table *t, int key) {
const TValue *p = luaH_getnum(t, key);
if (p != &luaO_nilobject)
if (p != luaO_nilobject)
return cast(TValue *, p);
else {
TValue k;
setnvalue(&k, cast(lua_Number, key));
setnvalue(&k, cast_num(key));
return newkey(L, t, &k);
}
}
@@ -516,7 +519,7 @@ TValue *luaH_setnum (lua_State *L, Table *t, int key) {
TValue *luaH_setstr (lua_State *L, Table *t, TString *key) {
const TValue *p = luaH_getstr(t, key);
if (p != &luaO_nilobject)
if (p != luaO_nilobject)
return cast(TValue *, p);
else {
TValue k;
@@ -528,11 +531,11 @@ TValue *luaH_setstr (lua_State *L, Table *t, TString *key) {
static int unbound_search (Table *t, unsigned int j) {
unsigned int i = j; /* i is zero or a present index */
j = j+1;
j++;
/* find `i' and `j' such that i is present and j is not */
while (!ttisnil(luaH_getnum(t, j))) {
i = j;
j = i*2;
j *= 2;
if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
/* table was built with bad purposes: resort to linear search */
i = 1;
@@ -541,7 +544,7 @@ static int unbound_search (Table *t, unsigned int j) {
}
}
/* now do a binary search between them */
while (i < j-1) {
while (j - i > 1) {
unsigned int m = (i+j)/2;
if (ttisnil(luaH_getnum(t, m))) j = m;
else i = m;
@@ -567,8 +570,19 @@ int luaH_getn (Table *t) {
return i;
}
/* else must find a boundary in hash part */
else if (t->node == &luaH_dummynode) /* hash part is empty? */
else if (t->node == dummynode) /* hash part is empty? */
return j; /* that is easy... */
else return unbound_search(t, j);
}
#if defined(LUA_DEBUG)
Node *luaH_mainposition (const Table *t, const TValue *key) {
return mainposition(t, key);
}
int luaH_isdummy (Node *n) { return n == dummynode; }
#endif

View File

@@ -1,5 +1,5 @@
/*
** $Id: ltable.h,v 2.7 2005/04/25 19:24:10 roberto Exp roberto $
** $Id: ltable.h,v 2.9 2006/01/10 12:51:53 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -11,15 +11,13 @@
#define gnode(t,i) (&(t)->node[i])
#define gkey(n) (&(n)->i_key)
#define gkey(n) (&(n)->i_key.nk)
#define gval(n) (&(n)->i_val)
#define gnext(n) ((n)->i_key.next)
#define gnext(n) ((n)->i_key.nk.next)
#define key2tval(n) (cast(const TValue *, gkey(n)))
#define key2tval(n) (&(n)->i_key.tvk)
LUAI_DATA const Node luaH_dummynode;
LUAI_FUNC const TValue *luaH_getnum (Table *t, int key);
LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key);
LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
@@ -32,8 +30,11 @@ LUAI_FUNC void luaH_free (lua_State *L, Table *t);
LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
LUAI_FUNC int luaH_getn (Table *t);
/* exported only for debugging */
#if defined(LUA_DEBUG)
LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
LUAI_FUNC int luaH_isdummy (Node *n);
#endif
#endif

View File

@@ -1,5 +1,5 @@
/*
** $Id: ltests.c,v 2.32 2005/09/20 17:55:10 roberto Exp roberto $
** $Id: ltests.c,v 2.35 2006/01/10 12:50:00 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@@ -564,7 +564,7 @@ static int table_query (lua_State *L) {
t = hvalue(obj_at(L, 1));
if (i == -1) {
lua_pushinteger(L, t->sizearray);
lua_pushinteger(L, t->node == &luaH_dummynode ? 0 : sizenode(t));
lua_pushinteger(L, luaH_isdummy(t->node) ? 0 : sizenode(t));
lua_pushinteger(L, t->lastfree - t->node);
}
else if (i < t->sizearray) {
@@ -798,7 +798,7 @@ static int getnum_aux (lua_State *L, const char **pc) {
int sig = 1;
skip(pc);
if (**pc == '.') {
res = cast(int, lua_tonumber(L, -1));
res = cast_int(lua_tonumber(L, -1));
lua_pop(L, 1);
(*pc)++;
return res;
@@ -807,7 +807,7 @@ static int getnum_aux (lua_State *L, const char **pc) {
sig = -1;
(*pc)++;
}
while (isdigit(cast(int, **pc))) res = res*10 + (*(*pc)++) - '0';
while (isdigit(cast_int(**pc))) res = res*10 + (*(*pc)++) - '0';
return sig*res;
}
@@ -994,7 +994,7 @@ static int testC (lua_State *L) {
#ifndef luaL_setn
else if EQ("setn") {
int i = getindex;
int n = cast(int, lua_tonumber(L1, -1));
int n = cast_int(lua_tonumber(L1, -1));
luaL_setn(L1, i, n);
lua_pop(L1, 1);
}

View File

@@ -1,5 +1,5 @@
/*
** $Id: ltests.h,v 2.15 2005/06/06 13:30:25 roberto Exp roberto $
** $Id: ltests.h,v 2.16 2005/09/14 17:48:57 roberto Exp roberto $
** Internal Header for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@@ -15,7 +15,6 @@
#undef NDEBUG
#include <assert.h>
#undef lua_assert
#define lua_assert(c) assert(c)

6
ltm.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: ltm.c,v 2.5 2005/05/05 15:34:03 roberto Exp roberto $
** $Id: ltm.c,v 2.7 2005/12/22 16:19:56 roberto Exp roberto $
** Tag methods
** See Copyright Notice in lua.h
*/
@@ -51,7 +51,7 @@ const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
const TValue *tm = luaH_getstr(events, ename);
lua_assert(event <= TM_EQ);
if (ttisnil(tm)) { /* no tag method? */
events->flags |= cast(lu_byte, 1u<<event); /* cache this fact */
events->flags |= cast_byte(1u<<event); /* cache this fact */
return NULL;
}
else return tm;
@@ -70,6 +70,6 @@ const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
default:
mt = G(L)->mt[ttype(o)];
}
return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : &luaO_nilobject);
return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
}

14
lua.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lua.c,v 1.153 2005/10/21 13:48:31 roberto Exp roberto $
** $Id: lua.c,v 1.156 2005/12/29 12:30:16 roberto Exp roberto $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@@ -120,7 +120,7 @@ static int getargs (lua_State *L, char **argv, int n) {
luaL_checkstack(L, narg + 3, "too many arguments to script");
for (i=n+1; i < argc; i++)
lua_pushstring(L, argv[i]);
lua_newtable(L);
lua_createtable(L, narg, n + 1);
for (i=0; i < argc; i++) {
lua_pushstring(L, argv[i]);
lua_rawseti(L, -2, i - n);
@@ -215,7 +215,6 @@ static void dotty (lua_State *L) {
int status;
const char *oldprogname = progname;
progname = NULL;
print_version();
while ((status = loadline(L)) != -1) {
if (status == 0) status = docall(L, 0, 0);
report(L, status);
@@ -261,7 +260,7 @@ static int collectargs (char **argv, int *pi, int *pv, int *pe) {
switch (argv[i][1]) { /* option */
case '-': return (argv[i+1] != NULL ? i+1 : 0);
case '\0': return i;
case 'i': *pi = 1; break;
case 'i': *pi = 1; /* go through */
case 'v': *pv = 1; break;
case 'e': *pe = 1; /* go through */
case 'l':
@@ -330,7 +329,9 @@ static int pmain (lua_State *L) {
int has_i = 0, has_v = 0, has_e = 0;
globalL = L;
if (argv[0] && argv[0][0]) progname = argv[0];
lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
luaL_openlibs(L); /* open libraries */
lua_gc(L, LUA_GCRESTART, 0);
s->status = handle_luainit(L);
if (s->status != 0) return 0;
script = collectargs(argv, &has_i, &has_v, &has_e);
@@ -348,7 +349,10 @@ static int pmain (lua_State *L) {
if (has_i)
dotty(L);
else if (script == 0 && !has_e && !has_v) {
if (lua_stdin_is_tty()) dotty(L);
if (lua_stdin_is_tty()) {
print_version();
dotty(L);
}
else dofile(L, NULL); /* executes stdin as a file */
}
return 0;

6
lua.h
View File

@@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.213 2005/09/20 17:55:10 roberto Exp roberto $
** $Id: lua.h,v 1.215 2005/12/27 17:09:50 roberto Exp roberto $
** Lua - An Extensible Extension Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@@ -18,7 +18,7 @@
#define LUA_VERSION "Lua 5.1"
#define LUA_VERSION_NUM 501
#define LUA_COPYRIGHT "Copyright (C) 1994-2005 Lua.org, PUC-Rio"
#define LUA_COPYRIGHT "Copyright (C) 1994-2006 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
@@ -358,7 +358,7 @@ struct lua_Debug {
/******************************************************************************
* Copyright (C) 1994-2005 Lua.org, PUC-Rio. All rights reserved.
* Copyright (C) 1994-2006 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

View File

@@ -1,5 +1,5 @@
/*
** $Id: luaconf.h,v 1.73 2005/11/16 11:56:28 roberto Exp $
** $Id: luaconf.h,v 1.80 2006/01/27 13:54:39 roberto Exp roberto $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@@ -28,6 +28,11 @@
#define LUA_ANSI
#endif
#if !defined(LUA_ANSI) && defined(_WIN32)
#define LUA_WIN
#endif
#if defined(LUA_USE_LINUX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
@@ -177,13 +182,6 @@
/*
@@ lua_assert describes the internal assertions in Lua.
** CHANGE that only if you need to debug Lua.
*/
#define lua_assert(c) ((void)0)
/*
@@ LUA_QL describes how error messages quote program elements.
** CHANGE it if you want a different appearance.
@@ -217,7 +215,7 @@
#if defined(LUA_USE_ISATTY)
#include <unistd.h>
#define lua_stdin_is_tty() isatty(0)
#elif !defined(LUA_ANSI) && defined(_WIN32)
#elif defined(LUA_WIN)
#include <io.h>
#include <stdio.h>
#define lua_stdin_is_tty() _isatty(_fileno(stdin))
@@ -368,8 +366,7 @@
#include <assert.h>
#define luai_apicheck(L,o) { (void)L; assert(o); }
#else
/* (By default lua_assert is empty, so luai_apicheck is also empty.) */
#define luai_apicheck(L,o) { (void)L; lua_assert(o); }
#define luai_apicheck(L,o) { (void)L; }
#endif
@@ -491,6 +488,7 @@
** ===================================================================
*/
#define LUA_NUMBER_DOUBLE
#define LUA_NUMBER double
/*
@@ -529,6 +527,7 @@
#define luai_numeq(a,b) ((a)==(b))
#define luai_numlt(a,b) ((a)<(b))
#define luai_numle(a,b) ((a)<=(b))
#define luai_numisnan(a) (!luai_numeq((a), (a)))
#endif
@@ -542,7 +541,7 @@
*/
/* On a Pentium, resort to a trick */
#if !defined(LUA_ANSI) && !defined(__SSE2__) && \
#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
(defined(__i386) || defined (_M_IX86) || defined(__i386__))
union luai_Cast { double l_d; long l_l; };
#define lua_number2int(i,d) \
@@ -644,16 +643,16 @@ union luai_Cast { double l_d; long l_l; };
#define lua_popen(L,c,m) ((void)L, popen(c,m))
#define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
#elif !defined(LUA_ANSI) && defined(_WIN32)
#elif defined(LUA_WIN)
#define lua_popen(L,c,m) ((void)L, _popen(c,m))
#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1))
#else
#define lua_popen(L,c,m) \
((void)c, (void)m, luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
#define lua_pclose(L,file) ((void)L, (void)file, 0)
#define lua_popen(L,c,m) ((void)((void)c, m), \
luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
#define lua_pclose(L,file) ((void)((void)L, file), 0)
#endif
@@ -675,7 +674,7 @@ union luai_Cast { double l_d; long l_l; };
#define LUA_DL_DLOPEN
#endif
#if !defined(LUA_ANSI) && defined(_WIN32)
#if defined(LUA_WIN)
#define LUA_DL_DLL
#endif
@@ -702,6 +701,26 @@ union luai_Cast { double l_d; long l_l; };
#define luai_userstateyield(L,n) ((void)L)
/*
@@ LUA_INTFRMLEN is the length modifier for integer conversions
@* in 'string.format'.
@@ LUA_INTFRM_T is the integer type correspoding to the previous length
@* modifier.
** CHANGE them if your system supports long long or does not support long.
*/
#if defined(LUA_USELONGLONG)
#define LUA_INTFRMLEN "ll"
#define LUA_INTFRM_T long long
#else
#define LUA_INTFRMLEN "l"
#define LUA_INTFRM_T long
#endif
/* =================================================================== */

View File

@@ -1,5 +1,5 @@
/*
** $Id: lualib.h,v 1.34 2005/04/13 17:24:20 roberto Exp roberto $
** $Id: lualib.h,v 1.35 2005/08/10 18:06:58 roberto Exp roberto $
** Lua standard libraries
** See Copyright Notice in lua.h
*/
@@ -44,4 +44,10 @@ LUALIB_API int (luaopen_package) (lua_State *L);
LUALIB_API void (luaL_openlibs) (lua_State *L);
#ifndef lua_assert
#define lua_assert(x) ((void)0)
#endif
#endif

View File

@@ -1,5 +1,5 @@
/*
** $Id: lundump.c,v 1.58 2005/09/02 01:54:47 lhf Exp lhf $
** $Id: lundump.c,v 1.60 2006/02/16 15:53:49 lhf Exp $
** load precompiled Lua chunks
** See Copyright Notice in lua.h
*/
@@ -201,7 +201,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
S.Z=Z;
S.b=buff;
LoadHeader(&S);
return LoadFunction(&S,NULL);
return LoadFunction(&S,luaS_newliteral(L,"=?"));
}
/*

20
lvm.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 2.58 2005/10/24 17:37:52 roberto Exp roberto $
** $Id: lvm.c,v 2.61 2006/01/10 12:50:00 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -95,7 +95,8 @@ static void callTMres (lua_State *L, StkId res, const TValue *f,
static void callTM (lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, const TValue *p3) {
static void callTM (lua_State *L, const TValue *f, const TValue *p1,
const TValue *p2, const TValue *p3) {
setobj2s(L, L->top, f); /* push function */
setobj2s(L, L->top+1, p1); /* 1st argument */
setobj2s(L, L->top+2, p2); /* 2nd argument */
@@ -509,16 +510,16 @@ void luaV_execute (lua_State *L, int nexeccalls) {
const TValue *rb = RB(i);
switch (ttype(rb)) {
case LUA_TTABLE: {
setnvalue(ra, cast(lua_Number, luaH_getn(hvalue(rb))));
setnvalue(ra, cast_num(luaH_getn(hvalue(rb))));
break;
}
case LUA_TSTRING: {
setnvalue(ra, cast(lua_Number, tsvalue(rb)->len));
setnvalue(ra, cast_num(tsvalue(rb)->len));
break;
}
default: { /* try metamethod */
Protect(
if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_LEN))
if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))
luaG_typeerror(L, rb, "get length of");
)
}
@@ -649,7 +650,8 @@ void luaV_execute (lua_State *L, int nexeccalls) {
lua_Number step = nvalue(ra+2);
lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */
lua_Number limit = nvalue(ra+1);
if (step > 0 ? luai_numle(idx, limit) : luai_numle(limit, idx)) {
if (luai_numlt(0, step) ? luai_numle(idx, limit)
: luai_numle(limit, idx)) {
dojump(L, pc, GETARG_sBx(i)); /* jump back */
setnvalue(ra, idx); /* update internal index... */
setnvalue(ra+3, idx); /* ...and external index */
@@ -693,10 +695,10 @@ void luaV_execute (lua_State *L, int nexeccalls) {
int last;
Table *h;
if (n == 0) {
n = cast(int, L->top - ra) - 1;
n = cast_int(L->top - ra) - 1;
L->top = L->ci->top;
}
if (c == 0) c = cast(int, *pc++);
if (c == 0) c = cast_int(*pc++);
runtime_check(L, ttistable(ra));
h = hvalue(ra);
last = ((c-1)*LFIELDS_PER_FLUSH) + n;
@@ -737,7 +739,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
int b = GETARG_B(i) - 1;
int j;
CallInfo *ci = L->ci;
int n = cast(int, ci->base - ci->func) - cl->p->numparams - 1;
int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1;
if (b == LUA_MULTRET) {
Protect(luaD_checkstack(L, n));
ra = RA(i); /* previous call may change the stack */