aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-10-20 15:42:41 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-10-20 15:42:41 -0200
commitc51bcf4796d1e39bb9840825a72085c9a51ec402 (patch)
tree221a63329b5fc7cbca88110c36022df8026b13e9
parent03bab90303270534ba6a415b5379d4659757082d (diff)
downloadlua-c51bcf4796d1e39bb9840825a72085c9a51ec402.tar.gz
lua-c51bcf4796d1e39bb9840825a72085c9a51ec402.tar.bz2
lua-c51bcf4796d1e39bb9840825a72085c9a51ec402.zip
it's ok to dump functions with upvalues
-rw-r--r--lapi.c4
-rw-r--r--ldo.c7
-rw-r--r--lfunc.c11
-rw-r--r--lfunc.h3
4 files changed, 19 insertions, 6 deletions
diff --git a/lapi.c b/lapi.c
index 80144154..c078160a 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.247 2003/10/10 13:29:08 roberto Exp roberto $ 2** $Id: lapi.c,v 1.248 2003/10/20 12:25:23 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -784,7 +784,7 @@ LUA_API int lua_dump (lua_State *L, lua_Chunkwriter writer, void *data) {
784 lua_lock(L); 784 lua_lock(L);
785 api_checknelems(L, 1); 785 api_checknelems(L, 1);
786 o = L->top - 1; 786 o = L->top - 1;
787 if (isLfunction(o) && clvalue(o)->l.nupvalues == 0) 787 if (isLfunction(o))
788 status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0); 788 status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0);
789 else 789 else
790 status = 0; 790 status = 0;
diff --git a/ldo.c b/ldo.c
index 48264ce3..37cf58a8 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.226 2003/10/03 16:04:11 roberto Exp roberto $ 2** $Id: ldo.c,v 1.227 2003/10/20 12:24:26 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -445,6 +445,7 @@ struct SParser { /* data to `f_parser' */
445}; 445};
446 446
447static void f_parser (lua_State *L, void *ud) { 447static void f_parser (lua_State *L, void *ud) {
448 int i;
448 Proto *tf; 449 Proto *tf;
449 Closure *cl; 450 Closure *cl;
450 struct SParser *p = cast(struct SParser *, ud); 451 struct SParser *p = cast(struct SParser *, ud);
@@ -452,8 +453,10 @@ static void f_parser (lua_State *L, void *ud) {
452 luaC_checkGC(L); 453 luaC_checkGC(L);
453 tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, 454 tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z,
454 &p->buff, p->name); 455 &p->buff, p->name);
455 cl = luaF_newLclosure(L, 0, gt(L)); 456 cl = luaF_newLclosure(L, tf->nups, gt(L));
456 cl->l.p = tf; 457 cl->l.p = tf;
458 for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */
459 cl->l.upvals[i] = luaF_newupval(L);
457 setclvalue(L->top, cl); 460 setclvalue(L->top, cl);
458 incr_top(L); 461 incr_top(L);
459} 462}
diff --git a/lfunc.c b/lfunc.c
index bd885caa..7117b783 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 1.67 2003/03/18 12:50:04 roberto Exp roberto $ 2** $Id: lfunc.c,v 1.68 2003/10/02 19:21:09 roberto Exp roberto $
3** Auxiliary functions to manipulate prototypes and closures 3** Auxiliary functions to manipulate prototypes and closures
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -45,6 +45,15 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e) {
45} 45}
46 46
47 47
48UpVal *luaF_newupval (lua_State *L) {
49 UpVal *p = luaM_new(L, UpVal);
50 luaC_link(L, valtogco(p), LUA_TUPVAL);
51 p->v = &p->value;
52 setnilvalue(p->v);
53 return p;
54}
55
56
48UpVal *luaF_findupval (lua_State *L, StkId level) { 57UpVal *luaF_findupval (lua_State *L, StkId level) {
49 GCObject **pp = &L->openupval; 58 GCObject **pp = &L->openupval;
50 UpVal *p; 59 UpVal *p;
diff --git a/lfunc.h b/lfunc.h
index 34aa9d1a..ae55e289 100644
--- a/lfunc.h
+++ b/lfunc.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.h,v 1.20 2002/06/20 20:41:46 roberto Exp roberto $ 2** $Id: lfunc.h,v 1.21 2003/03/18 12:50:04 roberto Exp roberto $
3** Auxiliary functions to manipulate prototypes and closures 3** Auxiliary functions to manipulate prototypes and closures
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -14,6 +14,7 @@
14Proto *luaF_newproto (lua_State *L); 14Proto *luaF_newproto (lua_State *L);
15Closure *luaF_newCclosure (lua_State *L, int nelems); 15Closure *luaF_newCclosure (lua_State *L, int nelems);
16Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e); 16Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e);
17UpVal *luaF_newupval (lua_State *L);
17UpVal *luaF_findupval (lua_State *L, StkId level); 18UpVal *luaF_findupval (lua_State *L, StkId level);
18void luaF_close (lua_State *L, StkId level); 19void luaF_close (lua_State *L, StkId level);
19void luaF_freeproto (lua_State *L, Proto *f); 20void luaF_freeproto (lua_State *L, Proto *f);