Lines Matching refs:L

52 #define isvalid(L, o)	(!ttisnil(o) || o != &G(L)->nilvalue)  argument
66 static TValue *index2value (lua_State *L, int idx) { in index2value() argument
67 CallInfo *ci = L->ci; in index2value()
70 api_check(L, idx <= ci->top.p - (ci->func.p + 1), "unacceptable index"); in index2value()
71 if (o >= L->top.p) return &G(L)->nilvalue; in index2value()
75 api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1), in index2value()
77 return s2v(L->top.p + idx); in index2value()
80 return &G(L)->l_registry; in index2value()
83 api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); in index2value()
87 : &G(L)->nilvalue; in index2value()
90 api_check(L, ttislcf(s2v(ci->func.p)), "caller not a C function"); in index2value()
91 return &G(L)->nilvalue; /* no upvalues */ in index2value()
101 l_sinline StkId index2stack (lua_State *L, int idx) { in index2stack() argument
102 CallInfo *ci = L->ci; in index2stack()
105 api_check(L, o < L->top.p, "invalid index"); in index2stack()
109 api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1), in index2stack()
111 api_check(L, !ispseudo(idx), "invalid index"); in index2stack()
112 return L->top.p + idx; in index2stack()
117 LUA_API int lua_checkstack (lua_State *L, int n) { in lua_checkstack() argument
120 lua_lock(L); in lua_checkstack()
121 ci = L->ci; in lua_checkstack()
122 api_check(L, n >= 0, "negative 'n'"); in lua_checkstack()
123 if (L->stack_last.p - L->top.p > n) /* stack large enough? */ in lua_checkstack()
126 res = luaD_growstack(L, n, 0); in lua_checkstack()
127 if (res && ci->top.p < L->top.p + n) in lua_checkstack()
128 ci->top.p = L->top.p + n; /* adjust frame top */ in lua_checkstack()
129 lua_unlock(L); in lua_checkstack()
150 LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { in lua_atpanic() argument
152 lua_lock(L); in lua_atpanic()
153 old = G(L)->panic; in lua_atpanic()
154 G(L)->panic = panicf; in lua_atpanic()
155 lua_unlock(L); in lua_atpanic()
160 LUA_API lua_Number lua_version (lua_State *L) { in lua_version() argument
161 UNUSED(L); in lua_version()
175 LUA_API int lua_absindex (lua_State *L, int idx) { in lua_absindex() argument
178 : cast_int(L->top.p - L->ci->func.p) + idx; in lua_absindex()
182 LUA_API int lua_gettop (lua_State *L) { in lua_gettop() argument
183 return cast_int(L->top.p - (L->ci->func.p + 1)); in lua_gettop()
187 LUA_API void lua_settop (lua_State *L, int idx) { in lua_settop() argument
191 lua_lock(L); in lua_settop()
192 ci = L->ci; in lua_settop()
195 api_check(L, idx <= ci->top.p - (func + 1), "new top too large"); in lua_settop()
196 diff = ((func + 1) + idx) - L->top.p; in lua_settop()
198 setnilvalue(s2v(L->top.p++)); /* clear new slots */ in lua_settop()
201 api_check(L, -(idx+1) <= (L->top.p - (func + 1)), "invalid new top"); in lua_settop()
204 api_check(L, L->tbclist.p < L->top.p, "previous pop of an unclosed slot"); in lua_settop()
205 newtop = L->top.p + diff; in lua_settop()
206 if (diff < 0 && L->tbclist.p >= newtop) { in lua_settop()
208 newtop = luaF_close(L, newtop, CLOSEKTOP, 0); in lua_settop()
210 L->top.p = newtop; /* correct top only after closing any upvalue */ in lua_settop()
211 lua_unlock(L); in lua_settop()
215 LUA_API void lua_closeslot (lua_State *L, int idx) { in lua_closeslot() argument
217 lua_lock(L); in lua_closeslot()
218 level = index2stack(L, idx); in lua_closeslot()
219 api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist.p == level, in lua_closeslot()
221 level = luaF_close(L, level, CLOSEKTOP, 0); in lua_closeslot()
223 lua_unlock(L); in lua_closeslot()
233 l_sinline void reverse (lua_State *L, StkId from, StkId to) { in reverse() argument
236 setobj(L, &temp, s2v(from)); in reverse()
237 setobjs2s(L, from, to); in reverse()
238 setobj2s(L, to, &temp); in reverse()
247 LUA_API void lua_rotate (lua_State *L, int idx, int n) { in lua_rotate() argument
249 lua_lock(L); in lua_rotate()
250 t = L->top.p - 1; /* end of stack segment being rotated */ in lua_rotate()
251 p = index2stack(L, idx); /* start of segment */ in lua_rotate()
252 api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); in lua_rotate()
254 reverse(L, p, m); /* reverse the prefix with length 'n' */ in lua_rotate()
255 reverse(L, m + 1, t); /* reverse the suffix */ in lua_rotate()
256 reverse(L, p, t); /* reverse the entire segment */ in lua_rotate()
257 lua_unlock(L); in lua_rotate()
261 LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { in lua_copy() argument
263 lua_lock(L); in lua_copy()
264 fr = index2value(L, fromidx); in lua_copy()
265 to = index2value(L, toidx); in lua_copy()
266 api_check(L, isvalid(L, to), "invalid index"); in lua_copy()
267 setobj(L, to, fr); in lua_copy()
269 luaC_barrier(L, clCvalue(s2v(L->ci->func.p)), fr); in lua_copy()
272 lua_unlock(L); in lua_copy()
276 LUA_API void lua_pushvalue (lua_State *L, int idx) { in lua_pushvalue() argument
277 lua_lock(L); in lua_pushvalue()
278 setobj2s(L, L->top.p, index2value(L, idx)); in lua_pushvalue()
279 api_incr_top(L); in lua_pushvalue()
280 lua_unlock(L); in lua_pushvalue()
290 LUA_API int lua_type (lua_State *L, int idx) { in lua_type() argument
291 const TValue *o = index2value(L, idx); in lua_type()
292 return (isvalid(L, o) ? ttype(o) : LUA_TNONE); in lua_type()
296 LUA_API const char *lua_typename (lua_State *L, int t) { in lua_typename() argument
297 UNUSED(L); in lua_typename()
298 api_check(L, LUA_TNONE <= t && t < LUA_NUMTYPES, "invalid type"); in lua_typename()
303 LUA_API int lua_iscfunction (lua_State *L, int idx) { in lua_iscfunction() argument
304 const TValue *o = index2value(L, idx); in lua_iscfunction()
309 LUA_API int lua_isinteger (lua_State *L, int idx) { in lua_isinteger() argument
310 const TValue *o = index2value(L, idx); in lua_isinteger()
315 LUA_API int lua_isnumber (lua_State *L, int idx) { in lua_isnumber() argument
317 const TValue *o = index2value(L, idx); in lua_isnumber()
322 LUA_API int lua_isstring (lua_State *L, int idx) { in lua_isstring() argument
323 const TValue *o = index2value(L, idx); in lua_isstring()
328 LUA_API int lua_isuserdata (lua_State *L, int idx) { in lua_isuserdata() argument
329 const TValue *o = index2value(L, idx); in lua_isuserdata()
334 LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { in lua_rawequal() argument
335 const TValue *o1 = index2value(L, index1); in lua_rawequal()
336 const TValue *o2 = index2value(L, index2); in lua_rawequal()
337 return (isvalid(L, o1) && isvalid(L, o2)) ? luaV_rawequalobj(o1, o2) : 0; in lua_rawequal()
341 LUA_API void lua_arith (lua_State *L, int op) { in lua_arith() argument
342 lua_lock(L); in lua_arith()
344 api_checknelems(L, 2); /* all other operations expect two operands */ in lua_arith()
346 api_checknelems(L, 1); in lua_arith()
347 setobjs2s(L, L->top.p, L->top.p - 1); in lua_arith()
348 api_incr_top(L); in lua_arith()
351 luaO_arith(L, op, s2v(L->top.p - 2), s2v(L->top.p - 1), L->top.p - 2); in lua_arith()
352 L->top.p--; /* remove second operand */ in lua_arith()
353 lua_unlock(L); in lua_arith()
357 LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { in lua_compare() argument
361 lua_lock(L); /* may call tag method */ in lua_compare()
362 o1 = index2value(L, index1); in lua_compare()
363 o2 = index2value(L, index2); in lua_compare()
364 if (isvalid(L, o1) && isvalid(L, o2)) { in lua_compare()
366 case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break; in lua_compare()
367 case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; in lua_compare()
368 case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; in lua_compare()
369 default: api_check(L, 0, "invalid option"); in lua_compare()
372 lua_unlock(L); in lua_compare()
377 LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { in lua_stringtonumber() argument
378 size_t sz = luaO_str2num(s, s2v(L->top.p)); in lua_stringtonumber()
380 api_incr_top(L); in lua_stringtonumber()
386 LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { in lua_tonumberx() argument
388 const TValue *o = index2value(L, idx); in lua_tonumberx()
397 LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { in lua_tointegerx() argument
399 const TValue *o = index2value(L, idx); in lua_tointegerx()
407 LUA_API int lua_toboolean (lua_State *L, int idx) { in lua_toboolean() argument
408 const TValue *o = index2value(L, idx); in lua_toboolean()
413 LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { in lua_tolstring() argument
415 lua_lock(L); in lua_tolstring()
416 o = index2value(L, idx); in lua_tolstring()
420 lua_unlock(L); in lua_tolstring()
423 luaO_tostring(L, o); in lua_tolstring()
424 luaC_checkGC(L); in lua_tolstring()
425 o = index2value(L, idx); /* previous call may reallocate the stack */ in lua_tolstring()
429 lua_unlock(L); in lua_tolstring()
434 LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) { in lua_rawlen() argument
435 const TValue *o = index2value(L, idx); in lua_rawlen()
446 LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { in lua_tocfunction() argument
447 const TValue *o = index2value(L, idx); in lua_tocfunction()
464 LUA_API void *lua_touserdata (lua_State *L, int idx) { in lua_touserdata() argument
465 const TValue *o = index2value(L, idx); in lua_touserdata()
470 LUA_API lua_State *lua_tothread (lua_State *L, int idx) { in lua_tothread() argument
471 const TValue *o = index2value(L, idx); in lua_tothread()
483 LUA_API const void *lua_topointer (lua_State *L, int idx) { in lua_topointer() argument
484 const TValue *o = index2value(L, idx); in lua_topointer()
505 LUA_API void lua_pushnil (lua_State *L) { in lua_pushnil() argument
506 lua_lock(L); in lua_pushnil()
507 setnilvalue(s2v(L->top.p)); in lua_pushnil()
508 api_incr_top(L); in lua_pushnil()
509 lua_unlock(L); in lua_pushnil()
514 LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { in lua_pushnumber() argument
515 lua_lock(L); in lua_pushnumber()
516 setfltvalue(s2v(L->top.p), n); in lua_pushnumber()
517 api_incr_top(L); in lua_pushnumber()
518 lua_unlock(L); in lua_pushnumber()
523 LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { in lua_pushinteger() argument
524 lua_lock(L); in lua_pushinteger()
525 setivalue(s2v(L->top.p), n); in lua_pushinteger()
526 api_incr_top(L); in lua_pushinteger()
527 lua_unlock(L); in lua_pushinteger()
536 LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { in lua_pushlstring() argument
538 lua_lock(L); in lua_pushlstring()
539 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len); in lua_pushlstring()
540 setsvalue2s(L, L->top.p, ts); in lua_pushlstring()
541 api_incr_top(L); in lua_pushlstring()
542 luaC_checkGC(L); in lua_pushlstring()
543 lua_unlock(L); in lua_pushlstring()
548 LUA_API const char *lua_pushstring (lua_State *L, const char *s) { in lua_pushstring() argument
549 lua_lock(L); in lua_pushstring()
551 setnilvalue(s2v(L->top.p)); in lua_pushstring()
554 ts = luaS_new(L, s); in lua_pushstring()
555 setsvalue2s(L, L->top.p, ts); in lua_pushstring()
558 api_incr_top(L); in lua_pushstring()
559 luaC_checkGC(L); in lua_pushstring()
560 lua_unlock(L); in lua_pushstring()
565 LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, in lua_pushvfstring() argument
568 lua_lock(L); in lua_pushvfstring()
569 ret = luaO_pushvfstring(L, fmt, argp); in lua_pushvfstring()
570 luaC_checkGC(L); in lua_pushvfstring()
571 lua_unlock(L); in lua_pushvfstring()
576 LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { in lua_pushfstring() argument
579 lua_lock(L); in lua_pushfstring()
581 ret = luaO_pushvfstring(L, fmt, argp); in lua_pushfstring()
583 luaC_checkGC(L); in lua_pushfstring()
584 lua_unlock(L); in lua_pushfstring()
589 LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { in lua_pushcclosure() argument
590 lua_lock(L); in lua_pushcclosure()
592 setfvalue(s2v(L->top.p), fn); in lua_pushcclosure()
593 api_incr_top(L); in lua_pushcclosure()
597 api_checknelems(L, n); in lua_pushcclosure()
598 api_check(L, n <= MAXUPVAL, "upvalue index too large"); in lua_pushcclosure()
599 cl = luaF_newCclosure(L, n); in lua_pushcclosure()
601 L->top.p -= n; in lua_pushcclosure()
603 setobj2n(L, &cl->upvalue[n], s2v(L->top.p + n)); in lua_pushcclosure()
607 setclCvalue(L, s2v(L->top.p), cl); in lua_pushcclosure()
608 api_incr_top(L); in lua_pushcclosure()
609 luaC_checkGC(L); in lua_pushcclosure()
611 lua_unlock(L); in lua_pushcclosure()
615 LUA_API void lua_pushboolean (lua_State *L, int b) { in lua_pushboolean() argument
616 lua_lock(L); in lua_pushboolean()
618 setbtvalue(s2v(L->top.p)); in lua_pushboolean()
620 setbfvalue(s2v(L->top.p)); in lua_pushboolean()
621 api_incr_top(L); in lua_pushboolean()
622 lua_unlock(L); in lua_pushboolean()
626 LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { in lua_pushlightuserdata() argument
627 lua_lock(L); in lua_pushlightuserdata()
628 setpvalue(s2v(L->top.p), p); in lua_pushlightuserdata()
629 api_incr_top(L); in lua_pushlightuserdata()
630 lua_unlock(L); in lua_pushlightuserdata()
634 LUA_API int lua_pushthread (lua_State *L) { in lua_pushthread() argument
635 lua_lock(L); in lua_pushthread()
636 setthvalue(L, s2v(L->top.p), L); in lua_pushthread()
637 api_incr_top(L); in lua_pushthread()
638 lua_unlock(L); in lua_pushthread()
639 return (G(L)->mainthread == L); in lua_pushthread()
649 l_sinline int auxgetstr (lua_State *L, const TValue *t, const char *k) { in auxgetstr() argument
651 TString *str = luaS_new(L, k); in auxgetstr()
652 if (luaV_fastget(L, t, str, slot, luaH_getstr)) { in auxgetstr()
653 setobj2s(L, L->top.p, slot); in auxgetstr()
654 api_incr_top(L); in auxgetstr()
657 setsvalue2s(L, L->top.p, str); in auxgetstr()
658 api_incr_top(L); in auxgetstr()
659 luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot); in auxgetstr()
661 lua_unlock(L); in auxgetstr()
662 return ttype(s2v(L->top.p - 1)); in auxgetstr()
672 #define getGtable(L) \ argument
673 (&hvalue(&G(L)->l_registry)->array[LUA_RIDX_GLOBALS - 1])
676 LUA_API int lua_getglobal (lua_State *L, const char *name) { in lua_getglobal() argument
678 lua_lock(L); in lua_getglobal()
679 G = getGtable(L); in lua_getglobal()
680 return auxgetstr(L, G, name); in lua_getglobal()
684 LUA_API int lua_gettable (lua_State *L, int idx) { in lua_gettable() argument
687 lua_lock(L); in lua_gettable()
688 t = index2value(L, idx); in lua_gettable()
689 if (luaV_fastget(L, t, s2v(L->top.p - 1), slot, luaH_get)) { in lua_gettable()
690 setobj2s(L, L->top.p - 1, slot); in lua_gettable()
693 luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot); in lua_gettable()
694 lua_unlock(L); in lua_gettable()
695 return ttype(s2v(L->top.p - 1)); in lua_gettable()
699 LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { in lua_getfield() argument
700 lua_lock(L); in lua_getfield()
701 return auxgetstr(L, index2value(L, idx), k); in lua_getfield()
705 LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { in lua_geti() argument
708 lua_lock(L); in lua_geti()
709 t = index2value(L, idx); in lua_geti()
710 if (luaV_fastgeti(L, t, n, slot)) { in lua_geti()
711 setobj2s(L, L->top.p, slot); in lua_geti()
716 luaV_finishget(L, t, &aux, L->top.p, slot); in lua_geti()
718 api_incr_top(L); in lua_geti()
719 lua_unlock(L); in lua_geti()
720 return ttype(s2v(L->top.p - 1)); in lua_geti()
724 l_sinline int finishrawget (lua_State *L, const TValue *val) { in finishrawget() argument
726 setnilvalue(s2v(L->top.p)); in finishrawget()
728 setobj2s(L, L->top.p, val); in finishrawget()
729 api_incr_top(L); in finishrawget()
730 lua_unlock(L); in finishrawget()
731 return ttype(s2v(L->top.p - 1)); in finishrawget()
735 static Table *gettable (lua_State *L, int idx) { in gettable() argument
736 TValue *t = index2value(L, idx); in gettable()
737 api_check(L, ttistable(t), "table expected"); in gettable()
742 LUA_API int lua_rawget (lua_State *L, int idx) { in lua_rawget() argument
745 lua_lock(L); in lua_rawget()
746 api_checknelems(L, 1); in lua_rawget()
747 t = gettable(L, idx); in lua_rawget()
748 val = luaH_get(t, s2v(L->top.p - 1)); in lua_rawget()
749 L->top.p--; /* remove key */ in lua_rawget()
750 return finishrawget(L, val); in lua_rawget()
754 LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { in lua_rawgeti() argument
756 lua_lock(L); in lua_rawgeti()
757 t = gettable(L, idx); in lua_rawgeti()
758 return finishrawget(L, luaH_getint(t, n)); in lua_rawgeti()
762 LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { in lua_rawgetp() argument
765 lua_lock(L); in lua_rawgetp()
766 t = gettable(L, idx); in lua_rawgetp()
768 return finishrawget(L, luaH_get(t, &k)); in lua_rawgetp()
772 LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { in lua_createtable() argument
774 lua_lock(L); in lua_createtable()
775 t = luaH_new(L); in lua_createtable()
776 sethvalue2s(L, L->top.p, t); in lua_createtable()
777 api_incr_top(L); in lua_createtable()
779 luaH_resize(L, t, narray, nrec); in lua_createtable()
780 luaC_checkGC(L); in lua_createtable()
781 lua_unlock(L); in lua_createtable()
785 LUA_API int lua_getmetatable (lua_State *L, int objindex) { in lua_getmetatable() argument
789 lua_lock(L); in lua_getmetatable()
790 obj = index2value(L, objindex); in lua_getmetatable()
799 mt = G(L)->mt[ttype(obj)]; in lua_getmetatable()
803 sethvalue2s(L, L->top.p, mt); in lua_getmetatable()
804 api_incr_top(L); in lua_getmetatable()
807 lua_unlock(L); in lua_getmetatable()
812 LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) { in lua_getiuservalue() argument
815 lua_lock(L); in lua_getiuservalue()
816 o = index2value(L, idx); in lua_getiuservalue()
817 api_check(L, ttisfulluserdata(o), "full userdata expected"); in lua_getiuservalue()
819 setnilvalue(s2v(L->top.p)); in lua_getiuservalue()
823 setobj2s(L, L->top.p, &uvalue(o)->uv[n - 1].uv); in lua_getiuservalue()
824 t = ttype(s2v(L->top.p)); in lua_getiuservalue()
826 api_incr_top(L); in lua_getiuservalue()
827 lua_unlock(L); in lua_getiuservalue()
839 static void auxsetstr (lua_State *L, const TValue *t, const char *k) { in auxsetstr() argument
841 TString *str = luaS_new(L, k); in auxsetstr()
842 api_checknelems(L, 1); in auxsetstr()
843 if (luaV_fastget(L, t, str, slot, luaH_getstr)) { in auxsetstr()
844 luaV_finishfastset(L, t, slot, s2v(L->top.p - 1)); in auxsetstr()
845 L->top.p--; /* pop value */ in auxsetstr()
848 setsvalue2s(L, L->top.p, str); /* push 'str' (to make it a TValue) */ in auxsetstr()
849 api_incr_top(L); in auxsetstr()
850 luaV_finishset(L, t, s2v(L->top.p - 1), s2v(L->top.p - 2), slot); in auxsetstr()
851 L->top.p -= 2; /* pop value and key */ in auxsetstr()
853 lua_unlock(L); /* lock done by caller */ in auxsetstr()
857 LUA_API void lua_setglobal (lua_State *L, const char *name) { in lua_setglobal() argument
859 lua_lock(L); /* unlock done in 'auxsetstr' */ in lua_setglobal()
860 G = getGtable(L); in lua_setglobal()
861 auxsetstr(L, G, name); in lua_setglobal()
865 LUA_API void lua_settable (lua_State *L, int idx) { in lua_settable() argument
868 lua_lock(L); in lua_settable()
869 api_checknelems(L, 2); in lua_settable()
870 t = index2value(L, idx); in lua_settable()
871 if (luaV_fastget(L, t, s2v(L->top.p - 2), slot, luaH_get)) { in lua_settable()
872 luaV_finishfastset(L, t, slot, s2v(L->top.p - 1)); in lua_settable()
875 luaV_finishset(L, t, s2v(L->top.p - 2), s2v(L->top.p - 1), slot); in lua_settable()
876 L->top.p -= 2; /* pop index and value */ in lua_settable()
877 lua_unlock(L); in lua_settable()
881 LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { in lua_setfield() argument
882 lua_lock(L); /* unlock done in 'auxsetstr' */ in lua_setfield()
883 auxsetstr(L, index2value(L, idx), k); in lua_setfield()
887 LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { in lua_seti() argument
890 lua_lock(L); in lua_seti()
891 api_checknelems(L, 1); in lua_seti()
892 t = index2value(L, idx); in lua_seti()
893 if (luaV_fastgeti(L, t, n, slot)) { in lua_seti()
894 luaV_finishfastset(L, t, slot, s2v(L->top.p - 1)); in lua_seti()
899 luaV_finishset(L, t, &aux, s2v(L->top.p - 1), slot); in lua_seti()
901 L->top.p--; /* pop value */ in lua_seti()
902 lua_unlock(L); in lua_seti()
906 static void aux_rawset (lua_State *L, int idx, TValue *key, int n) { in aux_rawset() argument
908 lua_lock(L); in aux_rawset()
909 api_checknelems(L, n); in aux_rawset()
910 t = gettable(L, idx); in aux_rawset()
911 luaH_set(L, t, key, s2v(L->top.p - 1)); in aux_rawset()
913 luaC_barrierback(L, obj2gco(t), s2v(L->top.p - 1)); in aux_rawset()
914 L->top.p -= n; in aux_rawset()
915 lua_unlock(L); in aux_rawset()
919 LUA_API void lua_rawset (lua_State *L, int idx) { in lua_rawset() argument
920 aux_rawset(L, idx, s2v(L->top.p - 2), 2); in lua_rawset()
924 LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { in lua_rawsetp() argument
927 aux_rawset(L, idx, &k, 1); in lua_rawsetp()
931 LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { in lua_rawseti() argument
933 lua_lock(L); in lua_rawseti()
934 api_checknelems(L, 1); in lua_rawseti()
935 t = gettable(L, idx); in lua_rawseti()
936 luaH_setint(L, t, n, s2v(L->top.p - 1)); in lua_rawseti()
937 luaC_barrierback(L, obj2gco(t), s2v(L->top.p - 1)); in lua_rawseti()
938 L->top.p--; in lua_rawseti()
939 lua_unlock(L); in lua_rawseti()
943 LUA_API int lua_setmetatable (lua_State *L, int objindex) { in lua_setmetatable() argument
946 lua_lock(L); in lua_setmetatable()
947 api_checknelems(L, 1); in lua_setmetatable()
948 obj = index2value(L, objindex); in lua_setmetatable()
949 if (ttisnil(s2v(L->top.p - 1))) in lua_setmetatable()
952 api_check(L, ttistable(s2v(L->top.p - 1)), "table expected"); in lua_setmetatable()
953 mt = hvalue(s2v(L->top.p - 1)); in lua_setmetatable()
959 luaC_objbarrier(L, gcvalue(obj), mt); in lua_setmetatable()
960 luaC_checkfinalizer(L, gcvalue(obj), mt); in lua_setmetatable()
967 luaC_objbarrier(L, uvalue(obj), mt); in lua_setmetatable()
968 luaC_checkfinalizer(L, gcvalue(obj), mt); in lua_setmetatable()
973 G(L)->mt[ttype(obj)] = mt; in lua_setmetatable()
977 L->top.p--; in lua_setmetatable()
978 lua_unlock(L); in lua_setmetatable()
983 LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) { in lua_setiuservalue() argument
986 lua_lock(L); in lua_setiuservalue()
987 api_checknelems(L, 1); in lua_setiuservalue()
988 o = index2value(L, idx); in lua_setiuservalue()
989 api_check(L, ttisfulluserdata(o), "full userdata expected"); in lua_setiuservalue()
993 setobj(L, &uvalue(o)->uv[n - 1].uv, s2v(L->top.p - 1)); in lua_setiuservalue()
994 luaC_barrierback(L, gcvalue(o), s2v(L->top.p - 1)); in lua_setiuservalue()
997 L->top.p--; in lua_setiuservalue()
998 lua_unlock(L); in lua_setiuservalue()
1008 #define checkresults(L,na,nr) \ argument
1009 api_check(L, (nr) == LUA_MULTRET \
1010 || (L->ci->top.p - L->top.p >= (nr) - (na)), \
1014 LUA_API void lua_callk (lua_State *L, int nargs, int nresults, in lua_callk() argument
1017 lua_lock(L); in lua_callk()
1018 api_check(L, k == NULL || !isLua(L->ci), in lua_callk()
1020 api_checknelems(L, nargs+1); in lua_callk()
1021 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); in lua_callk()
1022 checkresults(L, nargs, nresults); in lua_callk()
1023 func = L->top.p - (nargs+1); in lua_callk()
1024 if (k != NULL && yieldable(L)) { /* need to prepare continuation? */ in lua_callk()
1025 L->ci->u.c.k = k; /* save continuation */ in lua_callk()
1026 L->ci->u.c.ctx = ctx; /* save context */ in lua_callk()
1027 luaD_call(L, func, nresults); /* do the call */ in lua_callk()
1030 luaD_callnoyield(L, func, nresults); /* just do the call */ in lua_callk()
1031 adjustresults(L, nresults); in lua_callk()
1032 lua_unlock(L); in lua_callk()
1046 static void f_call (lua_State *L, void *ud) { in f_call() argument
1048 luaD_callnoyield(L, c->func, c->nresults); in f_call()
1053 LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, in lua_pcallk() argument
1058 lua_lock(L); in lua_pcallk()
1059 api_check(L, k == NULL || !isLua(L->ci), in lua_pcallk()
1061 api_checknelems(L, nargs+1); in lua_pcallk()
1062 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); in lua_pcallk()
1063 checkresults(L, nargs, nresults); in lua_pcallk()
1067 StkId o = index2stack(L, errfunc); in lua_pcallk()
1068 api_check(L, ttisfunction(s2v(o)), "error handler must be a function"); in lua_pcallk()
1069 func = savestack(L, o); in lua_pcallk()
1071 c.func = L->top.p - (nargs+1); /* function to be called */ in lua_pcallk()
1072 if (k == NULL || !yieldable(L)) { /* no continuation or no yieldable? */ in lua_pcallk()
1074 status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); in lua_pcallk()
1077 CallInfo *ci = L->ci; in lua_pcallk()
1081 ci->u2.funcidx = cast_int(savestack(L, c.func)); in lua_pcallk()
1082 ci->u.c.old_errfunc = L->errfunc; in lua_pcallk()
1083 L->errfunc = func; in lua_pcallk()
1084 setoah(ci->callstatus, L->allowhook); /* save value of 'allowhook' */ in lua_pcallk()
1086 luaD_call(L, c.func, nresults); /* do the call */ in lua_pcallk()
1088 L->errfunc = ci->u.c.old_errfunc; in lua_pcallk()
1091 adjustresults(L, nresults); in lua_pcallk()
1092 lua_unlock(L); in lua_pcallk()
1097 LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, in lua_load() argument
1101 lua_lock(L); in lua_load()
1103 luaZ_init(L, &z, reader, data); in lua_load()
1104 status = luaD_protectedparser(L, &z, chunkname, mode); in lua_load()
1106 LClosure *f = clLvalue(s2v(L->top.p - 1)); /* get new function */ in lua_load()
1109 const TValue *gt = getGtable(L); in lua_load()
1111 setobj(L, f->upvals[0]->v.p, gt); in lua_load()
1112 luaC_barrier(L, f->upvals[0], gt); in lua_load()
1115 lua_unlock(L); in lua_load()
1120 LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) { in lua_dump() argument
1123 lua_lock(L); in lua_dump()
1124 api_checknelems(L, 1); in lua_dump()
1125 o = s2v(L->top.p - 1); in lua_dump()
1127 status = luaU_dump(L, getproto(o), writer, data, strip); in lua_dump()
1130 lua_unlock(L); in lua_dump()
1135 LUA_API int lua_status (lua_State *L) { in lua_status() argument
1136 return L->status; in lua_status()
1143 LUA_API int lua_gc (lua_State *L, int what, ...) { in lua_gc() argument
1146 global_State *g = G(L); in lua_gc()
1149 lua_lock(L); in lua_gc()
1162 luaC_fullgc(L, 0); in lua_gc()
1181 luaC_step(L); in lua_gc()
1186 luaC_checkGC(L); in lua_gc()
1217 luaC_changemode(L, KGC_GEN); in lua_gc()
1231 luaC_changemode(L, KGC_INC); in lua_gc()
1237 lua_unlock(L); in lua_gc()
1248 LUA_API int lua_error (lua_State *L) { in lua_error() argument
1250 lua_lock(L); in lua_error()
1251 errobj = s2v(L->top.p - 1); in lua_error()
1252 api_checknelems(L, 1); in lua_error()
1254 if (ttisshrstring(errobj) && eqshrstr(tsvalue(errobj), G(L)->memerrmsg)) in lua_error()
1255 luaM_error(L); /* raise a memory error */ in lua_error()
1257 luaG_errormsg(L); /* raise a regular error */ in lua_error()
1263 LUA_API int lua_next (lua_State *L, int idx) { in lua_next() argument
1266 lua_lock(L); in lua_next()
1267 api_checknelems(L, 1); in lua_next()
1268 t = gettable(L, idx); in lua_next()
1269 more = luaH_next(L, t, L->top.p - 1); in lua_next()
1271 api_incr_top(L); in lua_next()
1274 L->top.p -= 1; /* remove key */ in lua_next()
1275 lua_unlock(L); in lua_next()
1280 LUA_API void lua_toclose (lua_State *L, int idx) { in lua_toclose() argument
1283 lua_lock(L); in lua_toclose()
1284 o = index2stack(L, idx); in lua_toclose()
1285 nresults = L->ci->nresults; in lua_toclose()
1286 api_check(L, L->tbclist.p < o, "given index below or equal a marked one"); in lua_toclose()
1287 luaF_newtbcupval(L, o); /* create new to-be-closed upvalue */ in lua_toclose()
1289 L->ci->nresults = codeNresults(nresults); /* mark it */ in lua_toclose()
1290 lua_assert(hastocloseCfunc(L->ci->nresults)); in lua_toclose()
1291 lua_unlock(L); in lua_toclose()
1295 LUA_API void lua_concat (lua_State *L, int n) { in lua_concat() argument
1296 lua_lock(L); in lua_concat()
1297 api_checknelems(L, n); in lua_concat()
1299 luaV_concat(L, n); in lua_concat()
1301 setsvalue2s(L, L->top.p, luaS_newlstr(L, "", 0)); /* push empty string */ in lua_concat()
1302 api_incr_top(L); in lua_concat()
1304 luaC_checkGC(L); in lua_concat()
1305 lua_unlock(L); in lua_concat()
1309 LUA_API void lua_len (lua_State *L, int idx) { in lua_len() argument
1311 lua_lock(L); in lua_len()
1312 t = index2value(L, idx); in lua_len()
1313 luaV_objlen(L, L->top.p, t); in lua_len()
1314 api_incr_top(L); in lua_len()
1315 lua_unlock(L); in lua_len()
1319 LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { in lua_getallocf() argument
1321 lua_lock(L); in lua_getallocf()
1322 if (ud) *ud = G(L)->ud; in lua_getallocf()
1323 f = G(L)->frealloc; in lua_getallocf()
1324 lua_unlock(L); in lua_getallocf()
1329 LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) { in lua_setallocf() argument
1330 lua_lock(L); in lua_setallocf()
1331 G(L)->ud = ud; in lua_setallocf()
1332 G(L)->frealloc = f; in lua_setallocf()
1333 lua_unlock(L); in lua_setallocf()
1337 void lua_setwarnf (lua_State *L, lua_WarnFunction f, void *ud) { in lua_setwarnf() argument
1338 lua_lock(L); in lua_setwarnf()
1339 G(L)->ud_warn = ud; in lua_setwarnf()
1340 G(L)->warnf = f; in lua_setwarnf()
1341 lua_unlock(L); in lua_setwarnf()
1345 void lua_warning (lua_State *L, const char *msg, int tocont) { in lua_warning() argument
1346 lua_lock(L); in lua_warning()
1347 luaE_warning(L, msg, tocont); in lua_warning()
1348 lua_unlock(L); in lua_warning()
1353 LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) { in lua_newuserdatauv() argument
1355 lua_lock(L); in lua_newuserdatauv()
1356 api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, "invalid value"); in lua_newuserdatauv()
1357 u = luaS_newudata(L, size, nuvalue); in lua_newuserdatauv()
1358 setuvalue(L, s2v(L->top.p), u); in lua_newuserdatauv()
1359 api_incr_top(L); in lua_newuserdatauv()
1360 luaC_checkGC(L); in lua_newuserdatauv()
1361 lua_unlock(L); in lua_newuserdatauv()
1394 LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { in lua_getupvalue() argument
1397 lua_lock(L); in lua_getupvalue()
1398 name = aux_upvalue(index2value(L, funcindex), n, &val, NULL); in lua_getupvalue()
1400 setobj2s(L, L->top.p, val); in lua_getupvalue()
1401 api_incr_top(L); in lua_getupvalue()
1403 lua_unlock(L); in lua_getupvalue()
1408 LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { in lua_setupvalue() argument
1413 lua_lock(L); in lua_setupvalue()
1414 fi = index2value(L, funcindex); in lua_setupvalue()
1415 api_checknelems(L, 1); in lua_setupvalue()
1418 L->top.p--; in lua_setupvalue()
1419 setobj(L, val, s2v(L->top.p)); in lua_setupvalue()
1420 luaC_barrier(L, owner, val); in lua_setupvalue()
1422 lua_unlock(L); in lua_setupvalue()
1427 static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { in getupvalref() argument
1430 TValue *fi = index2value(L, fidx); in getupvalref()
1431 api_check(L, ttisLclosure(fi), "Lua function expected"); in getupvalref()
1441 LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { in lua_upvalueid() argument
1442 TValue *fi = index2value(L, fidx); in lua_upvalueid()
1445 return *getupvalref(L, fidx, n, NULL); in lua_upvalueid()
1456 api_check(L, 0, "function expected"); in lua_upvalueid()
1463 LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1, in lua_upvaluejoin() argument
1466 UpVal **up1 = getupvalref(L, fidx1, n1, &f1); in lua_upvaluejoin()
1467 UpVal **up2 = getupvalref(L, fidx2, n2, NULL); in lua_upvaluejoin()
1468 api_check(L, *up1 != NULL && *up2 != NULL, "invalid upvalue index"); in lua_upvaluejoin()
1470 luaC_objbarrier(L, f1, *up1); in lua_upvaluejoin()