mirror of
https://github.com/lua/lua.git
synced 2025-01-14 05:43:00 +08:00
it's ok to dump functions with upvalues
This commit is contained in:
parent
03bab90303
commit
c51bcf4796
4
lapi.c
4
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;
|
||||
|
7
ldo.c
7
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);
|
||||
}
|
||||
|
11
lfunc.c
11
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;
|
||||
|
3
lfunc.h
3
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user