diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-10-29 12:06:37 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-10-29 12:06:37 -0300 |
commit | 413a393e6222482f46599e138bebac162610a572 (patch) | |
tree | 181517f8ec8d56f9101de33f4891729044f244de /lapi.c | |
parent | ba089bcb08a0efc6c26fb5c1e3c9d61c00cc012c (diff) | |
download | lua-413a393e6222482f46599e138bebac162610a572.tar.gz lua-413a393e6222482f46599e138bebac162610a572.tar.bz2 lua-413a393e6222482f46599e138bebac162610a572.zip |
Stack indices changed to union's
That will allow to change pointers to offsets while reallocating
the stack.
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 235 |
1 files changed, 119 insertions, 116 deletions
@@ -60,27 +60,28 @@ const char lua_ident[] = | |||
60 | static TValue *index2value (lua_State *L, int idx) { | 60 | static TValue *index2value (lua_State *L, int idx) { |
61 | CallInfo *ci = L->ci; | 61 | CallInfo *ci = L->ci; |
62 | if (idx > 0) { | 62 | if (idx > 0) { |
63 | StkId o = ci->func + idx; | 63 | StkId o = ci->func.p + idx; |
64 | api_check(L, idx <= L->ci->top - (ci->func + 1), "unacceptable index"); | 64 | api_check(L, idx <= ci->top.p - (ci->func.p + 1), "unacceptable index"); |
65 | if (o >= L->top) return &G(L)->nilvalue; | 65 | if (o >= L->top.p) return &G(L)->nilvalue; |
66 | else return s2v(o); | 66 | else return s2v(o); |
67 | } | 67 | } |
68 | else if (!ispseudo(idx)) { /* negative index */ | 68 | else if (!ispseudo(idx)) { /* negative index */ |
69 | api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); | 69 | api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1), |
70 | return s2v(L->top + idx); | 70 | "invalid index"); |
71 | return s2v(L->top.p + idx); | ||
71 | } | 72 | } |
72 | else if (idx == LUA_REGISTRYINDEX) | 73 | else if (idx == LUA_REGISTRYINDEX) |
73 | return &G(L)->l_registry; | 74 | return &G(L)->l_registry; |
74 | else { /* upvalues */ | 75 | else { /* upvalues */ |
75 | idx = LUA_REGISTRYINDEX - idx; | 76 | idx = LUA_REGISTRYINDEX - idx; |
76 | api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); | 77 | api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); |
77 | if (ttisCclosure(s2v(ci->func))) { /* C closure? */ | 78 | if (ttisCclosure(s2v(ci->func.p))) { /* C closure? */ |
78 | CClosure *func = clCvalue(s2v(ci->func)); | 79 | CClosure *func = clCvalue(s2v(ci->func.p)); |
79 | return (idx <= func->nupvalues) ? &func->upvalue[idx-1] | 80 | return (idx <= func->nupvalues) ? &func->upvalue[idx-1] |
80 | : &G(L)->nilvalue; | 81 | : &G(L)->nilvalue; |
81 | } | 82 | } |
82 | else { /* light C function or Lua function (through a hook)?) */ | 83 | else { /* light C function or Lua function (through a hook)?) */ |
83 | api_check(L, ttislcf(s2v(ci->func)), "caller not a C function"); | 84 | api_check(L, ttislcf(s2v(ci->func.p)), "caller not a C function"); |
84 | return &G(L)->nilvalue; /* no upvalues */ | 85 | return &G(L)->nilvalue; /* no upvalues */ |
85 | } | 86 | } |
86 | } | 87 | } |
@@ -94,14 +95,15 @@ static TValue *index2value (lua_State *L, int idx) { | |||
94 | l_sinline StkId index2stack (lua_State *L, int idx) { | 95 | l_sinline StkId index2stack (lua_State *L, int idx) { |
95 | CallInfo *ci = L->ci; | 96 | CallInfo *ci = L->ci; |
96 | if (idx > 0) { | 97 | if (idx > 0) { |
97 | StkId o = ci->func + idx; | 98 | StkId o = ci->func.p + idx; |
98 | api_check(L, o < L->top, "invalid index"); | 99 | api_check(L, o < L->top.p, "invalid index"); |
99 | return o; | 100 | return o; |
100 | } | 101 | } |
101 | else { /* non-positive index */ | 102 | else { /* non-positive index */ |
102 | api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); | 103 | api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1), |
104 | "invalid index"); | ||
103 | api_check(L, !ispseudo(idx), "invalid index"); | 105 | api_check(L, !ispseudo(idx), "invalid index"); |
104 | return L->top + idx; | 106 | return L->top.p + idx; |
105 | } | 107 | } |
106 | } | 108 | } |
107 | 109 | ||
@@ -112,12 +114,12 @@ LUA_API int lua_checkstack (lua_State *L, int n) { | |||
112 | lua_lock(L); | 114 | lua_lock(L); |
113 | ci = L->ci; | 115 | ci = L->ci; |
114 | api_check(L, n >= 0, "negative 'n'"); | 116 | api_check(L, n >= 0, "negative 'n'"); |
115 | if (L->stack_last - L->top > n) /* stack large enough? */ | 117 | if (L->stack_last.p - L->top.p > n) /* stack large enough? */ |
116 | res = 1; /* yes; check is OK */ | 118 | res = 1; /* yes; check is OK */ |
117 | else /* need to grow stack */ | 119 | else /* need to grow stack */ |
118 | res = luaD_growstack(L, n, 0); | 120 | res = luaD_growstack(L, n, 0); |
119 | if (res && ci->top < L->top + n) | 121 | if (res && ci->top.p < L->top.p + n) |
120 | ci->top = L->top + n; /* adjust frame top */ | 122 | ci->top.p = L->top.p + n; /* adjust frame top */ |
121 | lua_unlock(L); | 123 | lua_unlock(L); |
122 | return res; | 124 | return res; |
123 | } | 125 | } |
@@ -129,11 +131,11 @@ LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { | |||
129 | lua_lock(to); | 131 | lua_lock(to); |
130 | api_checknelems(from, n); | 132 | api_checknelems(from, n); |
131 | api_check(from, G(from) == G(to), "moving among independent states"); | 133 | api_check(from, G(from) == G(to), "moving among independent states"); |
132 | api_check(from, to->ci->top - to->top >= n, "stack overflow"); | 134 | api_check(from, to->ci->top.p - to->top.p >= n, "stack overflow"); |
133 | from->top -= n; | 135 | from->top.p -= n; |
134 | for (i = 0; i < n; i++) { | 136 | for (i = 0; i < n; i++) { |
135 | setobjs2s(to, to->top, from->top + i); | 137 | setobjs2s(to, to->top.p, from->top.p + i); |
136 | to->top++; /* stack already checked by previous 'api_check' */ | 138 | to->top.p++; /* stack already checked by previous 'api_check' */ |
137 | } | 139 | } |
138 | lua_unlock(to); | 140 | lua_unlock(to); |
139 | } | 141 | } |
@@ -167,12 +169,12 @@ LUA_API lua_Number lua_version (lua_State *L) { | |||
167 | LUA_API int lua_absindex (lua_State *L, int idx) { | 169 | LUA_API int lua_absindex (lua_State *L, int idx) { |
168 | return (idx > 0 || ispseudo(idx)) | 170 | return (idx > 0 || ispseudo(idx)) |
169 | ? idx | 171 | ? idx |
170 | : cast_int(L->top - L->ci->func) + idx; | 172 | : cast_int(L->top.p - L->ci->func.p) + idx; |
171 | } | 173 | } |
172 | 174 | ||
173 | 175 | ||
174 | LUA_API int lua_gettop (lua_State *L) { | 176 | LUA_API int lua_gettop (lua_State *L) { |
175 | return cast_int(L->top - (L->ci->func + 1)); | 177 | return cast_int(L->top.p - (L->ci->func.p + 1)); |
176 | } | 178 | } |
177 | 179 | ||
178 | 180 | ||
@@ -182,24 +184,24 @@ LUA_API void lua_settop (lua_State *L, int idx) { | |||
182 | ptrdiff_t diff; /* difference for new top */ | 184 | ptrdiff_t diff; /* difference for new top */ |
183 | lua_lock(L); | 185 | lua_lock(L); |
184 | ci = L->ci; | 186 | ci = L->ci; |
185 | func = ci->func; | 187 | func = ci->func.p; |
186 | if (idx >= 0) { | 188 | if (idx >= 0) { |
187 | api_check(L, idx <= ci->top - (func + 1), "new top too large"); | 189 | api_check(L, idx <= ci->top.p - (func + 1), "new top too large"); |
188 | diff = ((func + 1) + idx) - L->top; | 190 | diff = ((func + 1) + idx) - L->top.p; |
189 | for (; diff > 0; diff--) | 191 | for (; diff > 0; diff--) |
190 | setnilvalue(s2v(L->top++)); /* clear new slots */ | 192 | setnilvalue(s2v(L->top.p++)); /* clear new slots */ |
191 | } | 193 | } |
192 | else { | 194 | else { |
193 | api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top"); | 195 | api_check(L, -(idx+1) <= (L->top.p - (func + 1)), "invalid new top"); |
194 | diff = idx + 1; /* will "subtract" index (as it is negative) */ | 196 | diff = idx + 1; /* will "subtract" index (as it is negative) */ |
195 | } | 197 | } |
196 | api_check(L, L->tbclist < L->top, "previous pop of an unclosed slot"); | 198 | api_check(L, L->tbclist.p < L->top.p, "previous pop of an unclosed slot"); |
197 | newtop = L->top + diff; | 199 | newtop = L->top.p + diff; |
198 | if (diff < 0 && L->tbclist >= newtop) { | 200 | if (diff < 0 && L->tbclist.p >= newtop) { |
199 | lua_assert(hastocloseCfunc(ci->nresults)); | 201 | lua_assert(hastocloseCfunc(ci->nresults)); |
200 | newtop = luaF_close(L, newtop, CLOSEKTOP, 0); | 202 | newtop = luaF_close(L, newtop, CLOSEKTOP, 0); |
201 | } | 203 | } |
202 | L->top = newtop; /* correct top only after closing any upvalue */ | 204 | L->top.p = newtop; /* correct top only after closing any upvalue */ |
203 | lua_unlock(L); | 205 | lua_unlock(L); |
204 | } | 206 | } |
205 | 207 | ||
@@ -208,7 +210,7 @@ LUA_API void lua_closeslot (lua_State *L, int idx) { | |||
208 | StkId level; | 210 | StkId level; |
209 | lua_lock(L); | 211 | lua_lock(L); |
210 | level = index2stack(L, idx); | 212 | level = index2stack(L, idx); |
211 | api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist == level, | 213 | api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist.p == level, |
212 | "no variable to close at given level"); | 214 | "no variable to close at given level"); |
213 | level = luaF_close(L, level, CLOSEKTOP, 0); | 215 | level = luaF_close(L, level, CLOSEKTOP, 0); |
214 | setnilvalue(s2v(level)); | 216 | setnilvalue(s2v(level)); |
@@ -239,7 +241,7 @@ l_sinline void reverse (lua_State *L, StkId from, StkId to) { | |||
239 | LUA_API void lua_rotate (lua_State *L, int idx, int n) { | 241 | LUA_API void lua_rotate (lua_State *L, int idx, int n) { |
240 | StkId p, t, m; | 242 | StkId p, t, m; |
241 | lua_lock(L); | 243 | lua_lock(L); |
242 | t = L->top - 1; /* end of stack segment being rotated */ | 244 | t = L->top.p - 1; /* end of stack segment being rotated */ |
243 | p = index2stack(L, idx); /* start of segment */ | 245 | p = index2stack(L, idx); /* start of segment */ |
244 | api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); | 246 | api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); |
245 | m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ | 247 | m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ |
@@ -258,7 +260,7 @@ LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { | |||
258 | api_check(L, isvalid(L, to), "invalid index"); | 260 | api_check(L, isvalid(L, to), "invalid index"); |
259 | setobj(L, to, fr); | 261 | setobj(L, to, fr); |
260 | if (isupvalue(toidx)) /* function upvalue? */ | 262 | if (isupvalue(toidx)) /* function upvalue? */ |
261 | luaC_barrier(L, clCvalue(s2v(L->ci->func)), fr); | 263 | luaC_barrier(L, clCvalue(s2v(L->ci->func.p)), fr); |
262 | /* LUA_REGISTRYINDEX does not need gc barrier | 264 | /* LUA_REGISTRYINDEX does not need gc barrier |
263 | (collector revisits it before finishing collection) */ | 265 | (collector revisits it before finishing collection) */ |
264 | lua_unlock(L); | 266 | lua_unlock(L); |
@@ -267,7 +269,7 @@ LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { | |||
267 | 269 | ||
268 | LUA_API void lua_pushvalue (lua_State *L, int idx) { | 270 | LUA_API void lua_pushvalue (lua_State *L, int idx) { |
269 | lua_lock(L); | 271 | lua_lock(L); |
270 | setobj2s(L, L->top, index2value(L, idx)); | 272 | setobj2s(L, L->top.p, index2value(L, idx)); |
271 | api_incr_top(L); | 273 | api_incr_top(L); |
272 | lua_unlock(L); | 274 | lua_unlock(L); |
273 | } | 275 | } |
@@ -336,12 +338,12 @@ LUA_API void lua_arith (lua_State *L, int op) { | |||
336 | api_checknelems(L, 2); /* all other operations expect two operands */ | 338 | api_checknelems(L, 2); /* all other operations expect two operands */ |
337 | else { /* for unary operations, add fake 2nd operand */ | 339 | else { /* for unary operations, add fake 2nd operand */ |
338 | api_checknelems(L, 1); | 340 | api_checknelems(L, 1); |
339 | setobjs2s(L, L->top, L->top - 1); | 341 | setobjs2s(L, L->top.p, L->top.p - 1); |
340 | api_incr_top(L); | 342 | api_incr_top(L); |
341 | } | 343 | } |
342 | /* first operand at top - 2, second at top - 1; result go to top - 2 */ | 344 | /* first operand at top - 2, second at top - 1; result go to top - 2 */ |
343 | luaO_arith(L, op, s2v(L->top - 2), s2v(L->top - 1), L->top - 2); | 345 | luaO_arith(L, op, s2v(L->top.p - 2), s2v(L->top.p - 1), L->top.p - 2); |
344 | L->top--; /* remove second operand */ | 346 | L->top.p--; /* remove second operand */ |
345 | lua_unlock(L); | 347 | lua_unlock(L); |
346 | } | 348 | } |
347 | 349 | ||
@@ -367,7 +369,7 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { | |||
367 | 369 | ||
368 | 370 | ||
369 | LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { | 371 | LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { |
370 | size_t sz = luaO_str2num(s, s2v(L->top)); | 372 | size_t sz = luaO_str2num(s, s2v(L->top.p)); |
371 | if (sz != 0) | 373 | if (sz != 0) |
372 | api_incr_top(L); | 374 | api_incr_top(L); |
373 | return sz; | 375 | return sz; |
@@ -494,7 +496,7 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) { | |||
494 | 496 | ||
495 | LUA_API void lua_pushnil (lua_State *L) { | 497 | LUA_API void lua_pushnil (lua_State *L) { |
496 | lua_lock(L); | 498 | lua_lock(L); |
497 | setnilvalue(s2v(L->top)); | 499 | setnilvalue(s2v(L->top.p)); |
498 | api_incr_top(L); | 500 | api_incr_top(L); |
499 | lua_unlock(L); | 501 | lua_unlock(L); |
500 | } | 502 | } |
@@ -502,7 +504,7 @@ LUA_API void lua_pushnil (lua_State *L) { | |||
502 | 504 | ||
503 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | 505 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { |
504 | lua_lock(L); | 506 | lua_lock(L); |
505 | setfltvalue(s2v(L->top), n); | 507 | setfltvalue(s2v(L->top.p), n); |
506 | api_incr_top(L); | 508 | api_incr_top(L); |
507 | lua_unlock(L); | 509 | lua_unlock(L); |
508 | } | 510 | } |
@@ -510,7 +512,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | |||
510 | 512 | ||
511 | LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { | 513 | LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { |
512 | lua_lock(L); | 514 | lua_lock(L); |
513 | setivalue(s2v(L->top), n); | 515 | setivalue(s2v(L->top.p), n); |
514 | api_incr_top(L); | 516 | api_incr_top(L); |
515 | lua_unlock(L); | 517 | lua_unlock(L); |
516 | } | 518 | } |
@@ -525,7 +527,7 @@ LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { | |||
525 | TString *ts; | 527 | TString *ts; |
526 | lua_lock(L); | 528 | lua_lock(L); |
527 | ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len); | 529 | ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len); |
528 | setsvalue2s(L, L->top, ts); | 530 | setsvalue2s(L, L->top.p, ts); |
529 | api_incr_top(L); | 531 | api_incr_top(L); |
530 | luaC_checkGC(L); | 532 | luaC_checkGC(L); |
531 | lua_unlock(L); | 533 | lua_unlock(L); |
@@ -536,11 +538,11 @@ LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { | |||
536 | LUA_API const char *lua_pushstring (lua_State *L, const char *s) { | 538 | LUA_API const char *lua_pushstring (lua_State *L, const char *s) { |
537 | lua_lock(L); | 539 | lua_lock(L); |
538 | if (s == NULL) | 540 | if (s == NULL) |
539 | setnilvalue(s2v(L->top)); | 541 | setnilvalue(s2v(L->top.p)); |
540 | else { | 542 | else { |
541 | TString *ts; | 543 | TString *ts; |
542 | ts = luaS_new(L, s); | 544 | ts = luaS_new(L, s); |
543 | setsvalue2s(L, L->top, ts); | 545 | setsvalue2s(L, L->top.p, ts); |
544 | s = getstr(ts); /* internal copy's address */ | 546 | s = getstr(ts); /* internal copy's address */ |
545 | } | 547 | } |
546 | api_incr_top(L); | 548 | api_incr_top(L); |
@@ -577,7 +579,7 @@ LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { | |||
577 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | 579 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { |
578 | lua_lock(L); | 580 | lua_lock(L); |
579 | if (n == 0) { | 581 | if (n == 0) { |
580 | setfvalue(s2v(L->top), fn); | 582 | setfvalue(s2v(L->top.p), fn); |
581 | api_incr_top(L); | 583 | api_incr_top(L); |
582 | } | 584 | } |
583 | else { | 585 | else { |
@@ -586,13 +588,13 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | |||
586 | api_check(L, n <= MAXUPVAL, "upvalue index too large"); | 588 | api_check(L, n <= MAXUPVAL, "upvalue index too large"); |
587 | cl = luaF_newCclosure(L, n); | 589 | cl = luaF_newCclosure(L, n); |
588 | cl->f = fn; | 590 | cl->f = fn; |
589 | L->top -= n; | 591 | L->top.p -= n; |
590 | while (n--) { | 592 | while (n--) { |
591 | setobj2n(L, &cl->upvalue[n], s2v(L->top + n)); | 593 | setobj2n(L, &cl->upvalue[n], s2v(L->top.p + n)); |
592 | /* does not need barrier because closure is white */ | 594 | /* does not need barrier because closure is white */ |
593 | lua_assert(iswhite(cl)); | 595 | lua_assert(iswhite(cl)); |
594 | } | 596 | } |
595 | setclCvalue(L, s2v(L->top), cl); | 597 | setclCvalue(L, s2v(L->top.p), cl); |
596 | api_incr_top(L); | 598 | api_incr_top(L); |
597 | luaC_checkGC(L); | 599 | luaC_checkGC(L); |
598 | } | 600 | } |
@@ -603,9 +605,9 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | |||
603 | LUA_API void lua_pushboolean (lua_State *L, int b) { | 605 | LUA_API void lua_pushboolean (lua_State *L, int b) { |
604 | lua_lock(L); | 606 | lua_lock(L); |
605 | if (b) | 607 | if (b) |
606 | setbtvalue(s2v(L->top)); | 608 | setbtvalue(s2v(L->top.p)); |
607 | else | 609 | else |
608 | setbfvalue(s2v(L->top)); | 610 | setbfvalue(s2v(L->top.p)); |
609 | api_incr_top(L); | 611 | api_incr_top(L); |
610 | lua_unlock(L); | 612 | lua_unlock(L); |
611 | } | 613 | } |
@@ -613,7 +615,7 @@ LUA_API void lua_pushboolean (lua_State *L, int b) { | |||
613 | 615 | ||
614 | LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { | 616 | LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { |
615 | lua_lock(L); | 617 | lua_lock(L); |
616 | setpvalue(s2v(L->top), p); | 618 | setpvalue(s2v(L->top.p), p); |
617 | api_incr_top(L); | 619 | api_incr_top(L); |
618 | lua_unlock(L); | 620 | lua_unlock(L); |
619 | } | 621 | } |
@@ -621,7 +623,7 @@ LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { | |||
621 | 623 | ||
622 | LUA_API int lua_pushthread (lua_State *L) { | 624 | LUA_API int lua_pushthread (lua_State *L) { |
623 | lua_lock(L); | 625 | lua_lock(L); |
624 | setthvalue(L, s2v(L->top), L); | 626 | setthvalue(L, s2v(L->top.p), L); |
625 | api_incr_top(L); | 627 | api_incr_top(L); |
626 | lua_unlock(L); | 628 | lua_unlock(L); |
627 | return (G(L)->mainthread == L); | 629 | return (G(L)->mainthread == L); |
@@ -638,16 +640,16 @@ l_sinline int auxgetstr (lua_State *L, const TValue *t, const char *k) { | |||
638 | const TValue *slot; | 640 | const TValue *slot; |
639 | TString *str = luaS_new(L, k); | 641 | TString *str = luaS_new(L, k); |
640 | if (luaV_fastget(L, t, str, slot, luaH_getstr)) { | 642 | if (luaV_fastget(L, t, str, slot, luaH_getstr)) { |
641 | setobj2s(L, L->top, slot); | 643 | setobj2s(L, L->top.p, slot); |
642 | api_incr_top(L); | 644 | api_incr_top(L); |
643 | } | 645 | } |
644 | else { | 646 | else { |
645 | setsvalue2s(L, L->top, str); | 647 | setsvalue2s(L, L->top.p, str); |
646 | api_incr_top(L); | 648 | api_incr_top(L); |
647 | luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot); | 649 | luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot); |
648 | } | 650 | } |
649 | lua_unlock(L); | 651 | lua_unlock(L); |
650 | return ttype(s2v(L->top - 1)); | 652 | return ttype(s2v(L->top.p - 1)); |
651 | } | 653 | } |
652 | 654 | ||
653 | 655 | ||
@@ -674,13 +676,13 @@ LUA_API int lua_gettable (lua_State *L, int idx) { | |||
674 | TValue *t; | 676 | TValue *t; |
675 | lua_lock(L); | 677 | lua_lock(L); |
676 | t = index2value(L, idx); | 678 | t = index2value(L, idx); |
677 | if (luaV_fastget(L, t, s2v(L->top - 1), slot, luaH_get)) { | 679 | if (luaV_fastget(L, t, s2v(L->top.p - 1), slot, luaH_get)) { |
678 | setobj2s(L, L->top - 1, slot); | 680 | setobj2s(L, L->top.p - 1, slot); |
679 | } | 681 | } |
680 | else | 682 | else |
681 | luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot); | 683 | luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot); |
682 | lua_unlock(L); | 684 | lua_unlock(L); |
683 | return ttype(s2v(L->top - 1)); | 685 | return ttype(s2v(L->top.p - 1)); |
684 | } | 686 | } |
685 | 687 | ||
686 | 688 | ||
@@ -696,27 +698,27 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | |||
696 | lua_lock(L); | 698 | lua_lock(L); |
697 | t = index2value(L, idx); | 699 | t = index2value(L, idx); |
698 | if (luaV_fastgeti(L, t, n, slot)) { | 700 | if (luaV_fastgeti(L, t, n, slot)) { |
699 | setobj2s(L, L->top, slot); | 701 | setobj2s(L, L->top.p, slot); |
700 | } | 702 | } |
701 | else { | 703 | else { |
702 | TValue aux; | 704 | TValue aux; |
703 | setivalue(&aux, n); | 705 | setivalue(&aux, n); |
704 | luaV_finishget(L, t, &aux, L->top, slot); | 706 | luaV_finishget(L, t, &aux, L->top.p, slot); |
705 | } | 707 | } |
706 | api_incr_top(L); | 708 | api_incr_top(L); |
707 | lua_unlock(L); | 709 | lua_unlock(L); |
708 | return ttype(s2v(L->top - 1)); | 710 | return ttype(s2v(L->top.p - 1)); |
709 | } | 711 | } |
710 | 712 | ||
711 | 713 | ||
712 | l_sinline int finishrawget (lua_State *L, const TValue *val) { | 714 | l_sinline int finishrawget (lua_State *L, const TValue *val) { |
713 | if (isempty(val)) /* avoid copying empty items to the stack */ | 715 | if (isempty(val)) /* avoid copying empty items to the stack */ |
714 | setnilvalue(s2v(L->top)); | 716 | setnilvalue(s2v(L->top.p)); |
715 | else | 717 | else |
716 | setobj2s(L, L->top, val); | 718 | setobj2s(L, L->top.p, val); |
717 | api_incr_top(L); | 719 | api_incr_top(L); |
718 | lua_unlock(L); | 720 | lua_unlock(L); |
719 | return ttype(s2v(L->top - 1)); | 721 | return ttype(s2v(L->top.p - 1)); |
720 | } | 722 | } |
721 | 723 | ||
722 | 724 | ||
@@ -733,8 +735,8 @@ LUA_API int lua_rawget (lua_State *L, int idx) { | |||
733 | lua_lock(L); | 735 | lua_lock(L); |
734 | api_checknelems(L, 1); | 736 | api_checknelems(L, 1); |
735 | t = gettable(L, idx); | 737 | t = gettable(L, idx); |
736 | val = luaH_get(t, s2v(L->top - 1)); | 738 | val = luaH_get(t, s2v(L->top.p - 1)); |
737 | L->top--; /* remove key */ | 739 | L->top.p--; /* remove key */ |
738 | return finishrawget(L, val); | 740 | return finishrawget(L, val); |
739 | } | 741 | } |
740 | 742 | ||
@@ -761,7 +763,7 @@ LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { | |||
761 | Table *t; | 763 | Table *t; |
762 | lua_lock(L); | 764 | lua_lock(L); |
763 | t = luaH_new(L); | 765 | t = luaH_new(L); |
764 | sethvalue2s(L, L->top, t); | 766 | sethvalue2s(L, L->top.p, t); |
765 | api_incr_top(L); | 767 | api_incr_top(L); |
766 | if (narray > 0 || nrec > 0) | 768 | if (narray > 0 || nrec > 0) |
767 | luaH_resize(L, t, narray, nrec); | 769 | luaH_resize(L, t, narray, nrec); |
@@ -788,7 +790,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { | |||
788 | break; | 790 | break; |
789 | } | 791 | } |
790 | if (mt != NULL) { | 792 | if (mt != NULL) { |
791 | sethvalue2s(L, L->top, mt); | 793 | sethvalue2s(L, L->top.p, mt); |
792 | api_incr_top(L); | 794 | api_incr_top(L); |
793 | res = 1; | 795 | res = 1; |
794 | } | 796 | } |
@@ -804,12 +806,12 @@ LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) { | |||
804 | o = index2value(L, idx); | 806 | o = index2value(L, idx); |
805 | api_check(L, ttisfulluserdata(o), "full userdata expected"); | 807 | api_check(L, ttisfulluserdata(o), "full userdata expected"); |
806 | if (n <= 0 || n > uvalue(o)->nuvalue) { | 808 | if (n <= 0 || n > uvalue(o)->nuvalue) { |
807 | setnilvalue(s2v(L->top)); | 809 | setnilvalue(s2v(L->top.p)); |
808 | t = LUA_TNONE; | 810 | t = LUA_TNONE; |
809 | } | 811 | } |
810 | else { | 812 | else { |
811 | setobj2s(L, L->top, &uvalue(o)->uv[n - 1].uv); | 813 | setobj2s(L, L->top.p, &uvalue(o)->uv[n - 1].uv); |
812 | t = ttype(s2v(L->top)); | 814 | t = ttype(s2v(L->top.p)); |
813 | } | 815 | } |
814 | api_incr_top(L); | 816 | api_incr_top(L); |
815 | lua_unlock(L); | 817 | lua_unlock(L); |
@@ -829,14 +831,14 @@ static void auxsetstr (lua_State *L, const TValue *t, const char *k) { | |||
829 | TString *str = luaS_new(L, k); | 831 | TString *str = luaS_new(L, k); |
830 | api_checknelems(L, 1); | 832 | api_checknelems(L, 1); |
831 | if (luaV_fastget(L, t, str, slot, luaH_getstr)) { | 833 | if (luaV_fastget(L, t, str, slot, luaH_getstr)) { |
832 | luaV_finishfastset(L, t, slot, s2v(L->top - 1)); | 834 | luaV_finishfastset(L, t, slot, s2v(L->top.p - 1)); |
833 | L->top--; /* pop value */ | 835 | L->top.p--; /* pop value */ |
834 | } | 836 | } |
835 | else { | 837 | else { |
836 | setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */ | 838 | setsvalue2s(L, L->top.p, str); /* push 'str' (to make it a TValue) */ |
837 | api_incr_top(L); | 839 | api_incr_top(L); |
838 | luaV_finishset(L, t, s2v(L->top - 1), s2v(L->top - 2), slot); | 840 | luaV_finishset(L, t, s2v(L->top.p - 1), s2v(L->top.p - 2), slot); |
839 | L->top -= 2; /* pop value and key */ | 841 | L->top.p -= 2; /* pop value and key */ |
840 | } | 842 | } |
841 | lua_unlock(L); /* lock done by caller */ | 843 | lua_unlock(L); /* lock done by caller */ |
842 | } | 844 | } |
@@ -856,12 +858,12 @@ LUA_API void lua_settable (lua_State *L, int idx) { | |||
856 | lua_lock(L); | 858 | lua_lock(L); |
857 | api_checknelems(L, 2); | 859 | api_checknelems(L, 2); |
858 | t = index2value(L, idx); | 860 | t = index2value(L, idx); |
859 | if (luaV_fastget(L, t, s2v(L->top - 2), slot, luaH_get)) { | 861 | if (luaV_fastget(L, t, s2v(L->top.p - 2), slot, luaH_get)) { |
860 | luaV_finishfastset(L, t, slot, s2v(L->top - 1)); | 862 | luaV_finishfastset(L, t, slot, s2v(L->top.p - 1)); |
861 | } | 863 | } |
862 | else | 864 | else |
863 | luaV_finishset(L, t, s2v(L->top - 2), s2v(L->top - 1), slot); | 865 | luaV_finishset(L, t, s2v(L->top.p - 2), s2v(L->top.p - 1), slot); |
864 | L->top -= 2; /* pop index and value */ | 866 | L->top.p -= 2; /* pop index and value */ |
865 | lua_unlock(L); | 867 | lua_unlock(L); |
866 | } | 868 | } |
867 | 869 | ||
@@ -879,14 +881,14 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { | |||
879 | api_checknelems(L, 1); | 881 | api_checknelems(L, 1); |
880 | t = index2value(L, idx); | 882 | t = index2value(L, idx); |
881 | if (luaV_fastgeti(L, t, n, slot)) { | 883 | if (luaV_fastgeti(L, t, n, slot)) { |
882 | luaV_finishfastset(L, t, slot, s2v(L->top - 1)); | 884 | luaV_finishfastset(L, t, slot, s2v(L->top.p - 1)); |
883 | } | 885 | } |
884 | else { | 886 | else { |
885 | TValue aux; | 887 | TValue aux; |
886 | setivalue(&aux, n); | 888 | setivalue(&aux, n); |
887 | luaV_finishset(L, t, &aux, s2v(L->top - 1), slot); | 889 | luaV_finishset(L, t, &aux, s2v(L->top.p - 1), slot); |
888 | } | 890 | } |
889 | L->top--; /* pop value */ | 891 | L->top.p--; /* pop value */ |
890 | lua_unlock(L); | 892 | lua_unlock(L); |
891 | } | 893 | } |
892 | 894 | ||
@@ -896,16 +898,16 @@ static void aux_rawset (lua_State *L, int idx, TValue *key, int n) { | |||
896 | lua_lock(L); | 898 | lua_lock(L); |
897 | api_checknelems(L, n); | 899 | api_checknelems(L, n); |
898 | t = gettable(L, idx); | 900 | t = gettable(L, idx); |
899 | luaH_set(L, t, key, s2v(L->top - 1)); | 901 | luaH_set(L, t, key, s2v(L->top.p - 1)); |
900 | invalidateTMcache(t); | 902 | invalidateTMcache(t); |
901 | luaC_barrierback(L, obj2gco(t), s2v(L->top - 1)); | 903 | luaC_barrierback(L, obj2gco(t), s2v(L->top.p - 1)); |
902 | L->top -= n; | 904 | L->top.p -= n; |
903 | lua_unlock(L); | 905 | lua_unlock(L); |
904 | } | 906 | } |
905 | 907 | ||
906 | 908 | ||
907 | LUA_API void lua_rawset (lua_State *L, int idx) { | 909 | LUA_API void lua_rawset (lua_State *L, int idx) { |
908 | aux_rawset(L, idx, s2v(L->top - 2), 2); | 910 | aux_rawset(L, idx, s2v(L->top.p - 2), 2); |
909 | } | 911 | } |
910 | 912 | ||
911 | 913 | ||
@@ -921,9 +923,9 @@ LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { | |||
921 | lua_lock(L); | 923 | lua_lock(L); |
922 | api_checknelems(L, 1); | 924 | api_checknelems(L, 1); |
923 | t = gettable(L, idx); | 925 | t = gettable(L, idx); |
924 | luaH_setint(L, t, n, s2v(L->top - 1)); | 926 | luaH_setint(L, t, n, s2v(L->top.p - 1)); |
925 | luaC_barrierback(L, obj2gco(t), s2v(L->top - 1)); | 927 | luaC_barrierback(L, obj2gco(t), s2v(L->top.p - 1)); |
926 | L->top--; | 928 | L->top.p--; |
927 | lua_unlock(L); | 929 | lua_unlock(L); |
928 | } | 930 | } |
929 | 931 | ||
@@ -934,11 +936,11 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { | |||
934 | lua_lock(L); | 936 | lua_lock(L); |
935 | api_checknelems(L, 1); | 937 | api_checknelems(L, 1); |
936 | obj = index2value(L, objindex); | 938 | obj = index2value(L, objindex); |
937 | if (ttisnil(s2v(L->top - 1))) | 939 | if (ttisnil(s2v(L->top.p - 1))) |
938 | mt = NULL; | 940 | mt = NULL; |
939 | else { | 941 | else { |
940 | api_check(L, ttistable(s2v(L->top - 1)), "table expected"); | 942 | api_check(L, ttistable(s2v(L->top.p - 1)), "table expected"); |
941 | mt = hvalue(s2v(L->top - 1)); | 943 | mt = hvalue(s2v(L->top.p - 1)); |
942 | } | 944 | } |
943 | switch (ttype(obj)) { | 945 | switch (ttype(obj)) { |
944 | case LUA_TTABLE: { | 946 | case LUA_TTABLE: { |
@@ -962,7 +964,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { | |||
962 | break; | 964 | break; |
963 | } | 965 | } |
964 | } | 966 | } |
965 | L->top--; | 967 | L->top.p--; |
966 | lua_unlock(L); | 968 | lua_unlock(L); |
967 | return 1; | 969 | return 1; |
968 | } | 970 | } |
@@ -978,11 +980,11 @@ LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) { | |||
978 | if (!(cast_uint(n) - 1u < cast_uint(uvalue(o)->nuvalue))) | 980 | if (!(cast_uint(n) - 1u < cast_uint(uvalue(o)->nuvalue))) |
979 | res = 0; /* 'n' not in [1, uvalue(o)->nuvalue] */ | 981 | res = 0; /* 'n' not in [1, uvalue(o)->nuvalue] */ |
980 | else { | 982 | else { |
981 | setobj(L, &uvalue(o)->uv[n - 1].uv, s2v(L->top - 1)); | 983 | setobj(L, &uvalue(o)->uv[n - 1].uv, s2v(L->top.p - 1)); |
982 | luaC_barrierback(L, gcvalue(o), s2v(L->top - 1)); | 984 | luaC_barrierback(L, gcvalue(o), s2v(L->top.p - 1)); |
983 | res = 1; | 985 | res = 1; |
984 | } | 986 | } |
985 | L->top--; | 987 | L->top.p--; |
986 | lua_unlock(L); | 988 | lua_unlock(L); |
987 | return res; | 989 | return res; |
988 | } | 990 | } |
@@ -994,7 +996,8 @@ LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) { | |||
994 | 996 | ||
995 | 997 | ||
996 | #define checkresults(L,na,nr) \ | 998 | #define checkresults(L,na,nr) \ |
997 | api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \ | 999 | api_check(L, (nr) == LUA_MULTRET \ |
1000 | || (L->ci->top.p - L->top.p >= (nr) - (na)), \ | ||
998 | "results from function overflow current stack size") | 1001 | "results from function overflow current stack size") |
999 | 1002 | ||
1000 | 1003 | ||
@@ -1007,7 +1010,7 @@ LUA_API void lua_callk (lua_State *L, int nargs, int nresults, | |||
1007 | api_checknelems(L, nargs+1); | 1010 | api_checknelems(L, nargs+1); |
1008 | api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); | 1011 | api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); |
1009 | checkresults(L, nargs, nresults); | 1012 | checkresults(L, nargs, nresults); |
1010 | func = L->top - (nargs+1); | 1013 | func = L->top.p - (nargs+1); |
1011 | if (k != NULL && yieldable(L)) { /* need to prepare continuation? */ | 1014 | if (k != NULL && yieldable(L)) { /* need to prepare continuation? */ |
1012 | L->ci->u.c.k = k; /* save continuation */ | 1015 | L->ci->u.c.k = k; /* save continuation */ |
1013 | L->ci->u.c.ctx = ctx; /* save context */ | 1016 | L->ci->u.c.ctx = ctx; /* save context */ |
@@ -1055,7 +1058,7 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, | |||
1055 | api_check(L, ttisfunction(s2v(o)), "error handler must be a function"); | 1058 | api_check(L, ttisfunction(s2v(o)), "error handler must be a function"); |
1056 | func = savestack(L, o); | 1059 | func = savestack(L, o); |
1057 | } | 1060 | } |
1058 | c.func = L->top - (nargs+1); /* function to be called */ | 1061 | c.func = L->top.p - (nargs+1); /* function to be called */ |
1059 | if (k == NULL || !yieldable(L)) { /* no continuation or no yieldable? */ | 1062 | if (k == NULL || !yieldable(L)) { /* no continuation or no yieldable? */ |
1060 | c.nresults = nresults; /* do a 'conventional' protected call */ | 1063 | c.nresults = nresults; /* do a 'conventional' protected call */ |
1061 | status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); | 1064 | status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); |
@@ -1090,12 +1093,12 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, | |||
1090 | luaZ_init(L, &z, reader, data); | 1093 | luaZ_init(L, &z, reader, data); |
1091 | status = luaD_protectedparser(L, &z, chunkname, mode); | 1094 | status = luaD_protectedparser(L, &z, chunkname, mode); |
1092 | if (status == LUA_OK) { /* no errors? */ | 1095 | if (status == LUA_OK) { /* no errors? */ |
1093 | LClosure *f = clLvalue(s2v(L->top - 1)); /* get newly created function */ | 1096 | LClosure *f = clLvalue(s2v(L->top.p - 1)); /* get new function */ |
1094 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ | 1097 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ |
1095 | /* get global table from registry */ | 1098 | /* get global table from registry */ |
1096 | const TValue *gt = getGtable(L); | 1099 | const TValue *gt = getGtable(L); |
1097 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ | 1100 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ |
1098 | setobj(L, f->upvals[0]->v, gt); | 1101 | setobj(L, f->upvals[0]->v.p, gt); |
1099 | luaC_barrier(L, f->upvals[0], gt); | 1102 | luaC_barrier(L, f->upvals[0], gt); |
1100 | } | 1103 | } |
1101 | } | 1104 | } |
@@ -1109,7 +1112,7 @@ LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) { | |||
1109 | TValue *o; | 1112 | TValue *o; |
1110 | lua_lock(L); | 1113 | lua_lock(L); |
1111 | api_checknelems(L, 1); | 1114 | api_checknelems(L, 1); |
1112 | o = s2v(L->top - 1); | 1115 | o = s2v(L->top.p - 1); |
1113 | if (isLfunction(o)) | 1116 | if (isLfunction(o)) |
1114 | status = luaU_dump(L, getproto(o), writer, data, strip); | 1117 | status = luaU_dump(L, getproto(o), writer, data, strip); |
1115 | else | 1118 | else |
@@ -1235,7 +1238,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) { | |||
1235 | LUA_API int lua_error (lua_State *L) { | 1238 | LUA_API int lua_error (lua_State *L) { |
1236 | TValue *errobj; | 1239 | TValue *errobj; |
1237 | lua_lock(L); | 1240 | lua_lock(L); |
1238 | errobj = s2v(L->top - 1); | 1241 | errobj = s2v(L->top.p - 1); |
1239 | api_checknelems(L, 1); | 1242 | api_checknelems(L, 1); |
1240 | /* error object is the memory error message? */ | 1243 | /* error object is the memory error message? */ |
1241 | if (ttisshrstring(errobj) && eqshrstr(tsvalue(errobj), G(L)->memerrmsg)) | 1244 | if (ttisshrstring(errobj) && eqshrstr(tsvalue(errobj), G(L)->memerrmsg)) |
@@ -1253,12 +1256,12 @@ LUA_API int lua_next (lua_State *L, int idx) { | |||
1253 | lua_lock(L); | 1256 | lua_lock(L); |
1254 | api_checknelems(L, 1); | 1257 | api_checknelems(L, 1); |
1255 | t = gettable(L, idx); | 1258 | t = gettable(L, idx); |
1256 | more = luaH_next(L, t, L->top - 1); | 1259 | more = luaH_next(L, t, L->top.p - 1); |
1257 | if (more) { | 1260 | if (more) { |
1258 | api_incr_top(L); | 1261 | api_incr_top(L); |
1259 | } | 1262 | } |
1260 | else /* no more elements */ | 1263 | else /* no more elements */ |
1261 | L->top -= 1; /* remove key */ | 1264 | L->top.p -= 1; /* remove key */ |
1262 | lua_unlock(L); | 1265 | lua_unlock(L); |
1263 | return more; | 1266 | return more; |
1264 | } | 1267 | } |
@@ -1270,7 +1273,7 @@ LUA_API void lua_toclose (lua_State *L, int idx) { | |||
1270 | lua_lock(L); | 1273 | lua_lock(L); |
1271 | o = index2stack(L, idx); | 1274 | o = index2stack(L, idx); |
1272 | nresults = L->ci->nresults; | 1275 | nresults = L->ci->nresults; |
1273 | api_check(L, L->tbclist < o, "given index below or equal a marked one"); | 1276 | api_check(L, L->tbclist.p < o, "given index below or equal a marked one"); |
1274 | luaF_newtbcupval(L, o); /* create new to-be-closed upvalue */ | 1277 | luaF_newtbcupval(L, o); /* create new to-be-closed upvalue */ |
1275 | if (!hastocloseCfunc(nresults)) /* function not marked yet? */ | 1278 | if (!hastocloseCfunc(nresults)) /* function not marked yet? */ |
1276 | L->ci->nresults = codeNresults(nresults); /* mark it */ | 1279 | L->ci->nresults = codeNresults(nresults); /* mark it */ |
@@ -1285,7 +1288,7 @@ LUA_API void lua_concat (lua_State *L, int n) { | |||
1285 | if (n > 0) | 1288 | if (n > 0) |
1286 | luaV_concat(L, n); | 1289 | luaV_concat(L, n); |
1287 | else { /* nothing to concatenate */ | 1290 | else { /* nothing to concatenate */ |
1288 | setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); /* push empty string */ | 1291 | setsvalue2s(L, L->top.p, luaS_newlstr(L, "", 0)); /* push empty string */ |
1289 | api_incr_top(L); | 1292 | api_incr_top(L); |
1290 | } | 1293 | } |
1291 | luaC_checkGC(L); | 1294 | luaC_checkGC(L); |
@@ -1297,7 +1300,7 @@ LUA_API void lua_len (lua_State *L, int idx) { | |||
1297 | TValue *t; | 1300 | TValue *t; |
1298 | lua_lock(L); | 1301 | lua_lock(L); |
1299 | t = index2value(L, idx); | 1302 | t = index2value(L, idx); |
1300 | luaV_objlen(L, L->top, t); | 1303 | luaV_objlen(L, L->top.p, t); |
1301 | api_incr_top(L); | 1304 | api_incr_top(L); |
1302 | lua_unlock(L); | 1305 | lua_unlock(L); |
1303 | } | 1306 | } |
@@ -1342,7 +1345,7 @@ LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) { | |||
1342 | lua_lock(L); | 1345 | lua_lock(L); |
1343 | api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, "invalid value"); | 1346 | api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, "invalid value"); |
1344 | u = luaS_newudata(L, size, nuvalue); | 1347 | u = luaS_newudata(L, size, nuvalue); |
1345 | setuvalue(L, s2v(L->top), u); | 1348 | setuvalue(L, s2v(L->top.p), u); |
1346 | api_incr_top(L); | 1349 | api_incr_top(L); |
1347 | luaC_checkGC(L); | 1350 | luaC_checkGC(L); |
1348 | lua_unlock(L); | 1351 | lua_unlock(L); |
@@ -1368,7 +1371,7 @@ static const char *aux_upvalue (TValue *fi, int n, TValue **val, | |||
1368 | Proto *p = f->p; | 1371 | Proto *p = f->p; |
1369 | if (!(cast_uint(n) - 1u < cast_uint(p->sizeupvalues))) | 1372 | if (!(cast_uint(n) - 1u < cast_uint(p->sizeupvalues))) |
1370 | return NULL; /* 'n' not in [1, p->sizeupvalues] */ | 1373 | return NULL; /* 'n' not in [1, p->sizeupvalues] */ |
1371 | *val = f->upvals[n-1]->v; | 1374 | *val = f->upvals[n-1]->v.p; |
1372 | if (owner) *owner = obj2gco(f->upvals[n - 1]); | 1375 | if (owner) *owner = obj2gco(f->upvals[n - 1]); |
1373 | name = p->upvalues[n-1].name; | 1376 | name = p->upvalues[n-1].name; |
1374 | return (name == NULL) ? "(no name)" : getstr(name); | 1377 | return (name == NULL) ? "(no name)" : getstr(name); |
@@ -1384,7 +1387,7 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { | |||
1384 | lua_lock(L); | 1387 | lua_lock(L); |
1385 | name = aux_upvalue(index2value(L, funcindex), n, &val, NULL); | 1388 | name = aux_upvalue(index2value(L, funcindex), n, &val, NULL); |
1386 | if (name) { | 1389 | if (name) { |
1387 | setobj2s(L, L->top, val); | 1390 | setobj2s(L, L->top.p, val); |
1388 | api_incr_top(L); | 1391 | api_incr_top(L); |
1389 | } | 1392 | } |
1390 | lua_unlock(L); | 1393 | lua_unlock(L); |
@@ -1402,8 +1405,8 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { | |||
1402 | api_checknelems(L, 1); | 1405 | api_checknelems(L, 1); |
1403 | name = aux_upvalue(fi, n, &val, &owner); | 1406 | name = aux_upvalue(fi, n, &val, &owner); |
1404 | if (name) { | 1407 | if (name) { |
1405 | L->top--; | 1408 | L->top.p--; |
1406 | setobj(L, val, s2v(L->top)); | 1409 | setobj(L, val, s2v(L->top.p)); |
1407 | luaC_barrier(L, owner, val); | 1410 | luaC_barrier(L, owner, val); |
1408 | } | 1411 | } |
1409 | lua_unlock(L); | 1412 | lua_unlock(L); |