summaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/lapi.c b/lapi.c
index 62b5f1a3..f4a8beb4 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.186 2013/08/05 16:58:28 roberto Exp roberto $ 2** $Id: lapi.c,v 2.187 2013/08/16 18:55:49 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*/
@@ -1192,7 +1192,7 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
1192 1192
1193 1193
1194static const char *aux_upvalue (StkId fi, int n, TValue **val, 1194static const char *aux_upvalue (StkId fi, int n, TValue **val,
1195 GCObject **owner) { 1195 GCObject **owner, UpVal **uv) {
1196 switch (ttype(fi)) { 1196 switch (ttype(fi)) {
1197 case LUA_TCCL: { /* C closure */ 1197 case LUA_TCCL: { /* C closure */
1198 CClosure *f = clCvalue(fi); 1198 CClosure *f = clCvalue(fi);
@@ -1207,7 +1207,7 @@ static const char *aux_upvalue (StkId fi, int n, TValue **val,
1207 Proto *p = f->p; 1207 Proto *p = f->p;
1208 if (!(1 <= n && n <= p->sizeupvalues)) return NULL; 1208 if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
1209 *val = f->upvals[n-1]->v; 1209 *val = f->upvals[n-1]->v;
1210 if (owner) *owner = obj2gco(f->upvals[n - 1]); 1210 if (uv) *uv = f->upvals[n - 1];
1211 name = p->upvalues[n-1].name; 1211 name = p->upvalues[n-1].name;
1212 return (name == NULL) ? "" : getstr(name); 1212 return (name == NULL) ? "" : getstr(name);
1213 } 1213 }
@@ -1220,7 +1220,7 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
1220 const char *name; 1220 const char *name;
1221 TValue *val = NULL; /* to avoid warnings */ 1221 TValue *val = NULL; /* to avoid warnings */
1222 lua_lock(L); 1222 lua_lock(L);
1223 name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL); 1223 name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL, NULL);
1224 if (name) { 1224 if (name) {
1225 setobj2s(L, L->top, val); 1225 setobj2s(L, L->top, val);
1226 api_incr_top(L); 1226 api_incr_top(L);
@@ -1233,16 +1233,18 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
1233LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { 1233LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
1234 const char *name; 1234 const char *name;
1235 TValue *val = NULL; /* to avoid warnings */ 1235 TValue *val = NULL; /* to avoid warnings */
1236 GCObject *owner = NULL; /* to avoid warnings */ 1236 GCObject *owner = NULL;
1237 UpVal *uv = NULL;
1237 StkId fi; 1238 StkId fi;
1238 lua_lock(L); 1239 lua_lock(L);
1239 fi = index2addr(L, funcindex); 1240 fi = index2addr(L, funcindex);
1240 api_checknelems(L, 1); 1241 api_checknelems(L, 1);
1241 name = aux_upvalue(fi, n, &val, &owner); 1242 name = aux_upvalue(fi, n, &val, &owner, &uv);
1242 if (name) { 1243 if (name) {
1243 L->top--; 1244 L->top--;
1244 setobj(L, val, L->top); 1245 setobj(L, val, L->top);
1245 luaC_barrier(L, owner, L->top); 1246 if (owner) { luaC_barrier(L, owner, L->top); }
1247 else if (uv) { luaC_upvalbarrier(L, uv); }
1246 } 1248 }
1247 lua_unlock(L); 1249 lua_unlock(L);
1248 return name; 1250 return name;
@@ -1284,7 +1286,11 @@ LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,
1284 LClosure *f1; 1286 LClosure *f1;
1285 UpVal **up1 = getupvalref(L, fidx1, n1, &f1); 1287 UpVal **up1 = getupvalref(L, fidx1, n1, &f1);
1286 UpVal **up2 = getupvalref(L, fidx2, n2, NULL); 1288 UpVal **up2 = getupvalref(L, fidx2, n2, NULL);
1289 luaC_upvdeccount(L, *up1);
1287 *up1 = *up2; 1290 *up1 = *up2;
1288 luaC_objbarrier(L, f1, *up2); 1291 (*up1)->refcount++;
1292 if (upisopen(*up1)) (*up1)->u.op.touched = 1;
1293 luaC_upvalbarrier(L, *up1);
1289} 1294}
1290 1295
1296