aboutsummaryrefslogtreecommitdiff
path: root/src/lua/lapi.c
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-03-03 21:31:01 +0800
committerLi Jin <dragon-fly@qq.com>2021-03-03 21:33:37 +0800
commit1df786307c1983b8ce693e3916081a8bcd4e95ae (patch)
tree6c7aeb2198d825877fd3d179c394b7a5c1f06a17 /src/lua/lapi.c
parent66168b112b707172b9035edf8c1daed469781e06 (diff)
downloadyuescript-1df786307c1983b8ce693e3916081a8bcd4e95ae.tar.gz
yuescript-1df786307c1983b8ce693e3916081a8bcd4e95ae.tar.bz2
yuescript-1df786307c1983b8ce693e3916081a8bcd4e95ae.zip
add new metatable syntax for issue #41, fix reusing local variable issue, update built-in Lua.
Diffstat (limited to 'src/lua/lapi.c')
-rw-r--r--src/lua/lapi.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/lua/lapi.c b/src/lua/lapi.c
index 3583e9c..a9cf2fd 100644
--- a/src/lua/lapi.c
+++ b/src/lua/lapi.c
@@ -39,7 +39,7 @@ const char lua_ident[] =
39 39
40 40
41/* 41/*
42** Test for a valid index. 42** Test for a valid index (one that is not the 'nilvalue').
43** '!ttisnil(o)' implies 'o != &G(L)->nilvalue', so it is not needed. 43** '!ttisnil(o)' implies 'o != &G(L)->nilvalue', so it is not needed.
44** However, it covers the most common cases in a faster way. 44** However, it covers the most common cases in a faster way.
45*/ 45*/
@@ -74,7 +74,8 @@ static TValue *index2value (lua_State *L, int idx) {
74 return &G(L)->nilvalue; /* it has no upvalues */ 74 return &G(L)->nilvalue; /* it has no upvalues */
75 else { 75 else {
76 CClosure *func = clCvalue(s2v(ci->func)); 76 CClosure *func = clCvalue(s2v(ci->func));
77 return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : &G(L)->nilvalue; 77 return (idx <= func->nupvalues) ? &func->upvalue[idx-1]
78 : &G(L)->nilvalue;
78 } 79 }
79 } 80 }
80} 81}
@@ -191,9 +192,8 @@ LUA_API void lua_settop (lua_State *L, int idx) {
191 if (diff < 0 && hastocloseCfunc(ci->nresults)) 192 if (diff < 0 && hastocloseCfunc(ci->nresults))
192 luaF_close(L, L->top + diff, CLOSEKTOP, 0); 193 luaF_close(L, L->top + diff, CLOSEKTOP, 0);
193#endif 194#endif
195 api_check(L, L->tbclist < L->top + diff, "cannot pop an unclosed slot");
194 L->top += diff; 196 L->top += diff;
195 api_check(L, L->openupval == NULL || uplevel(L->openupval) < L->top,
196 "cannot pop an unclosed slot");
197 lua_unlock(L); 197 lua_unlock(L);
198} 198}
199 199
@@ -202,10 +202,10 @@ LUA_API void lua_closeslot (lua_State *L, int idx) {
202 StkId level; 202 StkId level;
203 lua_lock(L); 203 lua_lock(L);
204 level = index2stack(L, idx); 204 level = index2stack(L, idx);
205 api_check(L, hastocloseCfunc(L->ci->nresults) && L->openupval != NULL && 205 api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist == level,
206 uplevel(L->openupval) == level,
207 "no variable to close at given level"); 206 "no variable to close at given level");
208 luaF_close(L, level, CLOSEKTOP, 0); 207 luaF_close(L, level, CLOSEKTOP, 0);
208 level = index2stack(L, idx); /* stack may be moved */
209 setnilvalue(s2v(level)); 209 setnilvalue(s2v(level));
210 lua_unlock(L); 210 lua_unlock(L);
211} 211}
@@ -1264,8 +1264,7 @@ LUA_API void lua_toclose (lua_State *L, int idx) {
1264 lua_lock(L); 1264 lua_lock(L);
1265 o = index2stack(L, idx); 1265 o = index2stack(L, idx);
1266 nresults = L->ci->nresults; 1266 nresults = L->ci->nresults;
1267 api_check(L, L->openupval == NULL || uplevel(L->openupval) <= o, 1267 api_check(L, L->tbclist < o, "given index below or equal a marked one");
1268 "marked index below or equal new one");
1269 luaF_newtbcupval(L, o); /* create new to-be-closed upvalue */ 1268 luaF_newtbcupval(L, o); /* create new to-be-closed upvalue */
1270 if (!hastocloseCfunc(nresults)) /* function not marked yet? */ 1269 if (!hastocloseCfunc(nresults)) /* function not marked yet? */
1271 L->ci->nresults = codeNresults(nresults); /* mark it */ 1270 L->ci->nresults = codeNresults(nresults); /* mark it */