Lines Matching full:l

43 ** '!ttisnil(o)' implies 'o != &G(L)->nilvalue', so it is not needed.
46 #define isvalid(L, o) (!ttisnil(o) || o != &G(L)->nilvalue) argument
58 ** Non-valid indices return the special nil value 'G(L)->nilvalue'.
60 static TValue *index2value (lua_State *L, int idx) { in index2value() argument
61 CallInfo *ci = L->ci; in index2value()
64 api_check(L, idx <= ci->top.p - (ci->func.p + 1), "unacceptable index"); in index2value()
65 if (o >= L->top.p) return &G(L)->nilvalue; in index2value()
69 api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1), in index2value()
71 return s2v(L->top.p + idx); in index2value()
74 return &G(L)->l_registry; in index2value()
77 api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); in index2value()
81 : &G(L)->nilvalue; in index2value()
84 api_check(L, ttislcf(s2v(ci->func.p)), "caller not a C function"); in index2value()
85 return &G(L)->nilvalue; /* no upvalues */ in index2value()
95 l_sinline StkId index2stack (lua_State *L, int idx) { in index2stack() argument
96 CallInfo *ci = L->ci; in index2stack()
99 api_check(L, o < L->top.p, "invalid index"); in index2stack()
103 api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1), in index2stack()
105 api_check(L, !ispseudo(idx), "invalid index"); in index2stack()
106 return L->top.p + idx; in index2stack()
111 LUA_API int lua_checkstack (lua_State *L, int n) { in lua_checkstack() argument
114 lua_lock(L); in lua_checkstack()
115 ci = L->ci; in lua_checkstack()
116 api_check(L, n >= 0, "negative 'n'"); in lua_checkstack()
117 if (L->stack_last.p - L->top.p > n) /* stack large enough? */ in lua_checkstack()
120 res = luaD_growstack(L, n, 0); in lua_checkstack()
121 if (res && ci->top.p < L->top.p + n) in lua_checkstack()
122 ci->top.p = L->top.p + n; /* adjust frame top */ in lua_checkstack()
123 lua_unlock(L); in lua_checkstack()
144 LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { in lua_atpanic() argument
146 lua_lock(L); in lua_atpanic()
147 old = G(L)->panic; in lua_atpanic()
148 G(L)->panic = panicf; in lua_atpanic()
149 lua_unlock(L); in lua_atpanic()
154 LUA_API lua_Number lua_version (lua_State *L) { in lua_version() argument
155 UNUSED(L); in lua_version()
169 LUA_API int lua_absindex (lua_State *L, int idx) { in lua_absindex() argument
172 : cast_int(L->top.p - L->ci->func.p) + idx; in lua_absindex()
176 LUA_API int lua_gettop (lua_State *L) { in lua_gettop() argument
177 return cast_int(L->top.p - (L->ci->func.p + 1)); in lua_gettop()
181 LUA_API void lua_settop (lua_State *L, int idx) { in lua_settop() argument
185 lua_lock(L); in lua_settop()
186 ci = L->ci; in lua_settop()
189 api_check(L, idx <= ci->top.p - (func + 1), "new top too large"); in lua_settop()
190 diff = ((func + 1) + idx) - L->top.p; in lua_settop()
192 setnilvalue(s2v(L->top.p++)); /* clear new slots */ in lua_settop()
195 api_check(L, -(idx+1) <= (L->top.p - (func + 1)), "invalid new top"); in lua_settop()
198 api_check(L, L->tbclist.p < L->top.p, "previous pop of an unclosed slot"); in lua_settop()
199 newtop = L->top.p + diff; in lua_settop()
200 if (diff < 0 && L->tbclist.p >= newtop) { in lua_settop()
202 newtop = luaF_close(L, newtop, CLOSEKTOP, 0); in lua_settop()
204 L->top.p = newtop; /* correct top only after closing any upvalue */ in lua_settop()
205 lua_unlock(L); in lua_settop()
209 LUA_API void lua_closeslot (lua_State *L, int idx) { in lua_closeslot() argument
211 lua_lock(L); in lua_closeslot()
212 level = index2stack(L, idx); in lua_closeslot()
213 api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist.p == level, in lua_closeslot()
215 level = luaF_close(L, level, CLOSEKTOP, 0); in lua_closeslot()
217 lua_unlock(L); in lua_closeslot()
227 l_sinline void reverse (lua_State *L, StkId from, StkId to) { in reverse() argument
230 setobj(L, &temp, s2v(from)); in reverse()
231 setobjs2s(L, from, to); in reverse()
232 setobj2s(L, to, &temp); in reverse()
241 LUA_API void lua_rotate (lua_State *L, int idx, int n) { in lua_rotate() argument
243 lua_lock(L); in lua_rotate()
244 t = L->top.p - 1; /* end of stack segment being rotated */ in lua_rotate()
245 p = index2stack(L, idx); /* start of segment */ in lua_rotate()
246 api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); in lua_rotate()
248 reverse(L, p, m); /* reverse the prefix with length 'n' */ in lua_rotate()
249 reverse(L, m + 1, t); /* reverse the suffix */ in lua_rotate()
250 reverse(L, p, t); /* reverse the entire segment */ in lua_rotate()
251 lua_unlock(L); in lua_rotate()
255 LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { in lua_copy() argument
257 lua_lock(L); in lua_copy()
258 fr = index2value(L, fromidx); in lua_copy()
259 to = index2value(L, toidx); in lua_copy()
260 api_check(L, isvalid(L, to), "invalid index"); in lua_copy()
261 setobj(L, to, fr); in lua_copy()
263 luaC_barrier(L, clCvalue(s2v(L->ci->func.p)), fr); in lua_copy()
266 lua_unlock(L); in lua_copy()
270 LUA_API void lua_pushvalue (lua_State *L, int idx) { in lua_pushvalue() argument
271 lua_lock(L); in lua_pushvalue()
272 setobj2s(L, L->top.p, index2value(L, idx)); in lua_pushvalue()
273 api_incr_top(L); in lua_pushvalue()
274 lua_unlock(L); in lua_pushvalue()
284 LUA_API int lua_type (lua_State *L, int idx) { in lua_type() argument
285 const TValue *o = index2value(L, idx); in lua_type()
286 return (isvalid(L, o) ? ttype(o) : LUA_TNONE); in lua_type()
290 LUA_API const char *lua_typename (lua_State *L, int t) { in lua_typename() argument
291 UNUSED(L); in lua_typename()
292 api_check(L, LUA_TNONE <= t && t < LUA_NUMTYPES, "invalid type"); in lua_typename()
297 LUA_API int lua_iscfunction (lua_State *L, int idx) { in lua_iscfunction() argument
298 const TValue *o = index2value(L, idx); in lua_iscfunction()
303 LUA_API int lua_isinteger (lua_State *L, int idx) { in lua_isinteger() argument
304 const TValue *o = index2value(L, idx); in lua_isinteger()
309 LUA_API int lua_isnumber (lua_State *L, int idx) { in lua_isnumber() argument
311 const TValue *o = index2value(L, idx); in lua_isnumber()
316 LUA_API int lua_isstring (lua_State *L, int idx) { in lua_isstring() argument
317 const TValue *o = index2value(L, idx); in lua_isstring()
322 LUA_API int lua_isuserdata (lua_State *L, int idx) { in lua_isuserdata() argument
323 const TValue *o = index2value(L, idx); in lua_isuserdata()
328 LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { in lua_rawequal() argument
329 const TValue *o1 = index2value(L, index1); in lua_rawequal()
330 const TValue *o2 = index2value(L, index2); in lua_rawequal()
331 return (isvalid(L, o1) && isvalid(L, o2)) ? luaV_rawequalobj(o1, o2) : 0; in lua_rawequal()
335 LUA_API void lua_arith (lua_State *L, int op) { in lua_arith() argument
336 lua_lock(L); in lua_arith()
338 api_checknelems(L, 2); /* all other operations expect two operands */ in lua_arith()
340 api_checknelems(L, 1); in lua_arith()
341 setobjs2s(L, L->top.p, L->top.p - 1); in lua_arith()
342 api_incr_top(L); in lua_arith()
345 luaO_arith(L, op, s2v(L->top.p - 2), s2v(L->top.p - 1), L->top.p - 2); in lua_arith()
346 L->top.p--; /* remove second operand */ in lua_arith()
347 lua_unlock(L); in lua_arith()
351 LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { in lua_compare() argument
355 lua_lock(L); /* may call tag method */ in lua_compare()
356 o1 = index2value(L, index1); in lua_compare()
357 o2 = index2value(L, index2); in lua_compare()
358 if (isvalid(L, o1) && isvalid(L, o2)) { in lua_compare()
360 case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break; in lua_compare()
361 case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; in lua_compare()
362 case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; in lua_compare()
363 default: api_check(L, 0, "invalid option"); in lua_compare()
366 lua_unlock(L); in lua_compare()
371 LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { in lua_stringtonumber() argument
372 size_t sz = luaO_str2num(s, s2v(L->top.p)); in lua_stringtonumber()
374 api_incr_top(L); in lua_stringtonumber()
379 LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { in lua_tonumberx() argument
381 const TValue *o = index2value(L, idx); in lua_tonumberx()
389 LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { in lua_tointegerx() argument
391 const TValue *o = index2value(L, idx); in lua_tointegerx()
399 LUA_API int lua_toboolean (lua_State *L, int idx) { in lua_toboolean() argument
400 const TValue *o = index2value(L, idx); in lua_toboolean()
405 LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { in lua_tolstring() argument
407 lua_lock(L); in lua_tolstring()
408 o = index2value(L, idx); in lua_tolstring()
412 lua_unlock(L); in lua_tolstring()
415 luaO_tostring(L, o); in lua_tolstring()
416 luaC_checkGC(L); in lua_tolstring()
417 o = index2value(L, idx); /* previous call may reallocate the stack */ in lua_tolstring()
421 lua_unlock(L); in lua_tolstring()
426 LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) { in lua_rawlen() argument
427 const TValue *o = index2value(L, idx); in lua_rawlen()
438 LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { in lua_tocfunction() argument
439 const TValue *o = index2value(L, idx); in lua_tocfunction()
456 LUA_API void *lua_touserdata (lua_State *L, int idx) { in lua_touserdata() argument
457 const TValue *o = index2value(L, idx); in lua_touserdata()
462 LUA_API lua_State *lua_tothread (lua_State *L, int idx) { in lua_tothread() argument
463 const TValue *o = index2value(L, idx); in lua_tothread()
475 LUA_API const void *lua_topointer (lua_State *L, int idx) { in lua_topointer() argument
476 const TValue *o = index2value(L, idx); in lua_topointer()
497 LUA_API void lua_pushnil (lua_State *L) { in lua_pushnil() argument
498 lua_lock(L); in lua_pushnil()
499 setnilvalue(s2v(L->top.p)); in lua_pushnil()
500 api_incr_top(L); in lua_pushnil()
501 lua_unlock(L); in lua_pushnil()
505 LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { in lua_pushnumber() argument
506 lua_lock(L); in lua_pushnumber()
507 setfltvalue(s2v(L->top.p), n); in lua_pushnumber()
508 api_incr_top(L); in lua_pushnumber()
509 lua_unlock(L); in lua_pushnumber()
513 LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { in lua_pushinteger() argument
514 lua_lock(L); in lua_pushinteger()
515 setivalue(s2v(L->top.p), n); in lua_pushinteger()
516 api_incr_top(L); in lua_pushinteger()
517 lua_unlock(L); in lua_pushinteger()
526 LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { in lua_pushlstring() argument
528 lua_lock(L); in lua_pushlstring()
529 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len); in lua_pushlstring()
530 setsvalue2s(L, L->top.p, ts); in lua_pushlstring()
531 api_incr_top(L); in lua_pushlstring()
532 luaC_checkGC(L); in lua_pushlstring()
533 lua_unlock(L); in lua_pushlstring()
538 LUA_API const char *lua_pushstring (lua_State *L, const char *s) { in lua_pushstring() argument
539 lua_lock(L); in lua_pushstring()
541 setnilvalue(s2v(L->top.p)); in lua_pushstring()
544 ts = luaS_new(L, s); in lua_pushstring()
545 setsvalue2s(L, L->top.p, ts); in lua_pushstring()
548 api_incr_top(L); in lua_pushstring()
549 luaC_checkGC(L); in lua_pushstring()
550 lua_unlock(L); in lua_pushstring()
555 LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, in lua_pushvfstring() argument
558 lua_lock(L); in lua_pushvfstring()
559 ret = luaO_pushvfstring(L, fmt, argp); in lua_pushvfstring()
560 luaC_checkGC(L); in lua_pushvfstring()
561 lua_unlock(L); in lua_pushvfstring()
566 LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { in lua_pushfstring() argument
569 lua_lock(L); in lua_pushfstring()
571 ret = luaO_pushvfstring(L, fmt, argp); in lua_pushfstring()
573 luaC_checkGC(L); in lua_pushfstring()
574 lua_unlock(L); in lua_pushfstring()
579 LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { in lua_pushcclosure() argument
580 lua_lock(L); in lua_pushcclosure()
582 setfvalue(s2v(L->top.p), fn); in lua_pushcclosure()
583 api_incr_top(L); in lua_pushcclosure()
587 api_checknelems(L, n); in lua_pushcclosure()
588 api_check(L, n <= MAXUPVAL, "upvalue index too large"); in lua_pushcclosure()
589 cl = luaF_newCclosure(L, n); in lua_pushcclosure()
591 L->top.p -= n; in lua_pushcclosure()
593 setobj2n(L, &cl->upvalue[n], s2v(L->top.p + n)); in lua_pushcclosure()
597 setclCvalue(L, s2v(L->top.p), cl); in lua_pushcclosure()
598 api_incr_top(L); in lua_pushcclosure()
599 luaC_checkGC(L); in lua_pushcclosure()
601 lua_unlock(L); in lua_pushcclosure()
605 LUA_API void lua_pushboolean (lua_State *L, int b) { in lua_pushboolean() argument
606 lua_lock(L); in lua_pushboolean()
608 setbtvalue(s2v(L->top.p)); in lua_pushboolean()
610 setbfvalue(s2v(L->top.p)); in lua_pushboolean()
611 api_incr_top(L); in lua_pushboolean()
612 lua_unlock(L); in lua_pushboolean()
616 LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { in lua_pushlightuserdata() argument
617 lua_lock(L); in lua_pushlightuserdata()
618 setpvalue(s2v(L->top.p), p); in lua_pushlightuserdata()
619 api_incr_top(L); in lua_pushlightuserdata()
620 lua_unlock(L); in lua_pushlightuserdata()
624 LUA_API int lua_pushthread (lua_State *L) { in lua_pushthread() argument
625 lua_lock(L); in lua_pushthread()
626 setthvalue(L, s2v(L->top.p), L); in lua_pushthread()
627 api_incr_top(L); in lua_pushthread()
628 lua_unlock(L); in lua_pushthread()
629 return (G(L)->mainthread == L); in lua_pushthread()
639 l_sinline int auxgetstr (lua_State *L, const TValue *t, const char *k) { in auxgetstr() argument
641 TString *str = luaS_new(L, k); in auxgetstr()
642 if (luaV_fastget(L, t, str, slot, luaH_getstr)) { in auxgetstr()
643 setobj2s(L, L->top.p, slot); in auxgetstr()
644 api_incr_top(L); in auxgetstr()
647 setsvalue2s(L, L->top.p, str); in auxgetstr()
648 api_incr_top(L); in auxgetstr()
649 luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot); in auxgetstr()
651 lua_unlock(L); in auxgetstr()
652 return ttype(s2v(L->top.p - 1)); in auxgetstr()
662 #define getGtable(L) \ argument
663 (&hvalue(&G(L)->l_registry)->array[LUA_RIDX_GLOBALS - 1])
666 LUA_API int lua_getglobal (lua_State *L, const char *name) { in lua_getglobal() argument
668 lua_lock(L); in lua_getglobal()
669 G = getGtable(L); in lua_getglobal()
670 return auxgetstr(L, G, name); in lua_getglobal()
674 LUA_API int lua_gettable (lua_State *L, int idx) { in lua_gettable() argument
677 lua_lock(L); in lua_gettable()
678 t = index2value(L, idx); in lua_gettable()
679 if (luaV_fastget(L, t, s2v(L->top.p - 1), slot, luaH_get)) { in lua_gettable()
680 setobj2s(L, L->top.p - 1, slot); in lua_gettable()
683 luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot); in lua_gettable()
684 lua_unlock(L); in lua_gettable()
685 return ttype(s2v(L->top.p - 1)); in lua_gettable()
689 LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { in lua_getfield() argument
690 lua_lock(L); in lua_getfield()
691 return auxgetstr(L, index2value(L, idx), k); in lua_getfield()
695 LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { in lua_geti() argument
698 lua_lock(L); in lua_geti()
699 t = index2value(L, idx); in lua_geti()
700 if (luaV_fastgeti(L, t, n, slot)) { in lua_geti()
701 setobj2s(L, L->top.p, slot); in lua_geti()
706 luaV_finishget(L, t, &aux, L->top.p, slot); in lua_geti()
708 api_incr_top(L); in lua_geti()
709 lua_unlock(L); in lua_geti()
710 return ttype(s2v(L->top.p - 1)); in lua_geti()
714 l_sinline int finishrawget (lua_State *L, const TValue *val) { in finishrawget() argument
716 setnilvalue(s2v(L->top.p)); in finishrawget()
718 setobj2s(L, L->top.p, val); in finishrawget()
719 api_incr_top(L); in finishrawget()
720 lua_unlock(L); in finishrawget()
721 return ttype(s2v(L->top.p - 1)); in finishrawget()
725 static Table *gettable (lua_State *L, int idx) { in gettable() argument
726 TValue *t = index2value(L, idx); in gettable()
727 api_check(L, ttistable(t), "table expected"); in gettable()
732 LUA_API int lua_rawget (lua_State *L, int idx) { in lua_rawget() argument
735 lua_lock(L); in lua_rawget()
736 api_checknelems(L, 1); in lua_rawget()
737 t = gettable(L, idx); in lua_rawget()
738 val = luaH_get(t, s2v(L->top.p - 1)); in lua_rawget()
739 L->top.p--; /* remove key */ in lua_rawget()
740 return finishrawget(L, val); in lua_rawget()
744 LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { in lua_rawgeti() argument
746 lua_lock(L); in lua_rawgeti()
747 t = gettable(L, idx); in lua_rawgeti()
748 return finishrawget(L, luaH_getint(t, n)); in lua_rawgeti()
752 LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { in lua_rawgetp() argument
755 lua_lock(L); in lua_rawgetp()
756 t = gettable(L, idx); in lua_rawgetp()
758 return finishrawget(L, luaH_get(t, &k)); in lua_rawgetp()
762 LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { in lua_createtable() argument
764 lua_lock(L); in lua_createtable()
765 t = luaH_new(L); in lua_createtable()
766 sethvalue2s(L, L->top.p, t); in lua_createtable()
767 api_incr_top(L); in lua_createtable()
769 luaH_resize(L, t, narray, nrec); in lua_createtable()
770 luaC_checkGC(L); in lua_createtable()
771 lua_unlock(L); in lua_createtable()
775 LUA_API int lua_getmetatable (lua_State *L, int objindex) { in lua_getmetatable() argument
779 lua_lock(L); in lua_getmetatable()
780 obj = index2value(L, objindex); in lua_getmetatable()
789 mt = G(L)->mt[ttype(obj)]; in lua_getmetatable()
793 sethvalue2s(L, L->top.p, mt); in lua_getmetatable()
794 api_incr_top(L); in lua_getmetatable()
797 lua_unlock(L); in lua_getmetatable()
802 LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) { in lua_getiuservalue() argument
805 lua_lock(L); in lua_getiuservalue()
806 o = index2value(L, idx); in lua_getiuservalue()
807 api_check(L, ttisfulluserdata(o), "full userdata expected"); in lua_getiuservalue()
809 setnilvalue(s2v(L->top.p)); in lua_getiuservalue()
813 setobj2s(L, L->top.p, &uvalue(o)->uv[n - 1].uv); in lua_getiuservalue()
814 t = ttype(s2v(L->top.p)); in lua_getiuservalue()
816 api_incr_top(L); in lua_getiuservalue()
817 lua_unlock(L); in lua_getiuservalue()
829 static void auxsetstr (lua_State *L, const TValue *t, const char *k) { in auxsetstr() argument
831 TString *str = luaS_new(L, k); in auxsetstr()
832 api_checknelems(L, 1); in auxsetstr()
833 if (luaV_fastget(L, t, str, slot, luaH_getstr)) { in auxsetstr()
834 luaV_finishfastset(L, t, slot, s2v(L->top.p - 1)); in auxsetstr()
835 L->top.p--; /* pop value */ in auxsetstr()
838 setsvalue2s(L, L->top.p, str); /* push 'str' (to make it a TValue) */ in auxsetstr()
839 api_incr_top(L); in auxsetstr()
840 luaV_finishset(L, t, s2v(L->top.p - 1), s2v(L->top.p - 2), slot); in auxsetstr()
841 L->top.p -= 2; /* pop value and key */ in auxsetstr()
843 lua_unlock(L); /* lock done by caller */ in auxsetstr()
847 LUA_API void lua_setglobal (lua_State *L, const char *name) { in lua_setglobal() argument
849 lua_lock(L); /* unlock done in 'auxsetstr' */ in lua_setglobal()
850 G = getGtable(L); in lua_setglobal()
851 auxsetstr(L, G, name); in lua_setglobal()
855 LUA_API void lua_settable (lua_State *L, int idx) { in lua_settable() argument
858 lua_lock(L); in lua_settable()
859 api_checknelems(L, 2); in lua_settable()
860 t = index2value(L, idx); in lua_settable()
861 if (luaV_fastget(L, t, s2v(L->top.p - 2), slot, luaH_get)) { in lua_settable()
862 luaV_finishfastset(L, t, slot, s2v(L->top.p - 1)); in lua_settable()
865 luaV_finishset(L, t, s2v(L->top.p - 2), s2v(L->top.p - 1), slot); in lua_settable()
866 L->top.p -= 2; /* pop index and value */ in lua_settable()
867 lua_unlock(L); in lua_settable()
871 LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { in lua_setfield() argument
872 lua_lock(L); /* unlock done in 'auxsetstr' */ in lua_setfield()
873 auxsetstr(L, index2value(L, idx), k); in lua_setfield()
877 LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { in lua_seti() argument
880 lua_lock(L); in lua_seti()
881 api_checknelems(L, 1); in lua_seti()
882 t = index2value(L, idx); in lua_seti()
883 if (luaV_fastgeti(L, t, n, slot)) { in lua_seti()
884 luaV_finishfastset(L, t, slot, s2v(L->top.p - 1)); in lua_seti()
889 luaV_finishset(L, t, &aux, s2v(L->top.p - 1), slot); in lua_seti()
891 L->top.p--; /* pop value */ in lua_seti()
892 lua_unlock(L); in lua_seti()
896 static void aux_rawset (lua_State *L, int idx, TValue *key, int n) { in aux_rawset() argument
898 lua_lock(L); in aux_rawset()
899 api_checknelems(L, n); in aux_rawset()
900 t = gettable(L, idx); in aux_rawset()
901 luaH_set(L, t, key, s2v(L->top.p - 1)); in aux_rawset()
903 luaC_barrierback(L, obj2gco(t), s2v(L->top.p - 1)); in aux_rawset()
904 L->top.p -= n; in aux_rawset()
905 lua_unlock(L); in aux_rawset()
909 LUA_API void lua_rawset (lua_State *L, int idx) { in lua_rawset() argument
910 aux_rawset(L, idx, s2v(L->top.p - 2), 2); in lua_rawset()
914 LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { in lua_rawsetp() argument
917 aux_rawset(L, idx, &k, 1); in lua_rawsetp()
921 LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { in lua_rawseti() argument
923 lua_lock(L); in lua_rawseti()
924 api_checknelems(L, 1); in lua_rawseti()
925 t = gettable(L, idx); in lua_rawseti()
926 luaH_setint(L, t, n, s2v(L->top.p - 1)); in lua_rawseti()
927 luaC_barrierback(L, obj2gco(t), s2v(L->top.p - 1)); in lua_rawseti()
928 L->top.p--; in lua_rawseti()
929 lua_unlock(L); in lua_rawseti()
933 LUA_API int lua_setmetatable (lua_State *L, int objindex) { in lua_setmetatable() argument
936 lua_lock(L); in lua_setmetatable()
937 api_checknelems(L, 1); in lua_setmetatable()
938 obj = index2value(L, objindex); in lua_setmetatable()
939 if (ttisnil(s2v(L->top.p - 1))) in lua_setmetatable()
942 api_check(L, ttistable(s2v(L->top.p - 1)), "table expected"); in lua_setmetatable()
943 mt = hvalue(s2v(L->top.p - 1)); in lua_setmetatable()
949 luaC_objbarrier(L, gcvalue(obj), mt); in lua_setmetatable()
950 luaC_checkfinalizer(L, gcvalue(obj), mt); in lua_setmetatable()
957 luaC_objbarrier(L, uvalue(obj), mt); in lua_setmetatable()
958 luaC_checkfinalizer(L, gcvalue(obj), mt); in lua_setmetatable()
963 G(L)->mt[ttype(obj)] = mt; in lua_setmetatable()
967 L->top.p--; in lua_setmetatable()
968 lua_unlock(L); in lua_setmetatable()
973 LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) { in lua_setiuservalue() argument
976 lua_lock(L); in lua_setiuservalue()
977 api_checknelems(L, 1); in lua_setiuservalue()
978 o = index2value(L, idx); in lua_setiuservalue()
979 api_check(L, ttisfulluserdata(o), "full userdata expected"); in lua_setiuservalue()
983 setobj(L, &uvalue(o)->uv[n - 1].uv, s2v(L->top.p - 1)); in lua_setiuservalue()
984 luaC_barrierback(L, gcvalue(o), s2v(L->top.p - 1)); in lua_setiuservalue()
987 L->top.p--; in lua_setiuservalue()
988 lua_unlock(L); in lua_setiuservalue()
998 #define checkresults(L,na,nr) \ argument
999 api_check(L, (nr) == LUA_MULTRET \
1000 || (L->ci->top.p - L->top.p >= (nr) - (na)), \
1004 LUA_API void lua_callk (lua_State *L, int nargs, int nresults, in lua_callk() argument
1007 lua_lock(L); in lua_callk()
1008 api_check(L, k == NULL || !isLua(L->ci), in lua_callk()
1010 api_checknelems(L, nargs+1); in lua_callk()
1011 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); in lua_callk()
1012 checkresults(L, nargs, nresults); in lua_callk()
1013 func = L->top.p - (nargs+1); in lua_callk()
1014 if (k != NULL && yieldable(L)) { /* need to prepare continuation? */ in lua_callk()
1015 L->ci->u.c.k = k; /* save continuation */ in lua_callk()
1016 L->ci->u.c.ctx = ctx; /* save context */ in lua_callk()
1017 luaD_call(L, func, nresults); /* do the call */ in lua_callk()
1020 luaD_callnoyield(L, func, nresults); /* just do the call */ in lua_callk()
1021 adjustresults(L, nresults); in lua_callk()
1022 lua_unlock(L); in lua_callk()
1036 static void f_call (lua_State *L, void *ud) { in f_call() argument
1038 luaD_callnoyield(L, c->func, c->nresults); in f_call()
1043 LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, in lua_pcallk() argument
1048 lua_lock(L); in lua_pcallk()
1049 api_check(L, k == NULL || !isLua(L->ci), in lua_pcallk()
1051 api_checknelems(L, nargs+1); in lua_pcallk()
1052 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); in lua_pcallk()
1053 checkresults(L, nargs, nresults); in lua_pcallk()
1057 StkId o = index2stack(L, errfunc); in lua_pcallk()
1058 api_check(L, ttisfunction(s2v(o)), "error handler must be a function"); in lua_pcallk()
1059 func = savestack(L, o); in lua_pcallk()
1061 c.func = L->top.p - (nargs+1); /* function to be called */ in lua_pcallk()
1062 if (k == NULL || !yieldable(L)) { /* no continuation or no yieldable? */ in lua_pcallk()
1064 status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); in lua_pcallk()
1067 CallInfo *ci = L->ci; in lua_pcallk()
1071 ci->u2.funcidx = cast_int(savestack(L, c.func)); in lua_pcallk()
1072 ci->u.c.old_errfunc = L->errfunc; in lua_pcallk()
1073 L->errfunc = func; in lua_pcallk()
1074 setoah(ci->callstatus, L->allowhook); /* save value of 'allowhook' */ in lua_pcallk()
1076 luaD_call(L, c.func, nresults); /* do the call */ in lua_pcallk()
1078 L->errfunc = ci->u.c.old_errfunc; in lua_pcallk()
1081 adjustresults(L, nresults); in lua_pcallk()
1082 lua_unlock(L); in lua_pcallk()
1087 LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, in lua_load() argument
1091 lua_lock(L); in lua_load()
1093 luaZ_init(L, &z, reader, data); in lua_load()
1094 status = luaD_protectedparser(L, &z, chunkname, mode); in lua_load()
1096 LClosure *f = clLvalue(s2v(L->top.p - 1)); /* get new function */ in lua_load()
1099 const TValue *gt = getGtable(L); in lua_load()
1101 setobj(L, f->upvals[0]->v.p, gt); in lua_load()
1102 luaC_barrier(L, f->upvals[0], gt); in lua_load()
1105 lua_unlock(L); in lua_load()
1110 LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) { in lua_dump() argument
1113 lua_lock(L); in lua_dump()
1114 api_checknelems(L, 1); in lua_dump()
1115 o = s2v(L->top.p - 1); in lua_dump()
1117 status = luaU_dump(L, getproto(o), writer, data, strip); in lua_dump()
1120 lua_unlock(L); in lua_dump()
1125 LUA_API int lua_status (lua_State *L) { in lua_status() argument
1126 return L->status; in lua_status()
1133 LUA_API int lua_gc (lua_State *L, int what, ...) { in lua_gc() argument
1136 global_State *g = G(L); in lua_gc()
1139 lua_lock(L); in lua_gc()
1152 luaC_fullgc(L, 0); in lua_gc()
1171 luaC_step(L); in lua_gc()
1176 luaC_checkGC(L); in lua_gc()
1207 luaC_changemode(L, KGC_GEN); in lua_gc()
1221 luaC_changemode(L, KGC_INC); in lua_gc()
1227 lua_unlock(L); in lua_gc()
1238 LUA_API int lua_error (lua_State *L) { in lua_error() argument
1240 lua_lock(L); in lua_error()
1241 errobj = s2v(L->top.p - 1); in lua_error()
1242 api_checknelems(L, 1); in lua_error()
1244 if (ttisshrstring(errobj) && eqshrstr(tsvalue(errobj), G(L)->memerrmsg)) in lua_error()
1245 luaM_error(L); /* raise a memory error */ in lua_error()
1247 luaG_errormsg(L); /* raise a regular error */ in lua_error()
1253 LUA_API int lua_next (lua_State *L, int idx) { in lua_next() argument
1256 lua_lock(L); in lua_next()
1257 api_checknelems(L, 1); in lua_next()
1258 t = gettable(L, idx); in lua_next()
1259 more = luaH_next(L, t, L->top.p - 1); in lua_next()
1261 api_incr_top(L); in lua_next()
1264 L->top.p -= 1; /* remove key */ in lua_next()
1265 lua_unlock(L); in lua_next()
1270 LUA_API void lua_toclose (lua_State *L, int idx) { in lua_toclose() argument
1273 lua_lock(L); in lua_toclose()
1274 o = index2stack(L, idx); in lua_toclose()
1275 nresults = L->ci->nresults; in lua_toclose()
1276 api_check(L, L->tbclist.p < o, "given index below or equal a marked one"); in lua_toclose()
1277 luaF_newtbcupval(L, o); /* create new to-be-closed upvalue */ in lua_toclose()
1279 L->ci->nresults = codeNresults(nresults); /* mark it */ in lua_toclose()
1280 lua_assert(hastocloseCfunc(L->ci->nresults)); in lua_toclose()
1281 lua_unlock(L); in lua_toclose()
1285 LUA_API void lua_concat (lua_State *L, int n) { in lua_concat() argument
1286 lua_lock(L); in lua_concat()
1287 api_checknelems(L, n); in lua_concat()
1289 luaV_concat(L, n); in lua_concat()
1291 setsvalue2s(L, L->top.p, luaS_newlstr(L, "", 0)); /* push empty string */ in lua_concat()
1292 api_incr_top(L); in lua_concat()
1294 luaC_checkGC(L); in lua_concat()
1295 lua_unlock(L); in lua_concat()
1299 LUA_API void lua_len (lua_State *L, int idx) { in lua_len() argument
1301 lua_lock(L); in lua_len()
1302 t = index2value(L, idx); in lua_len()
1303 luaV_objlen(L, L->top.p, t); in lua_len()
1304 api_incr_top(L); in lua_len()
1305 lua_unlock(L); in lua_len()
1309 LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { in lua_getallocf() argument
1311 lua_lock(L); in lua_getallocf()
1312 if (ud) *ud = G(L)->ud; in lua_getallocf()
1313 f = G(L)->frealloc; in lua_getallocf()
1314 lua_unlock(L); in lua_getallocf()
1319 LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) { in lua_setallocf() argument
1320 lua_lock(L); in lua_setallocf()
1321 G(L)->ud = ud; in lua_setallocf()
1322 G(L)->frealloc = f; in lua_setallocf()
1323 lua_unlock(L); in lua_setallocf()
1327 void lua_setwarnf (lua_State *L, lua_WarnFunction f, void *ud) { in lua_setwarnf() argument
1328 lua_lock(L); in lua_setwarnf()
1329 G(L)->ud_warn = ud; in lua_setwarnf()
1330 G(L)->warnf = f; in lua_setwarnf()
1331 lua_unlock(L); in lua_setwarnf()
1335 void lua_warning (lua_State *L, const char *msg, int tocont) { in lua_warning() argument
1336 lua_lock(L); in lua_warning()
1337 luaE_warning(L, msg, tocont); in lua_warning()
1338 lua_unlock(L); in lua_warning()
1343 LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) { in lua_newuserdatauv() argument
1345 lua_lock(L); in lua_newuserdatauv()
1346 api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, "invalid value"); in lua_newuserdatauv()
1347 u = luaS_newudata(L, size, nuvalue); in lua_newuserdatauv()
1348 setuvalue(L, s2v(L->top.p), u); in lua_newuserdatauv()
1349 api_incr_top(L); in lua_newuserdatauv()
1350 luaC_checkGC(L); in lua_newuserdatauv()
1351 lua_unlock(L); in lua_newuserdatauv()
1384 LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { in lua_getupvalue() argument
1387 lua_lock(L); in lua_getupvalue()
1388 name = aux_upvalue(index2value(L, funcindex), n, &val, NULL); in lua_getupvalue()
1390 setobj2s(L, L->top.p, val); in lua_getupvalue()
1391 api_incr_top(L); in lua_getupvalue()
1393 lua_unlock(L); in lua_getupvalue()
1398 LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { in lua_setupvalue() argument
1403 lua_lock(L); in lua_setupvalue()
1404 fi = index2value(L, funcindex); in lua_setupvalue()
1405 api_checknelems(L, 1); in lua_setupvalue()
1408 L->top.p--; in lua_setupvalue()
1409 setobj(L, val, s2v(L->top.p)); in lua_setupvalue()
1410 luaC_barrier(L, owner, val); in lua_setupvalue()
1412 lua_unlock(L); in lua_setupvalue()
1417 static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { in getupvalref() argument
1420 TValue *fi = index2value(L, fidx); in getupvalref()
1421 api_check(L, ttisLclosure(fi), "Lua function expected"); in getupvalref()
1431 LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { in lua_upvalueid() argument
1432 TValue *fi = index2value(L, fidx); in lua_upvalueid()
1435 return *getupvalref(L, fidx, n, NULL); in lua_upvalueid()
1446 api_check(L, 0, "function expected"); in lua_upvalueid()
1453 LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1, in lua_upvaluejoin() argument
1456 UpVal **up1 = getupvalref(L, fidx1, n1, &f1); in lua_upvaluejoin()
1457 UpVal **up2 = getupvalref(L, fidx2, n2, NULL); in lua_upvaluejoin()
1458 api_check(L, *up1 != NULL && *up2 != NULL, "invalid upvalue index"); in lua_upvaluejoin()
1460 luaC_objbarrier(L, f1, *up1); in lua_upvaluejoin()