diff options
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -1254,13 +1254,12 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { | |||
1254 | } | 1254 | } |
1255 | 1255 | ||
1256 | 1256 | ||
1257 | static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { | 1257 | static UpVal **getupvalref (lua_State *L, int fidx, int n) { |
1258 | LClosure *f; | 1258 | LClosure *f; |
1259 | StkId fi = index2addr(L, fidx); | 1259 | StkId fi = index2addr(L, fidx); |
1260 | api_check(L, ttisLclosure(fi), "Lua function expected"); | 1260 | api_check(L, ttisLclosure(fi), "Lua function expected"); |
1261 | f = clLvalue(fi); | 1261 | f = clLvalue(fi); |
1262 | api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index"); | 1262 | api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index"); |
1263 | if (pf) *pf = f; | ||
1264 | return &f->upvals[n - 1]; /* get its upvalue pointer */ | 1263 | return &f->upvals[n - 1]; /* get its upvalue pointer */ |
1265 | } | 1264 | } |
1266 | 1265 | ||
@@ -1269,7 +1268,7 @@ LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { | |||
1269 | StkId fi = index2addr(L, fidx); | 1268 | StkId fi = index2addr(L, fidx); |
1270 | switch (ttype(fi)) { | 1269 | switch (ttype(fi)) { |
1271 | case LUA_TLCL: { /* lua closure */ | 1270 | case LUA_TLCL: { /* lua closure */ |
1272 | return *getupvalref(L, fidx, n, NULL); | 1271 | return *getupvalref(L, fidx, n); |
1273 | } | 1272 | } |
1274 | case LUA_TCCL: { /* C closure */ | 1273 | case LUA_TCCL: { /* C closure */ |
1275 | CClosure *f = clCvalue(fi); | 1274 | CClosure *f = clCvalue(fi); |
@@ -1286,9 +1285,10 @@ LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { | |||
1286 | 1285 | ||
1287 | LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1, | 1286 | LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1, |
1288 | int fidx2, int n2) { | 1287 | int fidx2, int n2) { |
1289 | LClosure *f1; | 1288 | UpVal **up1 = getupvalref(L, fidx1, n1); |
1290 | UpVal **up1 = getupvalref(L, fidx1, n1, &f1); | 1289 | UpVal **up2 = getupvalref(L, fidx2, n2); |
1291 | UpVal **up2 = getupvalref(L, fidx2, n2, NULL); | 1290 | if (*up1 == *up2) |
1291 | return; | ||
1292 | luaC_upvdeccount(L, *up1); | 1292 | luaC_upvdeccount(L, *up1); |
1293 | *up1 = *up2; | 1293 | *up1 = *up2; |
1294 | (*up1)->refcount++; | 1294 | (*up1)->refcount++; |