lua-users home
lua-l archive

Re: environment as upvalue

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2010年1月19日 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 */

AltStyle によって変換されたページ (->オリジナル) /