diff --git a/lapi.c b/lapi.c index 80144154..c078160a 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 1.247 2003/10/10 13:29:08 roberto Exp roberto $ +** $Id: lapi.c,v 1.248 2003/10/20 12:25:23 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -784,7 +784,7 @@ LUA_API int lua_dump (lua_State *L, lua_Chunkwriter writer, void *data) { lua_lock(L); api_checknelems(L, 1); o = L->top - 1; - if (isLfunction(o) && clvalue(o)->l.nupvalues == 0) + if (isLfunction(o)) status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0); else status = 0; diff --git a/ldo.c b/ldo.c index 48264ce3..37cf58a8 100644 --- a/ldo.c +++ b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 1.226 2003/10/03 16:04:11 roberto Exp roberto $ +** $Id: ldo.c,v 1.227 2003/10/20 12:24:26 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -445,6 +445,7 @@ struct SParser { /* data to `f_parser' */ }; static void f_parser (lua_State *L, void *ud) { + int i; Proto *tf; Closure *cl; struct SParser *p = cast(struct SParser *, ud); @@ -452,8 +453,10 @@ static void f_parser (lua_State *L, void *ud) { luaC_checkGC(L); tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, &p->buff, p->name); - cl = luaF_newLclosure(L, 0, gt(L)); + cl = luaF_newLclosure(L, tf->nups, gt(L)); cl->l.p = tf; + for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ + cl->l.upvals[i] = luaF_newupval(L); setclvalue(L->top, cl); incr_top(L); } diff --git a/lfunc.c b/lfunc.c index bd885caa..7117b783 100644 --- a/lfunc.c +++ b/lfunc.c @@ -1,5 +1,5 @@ /* -** $Id: lfunc.c,v 1.67 2003/03/18 12:50:04 roberto Exp roberto $ +** $Id: lfunc.c,v 1.68 2003/10/02 19:21:09 roberto Exp roberto $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ @@ -45,6 +45,15 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e) { } +UpVal *luaF_newupval (lua_State *L) { + UpVal *p = luaM_new(L, UpVal); + luaC_link(L, valtogco(p), LUA_TUPVAL); + p->v = &p->value; + setnilvalue(p->v); + return p; +} + + UpVal *luaF_findupval (lua_State *L, StkId level) { GCObject **pp = &L->openupval; UpVal *p; diff --git a/lfunc.h b/lfunc.h index 34aa9d1a..ae55e289 100644 --- a/lfunc.h +++ b/lfunc.h @@ -1,5 +1,5 @@ /* -** $Id: lfunc.h,v 1.20 2002/06/20 20:41:46 roberto Exp roberto $ +** $Id: lfunc.h,v 1.21 2003/03/18 12:50:04 roberto Exp roberto $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ @@ -14,6 +14,7 @@ Proto *luaF_newproto (lua_State *L); Closure *luaF_newCclosure (lua_State *L, int nelems); Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e); +UpVal *luaF_newupval (lua_State *L); UpVal *luaF_findupval (lua_State *L, StkId level); void luaF_close (lua_State *L, StkId level); void luaF_freeproto (lua_State *L, Proto *f);