Lines Matching +full:- +full:l
39 /* value at a non-valid index */
54 #define api_checkvalidindex(l,o) api_check(l, isvalid(o), "invalid index") argument
56 #define api_checkstackindex(l, i, o) \ argument
57 api_check(l, isstackindex(i, o), "index not in the stack")
60 static TValue *index2addr (lua_State *L, int idx) { in index2addr() argument
61 CallInfo *ci = L->ci; in index2addr()
63 TValue *o = ci->func + idx; in index2addr()
64 api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index"); in index2addr()
65 if (o >= L->top) return NONVALIDVALUE; in index2addr()
69 api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); in index2addr()
70 return L->top + idx; in index2addr()
73 return &G(L)->l_registry; in index2addr()
75 idx = LUA_REGISTRYINDEX - idx; in index2addr()
76 api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); in index2addr()
77 if (ttislcf(ci->func)) /* light C function? */ in index2addr()
80 CClosure *func = clCvalue(ci->func); in index2addr()
81 return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE; in index2addr()
91 static void growstack (lua_State *L, void *ud) { in growstack() argument
93 luaD_growstack(L, size); in growstack()
97 LUA_API int lua_checkstack (lua_State *L, int n) { in lua_checkstack() argument
99 CallInfo *ci = L->ci; in lua_checkstack()
100 lua_lock(L); in lua_checkstack()
101 api_check(L, n >= 0, "negative 'n'"); in lua_checkstack()
102 if (L->stack_last - L->top > n) /* stack large enough? */ in lua_checkstack()
105 int inuse = cast_int(L->top - L->stack) + EXTRA_STACK; in lua_checkstack()
106 if (inuse > LUAI_MAXSTACK - n) /* can grow without overflow? */ in lua_checkstack()
109 res = (luaD_rawrunprotected(L, &growstack, &n) == LUA_OK); in lua_checkstack()
111 if (res && ci->top < L->top + n) in lua_checkstack()
112 ci->top = L->top + n; /* adjust frame top */ in lua_checkstack()
113 lua_unlock(L); in lua_checkstack()
124 api_check(from, to->ci->top - to->top >= n, "stack overflow"); in lua_xmove()
125 from->top -= n; in lua_xmove()
127 setobj2s(to, to->top, from->top + i); in lua_xmove()
128 to->top++; /* stack already checked by previous 'api_check' */ in lua_xmove()
134 LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { in lua_atpanic() argument
136 lua_lock(L); in lua_atpanic()
137 old = G(L)->panic; in lua_atpanic()
138 G(L)->panic = panicf; in lua_atpanic()
139 lua_unlock(L); in lua_atpanic()
144 LUA_API const lua_Number *lua_version (lua_State *L) { in lua_version() argument
146 if (L == NULL) return &version; in lua_version()
147 else return G(L)->version; in lua_version()
160 LUA_API int lua_absindex (lua_State *L, int idx) { in lua_absindex() argument
163 : cast_int(L->top - L->ci->func) + idx; in lua_absindex()
167 LUA_API int lua_gettop (lua_State *L) { in lua_gettop() argument
168 return cast_int(L->top - (L->ci->func + 1)); in lua_gettop()
172 LUA_API void lua_settop (lua_State *L, int idx) { in lua_settop() argument
173 StkId func = L->ci->func; in lua_settop()
174 lua_lock(L); in lua_settop()
176 api_check(L, idx <= L->stack_last - (func + 1), "new top too large"); in lua_settop()
177 while (L->top < (func + 1) + idx) in lua_settop()
178 setnilvalue(L->top++); in lua_settop()
179 L->top = (func + 1) + idx; in lua_settop()
182 api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top"); in lua_settop()
183 L->top += idx+1; /* 'subtract' index (index is negative) */ in lua_settop()
185 lua_unlock(L); in lua_settop()
193 static void reverse (lua_State *L, StkId from, StkId to) { in reverse() argument
194 for (; from < to; from++, to--) { in reverse()
196 setobj(L, &temp, from); in reverse()
197 setobjs2s(L, from, to); in reverse()
198 setobj2s(L, to, &temp); in reverse()
207 LUA_API void lua_rotate (lua_State *L, int idx, int n) { in lua_rotate() argument
209 lua_lock(L); in lua_rotate()
210 t = L->top - 1; /* end of stack segment being rotated */ in lua_rotate()
211 p = index2addr(L, idx); /* start of segment */ in lua_rotate()
212 api_checkstackindex(L, idx, p); in lua_rotate()
213 api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); in lua_rotate()
214 m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ in lua_rotate()
215 reverse(L, p, m); /* reverse the prefix with length 'n' */ in lua_rotate()
216 reverse(L, m + 1, t); /* reverse the suffix */ in lua_rotate()
217 reverse(L, p, t); /* reverse the entire segment */ in lua_rotate()
218 lua_unlock(L); in lua_rotate()
222 LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { in lua_copy() argument
224 lua_lock(L); in lua_copy()
225 fr = index2addr(L, fromidx); in lua_copy()
226 to = index2addr(L, toidx); in lua_copy()
227 api_checkvalidindex(L, to); in lua_copy()
228 setobj(L, to, fr); in lua_copy()
230 luaC_barrier(L, clCvalue(L->ci->func), fr); in lua_copy()
233 lua_unlock(L); in lua_copy()
237 LUA_API void lua_pushvalue (lua_State *L, int idx) { in lua_pushvalue() argument
238 lua_lock(L); in lua_pushvalue()
239 setobj2s(L, L->top, index2addr(L, idx)); in lua_pushvalue()
240 api_incr_top(L); in lua_pushvalue()
241 lua_unlock(L); in lua_pushvalue()
247 ** access functions (stack -> C)
251 LUA_API int lua_type (lua_State *L, int idx) { in lua_type() argument
252 StkId o = index2addr(L, idx); in lua_type()
257 LUA_API const char *lua_typename (lua_State *L, int t) { in lua_typename() argument
258 UNUSED(L); in lua_typename()
259 api_check(L, LUA_TNONE <= t && t < LUA_NUMTAGS, "invalid tag"); in lua_typename()
264 LUA_API int lua_iscfunction (lua_State *L, int idx) { in lua_iscfunction() argument
265 StkId o = index2addr(L, idx); in lua_iscfunction()
270 LUA_API int lua_isinteger (lua_State *L, int idx) { in lua_isinteger() argument
271 StkId o = index2addr(L, idx); in lua_isinteger()
276 LUA_API int lua_isnumber (lua_State *L, int idx) { in lua_isnumber() argument
278 const TValue *o = index2addr(L, idx); in lua_isnumber()
283 LUA_API int lua_isstring (lua_State *L, int idx) { in lua_isstring() argument
284 const TValue *o = index2addr(L, idx); in lua_isstring()
289 LUA_API int lua_isuserdata (lua_State *L, int idx) { in lua_isuserdata() argument
290 const TValue *o = index2addr(L, idx); in lua_isuserdata()
295 LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { in lua_rawequal() argument
296 StkId o1 = index2addr(L, index1); in lua_rawequal()
297 StkId o2 = index2addr(L, index2); in lua_rawequal()
302 LUA_API void lua_arith (lua_State *L, int op) { in lua_arith() argument
303 lua_lock(L); in lua_arith()
305 api_checknelems(L, 2); /* all other operations expect two operands */ in lua_arith()
307 api_checknelems(L, 1); in lua_arith()
308 setobjs2s(L, L->top, L->top - 1); in lua_arith()
309 api_incr_top(L); in lua_arith()
311 /* first operand at top - 2, second at top - 1; result go to top - 2 */ in lua_arith()
312 luaO_arith(L, op, L->top - 2, L->top - 1, L->top - 2); in lua_arith()
313 L->top--; /* remove second operand */ in lua_arith()
314 lua_unlock(L); in lua_arith()
318 LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { in lua_compare() argument
321 lua_lock(L); /* may call tag method */ in lua_compare()
322 o1 = index2addr(L, index1); in lua_compare()
323 o2 = index2addr(L, index2); in lua_compare()
326 case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break; in lua_compare()
327 case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; in lua_compare()
328 case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; in lua_compare()
329 default: api_check(L, 0, "invalid option"); in lua_compare()
332 lua_unlock(L); in lua_compare()
337 LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { in lua_stringtonumber() argument
338 size_t sz = luaO_str2num(s, L->top); in lua_stringtonumber()
340 api_incr_top(L); in lua_stringtonumber()
345 LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { in lua_tonumberx() argument
347 const TValue *o = index2addr(L, idx); in lua_tonumberx()
356 LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { in lua_tointegerx() argument
358 const TValue *o = index2addr(L, idx); in lua_tointegerx()
367 LUA_API int lua_toboolean (lua_State *L, int idx) { in lua_toboolean() argument
368 const TValue *o = index2addr(L, idx); in lua_toboolean()
373 LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { in lua_tolstring() argument
374 StkId o = index2addr(L, idx); in lua_tolstring()
380 lua_lock(L); /* 'luaO_tostring' may create a new string */ in lua_tolstring()
381 luaO_tostring(L, o); in lua_tolstring()
382 luaC_checkGC(L); in lua_tolstring()
383 o = index2addr(L, idx); /* previous call may reallocate the stack */ in lua_tolstring()
384 lua_unlock(L); in lua_tolstring()
392 LUA_API size_t lua_rawlen (lua_State *L, int idx) { in lua_rawlen() argument
393 StkId o = index2addr(L, idx); in lua_rawlen()
395 case LUA_TSHRSTR: return tsvalue(o)->shrlen; in lua_rawlen()
396 case LUA_TLNGSTR: return tsvalue(o)->u.lnglen; in lua_rawlen()
397 case LUA_TUSERDATA: return uvalue(o)->len; in lua_rawlen()
404 LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { in lua_tocfunction() argument
405 StkId o = index2addr(L, idx); in lua_tocfunction()
408 return clCvalue(o)->f; in lua_tocfunction()
413 LUA_API void *lua_touserdata (lua_State *L, int idx) { in lua_touserdata() argument
414 StkId o = index2addr(L, idx); in lua_touserdata()
423 LUA_API lua_State *lua_tothread (lua_State *L, int idx) { in lua_tothread() argument
424 StkId o = index2addr(L, idx); in lua_tothread()
429 LUA_API const void *lua_topointer (lua_State *L, int idx) { in lua_topointer() argument
430 StkId o = index2addr(L, idx); in lua_topointer()
446 ** push functions (C -> stack)
450 LUA_API void lua_pushnil (lua_State *L) { in lua_pushnil() argument
451 lua_lock(L); in lua_pushnil()
452 setnilvalue(L->top); in lua_pushnil()
453 api_incr_top(L); in lua_pushnil()
454 lua_unlock(L); in lua_pushnil()
458 LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { in lua_pushnumber() argument
459 lua_lock(L); in lua_pushnumber()
460 setfltvalue(L->top, n); in lua_pushnumber()
461 api_incr_top(L); in lua_pushnumber()
462 lua_unlock(L); in lua_pushnumber()
466 LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { in lua_pushinteger() argument
467 lua_lock(L); in lua_pushinteger()
468 setivalue(L->top, n); in lua_pushinteger()
469 api_incr_top(L); in lua_pushinteger()
470 lua_unlock(L); in lua_pushinteger()
479 LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { in lua_pushlstring() argument
481 lua_lock(L); in lua_pushlstring()
482 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len); in lua_pushlstring()
483 setsvalue2s(L, L->top, ts); in lua_pushlstring()
484 api_incr_top(L); in lua_pushlstring()
485 luaC_checkGC(L); in lua_pushlstring()
486 lua_unlock(L); in lua_pushlstring()
491 LUA_API const char *lua_pushstring (lua_State *L, const char *s) { in lua_pushstring() argument
492 lua_lock(L); in lua_pushstring()
494 setnilvalue(L->top); in lua_pushstring()
497 ts = luaS_new(L, s); in lua_pushstring()
498 setsvalue2s(L, L->top, ts); in lua_pushstring()
501 api_incr_top(L); in lua_pushstring()
502 luaC_checkGC(L); in lua_pushstring()
503 lua_unlock(L); in lua_pushstring()
508 LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, in lua_pushvfstring() argument
511 lua_lock(L); in lua_pushvfstring()
512 ret = luaO_pushvfstring(L, fmt, argp); in lua_pushvfstring()
513 luaC_checkGC(L); in lua_pushvfstring()
514 lua_unlock(L); in lua_pushvfstring()
519 LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { in lua_pushfstring() argument
522 lua_lock(L); in lua_pushfstring()
524 ret = luaO_pushvfstring(L, fmt, argp); in lua_pushfstring()
526 luaC_checkGC(L); in lua_pushfstring()
527 lua_unlock(L); in lua_pushfstring()
532 LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { in lua_pushcclosure() argument
533 lua_lock(L); in lua_pushcclosure()
535 setfvalue(L->top, fn); in lua_pushcclosure()
536 api_incr_top(L); in lua_pushcclosure()
540 api_checknelems(L, n); in lua_pushcclosure()
541 api_check(L, n <= MAXUPVAL, "upvalue index too large"); in lua_pushcclosure()
542 cl = luaF_newCclosure(L, n); in lua_pushcclosure()
543 cl->f = fn; in lua_pushcclosure()
544 L->top -= n; in lua_pushcclosure()
545 while (n--) { in lua_pushcclosure()
546 setobj2n(L, &cl->upvalue[n], L->top + n); in lua_pushcclosure()
549 setclCvalue(L, L->top, cl); in lua_pushcclosure()
550 api_incr_top(L); in lua_pushcclosure()
551 luaC_checkGC(L); in lua_pushcclosure()
553 lua_unlock(L); in lua_pushcclosure()
557 LUA_API void lua_pushboolean (lua_State *L, int b) { in lua_pushboolean() argument
558 lua_lock(L); in lua_pushboolean()
559 setbvalue(L->top, (b != 0)); /* ensure that true is 1 */ in lua_pushboolean()
560 api_incr_top(L); in lua_pushboolean()
561 lua_unlock(L); in lua_pushboolean()
565 LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { in lua_pushlightuserdata() argument
566 lua_lock(L); in lua_pushlightuserdata()
567 setpvalue(L->top, p); in lua_pushlightuserdata()
568 api_incr_top(L); in lua_pushlightuserdata()
569 lua_unlock(L); in lua_pushlightuserdata()
573 LUA_API int lua_pushthread (lua_State *L) { in lua_pushthread() argument
574 lua_lock(L); in lua_pushthread()
575 setthvalue(L, L->top, L); in lua_pushthread()
576 api_incr_top(L); in lua_pushthread()
577 lua_unlock(L); in lua_pushthread()
578 return (G(L)->mainthread == L); in lua_pushthread()
584 ** get functions (Lua -> stack)
588 static int auxgetstr (lua_State *L, const TValue *t, const char *k) { in auxgetstr() argument
590 TString *str = luaS_new(L, k); in auxgetstr()
591 if (luaV_fastget(L, t, str, slot, luaH_getstr)) { in auxgetstr()
592 setobj2s(L, L->top, slot); in auxgetstr()
593 api_incr_top(L); in auxgetstr()
596 setsvalue2s(L, L->top, str); in auxgetstr()
597 api_incr_top(L); in auxgetstr()
598 luaV_finishget(L, t, L->top - 1, L->top - 1, slot); in auxgetstr()
600 lua_unlock(L); in auxgetstr()
601 return ttnov(L->top - 1); in auxgetstr()
605 LUA_API int lua_getglobal (lua_State *L, const char *name) { in lua_getglobal() argument
606 Table *reg = hvalue(&G(L)->l_registry); in lua_getglobal()
607 lua_lock(L); in lua_getglobal()
608 return auxgetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name); in lua_getglobal()
612 LUA_API int lua_gettable (lua_State *L, int idx) { in lua_gettable() argument
614 lua_lock(L); in lua_gettable()
615 t = index2addr(L, idx); in lua_gettable()
616 luaV_gettable(L, t, L->top - 1, L->top - 1); in lua_gettable()
617 lua_unlock(L); in lua_gettable()
618 return ttnov(L->top - 1); in lua_gettable()
622 LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { in lua_getfield() argument
623 lua_lock(L); in lua_getfield()
624 return auxgetstr(L, index2addr(L, idx), k); in lua_getfield()
628 LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { in lua_geti() argument
631 lua_lock(L); in lua_geti()
632 t = index2addr(L, idx); in lua_geti()
633 if (luaV_fastget(L, t, n, slot, luaH_getint)) { in lua_geti()
634 setobj2s(L, L->top, slot); in lua_geti()
635 api_incr_top(L); in lua_geti()
638 setivalue(L->top, n); in lua_geti()
639 api_incr_top(L); in lua_geti()
640 luaV_finishget(L, t, L->top - 1, L->top - 1, slot); in lua_geti()
642 lua_unlock(L); in lua_geti()
643 return ttnov(L->top - 1); in lua_geti()
647 LUA_API int lua_rawget (lua_State *L, int idx) { in lua_rawget() argument
649 lua_lock(L); in lua_rawget()
650 t = index2addr(L, idx); in lua_rawget()
651 api_check(L, ttistable(t), "table expected"); in lua_rawget()
652 setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); in lua_rawget()
653 lua_unlock(L); in lua_rawget()
654 return ttnov(L->top - 1); in lua_rawget()
658 LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { in lua_rawgeti() argument
660 lua_lock(L); in lua_rawgeti()
661 t = index2addr(L, idx); in lua_rawgeti()
662 api_check(L, ttistable(t), "table expected"); in lua_rawgeti()
663 setobj2s(L, L->top, luaH_getint(hvalue(t), n)); in lua_rawgeti()
664 api_incr_top(L); in lua_rawgeti()
665 lua_unlock(L); in lua_rawgeti()
666 return ttnov(L->top - 1); in lua_rawgeti()
670 LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { in lua_rawgetp() argument
673 lua_lock(L); in lua_rawgetp()
674 t = index2addr(L, idx); in lua_rawgetp()
675 api_check(L, ttistable(t), "table expected"); in lua_rawgetp()
677 setobj2s(L, L->top, luaH_get(hvalue(t), &k)); in lua_rawgetp()
678 api_incr_top(L); in lua_rawgetp()
679 lua_unlock(L); in lua_rawgetp()
680 return ttnov(L->top - 1); in lua_rawgetp()
684 LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { in lua_createtable() argument
686 lua_lock(L); in lua_createtable()
687 t = luaH_new(L); in lua_createtable()
688 sethvalue(L, L->top, t); in lua_createtable()
689 api_incr_top(L); in lua_createtable()
691 luaH_resize(L, t, narray, nrec); in lua_createtable()
692 luaC_checkGC(L); in lua_createtable()
693 lua_unlock(L); in lua_createtable()
697 LUA_API int lua_getmetatable (lua_State *L, int objindex) { in lua_getmetatable() argument
701 lua_lock(L); in lua_getmetatable()
702 obj = index2addr(L, objindex); in lua_getmetatable()
705 mt = hvalue(obj)->metatable; in lua_getmetatable()
708 mt = uvalue(obj)->metatable; in lua_getmetatable()
711 mt = G(L)->mt[ttnov(obj)]; in lua_getmetatable()
715 sethvalue(L, L->top, mt); in lua_getmetatable()
716 api_incr_top(L); in lua_getmetatable()
719 lua_unlock(L); in lua_getmetatable()
724 LUA_API int lua_getuservalue (lua_State *L, int idx) { in lua_getuservalue() argument
726 lua_lock(L); in lua_getuservalue()
727 o = index2addr(L, idx); in lua_getuservalue()
728 api_check(L, ttisfulluserdata(o), "full userdata expected"); in lua_getuservalue()
729 getuservalue(L, uvalue(o), L->top); in lua_getuservalue()
730 api_incr_top(L); in lua_getuservalue()
731 lua_unlock(L); in lua_getuservalue()
732 return ttnov(L->top - 1); in lua_getuservalue()
737 ** set functions (stack -> Lua)
743 static void auxsetstr (lua_State *L, const TValue *t, const char *k) { in auxsetstr() argument
745 TString *str = luaS_new(L, k); in auxsetstr()
746 api_checknelems(L, 1); in auxsetstr()
747 if (luaV_fastset(L, t, str, slot, luaH_getstr, L->top - 1)) in auxsetstr()
748 L->top--; /* pop value */ in auxsetstr()
750 setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */ in auxsetstr()
751 api_incr_top(L); in auxsetstr()
752 luaV_finishset(L, t, L->top - 1, L->top - 2, slot); in auxsetstr()
753 L->top -= 2; /* pop value and key */ in auxsetstr()
755 lua_unlock(L); /* lock done by caller */ in auxsetstr()
759 LUA_API void lua_setglobal (lua_State *L, const char *name) { in lua_setglobal() argument
760 Table *reg = hvalue(&G(L)->l_registry); in lua_setglobal()
761 lua_lock(L); /* unlock done in 'auxsetstr' */ in lua_setglobal()
762 auxsetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name); in lua_setglobal()
766 LUA_API void lua_settable (lua_State *L, int idx) { in lua_settable() argument
768 lua_lock(L); in lua_settable()
769 api_checknelems(L, 2); in lua_settable()
770 t = index2addr(L, idx); in lua_settable()
771 luaV_settable(L, t, L->top - 2, L->top - 1); in lua_settable()
772 L->top -= 2; /* pop index and value */ in lua_settable()
773 lua_unlock(L); in lua_settable()
777 LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { in lua_setfield() argument
778 lua_lock(L); /* unlock done in 'auxsetstr' */ in lua_setfield()
779 auxsetstr(L, index2addr(L, idx), k); in lua_setfield()
783 LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { in lua_seti() argument
786 lua_lock(L); in lua_seti()
787 api_checknelems(L, 1); in lua_seti()
788 t = index2addr(L, idx); in lua_seti()
789 if (luaV_fastset(L, t, n, slot, luaH_getint, L->top - 1)) in lua_seti()
790 L->top--; /* pop value */ in lua_seti()
792 setivalue(L->top, n); in lua_seti()
793 api_incr_top(L); in lua_seti()
794 luaV_finishset(L, t, L->top - 1, L->top - 2, slot); in lua_seti()
795 L->top -= 2; /* pop value and key */ in lua_seti()
797 lua_unlock(L); in lua_seti()
801 LUA_API void lua_rawset (lua_State *L, int idx) { in lua_rawset() argument
804 lua_lock(L); in lua_rawset()
805 api_checknelems(L, 2); in lua_rawset()
806 o = index2addr(L, idx); in lua_rawset()
807 api_check(L, ttistable(o), "table expected"); in lua_rawset()
808 slot = luaH_set(L, hvalue(o), L->top - 2); in lua_rawset()
809 setobj2t(L, slot, L->top - 1); in lua_rawset()
811 luaC_barrierback(L, hvalue(o), L->top-1); in lua_rawset()
812 L->top -= 2; in lua_rawset()
813 lua_unlock(L); in lua_rawset()
817 LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { in lua_rawseti() argument
819 lua_lock(L); in lua_rawseti()
820 api_checknelems(L, 1); in lua_rawseti()
821 o = index2addr(L, idx); in lua_rawseti()
822 api_check(L, ttistable(o), "table expected"); in lua_rawseti()
823 luaH_setint(L, hvalue(o), n, L->top - 1); in lua_rawseti()
824 luaC_barrierback(L, hvalue(o), L->top-1); in lua_rawseti()
825 L->top--; in lua_rawseti()
826 lua_unlock(L); in lua_rawseti()
830 LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { in lua_rawsetp() argument
833 lua_lock(L); in lua_rawsetp()
834 api_checknelems(L, 1); in lua_rawsetp()
835 o = index2addr(L, idx); in lua_rawsetp()
836 api_check(L, ttistable(o), "table expected"); in lua_rawsetp()
838 slot = luaH_set(L, hvalue(o), &k); in lua_rawsetp()
839 setobj2t(L, slot, L->top - 1); in lua_rawsetp()
840 luaC_barrierback(L, hvalue(o), L->top - 1); in lua_rawsetp()
841 L->top--; in lua_rawsetp()
842 lua_unlock(L); in lua_rawsetp()
846 LUA_API int lua_setmetatable (lua_State *L, int objindex) { in lua_setmetatable() argument
849 lua_lock(L); in lua_setmetatable()
850 api_checknelems(L, 1); in lua_setmetatable()
851 obj = index2addr(L, objindex); in lua_setmetatable()
852 if (ttisnil(L->top - 1)) in lua_setmetatable()
855 api_check(L, ttistable(L->top - 1), "table expected"); in lua_setmetatable()
856 mt = hvalue(L->top - 1); in lua_setmetatable()
860 hvalue(obj)->metatable = mt; in lua_setmetatable()
862 luaC_objbarrier(L, gcvalue(obj), mt); in lua_setmetatable()
863 luaC_checkfinalizer(L, gcvalue(obj), mt); in lua_setmetatable()
868 uvalue(obj)->metatable = mt; in lua_setmetatable()
870 luaC_objbarrier(L, uvalue(obj), mt); in lua_setmetatable()
871 luaC_checkfinalizer(L, gcvalue(obj), mt); in lua_setmetatable()
876 G(L)->mt[ttnov(obj)] = mt; in lua_setmetatable()
880 L->top--; in lua_setmetatable()
881 lua_unlock(L); in lua_setmetatable()
886 LUA_API void lua_setuservalue (lua_State *L, int idx) { in lua_setuservalue() argument
888 lua_lock(L); in lua_setuservalue()
889 api_checknelems(L, 1); in lua_setuservalue()
890 o = index2addr(L, idx); in lua_setuservalue()
891 api_check(L, ttisfulluserdata(o), "full userdata expected"); in lua_setuservalue()
892 setuservalue(L, uvalue(o), L->top - 1); in lua_setuservalue()
893 luaC_barrier(L, gcvalue(o), L->top - 1); in lua_setuservalue()
894 L->top--; in lua_setuservalue()
895 lua_unlock(L); in lua_setuservalue()
904 #define checkresults(L,na,nr) \ argument
905 api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \
909 LUA_API void lua_callk (lua_State *L, int nargs, int nresults, in lua_callk() argument
912 lua_lock(L); in lua_callk()
913 api_check(L, k == NULL || !isLua(L->ci), in lua_callk()
915 api_checknelems(L, nargs+1); in lua_callk()
916 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); in lua_callk()
917 checkresults(L, nargs, nresults); in lua_callk()
918 func = L->top - (nargs+1); in lua_callk()
919 if (k != NULL && L->nny == 0) { /* need to prepare continuation? */ in lua_callk()
920 L->ci->u.c.k = k; /* save continuation */ in lua_callk()
921 L->ci->u.c.ctx = ctx; /* save context */ in lua_callk()
922 luaD_call(L, func, nresults); /* do the call */ in lua_callk()
925 luaD_callnoyield(L, func, nresults); /* just do the call */ in lua_callk()
926 adjustresults(L, nresults); in lua_callk()
927 lua_unlock(L); in lua_callk()
941 static void f_call (lua_State *L, void *ud) { in f_call() argument
943 luaD_callnoyield(L, c->func, c->nresults); in f_call()
948 LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, in lua_pcallk() argument
953 lua_lock(L); in lua_pcallk()
954 api_check(L, k == NULL || !isLua(L->ci), in lua_pcallk()
956 api_checknelems(L, nargs+1); in lua_pcallk()
957 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); in lua_pcallk()
958 checkresults(L, nargs, nresults); in lua_pcallk()
962 StkId o = index2addr(L, errfunc); in lua_pcallk()
963 api_checkstackindex(L, errfunc, o); in lua_pcallk()
964 func = savestack(L, o); in lua_pcallk()
966 c.func = L->top - (nargs+1); /* function to be called */ in lua_pcallk()
967 if (k == NULL || L->nny > 0) { /* no continuation or no yieldable? */ in lua_pcallk()
969 status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); in lua_pcallk()
972 CallInfo *ci = L->ci; in lua_pcallk()
973 ci->u.c.k = k; /* save continuation */ in lua_pcallk()
974 ci->u.c.ctx = ctx; /* save context */ in lua_pcallk()
976 ci->extra = savestack(L, c.func); in lua_pcallk()
977 ci->u.c.old_errfunc = L->errfunc; in lua_pcallk()
978 L->errfunc = func; in lua_pcallk()
979 setoah(ci->callstatus, L->allowhook); /* save value of 'allowhook' */ in lua_pcallk()
980 ci->callstatus |= CIST_YPCALL; /* function can do error recovery */ in lua_pcallk()
981 luaD_call(L, c.func, nresults); /* do the call */ in lua_pcallk()
982 ci->callstatus &= ~CIST_YPCALL; in lua_pcallk()
983 L->errfunc = ci->u.c.old_errfunc; in lua_pcallk()
986 adjustresults(L, nresults); in lua_pcallk()
987 lua_unlock(L); in lua_pcallk()
992 LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, in lua_load() argument
996 lua_lock(L); in lua_load()
998 luaZ_init(L, &z, reader, data); in lua_load()
999 status = luaD_protectedparser(L, &z, chunkname, mode); in lua_load()
1001 LClosure *f = clLvalue(L->top - 1); /* get newly created function */ in lua_load()
1002 if (f->nupvalues >= 1) { /* does it have an upvalue? */ in lua_load()
1004 Table *reg = hvalue(&G(L)->l_registry); in lua_load()
1007 setobj(L, f->upvals[0]->v, gt); in lua_load()
1008 luaC_upvalbarrier(L, f->upvals[0]); in lua_load()
1011 lua_unlock(L); in lua_load()
1016 LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) { in lua_dump() argument
1019 lua_lock(L); in lua_dump()
1020 api_checknelems(L, 1); in lua_dump()
1021 o = L->top - 1; in lua_dump()
1023 status = luaU_dump(L, getproto(o), writer, data, strip); in lua_dump()
1026 lua_unlock(L); in lua_dump()
1031 LUA_API int lua_status (lua_State *L) { in lua_status() argument
1032 return L->status; in lua_status()
1037 ** Garbage-collection function
1040 LUA_API int lua_gc (lua_State *L, int what, int data) { in lua_gc() argument
1043 lua_lock(L); in lua_gc()
1044 g = G(L); in lua_gc()
1047 g->gcrunning = 0; in lua_gc()
1052 g->gcrunning = 1; in lua_gc()
1056 luaC_fullgc(L, 0); in lua_gc()
1070 lu_byte oldrunning = g->gcrunning; in lua_gc()
1071 g->gcrunning = 1; /* allow GC to run */ in lua_gc()
1073 luaE_setdebt(g, -GCSTEPSIZE); /* to do a "small" step */ in lua_gc()
1074 luaC_step(L); in lua_gc()
1077 debt = cast(l_mem, data) * 1024 + g->GCdebt; in lua_gc()
1079 luaC_checkGC(L); in lua_gc()
1081 g->gcrunning = oldrunning; /* restore previous state */ in lua_gc()
1082 if (debt > 0 && g->gcstate == GCSpause) /* end of cycle? */ in lua_gc()
1087 res = g->gcpause; in lua_gc()
1088 g->gcpause = data; in lua_gc()
1092 res = g->gcstepmul; in lua_gc()
1094 g->gcstepmul = data; in lua_gc()
1098 res = g->gcrunning; in lua_gc()
1101 default: res = -1; /* invalid option */ in lua_gc()
1103 lua_unlock(L); in lua_gc()
1114 LUA_API int lua_error (lua_State *L) { in lua_error() argument
1115 lua_lock(L); in lua_error()
1116 api_checknelems(L, 1); in lua_error()
1117 luaG_errormsg(L); in lua_error()
1123 LUA_API int lua_next (lua_State *L, int idx) { in lua_next() argument
1126 lua_lock(L); in lua_next()
1127 t = index2addr(L, idx); in lua_next()
1128 api_check(L, ttistable(t), "table expected"); in lua_next()
1129 more = luaH_next(L, hvalue(t), L->top - 1); in lua_next()
1131 api_incr_top(L); in lua_next()
1134 L->top -= 1; /* remove key */ in lua_next()
1135 lua_unlock(L); in lua_next()
1140 LUA_API void lua_concat (lua_State *L, int n) { in lua_concat() argument
1141 lua_lock(L); in lua_concat()
1142 api_checknelems(L, n); in lua_concat()
1144 luaV_concat(L, n); in lua_concat()
1147 setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); in lua_concat()
1148 api_incr_top(L); in lua_concat()
1151 luaC_checkGC(L); in lua_concat()
1152 lua_unlock(L); in lua_concat()
1156 LUA_API void lua_len (lua_State *L, int idx) { in lua_len() argument
1158 lua_lock(L); in lua_len()
1159 t = index2addr(L, idx); in lua_len()
1160 luaV_objlen(L, L->top, t); in lua_len()
1161 api_incr_top(L); in lua_len()
1162 lua_unlock(L); in lua_len()
1166 LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { in lua_getallocf() argument
1168 lua_lock(L); in lua_getallocf()
1169 if (ud) *ud = G(L)->ud; in lua_getallocf()
1170 f = G(L)->frealloc; in lua_getallocf()
1171 lua_unlock(L); in lua_getallocf()
1176 LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) { in lua_setallocf() argument
1177 lua_lock(L); in lua_setallocf()
1178 G(L)->ud = ud; in lua_setallocf()
1179 G(L)->frealloc = f; in lua_setallocf()
1180 lua_unlock(L); in lua_setallocf()
1184 LUA_API void *lua_newuserdata (lua_State *L, size_t size) { in lua_newuserdata() argument
1186 lua_lock(L); in lua_newuserdata()
1187 u = luaS_newudata(L, size); in lua_newuserdata()
1188 setuvalue(L, L->top, u); in lua_newuserdata()
1189 api_incr_top(L); in lua_newuserdata()
1190 luaC_checkGC(L); in lua_newuserdata()
1191 lua_unlock(L); in lua_newuserdata()
1202 if (!(1 <= n && n <= f->nupvalues)) return NULL; in aux_upvalue()
1203 *val = &f->upvalue[n-1]; in aux_upvalue()
1210 Proto *p = f->p; in aux_upvalue()
1211 if (!(1 <= n && n <= p->sizeupvalues)) return NULL; in aux_upvalue()
1212 *val = f->upvals[n-1]->v; in aux_upvalue()
1213 if (uv) *uv = f->upvals[n - 1]; in aux_upvalue()
1214 name = p->upvalues[n-1].name; in aux_upvalue()
1222 LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { in lua_getupvalue() argument
1225 lua_lock(L); in lua_getupvalue()
1226 name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL, NULL); in lua_getupvalue()
1228 setobj2s(L, L->top, val); in lua_getupvalue()
1229 api_incr_top(L); in lua_getupvalue()
1231 lua_unlock(L); in lua_getupvalue()
1236 LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { in lua_setupvalue() argument
1242 lua_lock(L); in lua_setupvalue()
1243 fi = index2addr(L, funcindex); in lua_setupvalue()
1244 api_checknelems(L, 1); in lua_setupvalue()
1247 L->top--; in lua_setupvalue()
1248 setobj(L, val, L->top); in lua_setupvalue()
1249 if (owner) { luaC_barrier(L, owner, L->top); } in lua_setupvalue()
1250 else if (uv) { luaC_upvalbarrier(L, uv); } in lua_setupvalue()
1252 lua_unlock(L); in lua_setupvalue()
1257 static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { in getupvalref() argument
1259 StkId fi = index2addr(L, fidx); in getupvalref()
1260 api_check(L, ttisLclosure(fi), "Lua function expected"); in getupvalref()
1262 api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index"); in getupvalref()
1264 return &f->upvals[n - 1]; /* get its upvalue pointer */ in getupvalref()
1268 LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { in lua_upvalueid() argument
1269 StkId fi = index2addr(L, fidx); in lua_upvalueid()
1272 return *getupvalref(L, fidx, n, NULL); in lua_upvalueid()
1276 api_check(L, 1 <= n && n <= f->nupvalues, "invalid upvalue index"); in lua_upvalueid()
1277 return &f->upvalue[n - 1]; in lua_upvalueid()
1280 api_check(L, 0, "closure expected"); in lua_upvalueid()
1287 LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1, in lua_upvaluejoin() argument
1290 UpVal **up1 = getupvalref(L, fidx1, n1, &f1); in lua_upvaluejoin()
1291 UpVal **up2 = getupvalref(L, fidx2, n2, NULL); in lua_upvaluejoin()
1292 luaC_upvdeccount(L, *up1); in lua_upvaluejoin()
1294 (*up1)->refcount++; in lua_upvaluejoin()
1295 if (upisopen(*up1)) (*up1)->u.open.touched = 1; in lua_upvaluejoin()
1296 luaC_upvalbarrier(L, *up1); in lua_upvaluejoin()