[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: environment as upvalue
- From: "Juris Kalnins" <juris@...>
- Date: Tue, 19 Jan 2010 13:57:48 +0200
On Tue, 19 Jan 2010 09:08:00 +0200, Juris Kalnins <juris@mt.lv> wrote:
==8<=== Incomplete and flawed patch, against work2
.... the patch was missing the following (important) piece:
diff -BubNrd lua-5.2.0-work2/src/lapi.c l520w2-dyen/src/lapi.c
--- lua-5.2.0-work2/src/lapi.c 2010-01-13 18:18:25.000000000 +0200
+++ l520w2-dyen/src/lapi.c 2010-01-19 11:12:39.000000000 +0200
@@ -1117,14 +1096,16 @@
static UpVal **getupvalref (lua_State *L, int fidx, int n, Closure **pf) {
Closure *f;
Proto *p;
- StkId fi = index2addr(L, fidx);
+ CallInfo *ci = L->ci;
+ while (!fidx && clvalue(ci->func)->c.isC && ci->previous) ci =
ci->previous;
+ StkId fi = fidx ? index2addr(L, fidx) : ci->func;
api_check(L, ttisfunction(fi), "function expected");
f = clvalue(fi);
api_check(L, !f->c.isC, "Lua function expected");
p = f->l.p;
- api_check(L, (1 <= n && n <= p->sizeupvalues), "invalid upvalue index");
+ api_check(L, (0 <= n && n <= p->sizeupvalues - 1), "invalid upvalue
index");
if (pf) *pf = f;
- return &f->l.upvals[n - 1]; /* get its upvalue pointer */
+ return &f->l.upvals[n]; /* get its upvalue pointer */
}
diff -BubNrd lua-5.2.0-work2/src/lbaselib.c l520w2-dyen/src/lbaselib.c
--- lua-5.2.0-work2/src/lbaselib.c 2009-12-28 18:30:31.000000000 +0200
+++ l520w2-dyen/src/lbaselib.c 2010-01-19 11:17:52.000000000 +0200
@@ -268,8 +268,10 @@
static int load_aux (lua_State *L, int status) {
- if (status == LUA_OK)
+ if (status == LUA_OK) {
+ lua_upvaluejoin(L, -1, 0, 0, 0);
return 1;
+ }
else {
lua_pushnil(L);
lua_insert(L, -2); /* put before error message */