diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-06-29 12:06:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-06-29 12:06:44 -0300 |
commit | f96497397addca22f22a6ba6eeabc906be43f16b (patch) | |
tree | af8d27b9af36dfe0b0b6e0f765ea90b95b110efc /lapi.c | |
parent | 5a1c8d8ef343bf0157851a4832c2c937b812b64f (diff) | |
download | lua-f96497397addca22f22a6ba6eeabc906be43f16b.tar.gz lua-f96497397addca22f22a6ba6eeabc906be43f16b.tar.bz2 lua-f96497397addca22f22a6ba6eeabc906be43f16b.zip |
new type 'StackValue' for stack elements
(we may want to put extra info there in the future)
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 268 |
1 files changed, 142 insertions, 126 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.268 2017/05/26 19:14:29 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.269 2017/06/01 20:22:33 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 | */ |
@@ -57,33 +57,48 @@ const char lua_ident[] = | |||
57 | api_check(l, isstackindex(i, o), "index not in the stack") | 57 | api_check(l, isstackindex(i, o), "index not in the stack") |
58 | 58 | ||
59 | 59 | ||
60 | static TValue *index2addr (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 | TValue *o = ci->func + idx; | 63 | StkId o = ci->func + idx; |
64 | api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index"); | 64 | api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index"); |
65 | if (o >= L->top) return NONVALIDVALUE; | 65 | if (o >= L->top) return NONVALIDVALUE; |
66 | else return 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 - (ci->func + 1), "invalid index"); |
70 | return L->top + idx; | 70 | return s2v(L->top + idx); |
71 | } | 71 | } |
72 | else if (idx == LUA_REGISTRYINDEX) | 72 | else if (idx == LUA_REGISTRYINDEX) |
73 | return &G(L)->l_registry; | 73 | return &G(L)->l_registry; |
74 | else { /* upvalues */ | 74 | else { /* upvalues */ |
75 | idx = LUA_REGISTRYINDEX - idx; | 75 | idx = LUA_REGISTRYINDEX - idx; |
76 | api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); | 76 | api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); |
77 | if (ttislcf(ci->func)) /* light C function? */ | 77 | if (ttislcf(s2v(ci->func))) /* light C function? */ |
78 | return NONVALIDVALUE; /* it has no upvalues */ | 78 | return NONVALIDVALUE; /* it has no upvalues */ |
79 | else { | 79 | else { |
80 | CClosure *func = clCvalue(ci->func); | 80 | CClosure *func = clCvalue(s2v(ci->func)); |
81 | return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE; | 81 | return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE; |
82 | } | 82 | } |
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
87 | static StkId index2stack (lua_State *L, int idx) { | ||
88 | CallInfo *ci = L->ci; | ||
89 | if (idx > 0) { | ||
90 | StkId o = ci->func + idx; | ||
91 | api_check(L, o < L->top, "unacceptable index"); | ||
92 | return o; | ||
93 | } | ||
94 | else { /* non-positive index */ | ||
95 | api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); | ||
96 | api_check(L, !ispseudo(idx), "invalid index"); | ||
97 | return L->top + idx; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | |||
87 | /* | 102 | /* |
88 | ** to be called by 'lua_checkstack' in protected mode, to grow stack | 103 | ** to be called by 'lua_checkstack' in protected mode, to grow stack |
89 | ** capturing memory errors | 104 | ** capturing memory errors |
@@ -124,7 +139,7 @@ LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { | |||
124 | api_check(from, to->ci->top - to->top >= n, "stack overflow"); | 139 | api_check(from, to->ci->top - to->top >= n, "stack overflow"); |
125 | from->top -= n; | 140 | from->top -= n; |
126 | for (i = 0; i < n; i++) { | 141 | for (i = 0; i < n; i++) { |
127 | setobj2s(to, to->top, from->top + i); | 142 | setobjs2s(to, to->top, from->top + i); |
128 | to->top++; /* stack already checked by previous 'api_check' */ | 143 | to->top++; /* stack already checked by previous 'api_check' */ |
129 | } | 144 | } |
130 | lua_unlock(to); | 145 | lua_unlock(to); |
@@ -175,7 +190,7 @@ LUA_API void lua_settop (lua_State *L, int idx) { | |||
175 | if (idx >= 0) { | 190 | if (idx >= 0) { |
176 | api_check(L, idx <= L->stack_last - (func + 1), "new top too large"); | 191 | api_check(L, idx <= L->stack_last - (func + 1), "new top too large"); |
177 | while (L->top < (func + 1) + idx) | 192 | while (L->top < (func + 1) + idx) |
178 | setnilvalue(L->top++); | 193 | setnilvalue(s2v(L->top++)); |
179 | L->top = (func + 1) + idx; | 194 | L->top = (func + 1) + idx; |
180 | } | 195 | } |
181 | else { | 196 | else { |
@@ -189,11 +204,13 @@ LUA_API void lua_settop (lua_State *L, int idx) { | |||
189 | /* | 204 | /* |
190 | ** Reverse the stack segment from 'from' to 'to' | 205 | ** Reverse the stack segment from 'from' to 'to' |
191 | ** (auxiliary to 'lua_rotate') | 206 | ** (auxiliary to 'lua_rotate') |
207 | ** Note that we move(copy) only the value inside the stack. | ||
208 | ** (We do not move addicional fields that may exist.) | ||
192 | */ | 209 | */ |
193 | static void reverse (lua_State *L, StkId from, StkId to) { | 210 | static void reverse (lua_State *L, StkId from, StkId to) { |
194 | for (; from < to; from++, to--) { | 211 | for (; from < to; from++, to--) { |
195 | TValue temp; | 212 | TValue temp; |
196 | setobj(L, &temp, from); | 213 | setobj(L, &temp, s2v(from)); |
197 | setobjs2s(L, from, to); | 214 | setobjs2s(L, from, to); |
198 | setobj2s(L, to, &temp); | 215 | setobj2s(L, to, &temp); |
199 | } | 216 | } |
@@ -208,8 +225,7 @@ LUA_API void lua_rotate (lua_State *L, int idx, int n) { | |||
208 | StkId p, t, m; | 225 | StkId p, t, m; |
209 | lua_lock(L); | 226 | lua_lock(L); |
210 | t = L->top - 1; /* end of stack segment being rotated */ | 227 | t = L->top - 1; /* end of stack segment being rotated */ |
211 | p = index2addr(L, idx); /* start of segment */ | 228 | p = index2stack(L, idx); /* start of segment */ |
212 | api_checkstackindex(L, idx, p); | ||
213 | api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); | 229 | api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); |
214 | m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ | 230 | m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ |
215 | reverse(L, p, m); /* reverse the prefix with length 'n' */ | 231 | reverse(L, p, m); /* reverse the prefix with length 'n' */ |
@@ -222,12 +238,12 @@ LUA_API void lua_rotate (lua_State *L, int idx, int n) { | |||
222 | LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { | 238 | LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { |
223 | TValue *fr, *to; | 239 | TValue *fr, *to; |
224 | lua_lock(L); | 240 | lua_lock(L); |
225 | fr = index2addr(L, fromidx); | 241 | fr = index2value(L, fromidx); |
226 | to = index2addr(L, toidx); | 242 | to = index2value(L, toidx); |
227 | api_checkvalidindex(L, to); | 243 | api_checkvalidindex(L, to); |
228 | setobj(L, to, fr); | 244 | setobj(L, to, fr); |
229 | if (isupvalue(toidx)) /* function upvalue? */ | 245 | if (isupvalue(toidx)) /* function upvalue? */ |
230 | luaC_barrier(L, clCvalue(L->ci->func), fr); | 246 | luaC_barrier(L, clCvalue(s2v(L->ci->func)), fr); |
231 | /* LUA_REGISTRYINDEX does not need gc barrier | 247 | /* LUA_REGISTRYINDEX does not need gc barrier |
232 | (collector revisits it before finishing collection) */ | 248 | (collector revisits it before finishing collection) */ |
233 | lua_unlock(L); | 249 | lua_unlock(L); |
@@ -236,7 +252,7 @@ LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { | |||
236 | 252 | ||
237 | LUA_API void lua_pushvalue (lua_State *L, int idx) { | 253 | LUA_API void lua_pushvalue (lua_State *L, int idx) { |
238 | lua_lock(L); | 254 | lua_lock(L); |
239 | setobj2s(L, L->top, index2addr(L, idx)); | 255 | setobj2s(L, L->top, index2value(L, idx)); |
240 | api_incr_top(L); | 256 | api_incr_top(L); |
241 | lua_unlock(L); | 257 | lua_unlock(L); |
242 | } | 258 | } |
@@ -249,7 +265,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { | |||
249 | 265 | ||
250 | 266 | ||
251 | LUA_API int lua_type (lua_State *L, int idx) { | 267 | LUA_API int lua_type (lua_State *L, int idx) { |
252 | StkId o = index2addr(L, idx); | 268 | const TValue *o = index2value(L, idx); |
253 | return (isvalid(o) ? ttnov(o) : LUA_TNONE); | 269 | return (isvalid(o) ? ttnov(o) : LUA_TNONE); |
254 | } | 270 | } |
255 | 271 | ||
@@ -262,39 +278,39 @@ LUA_API const char *lua_typename (lua_State *L, int t) { | |||
262 | 278 | ||
263 | 279 | ||
264 | LUA_API int lua_iscfunction (lua_State *L, int idx) { | 280 | LUA_API int lua_iscfunction (lua_State *L, int idx) { |
265 | StkId o = index2addr(L, idx); | 281 | const TValue *o = index2value(L, idx); |
266 | return (ttislcf(o) || (ttisCclosure(o))); | 282 | return (ttislcf(o) || (ttisCclosure(o))); |
267 | } | 283 | } |
268 | 284 | ||
269 | 285 | ||
270 | LUA_API int lua_isinteger (lua_State *L, int idx) { | 286 | LUA_API int lua_isinteger (lua_State *L, int idx) { |
271 | StkId o = index2addr(L, idx); | 287 | const TValue *o = index2value(L, idx); |
272 | return ttisinteger(o); | 288 | return ttisinteger(o); |
273 | } | 289 | } |
274 | 290 | ||
275 | 291 | ||
276 | LUA_API int lua_isnumber (lua_State *L, int idx) { | 292 | LUA_API int lua_isnumber (lua_State *L, int idx) { |
277 | lua_Number n; | 293 | lua_Number n; |
278 | const TValue *o = index2addr(L, idx); | 294 | const TValue *o = index2value(L, idx); |
279 | return tonumber(o, &n); | 295 | return tonumber(o, &n); |
280 | } | 296 | } |
281 | 297 | ||
282 | 298 | ||
283 | LUA_API int lua_isstring (lua_State *L, int idx) { | 299 | LUA_API int lua_isstring (lua_State *L, int idx) { |
284 | const TValue *o = index2addr(L, idx); | 300 | const TValue *o = index2value(L, idx); |
285 | return (ttisstring(o) || cvt2str(o)); | 301 | return (ttisstring(o) || cvt2str(o)); |
286 | } | 302 | } |
287 | 303 | ||
288 | 304 | ||
289 | LUA_API int lua_isuserdata (lua_State *L, int idx) { | 305 | LUA_API int lua_isuserdata (lua_State *L, int idx) { |
290 | const TValue *o = index2addr(L, idx); | 306 | const TValue *o = index2value(L, idx); |
291 | return (ttisfulluserdata(o) || ttislightuserdata(o)); | 307 | return (ttisfulluserdata(o) || ttislightuserdata(o)); |
292 | } | 308 | } |
293 | 309 | ||
294 | 310 | ||
295 | LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { | 311 | LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { |
296 | StkId o1 = index2addr(L, index1); | 312 | const TValue *o1 = index2value(L, index1); |
297 | StkId o2 = index2addr(L, index2); | 313 | const TValue *o2 = index2value(L, index2); |
298 | return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0; | 314 | return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0; |
299 | } | 315 | } |
300 | 316 | ||
@@ -309,18 +325,19 @@ LUA_API void lua_arith (lua_State *L, int op) { | |||
309 | api_incr_top(L); | 325 | api_incr_top(L); |
310 | } | 326 | } |
311 | /* first operand at top - 2, second at top - 1; result go to top - 2 */ | 327 | /* first operand at top - 2, second at top - 1; result go to top - 2 */ |
312 | luaO_arith(L, op, L->top - 2, L->top - 1, L->top - 2); | 328 | luaO_arith(L, op, s2v(L->top - 2), s2v(L->top - 1), L->top - 2); |
313 | L->top--; /* remove second operand */ | 329 | L->top--; /* remove second operand */ |
314 | lua_unlock(L); | 330 | lua_unlock(L); |
315 | } | 331 | } |
316 | 332 | ||
317 | 333 | ||
318 | LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { | 334 | LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { |
319 | StkId o1, o2; | 335 | const TValue *o1; |
336 | const TValue *o2; | ||
320 | int i = 0; | 337 | int i = 0; |
321 | lua_lock(L); /* may call tag method */ | 338 | lua_lock(L); /* may call tag method */ |
322 | o1 = index2addr(L, index1); | 339 | o1 = index2value(L, index1); |
323 | o2 = index2addr(L, index2); | 340 | o2 = index2value(L, index2); |
324 | if (isvalid(o1) && isvalid(o2)) { | 341 | if (isvalid(o1) && isvalid(o2)) { |
325 | switch (op) { | 342 | switch (op) { |
326 | case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break; | 343 | case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break; |
@@ -335,7 +352,7 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { | |||
335 | 352 | ||
336 | 353 | ||
337 | LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { | 354 | LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { |
338 | size_t sz = luaO_str2num(s, L->top); | 355 | size_t sz = luaO_str2num(s, s2v(L->top)); |
339 | if (sz != 0) | 356 | if (sz != 0) |
340 | api_incr_top(L); | 357 | api_incr_top(L); |
341 | return sz; | 358 | return sz; |
@@ -344,7 +361,7 @@ LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { | |||
344 | 361 | ||
345 | LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { | 362 | LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { |
346 | lua_Number n; | 363 | lua_Number n; |
347 | const TValue *o = index2addr(L, idx); | 364 | const TValue *o = index2value(L, idx); |
348 | int isnum = tonumber(o, &n); | 365 | int isnum = tonumber(o, &n); |
349 | if (!isnum) | 366 | if (!isnum) |
350 | n = 0; /* call to 'tonumber' may change 'n' even if it fails */ | 367 | n = 0; /* call to 'tonumber' may change 'n' even if it fails */ |
@@ -355,7 +372,7 @@ LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { | |||
355 | 372 | ||
356 | LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { | 373 | LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { |
357 | lua_Integer res; | 374 | lua_Integer res; |
358 | const TValue *o = index2addr(L, idx); | 375 | const TValue *o = index2value(L, idx); |
359 | int isnum = tointeger(o, &res); | 376 | int isnum = tointeger(o, &res); |
360 | if (!isnum) | 377 | if (!isnum) |
361 | res = 0; /* call to 'tointeger' may change 'n' even if it fails */ | 378 | res = 0; /* call to 'tointeger' may change 'n' even if it fails */ |
@@ -365,13 +382,13 @@ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { | |||
365 | 382 | ||
366 | 383 | ||
367 | LUA_API int lua_toboolean (lua_State *L, int idx) { | 384 | LUA_API int lua_toboolean (lua_State *L, int idx) { |
368 | const TValue *o = index2addr(L, idx); | 385 | const TValue *o = index2value(L, idx); |
369 | return !l_isfalse(o); | 386 | return !l_isfalse(o); |
370 | } | 387 | } |
371 | 388 | ||
372 | 389 | ||
373 | LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { | 390 | LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { |
374 | StkId o = index2addr(L, idx); | 391 | TValue *o = index2value(L, idx); |
375 | if (!ttisstring(o)) { | 392 | if (!ttisstring(o)) { |
376 | if (!cvt2str(o)) { /* not convertible? */ | 393 | if (!cvt2str(o)) { /* not convertible? */ |
377 | if (len != NULL) *len = 0; | 394 | if (len != NULL) *len = 0; |
@@ -380,7 +397,7 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { | |||
380 | lua_lock(L); /* 'luaO_tostring' may create a new string */ | 397 | lua_lock(L); /* 'luaO_tostring' may create a new string */ |
381 | luaO_tostring(L, o); | 398 | luaO_tostring(L, o); |
382 | luaC_checkGC(L); | 399 | luaC_checkGC(L); |
383 | o = index2addr(L, idx); /* previous call may reallocate the stack */ | 400 | o = index2value(L, idx); /* previous call may reallocate the stack */ |
384 | lua_unlock(L); | 401 | lua_unlock(L); |
385 | } | 402 | } |
386 | if (len != NULL) | 403 | if (len != NULL) |
@@ -390,7 +407,7 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { | |||
390 | 407 | ||
391 | 408 | ||
392 | LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) { | 409 | LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) { |
393 | StkId o = index2addr(L, idx); | 410 | const TValue *o = index2value(L, idx); |
394 | switch (ttype(o)) { | 411 | switch (ttype(o)) { |
395 | case LUA_TSHRSTR: return tsvalue(o)->shrlen; | 412 | case LUA_TSHRSTR: return tsvalue(o)->shrlen; |
396 | case LUA_TLNGSTR: return tsvalue(o)->u.lnglen; | 413 | case LUA_TLNGSTR: return tsvalue(o)->u.lnglen; |
@@ -402,7 +419,7 @@ LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) { | |||
402 | 419 | ||
403 | 420 | ||
404 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { | 421 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { |
405 | StkId o = index2addr(L, idx); | 422 | const TValue *o = index2value(L, idx); |
406 | if (ttislcf(o)) return fvalue(o); | 423 | if (ttislcf(o)) return fvalue(o); |
407 | else if (ttisCclosure(o)) | 424 | else if (ttisCclosure(o)) |
408 | return clCvalue(o)->f; | 425 | return clCvalue(o)->f; |
@@ -411,7 +428,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { | |||
411 | 428 | ||
412 | 429 | ||
413 | LUA_API void *lua_touserdata (lua_State *L, int idx) { | 430 | LUA_API void *lua_touserdata (lua_State *L, int idx) { |
414 | StkId o = index2addr(L, idx); | 431 | const TValue *o = index2value(L, idx); |
415 | switch (ttnov(o)) { | 432 | switch (ttnov(o)) { |
416 | case LUA_TUSERDATA: return getudatamem(uvalue(o)); | 433 | case LUA_TUSERDATA: return getudatamem(uvalue(o)); |
417 | case LUA_TLIGHTUSERDATA: return pvalue(o); | 434 | case LUA_TLIGHTUSERDATA: return pvalue(o); |
@@ -421,13 +438,13 @@ LUA_API void *lua_touserdata (lua_State *L, int idx) { | |||
421 | 438 | ||
422 | 439 | ||
423 | LUA_API lua_State *lua_tothread (lua_State *L, int idx) { | 440 | LUA_API lua_State *lua_tothread (lua_State *L, int idx) { |
424 | StkId o = index2addr(L, idx); | 441 | const TValue *o = index2value(L, idx); |
425 | return (!ttisthread(o)) ? NULL : thvalue(o); | 442 | return (!ttisthread(o)) ? NULL : thvalue(o); |
426 | } | 443 | } |
427 | 444 | ||
428 | 445 | ||
429 | LUA_API const void *lua_topointer (lua_State *L, int idx) { | 446 | LUA_API const void *lua_topointer (lua_State *L, int idx) { |
430 | StkId o = index2addr(L, idx); | 447 | const TValue *o = index2value(L, idx); |
431 | switch (ttype(o)) { | 448 | switch (ttype(o)) { |
432 | case LUA_TTABLE: return hvalue(o); | 449 | case LUA_TTABLE: return hvalue(o); |
433 | case LUA_TLCL: return clLvalue(o); | 450 | case LUA_TLCL: return clLvalue(o); |
@@ -449,7 +466,7 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) { | |||
449 | 466 | ||
450 | LUA_API void lua_pushnil (lua_State *L) { | 467 | LUA_API void lua_pushnil (lua_State *L) { |
451 | lua_lock(L); | 468 | lua_lock(L); |
452 | setnilvalue(L->top); | 469 | setnilvalue(s2v(L->top)); |
453 | api_incr_top(L); | 470 | api_incr_top(L); |
454 | lua_unlock(L); | 471 | lua_unlock(L); |
455 | } | 472 | } |
@@ -457,7 +474,7 @@ LUA_API void lua_pushnil (lua_State *L) { | |||
457 | 474 | ||
458 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | 475 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { |
459 | lua_lock(L); | 476 | lua_lock(L); |
460 | setfltvalue(L->top, n); | 477 | setfltvalue(s2v(L->top), n); |
461 | api_incr_top(L); | 478 | api_incr_top(L); |
462 | lua_unlock(L); | 479 | lua_unlock(L); |
463 | } | 480 | } |
@@ -465,7 +482,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | |||
465 | 482 | ||
466 | LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { | 483 | LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { |
467 | lua_lock(L); | 484 | lua_lock(L); |
468 | setivalue(L->top, n); | 485 | setivalue(s2v(L->top), n); |
469 | api_incr_top(L); | 486 | api_incr_top(L); |
470 | lua_unlock(L); | 487 | lua_unlock(L); |
471 | } | 488 | } |
@@ -491,7 +508,7 @@ LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { | |||
491 | LUA_API const char *lua_pushstring (lua_State *L, const char *s) { | 508 | LUA_API const char *lua_pushstring (lua_State *L, const char *s) { |
492 | lua_lock(L); | 509 | lua_lock(L); |
493 | if (s == NULL) | 510 | if (s == NULL) |
494 | setnilvalue(L->top); | 511 | setnilvalue(s2v(L->top)); |
495 | else { | 512 | else { |
496 | TString *ts; | 513 | TString *ts; |
497 | ts = luaS_new(L, s); | 514 | ts = luaS_new(L, s); |
@@ -532,7 +549,7 @@ LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { | |||
532 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | 549 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { |
533 | lua_lock(L); | 550 | lua_lock(L); |
534 | if (n == 0) { | 551 | if (n == 0) { |
535 | setfvalue(L->top, fn); | 552 | setfvalue(s2v(L->top), fn); |
536 | } | 553 | } |
537 | else { | 554 | else { |
538 | CClosure *cl; | 555 | CClosure *cl; |
@@ -542,10 +559,10 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | |||
542 | cl->f = fn; | 559 | cl->f = fn; |
543 | L->top -= n; | 560 | L->top -= n; |
544 | while (n--) { | 561 | while (n--) { |
545 | setobj2n(L, &cl->upvalue[n], L->top + n); | 562 | setobj2n(L, &cl->upvalue[n], s2v(L->top + n)); |
546 | /* does not need barrier because closure is white */ | 563 | /* does not need barrier because closure is white */ |
547 | } | 564 | } |
548 | setclCvalue(L, L->top, cl); | 565 | setclCvalue(L, s2v(L->top), cl); |
549 | } | 566 | } |
550 | api_incr_top(L); | 567 | api_incr_top(L); |
551 | luaC_checkGC(L); | 568 | luaC_checkGC(L); |
@@ -555,7 +572,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | |||
555 | 572 | ||
556 | LUA_API void lua_pushboolean (lua_State *L, int b) { | 573 | LUA_API void lua_pushboolean (lua_State *L, int b) { |
557 | lua_lock(L); | 574 | lua_lock(L); |
558 | setbvalue(L->top, (b != 0)); /* ensure that true is 1 */ | 575 | setbvalue(s2v(L->top), (b != 0)); /* ensure that true is 1 */ |
559 | api_incr_top(L); | 576 | api_incr_top(L); |
560 | lua_unlock(L); | 577 | lua_unlock(L); |
561 | } | 578 | } |
@@ -563,7 +580,7 @@ LUA_API void lua_pushboolean (lua_State *L, int b) { | |||
563 | 580 | ||
564 | LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { | 581 | LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { |
565 | lua_lock(L); | 582 | lua_lock(L); |
566 | setpvalue(L->top, p); | 583 | setpvalue(s2v(L->top), p); |
567 | api_incr_top(L); | 584 | api_incr_top(L); |
568 | lua_unlock(L); | 585 | lua_unlock(L); |
569 | } | 586 | } |
@@ -571,7 +588,7 @@ LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { | |||
571 | 588 | ||
572 | LUA_API int lua_pushthread (lua_State *L) { | 589 | LUA_API int lua_pushthread (lua_State *L) { |
573 | lua_lock(L); | 590 | lua_lock(L); |
574 | setthvalue(L, L->top, L); | 591 | setthvalue(L, s2v(L->top), L); |
575 | api_incr_top(L); | 592 | api_incr_top(L); |
576 | lua_unlock(L); | 593 | lua_unlock(L); |
577 | return (G(L)->mainthread == L); | 594 | return (G(L)->mainthread == L); |
@@ -594,10 +611,10 @@ static int auxgetstr (lua_State *L, const TValue *t, const char *k) { | |||
594 | else { | 611 | else { |
595 | setsvalue2s(L, L->top, str); | 612 | setsvalue2s(L, L->top, str); |
596 | api_incr_top(L); | 613 | api_incr_top(L); |
597 | luaV_finishget(L, t, L->top - 1, L->top - 1, slot); | 614 | luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot); |
598 | } | 615 | } |
599 | lua_unlock(L); | 616 | lua_unlock(L); |
600 | return ttnov(L->top - 1); | 617 | return ttnov(s2v(L->top - 1)); |
601 | } | 618 | } |
602 | 619 | ||
603 | 620 | ||
@@ -610,30 +627,30 @@ LUA_API int lua_getglobal (lua_State *L, const char *name) { | |||
610 | 627 | ||
611 | LUA_API int lua_gettable (lua_State *L, int idx) { | 628 | LUA_API int lua_gettable (lua_State *L, int idx) { |
612 | const TValue *slot; | 629 | const TValue *slot; |
613 | StkId t; | 630 | TValue *t; |
614 | lua_lock(L); | 631 | lua_lock(L); |
615 | t = index2addr(L, idx); | 632 | t = index2value(L, idx); |
616 | if (luaV_fastget(L, t, L->top - 1, slot, luaH_get)) { | 633 | if (luaV_fastget(L, t, s2v(L->top - 1), slot, luaH_get)) { |
617 | setobj2s(L, L->top - 1, slot); | 634 | setobj2s(L, L->top - 1, slot); |
618 | } | 635 | } |
619 | else | 636 | else |
620 | luaV_finishget(L, t, L->top - 1, L->top - 1, slot); | 637 | luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot); |
621 | lua_unlock(L); | 638 | lua_unlock(L); |
622 | return ttnov(L->top - 1); | 639 | return ttnov(s2v(L->top - 1)); |
623 | } | 640 | } |
624 | 641 | ||
625 | 642 | ||
626 | LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { | 643 | LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { |
627 | lua_lock(L); | 644 | lua_lock(L); |
628 | return auxgetstr(L, index2addr(L, idx), k); | 645 | return auxgetstr(L, index2value(L, idx), k); |
629 | } | 646 | } |
630 | 647 | ||
631 | 648 | ||
632 | LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | 649 | LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { |
633 | StkId t; | 650 | TValue *t; |
634 | const TValue *slot; | 651 | const TValue *slot; |
635 | lua_lock(L); | 652 | lua_lock(L); |
636 | t = index2addr(L, idx); | 653 | t = index2value(L, idx); |
637 | if (luaV_fastgeti(L, t, n, slot)) { | 654 | if (luaV_fastgeti(L, t, n, slot)) { |
638 | setobj2s(L, L->top, slot); | 655 | setobj2s(L, L->top, slot); |
639 | } | 656 | } |
@@ -644,44 +661,44 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | |||
644 | } | 661 | } |
645 | api_incr_top(L); | 662 | api_incr_top(L); |
646 | lua_unlock(L); | 663 | lua_unlock(L); |
647 | return ttnov(L->top - 1); | 664 | return ttnov(s2v(L->top - 1)); |
648 | } | 665 | } |
649 | 666 | ||
650 | 667 | ||
651 | LUA_API int lua_rawget (lua_State *L, int idx) { | 668 | LUA_API int lua_rawget (lua_State *L, int idx) { |
652 | StkId t; | 669 | TValue *t; |
653 | lua_lock(L); | 670 | lua_lock(L); |
654 | t = index2addr(L, idx); | 671 | t = index2value(L, idx); |
655 | api_check(L, ttistable(t), "table expected"); | 672 | api_check(L, ttistable(t), "table expected"); |
656 | setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); | 673 | setobj2s(L, L->top - 1, luaH_get(hvalue(t), s2v(L->top - 1))); |
657 | lua_unlock(L); | 674 | lua_unlock(L); |
658 | return ttnov(L->top - 1); | 675 | return ttnov(s2v(L->top - 1)); |
659 | } | 676 | } |
660 | 677 | ||
661 | 678 | ||
662 | LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { | 679 | LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { |
663 | StkId t; | 680 | TValue *t; |
664 | lua_lock(L); | 681 | lua_lock(L); |
665 | t = index2addr(L, idx); | 682 | t = index2value(L, idx); |
666 | api_check(L, ttistable(t), "table expected"); | 683 | api_check(L, ttistable(t), "table expected"); |
667 | setobj2s(L, L->top, luaH_getint(hvalue(t), n)); | 684 | setobj2s(L, L->top, luaH_getint(hvalue(t), n)); |
668 | api_incr_top(L); | 685 | api_incr_top(L); |
669 | lua_unlock(L); | 686 | lua_unlock(L); |
670 | return ttnov(L->top - 1); | 687 | return ttnov(s2v(L->top - 1)); |
671 | } | 688 | } |
672 | 689 | ||
673 | 690 | ||
674 | LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { | 691 | LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { |
675 | StkId t; | 692 | TValue *t; |
676 | TValue k; | 693 | TValue k; |
677 | lua_lock(L); | 694 | lua_lock(L); |
678 | t = index2addr(L, idx); | 695 | t = index2value(L, idx); |
679 | api_check(L, ttistable(t), "table expected"); | 696 | api_check(L, ttistable(t), "table expected"); |
680 | setpvalue(&k, cast(void *, p)); | 697 | setpvalue(&k, cast(void *, p)); |
681 | setobj2s(L, L->top, luaH_get(hvalue(t), &k)); | 698 | setobj2s(L, L->top, luaH_get(hvalue(t), &k)); |
682 | api_incr_top(L); | 699 | api_incr_top(L); |
683 | lua_unlock(L); | 700 | lua_unlock(L); |
684 | return ttnov(L->top - 1); | 701 | return ttnov(s2v(L->top - 1)); |
685 | } | 702 | } |
686 | 703 | ||
687 | 704 | ||
@@ -689,7 +706,7 @@ LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { | |||
689 | Table *t; | 706 | Table *t; |
690 | lua_lock(L); | 707 | lua_lock(L); |
691 | t = luaH_new(L); | 708 | t = luaH_new(L); |
692 | sethvalue(L, L->top, t); | 709 | sethvalue2s(L, L->top, t); |
693 | api_incr_top(L); | 710 | api_incr_top(L); |
694 | if (narray > 0 || nrec > 0) | 711 | if (narray > 0 || nrec > 0) |
695 | luaH_resize(L, t, narray, nrec); | 712 | luaH_resize(L, t, narray, nrec); |
@@ -703,7 +720,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { | |||
703 | Table *mt; | 720 | Table *mt; |
704 | int res = 0; | 721 | int res = 0; |
705 | lua_lock(L); | 722 | lua_lock(L); |
706 | obj = index2addr(L, objindex); | 723 | obj = index2value(L, objindex); |
707 | switch (ttnov(obj)) { | 724 | switch (ttnov(obj)) { |
708 | case LUA_TTABLE: | 725 | case LUA_TTABLE: |
709 | mt = hvalue(obj)->metatable; | 726 | mt = hvalue(obj)->metatable; |
@@ -716,7 +733,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { | |||
716 | break; | 733 | break; |
717 | } | 734 | } |
718 | if (mt != NULL) { | 735 | if (mt != NULL) { |
719 | sethvalue(L, L->top, mt); | 736 | sethvalue2s(L, L->top, mt); |
720 | api_incr_top(L); | 737 | api_incr_top(L); |
721 | res = 1; | 738 | res = 1; |
722 | } | 739 | } |
@@ -726,14 +743,14 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { | |||
726 | 743 | ||
727 | 744 | ||
728 | LUA_API int lua_getuservalue (lua_State *L, int idx) { | 745 | LUA_API int lua_getuservalue (lua_State *L, int idx) { |
729 | StkId o; | 746 | TValue *o; |
730 | lua_lock(L); | 747 | lua_lock(L); |
731 | o = index2addr(L, idx); | 748 | o = index2value(L, idx); |
732 | api_check(L, ttisfulluserdata(o), "full userdata expected"); | 749 | api_check(L, ttisfulluserdata(o), "full userdata expected"); |
733 | getuservalue(L, uvalue(o), L->top); | 750 | getuservalue(L, uvalue(o), s2v(L->top)); |
734 | api_incr_top(L); | 751 | api_incr_top(L); |
735 | lua_unlock(L); | 752 | lua_unlock(L); |
736 | return ttnov(L->top - 1); | 753 | return ttnov(s2v(L->top - 1)); |
737 | } | 754 | } |
738 | 755 | ||
739 | 756 | ||
@@ -749,13 +766,13 @@ static void auxsetstr (lua_State *L, const TValue *t, const char *k) { | |||
749 | TString *str = luaS_new(L, k); | 766 | TString *str = luaS_new(L, k); |
750 | api_checknelems(L, 1); | 767 | api_checknelems(L, 1); |
751 | if (luaV_fastget(L, t, str, slot, luaH_getstr)) { | 768 | if (luaV_fastget(L, t, str, slot, luaH_getstr)) { |
752 | luaV_finishfastset(L, t, slot, L->top - 1); | 769 | luaV_finishfastset(L, t, slot, s2v(L->top - 1)); |
753 | L->top--; /* pop value */ | 770 | L->top--; /* pop value */ |
754 | } | 771 | } |
755 | else { | 772 | else { |
756 | setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */ | 773 | setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */ |
757 | api_incr_top(L); | 774 | api_incr_top(L); |
758 | luaV_finishset(L, t, L->top - 1, L->top - 2, slot); | 775 | luaV_finishset(L, t, s2v(L->top - 1), s2v(L->top - 2), slot); |
759 | L->top -= 2; /* pop value and key */ | 776 | L->top -= 2; /* pop value and key */ |
760 | } | 777 | } |
761 | lua_unlock(L); /* lock done by caller */ | 778 | lua_unlock(L); /* lock done by caller */ |
@@ -770,16 +787,16 @@ LUA_API void lua_setglobal (lua_State *L, const char *name) { | |||
770 | 787 | ||
771 | 788 | ||
772 | LUA_API void lua_settable (lua_State *L, int idx) { | 789 | LUA_API void lua_settable (lua_State *L, int idx) { |
773 | StkId t; | 790 | TValue *t; |
774 | const TValue *slot; | 791 | const TValue *slot; |
775 | lua_lock(L); | 792 | lua_lock(L); |
776 | api_checknelems(L, 2); | 793 | api_checknelems(L, 2); |
777 | t = index2addr(L, idx); | 794 | t = index2value(L, idx); |
778 | if (luaV_fastget(L, t, L->top - 2, slot, luaH_get)) { | 795 | if (luaV_fastget(L, t, s2v(L->top - 2), slot, luaH_get)) { |
779 | luaV_finishfastset(L, t, slot, L->top - 1); | 796 | luaV_finishfastset(L, t, slot, s2v(L->top - 1)); |
780 | } | 797 | } |
781 | else | 798 | else |
782 | luaV_finishset(L, t, L->top - 2, L->top - 1, slot); | 799 | luaV_finishset(L, t, s2v(L->top - 2), s2v(L->top - 1), slot); |
783 | L->top -= 2; /* pop index and value */ | 800 | L->top -= 2; /* pop index and value */ |
784 | lua_unlock(L); | 801 | lua_unlock(L); |
785 | } | 802 | } |
@@ -787,23 +804,23 @@ LUA_API void lua_settable (lua_State *L, int idx) { | |||
787 | 804 | ||
788 | LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { | 805 | LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { |
789 | lua_lock(L); /* unlock done in 'auxsetstr' */ | 806 | lua_lock(L); /* unlock done in 'auxsetstr' */ |
790 | auxsetstr(L, index2addr(L, idx), k); | 807 | auxsetstr(L, index2value(L, idx), k); |
791 | } | 808 | } |
792 | 809 | ||
793 | 810 | ||
794 | LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { | 811 | LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { |
795 | StkId t; | 812 | TValue *t; |
796 | const TValue *slot; | 813 | const TValue *slot; |
797 | lua_lock(L); | 814 | lua_lock(L); |
798 | api_checknelems(L, 1); | 815 | api_checknelems(L, 1); |
799 | t = index2addr(L, idx); | 816 | t = index2value(L, idx); |
800 | if (luaV_fastgeti(L, t, n, slot)) { | 817 | if (luaV_fastgeti(L, t, n, slot)) { |
801 | luaV_finishfastset(L, t, slot, L->top - 1); | 818 | luaV_finishfastset(L, t, slot, s2v(L->top - 1)); |
802 | } | 819 | } |
803 | else { | 820 | else { |
804 | TValue aux; | 821 | TValue aux; |
805 | setivalue(&aux, n); | 822 | setivalue(&aux, n); |
806 | luaV_finishset(L, t, &aux, L->top - 1, slot); | 823 | luaV_finishset(L, t, &aux, s2v(L->top - 1), slot); |
807 | } | 824 | } |
808 | L->top--; /* pop value */ | 825 | L->top--; /* pop value */ |
809 | lua_unlock(L); | 826 | lua_unlock(L); |
@@ -811,45 +828,45 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { | |||
811 | 828 | ||
812 | 829 | ||
813 | LUA_API void lua_rawset (lua_State *L, int idx) { | 830 | LUA_API void lua_rawset (lua_State *L, int idx) { |
814 | StkId o; | 831 | TValue *o; |
815 | TValue *slot; | 832 | TValue *slot; |
816 | lua_lock(L); | 833 | lua_lock(L); |
817 | api_checknelems(L, 2); | 834 | api_checknelems(L, 2); |
818 | o = index2addr(L, idx); | 835 | o = index2value(L, idx); |
819 | api_check(L, ttistable(o), "table expected"); | 836 | api_check(L, ttistable(o), "table expected"); |
820 | slot = luaH_set(L, hvalue(o), L->top - 2); | 837 | slot = luaH_set(L, hvalue(o), s2v(L->top - 2)); |
821 | setobj2t(L, slot, L->top - 1); | 838 | setobj2t(L, slot, s2v(L->top - 1)); |
822 | invalidateTMcache(hvalue(o)); | 839 | invalidateTMcache(hvalue(o)); |
823 | luaC_barrierback(L, hvalue(o), L->top-1); | 840 | luaC_barrierback(L, hvalue(o), s2v(L->top - 1)); |
824 | L->top -= 2; | 841 | L->top -= 2; |
825 | lua_unlock(L); | 842 | lua_unlock(L); |
826 | } | 843 | } |
827 | 844 | ||
828 | 845 | ||
829 | LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { | 846 | LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { |
830 | StkId o; | 847 | TValue *o; |
831 | lua_lock(L); | 848 | lua_lock(L); |
832 | api_checknelems(L, 1); | 849 | api_checknelems(L, 1); |
833 | o = index2addr(L, idx); | 850 | o = index2value(L, idx); |
834 | api_check(L, ttistable(o), "table expected"); | 851 | api_check(L, ttistable(o), "table expected"); |
835 | luaH_setint(L, hvalue(o), n, L->top - 1); | 852 | luaH_setint(L, hvalue(o), n, s2v(L->top - 1)); |
836 | luaC_barrierback(L, hvalue(o), L->top-1); | 853 | luaC_barrierback(L, hvalue(o), s2v(L->top - 1)); |
837 | L->top--; | 854 | L->top--; |
838 | lua_unlock(L); | 855 | lua_unlock(L); |
839 | } | 856 | } |
840 | 857 | ||
841 | 858 | ||
842 | LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { | 859 | LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { |
843 | StkId o; | 860 | TValue *o; |
844 | TValue k, *slot; | 861 | TValue k, *slot; |
845 | lua_lock(L); | 862 | lua_lock(L); |
846 | api_checknelems(L, 1); | 863 | api_checknelems(L, 1); |
847 | o = index2addr(L, idx); | 864 | o = index2value(L, idx); |
848 | api_check(L, ttistable(o), "table expected"); | 865 | api_check(L, ttistable(o), "table expected"); |
849 | setpvalue(&k, cast(void *, p)); | 866 | setpvalue(&k, cast(void *, p)); |
850 | slot = luaH_set(L, hvalue(o), &k); | 867 | slot = luaH_set(L, hvalue(o), &k); |
851 | setobj2t(L, slot, L->top - 1); | 868 | setobj2t(L, slot, s2v(L->top - 1)); |
852 | luaC_barrierback(L, hvalue(o), L->top - 1); | 869 | luaC_barrierback(L, hvalue(o), s2v(L->top - 1)); |
853 | L->top--; | 870 | L->top--; |
854 | lua_unlock(L); | 871 | lua_unlock(L); |
855 | } | 872 | } |
@@ -860,12 +877,12 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { | |||
860 | Table *mt; | 877 | Table *mt; |
861 | lua_lock(L); | 878 | lua_lock(L); |
862 | api_checknelems(L, 1); | 879 | api_checknelems(L, 1); |
863 | obj = index2addr(L, objindex); | 880 | obj = index2value(L, objindex); |
864 | if (ttisnil(L->top - 1)) | 881 | if (ttisnil(s2v(L->top - 1))) |
865 | mt = NULL; | 882 | mt = NULL; |
866 | else { | 883 | else { |
867 | api_check(L, ttistable(L->top - 1), "table expected"); | 884 | api_check(L, ttistable(s2v(L->top - 1)), "table expected"); |
868 | mt = hvalue(L->top - 1); | 885 | mt = hvalue(s2v(L->top - 1)); |
869 | } | 886 | } |
870 | switch (ttnov(obj)) { | 887 | switch (ttnov(obj)) { |
871 | case LUA_TTABLE: { | 888 | case LUA_TTABLE: { |
@@ -896,13 +913,13 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { | |||
896 | 913 | ||
897 | 914 | ||
898 | LUA_API void lua_setuservalue (lua_State *L, int idx) { | 915 | LUA_API void lua_setuservalue (lua_State *L, int idx) { |
899 | StkId o; | 916 | TValue *o; |
900 | lua_lock(L); | 917 | lua_lock(L); |
901 | api_checknelems(L, 1); | 918 | api_checknelems(L, 1); |
902 | o = index2addr(L, idx); | 919 | o = index2value(L, idx); |
903 | api_check(L, ttisfulluserdata(o), "full userdata expected"); | 920 | api_check(L, ttisfulluserdata(o), "full userdata expected"); |
904 | setuservalue(L, uvalue(o), L->top - 1); | 921 | setuservalue(L, uvalue(o), s2v(L->top - 1)); |
905 | luaC_barrier(L, gcvalue(o), L->top - 1); | 922 | luaC_barrier(L, gcvalue(o), s2v(L->top - 1)); |
906 | L->top--; | 923 | L->top--; |
907 | lua_unlock(L); | 924 | lua_unlock(L); |
908 | } | 925 | } |
@@ -971,8 +988,7 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, | |||
971 | if (errfunc == 0) | 988 | if (errfunc == 0) |
972 | func = 0; | 989 | func = 0; |
973 | else { | 990 | else { |
974 | StkId o = index2addr(L, errfunc); | 991 | StkId o = index2stack(L, errfunc); |
975 | api_checkstackindex(L, errfunc, o); | ||
976 | func = savestack(L, o); | 992 | func = savestack(L, o); |
977 | } | 993 | } |
978 | c.func = L->top - (nargs+1); /* function to be called */ | 994 | c.func = L->top - (nargs+1); /* function to be called */ |
@@ -1010,7 +1026,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, | |||
1010 | luaZ_init(L, &z, reader, data); | 1026 | luaZ_init(L, &z, reader, data); |
1011 | status = luaD_protectedparser(L, &z, chunkname, mode); | 1027 | status = luaD_protectedparser(L, &z, chunkname, mode); |
1012 | if (status == LUA_OK) { /* no errors? */ | 1028 | if (status == LUA_OK) { /* no errors? */ |
1013 | LClosure *f = clLvalue(L->top - 1); /* get newly created function */ | 1029 | LClosure *f = clLvalue(s2v(L->top - 1)); /* get newly created function */ |
1014 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ | 1030 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ |
1015 | /* get global table from registry */ | 1031 | /* get global table from registry */ |
1016 | Table *reg = hvalue(&G(L)->l_registry); | 1032 | Table *reg = hvalue(&G(L)->l_registry); |
@@ -1030,7 +1046,7 @@ LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) { | |||
1030 | TValue *o; | 1046 | TValue *o; |
1031 | lua_lock(L); | 1047 | lua_lock(L); |
1032 | api_checknelems(L, 1); | 1048 | api_checknelems(L, 1); |
1033 | o = L->top - 1; | 1049 | o = s2v(L->top - 1); |
1034 | if (isLfunction(o)) | 1050 | if (isLfunction(o)) |
1035 | status = luaU_dump(L, getproto(o), writer, data, strip); | 1051 | status = luaU_dump(L, getproto(o), writer, data, strip); |
1036 | else | 1052 | else |
@@ -1154,10 +1170,10 @@ LUA_API int lua_error (lua_State *L) { | |||
1154 | 1170 | ||
1155 | 1171 | ||
1156 | LUA_API int lua_next (lua_State *L, int idx) { | 1172 | LUA_API int lua_next (lua_State *L, int idx) { |
1157 | StkId t; | 1173 | TValue *t; |
1158 | int more; | 1174 | int more; |
1159 | lua_lock(L); | 1175 | lua_lock(L); |
1160 | t = index2addr(L, idx); | 1176 | t = index2value(L, idx); |
1161 | api_check(L, ttistable(t), "table expected"); | 1177 | api_check(L, ttistable(t), "table expected"); |
1162 | more = luaH_next(L, hvalue(t), L->top - 1); | 1178 | more = luaH_next(L, hvalue(t), L->top - 1); |
1163 | if (more) { | 1179 | if (more) { |
@@ -1187,9 +1203,9 @@ LUA_API void lua_concat (lua_State *L, int n) { | |||
1187 | 1203 | ||
1188 | 1204 | ||
1189 | LUA_API void lua_len (lua_State *L, int idx) { | 1205 | LUA_API void lua_len (lua_State *L, int idx) { |
1190 | StkId t; | 1206 | TValue *t; |
1191 | lua_lock(L); | 1207 | lua_lock(L); |
1192 | t = index2addr(L, idx); | 1208 | t = index2value(L, idx); |
1193 | luaV_objlen(L, L->top, t); | 1209 | luaV_objlen(L, L->top, t); |
1194 | api_incr_top(L); | 1210 | api_incr_top(L); |
1195 | lua_unlock(L); | 1211 | lua_unlock(L); |
@@ -1218,7 +1234,7 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | |||
1218 | Udata *u; | 1234 | Udata *u; |
1219 | lua_lock(L); | 1235 | lua_lock(L); |
1220 | u = luaS_newudata(L, size); | 1236 | u = luaS_newudata(L, size); |
1221 | setuvalue(L, L->top, u); | 1237 | setuvalue(L, s2v(L->top), u); |
1222 | api_incr_top(L); | 1238 | api_incr_top(L); |
1223 | luaC_checkGC(L); | 1239 | luaC_checkGC(L); |
1224 | lua_unlock(L); | 1240 | lua_unlock(L); |
@@ -1227,7 +1243,7 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | |||
1227 | 1243 | ||
1228 | 1244 | ||
1229 | 1245 | ||
1230 | static const char *aux_upvalue (StkId fi, int n, TValue **val, | 1246 | static const char *aux_upvalue (TValue *fi, int n, TValue **val, |
1231 | GCObject **owner) { | 1247 | GCObject **owner) { |
1232 | switch (ttype(fi)) { | 1248 | switch (ttype(fi)) { |
1233 | case LUA_TCCL: { /* C closure */ | 1249 | case LUA_TCCL: { /* C closure */ |
@@ -1256,7 +1272,7 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { | |||
1256 | const char *name; | 1272 | const char *name; |
1257 | TValue *val = NULL; /* to avoid warnings */ | 1273 | TValue *val = NULL; /* to avoid warnings */ |
1258 | lua_lock(L); | 1274 | lua_lock(L); |
1259 | name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL); | 1275 | name = aux_upvalue(index2value(L, funcindex), n, &val, NULL); |
1260 | if (name) { | 1276 | if (name) { |
1261 | setobj2s(L, L->top, val); | 1277 | setobj2s(L, L->top, val); |
1262 | api_incr_top(L); | 1278 | api_incr_top(L); |
@@ -1270,14 +1286,14 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { | |||
1270 | const char *name; | 1286 | const char *name; |
1271 | TValue *val = NULL; /* to avoid warnings */ | 1287 | TValue *val = NULL; /* to avoid warnings */ |
1272 | GCObject *owner = NULL; /* to avoid warnings */ | 1288 | GCObject *owner = NULL; /* to avoid warnings */ |
1273 | StkId fi; | 1289 | TValue *fi; |
1274 | lua_lock(L); | 1290 | lua_lock(L); |
1275 | fi = index2addr(L, funcindex); | 1291 | fi = index2value(L, funcindex); |
1276 | api_checknelems(L, 1); | 1292 | api_checknelems(L, 1); |
1277 | name = aux_upvalue(fi, n, &val, &owner); | 1293 | name = aux_upvalue(fi, n, &val, &owner); |
1278 | if (name) { | 1294 | if (name) { |
1279 | L->top--; | 1295 | L->top--; |
1280 | setobj(L, val, L->top); | 1296 | setobj(L, val, s2v(L->top)); |
1281 | luaC_barrier(L, owner, val); | 1297 | luaC_barrier(L, owner, val); |
1282 | } | 1298 | } |
1283 | lua_unlock(L); | 1299 | lua_unlock(L); |
@@ -1287,7 +1303,7 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { | |||
1287 | 1303 | ||
1288 | static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { | 1304 | static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { |
1289 | LClosure *f; | 1305 | LClosure *f; |
1290 | StkId fi = index2addr(L, fidx); | 1306 | TValue *fi = index2value(L, fidx); |
1291 | api_check(L, ttisLclosure(fi), "Lua function expected"); | 1307 | api_check(L, ttisLclosure(fi), "Lua function expected"); |
1292 | f = clLvalue(fi); | 1308 | f = clLvalue(fi); |
1293 | api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index"); | 1309 | api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index"); |
@@ -1297,7 +1313,7 @@ static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { | |||
1297 | 1313 | ||
1298 | 1314 | ||
1299 | LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { | 1315 | LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { |
1300 | StkId fi = index2addr(L, fidx); | 1316 | TValue *fi = index2value(L, fidx); |
1301 | switch (ttype(fi)) { | 1317 | switch (ttype(fi)) { |
1302 | case LUA_TLCL: { /* lua closure */ | 1318 | case LUA_TLCL: { /* lua closure */ |
1303 | return *getupvalref(L, fidx, n, NULL); | 1319 | return *getupvalref(L, fidx, n, NULL); |