Lines Matching +full:- +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
56 static TValue *index2value (lua_State *L, int idx) { in index2value() argument
57 CallInfo *ci = L->ci; in index2value()
59 StkId o = ci->func + idx; in index2value()
60 api_check(L, idx <= L->ci->top - (ci->func + 1), "unacceptable index"); in index2value()
61 if (o >= L->top) return &G(L)->nilvalue; in index2value()
65 api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); in index2value()
66 return s2v(L->top + idx); in index2value()
69 return &G(L)->l_registry; in index2value()
71 idx = LUA_REGISTRYINDEX - idx; in index2value()
72 api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); in index2value()
73 if (ttislcf(s2v(ci->func))) /* light C function? */ in index2value()
74 return &G(L)->nilvalue; /* it has no upvalues */ in index2value()
76 CClosure *func = clCvalue(s2v(ci->func)); in index2value()
77 return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : &G(L)->nilvalue; in index2value()
83 static StkId index2stack (lua_State *L, int idx) { in index2stack() argument
84 CallInfo *ci = L->ci; in index2stack()
86 StkId o = ci->func + idx; in index2stack()
87 api_check(L, o < L->top, "unacceptable index"); in index2stack()
90 else { /* non-positive index */ in index2stack()
91 api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); in index2stack()
92 api_check(L, !ispseudo(idx), "invalid index"); in index2stack()
93 return L->top + idx; in index2stack()
98 LUA_API int lua_checkstack (lua_State *L, int n) { in lua_checkstack() argument
101 lua_lock(L); in lua_checkstack()
102 ci = L->ci; in lua_checkstack()
103 api_check(L, n >= 0, "negative 'n'"); in lua_checkstack()
104 if (L->stack_last - L->top > n) /* stack large enough? */ in lua_checkstack()
107 int inuse = cast_int(L->top - L->stack) + EXTRA_STACK; in lua_checkstack()
108 if (inuse > LUAI_MAXSTACK - n) /* can grow without overflow? */ in lua_checkstack()
111 res = luaD_growstack(L, n, 0); in lua_checkstack()
113 if (res && ci->top < L->top + n) in lua_checkstack()
114 ci->top = L->top + n; /* adjust frame top */ in lua_checkstack()
115 lua_unlock(L); in lua_checkstack()
126 api_check(from, to->ci->top - to->top >= n, "stack overflow"); in lua_xmove()
127 from->top -= n; in lua_xmove()
129 setobjs2s(to, to->top, from->top + i); in lua_xmove()
130 to->top++; /* stack already checked by previous 'api_check' */ in lua_xmove()
136 LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { in lua_atpanic() argument
138 lua_lock(L); in lua_atpanic()
139 old = G(L)->panic; in lua_atpanic()
140 G(L)->panic = panicf; in lua_atpanic()
141 lua_unlock(L); in lua_atpanic()
146 LUA_API lua_Number lua_version (lua_State *L) { in lua_version() argument
147 UNUSED(L); in lua_version()
161 LUA_API int lua_absindex (lua_State *L, int idx) { in lua_absindex() argument
164 : cast_int(L->top - L->ci->func) + idx; in lua_absindex()
168 LUA_API int lua_gettop (lua_State *L) { in lua_gettop() argument
169 return cast_int(L->top - (L->ci->func + 1)); in lua_gettop()
173 LUA_API void lua_settop (lua_State *L, int idx) { in lua_settop() argument
177 lua_lock(L); in lua_settop()
178 ci = L->ci; in lua_settop()
179 func = ci->func; in lua_settop()
181 api_check(L, idx <= ci->top - (func + 1), "new top too large"); in lua_settop()
182 diff = ((func + 1) + idx) - L->top; in lua_settop()
183 for (; diff > 0; diff--) in lua_settop()
184 setnilvalue(s2v(L->top++)); /* clear new slots */ in lua_settop()
187 api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top"); in lua_settop()
190 if (diff < 0 && hastocloseCfunc(ci->nresults)) in lua_settop()
191 luaF_close(L, L->top + diff, LUA_OK); in lua_settop()
192 L->top += diff; /* correct top only after closing any upvalue */ in lua_settop()
193 lua_unlock(L); in lua_settop()
203 static void reverse (lua_State *L, StkId from, StkId to) { in reverse() argument
204 for (; from < to; from++, to--) { in reverse()
206 setobj(L, &temp, s2v(from)); in reverse()
207 setobjs2s(L, from, to); in reverse()
208 setobj2s(L, to, &temp); in reverse()
217 LUA_API void lua_rotate (lua_State *L, int idx, int n) { in lua_rotate() argument
219 lua_lock(L); in lua_rotate()
220 t = L->top - 1; /* end of stack segment being rotated */ in lua_rotate()
221 p = index2stack(L, idx); /* start of segment */ in lua_rotate()
222 api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); in lua_rotate()
223 m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ in lua_rotate()
224 reverse(L, p, m); /* reverse the prefix with length 'n' */ in lua_rotate()
225 reverse(L, m + 1, t); /* reverse the suffix */ in lua_rotate()
226 reverse(L, p, t); /* reverse the entire segment */ in lua_rotate()
227 lua_unlock(L); in lua_rotate()
231 LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { in lua_copy() argument
233 lua_lock(L); in lua_copy()
234 fr = index2value(L, fromidx); in lua_copy()
235 to = index2value(L, toidx); in lua_copy()
236 api_check(L, isvalid(L, to), "invalid index"); in lua_copy()
237 setobj(L, to, fr); in lua_copy()
239 luaC_barrier(L, clCvalue(s2v(L->ci->func)), fr); in lua_copy()
242 lua_unlock(L); in lua_copy()
246 LUA_API void lua_pushvalue (lua_State *L, int idx) { in lua_pushvalue() argument
247 lua_lock(L); in lua_pushvalue()
248 setobj2s(L, L->top, index2value(L, idx)); in lua_pushvalue()
249 api_incr_top(L); in lua_pushvalue()
250 lua_unlock(L); in lua_pushvalue()
256 ** access functions (stack -> C)
260 LUA_API int lua_type (lua_State *L, int idx) { in lua_type() argument
261 const TValue *o = index2value(L, idx); in lua_type()
262 return (isvalid(L, o) ? ttype(o) : LUA_TNONE); in lua_type()
266 LUA_API const char *lua_typename (lua_State *L, int t) { in lua_typename() argument
267 UNUSED(L); in lua_typename()
268 api_check(L, LUA_TNONE <= t && t < LUA_NUMTYPES, "invalid type"); in lua_typename()
273 LUA_API int lua_iscfunction (lua_State *L, int idx) { in lua_iscfunction() argument
274 const TValue *o = index2value(L, idx); in lua_iscfunction()
279 LUA_API int lua_isinteger (lua_State *L, int idx) { in lua_isinteger() argument
280 const TValue *o = index2value(L, idx); in lua_isinteger()
285 LUA_API int lua_isnumber (lua_State *L, int idx) { in lua_isnumber() argument
287 const TValue *o = index2value(L, idx); in lua_isnumber()
292 LUA_API int lua_isstring (lua_State *L, int idx) { in lua_isstring() argument
293 const TValue *o = index2value(L, idx); in lua_isstring()
298 LUA_API int lua_isuserdata (lua_State *L, int idx) { in lua_isuserdata() argument
299 const TValue *o = index2value(L, idx); in lua_isuserdata()
304 LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { in lua_rawequal() argument
305 const TValue *o1 = index2value(L, index1); in lua_rawequal()
306 const TValue *o2 = index2value(L, index2); in lua_rawequal()
307 return (isvalid(L, o1) && isvalid(L, o2)) ? luaV_rawequalobj(o1, o2) : 0; in lua_rawequal()
311 LUA_API void lua_arith (lua_State *L, int op) { in lua_arith() argument
312 lua_lock(L); in lua_arith()
314 api_checknelems(L, 2); /* all other operations expect two operands */ in lua_arith()
316 api_checknelems(L, 1); in lua_arith()
317 setobjs2s(L, L->top, L->top - 1); in lua_arith()
318 api_incr_top(L); in lua_arith()
320 /* first operand at top - 2, second at top - 1; result go to top - 2 */ in lua_arith()
321 luaO_arith(L, op, s2v(L->top - 2), s2v(L->top - 1), L->top - 2); in lua_arith()
322 L->top--; /* remove second operand */ in lua_arith()
323 lua_unlock(L); in lua_arith()
327 LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { in lua_compare() argument
331 lua_lock(L); /* may call tag method */ in lua_compare()
332 o1 = index2value(L, index1); in lua_compare()
333 o2 = index2value(L, index2); in lua_compare()
334 if (isvalid(L, o1) && isvalid(L, o2)) { in lua_compare()
336 case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break; in lua_compare()
337 case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; in lua_compare()
338 case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; in lua_compare()
339 default: api_check(L, 0, "invalid option"); in lua_compare()
342 lua_unlock(L); in lua_compare()
347 LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { in lua_stringtonumber() argument
348 size_t sz = luaO_str2num(s, s2v(L->top)); in lua_stringtonumber()
350 api_incr_top(L); in lua_stringtonumber()
355 LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { in lua_tonumberx() argument
357 const TValue *o = index2value(L, idx); in lua_tonumberx()
365 LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { in lua_tointegerx() argument
367 const TValue *o = index2value(L, idx); in lua_tointegerx()
375 LUA_API int lua_toboolean (lua_State *L, int idx) { in lua_toboolean() argument
376 const TValue *o = index2value(L, idx); in lua_toboolean()
381 LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { in lua_tolstring() argument
383 lua_lock(L); in lua_tolstring()
384 o = index2value(L, idx); in lua_tolstring()
388 lua_unlock(L); in lua_tolstring()
391 luaO_tostring(L, o); in lua_tolstring()
392 luaC_checkGC(L); in lua_tolstring()
393 o = index2value(L, idx); /* previous call may reallocate the stack */ in lua_tolstring()
397 lua_unlock(L); in lua_tolstring()
402 LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) { in lua_rawlen() argument
403 const TValue *o = index2value(L, idx); in lua_rawlen()
405 case LUA_VSHRSTR: return tsvalue(o)->shrlen; in lua_rawlen()
406 case LUA_VLNGSTR: return tsvalue(o)->u.lnglen; in lua_rawlen()
407 case LUA_VUSERDATA: return uvalue(o)->len; in lua_rawlen()
414 LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { in lua_tocfunction() argument
415 const TValue *o = index2value(L, idx); in lua_tocfunction()
418 return clCvalue(o)->f; in lua_tocfunction()
432 LUA_API void *lua_touserdata (lua_State *L, int idx) { in lua_touserdata() argument
433 const TValue *o = index2value(L, idx); in lua_touserdata()
438 LUA_API lua_State *lua_tothread (lua_State *L, int idx) { in lua_tothread() argument
439 const TValue *o = index2value(L, idx); in lua_tothread()
451 LUA_API const void *lua_topointer (lua_State *L, int idx) { in lua_topointer() argument
452 const TValue *o = index2value(L, idx); in lua_topointer()
469 ** push functions (C -> stack)
473 LUA_API void lua_pushnil (lua_State *L) { in lua_pushnil() argument
474 lua_lock(L); in lua_pushnil()
475 setnilvalue(s2v(L->top)); in lua_pushnil()
476 api_incr_top(L); in lua_pushnil()
477 lua_unlock(L); in lua_pushnil()
481 LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { in lua_pushnumber() argument
482 lua_lock(L); in lua_pushnumber()
483 setfltvalue(s2v(L->top), n); in lua_pushnumber()
484 api_incr_top(L); in lua_pushnumber()
485 lua_unlock(L); in lua_pushnumber()
489 LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { in lua_pushinteger() argument
490 lua_lock(L); in lua_pushinteger()
491 setivalue(s2v(L->top), n); in lua_pushinteger()
492 api_incr_top(L); in lua_pushinteger()
493 lua_unlock(L); in lua_pushinteger()
502 LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { in lua_pushlstring() argument
504 lua_lock(L); in lua_pushlstring()
505 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len); in lua_pushlstring()
506 setsvalue2s(L, L->top, ts); in lua_pushlstring()
507 api_incr_top(L); in lua_pushlstring()
508 luaC_checkGC(L); in lua_pushlstring()
509 lua_unlock(L); in lua_pushlstring()
514 LUA_API const char *lua_pushstring (lua_State *L, const char *s) { in lua_pushstring() argument
515 lua_lock(L); in lua_pushstring()
517 setnilvalue(s2v(L->top)); in lua_pushstring()
520 ts = luaS_new(L, s); in lua_pushstring()
521 setsvalue2s(L, L->top, ts); in lua_pushstring()
524 api_incr_top(L); in lua_pushstring()
525 luaC_checkGC(L); in lua_pushstring()
526 lua_unlock(L); in lua_pushstring()
531 LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, in lua_pushvfstring() argument
534 lua_lock(L); in lua_pushvfstring()
535 ret = luaO_pushvfstring(L, fmt, argp); in lua_pushvfstring()
536 luaC_checkGC(L); in lua_pushvfstring()
537 lua_unlock(L); in lua_pushvfstring()
542 LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { in lua_pushfstring() argument
545 lua_lock(L); in lua_pushfstring()
547 ret = luaO_pushvfstring(L, fmt, argp); in lua_pushfstring()
549 luaC_checkGC(L); in lua_pushfstring()
550 lua_unlock(L); in lua_pushfstring()
555 LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { in lua_pushcclosure() argument
556 lua_lock(L); in lua_pushcclosure()
558 setfvalue(s2v(L->top), fn); in lua_pushcclosure()
559 api_incr_top(L); in lua_pushcclosure()
563 api_checknelems(L, n); in lua_pushcclosure()
564 api_check(L, n <= MAXUPVAL, "upvalue index too large"); in lua_pushcclosure()
565 cl = luaF_newCclosure(L, n); in lua_pushcclosure()
566 cl->f = fn; in lua_pushcclosure()
567 L->top -= n; in lua_pushcclosure()
568 while (n--) { in lua_pushcclosure()
569 setobj2n(L, &cl->upvalue[n], s2v(L->top + n)); in lua_pushcclosure()
573 setclCvalue(L, s2v(L->top), cl); in lua_pushcclosure()
574 api_incr_top(L); in lua_pushcclosure()
575 luaC_checkGC(L); in lua_pushcclosure()
577 lua_unlock(L); in lua_pushcclosure()
581 LUA_API void lua_pushboolean (lua_State *L, int b) { in lua_pushboolean() argument
582 lua_lock(L); in lua_pushboolean()
584 setbtvalue(s2v(L->top)); in lua_pushboolean()
586 setbfvalue(s2v(L->top)); in lua_pushboolean()
587 api_incr_top(L); in lua_pushboolean()
588 lua_unlock(L); in lua_pushboolean()
592 LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { in lua_pushlightuserdata() argument
593 lua_lock(L); in lua_pushlightuserdata()
594 setpvalue(s2v(L->top), p); in lua_pushlightuserdata()
595 api_incr_top(L); in lua_pushlightuserdata()
596 lua_unlock(L); in lua_pushlightuserdata()
600 LUA_API int lua_pushthread (lua_State *L) { in lua_pushthread() argument
601 lua_lock(L); in lua_pushthread()
602 setthvalue(L, s2v(L->top), L); in lua_pushthread()
603 api_incr_top(L); in lua_pushthread()
604 lua_unlock(L); in lua_pushthread()
605 return (G(L)->mainthread == L); in lua_pushthread()
611 ** get functions (Lua -> stack)
615 static int auxgetstr (lua_State *L, const TValue *t, const char *k) { in auxgetstr() argument
617 TString *str = luaS_new(L, k); in auxgetstr()
618 if (luaV_fastget(L, t, str, slot, luaH_getstr)) { in auxgetstr()
619 setobj2s(L, L->top, slot); in auxgetstr()
620 api_incr_top(L); in auxgetstr()
623 setsvalue2s(L, L->top, str); in auxgetstr()
624 api_incr_top(L); in auxgetstr()
625 luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot); in auxgetstr()
627 lua_unlock(L); in auxgetstr()
628 return ttype(s2v(L->top - 1)); in auxgetstr()
632 LUA_API int lua_getglobal (lua_State *L, const char *name) { in lua_getglobal() argument
634 lua_lock(L); in lua_getglobal()
635 reg = hvalue(&G(L)->l_registry); in lua_getglobal()
636 return auxgetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name); in lua_getglobal()
640 LUA_API int lua_gettable (lua_State *L, int idx) { in lua_gettable() argument
643 lua_lock(L); in lua_gettable()
644 t = index2value(L, idx); in lua_gettable()
645 if (luaV_fastget(L, t, s2v(L->top - 1), slot, luaH_get)) { in lua_gettable()
646 setobj2s(L, L->top - 1, slot); in lua_gettable()
649 luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot); in lua_gettable()
650 lua_unlock(L); in lua_gettable()
651 return ttype(s2v(L->top - 1)); in lua_gettable()
655 LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { in lua_getfield() argument
656 lua_lock(L); in lua_getfield()
657 return auxgetstr(L, index2value(L, idx), k); in lua_getfield()
661 LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { in lua_geti() argument
664 lua_lock(L); in lua_geti()
665 t = index2value(L, idx); in lua_geti()
666 if (luaV_fastgeti(L, t, n, slot)) { in lua_geti()
667 setobj2s(L, L->top, slot); in lua_geti()
672 luaV_finishget(L, t, &aux, L->top, slot); in lua_geti()
674 api_incr_top(L); in lua_geti()
675 lua_unlock(L); in lua_geti()
676 return ttype(s2v(L->top - 1)); in lua_geti()
680 static int finishrawget (lua_State *L, const TValue *val) { in finishrawget() argument
682 setnilvalue(s2v(L->top)); in finishrawget()
684 setobj2s(L, L->top, val); in finishrawget()
685 api_incr_top(L); in finishrawget()
686 lua_unlock(L); in finishrawget()
687 return ttype(s2v(L->top - 1)); in finishrawget()
691 static Table *gettable (lua_State *L, int idx) { in gettable() argument
692 TValue *t = index2value(L, idx); in gettable()
693 api_check(L, ttistable(t), "table expected"); in gettable()
698 LUA_API int lua_rawget (lua_State *L, int idx) { in lua_rawget() argument
701 lua_lock(L); in lua_rawget()
702 api_checknelems(L, 1); in lua_rawget()
703 t = gettable(L, idx); in lua_rawget()
704 val = luaH_get(t, s2v(L->top - 1)); in lua_rawget()
705 L->top--; /* remove key */ in lua_rawget()
706 return finishrawget(L, val); in lua_rawget()
710 LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { in lua_rawgeti() argument
712 lua_lock(L); in lua_rawgeti()
713 t = gettable(L, idx); in lua_rawgeti()
714 return finishrawget(L, luaH_getint(t, n)); in lua_rawgeti()
718 LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { in lua_rawgetp() argument
721 lua_lock(L); in lua_rawgetp()
722 t = gettable(L, idx); in lua_rawgetp()
724 return finishrawget(L, luaH_get(t, &k)); in lua_rawgetp()
728 LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { in lua_createtable() argument
730 lua_lock(L); in lua_createtable()
731 t = luaH_new(L); in lua_createtable()
732 sethvalue2s(L, L->top, t); in lua_createtable()
733 api_incr_top(L); in lua_createtable()
735 luaH_resize(L, t, narray, nrec); in lua_createtable()
736 luaC_checkGC(L); in lua_createtable()
737 lua_unlock(L); in lua_createtable()
741 LUA_API int lua_getmetatable (lua_State *L, int objindex) { in lua_getmetatable() argument
745 lua_lock(L); in lua_getmetatable()
746 obj = index2value(L, objindex); in lua_getmetatable()
749 mt = hvalue(obj)->metatable; in lua_getmetatable()
752 mt = uvalue(obj)->metatable; in lua_getmetatable()
755 mt = G(L)->mt[ttype(obj)]; in lua_getmetatable()
759 sethvalue2s(L, L->top, mt); in lua_getmetatable()
760 api_incr_top(L); in lua_getmetatable()
763 lua_unlock(L); in lua_getmetatable()
768 LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) { in lua_getiuservalue() argument
771 lua_lock(L); in lua_getiuservalue()
772 o = index2value(L, idx); in lua_getiuservalue()
773 api_check(L, ttisfulluserdata(o), "full userdata expected"); in lua_getiuservalue()
774 if (n <= 0 || n > uvalue(o)->nuvalue) { in lua_getiuservalue()
775 setnilvalue(s2v(L->top)); in lua_getiuservalue()
779 setobj2s(L, L->top, &uvalue(o)->uv[n - 1].uv); in lua_getiuservalue()
780 t = ttype(s2v(L->top)); in lua_getiuservalue()
782 api_incr_top(L); in lua_getiuservalue()
783 lua_unlock(L); in lua_getiuservalue()
789 ** set functions (stack -> Lua)
795 static void auxsetstr (lua_State *L, const TValue *t, const char *k) { in auxsetstr() argument
797 TString *str = luaS_new(L, k); in auxsetstr()
798 api_checknelems(L, 1); in auxsetstr()
799 if (luaV_fastget(L, t, str, slot, luaH_getstr)) { in auxsetstr()
800 luaV_finishfastset(L, t, slot, s2v(L->top - 1)); in auxsetstr()
801 L->top--; /* pop value */ in auxsetstr()
804 setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */ in auxsetstr()
805 api_incr_top(L); in auxsetstr()
806 luaV_finishset(L, t, s2v(L->top - 1), s2v(L->top - 2), slot); in auxsetstr()
807 L->top -= 2; /* pop value and key */ in auxsetstr()
809 lua_unlock(L); /* lock done by caller */ in auxsetstr()
813 LUA_API void lua_setglobal (lua_State *L, const char *name) { in lua_setglobal() argument
815 lua_lock(L); /* unlock done in 'auxsetstr' */ in lua_setglobal()
816 reg = hvalue(&G(L)->l_registry); in lua_setglobal()
817 auxsetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name); in lua_setglobal()
821 LUA_API void lua_settable (lua_State *L, int idx) { in lua_settable() argument
824 lua_lock(L); in lua_settable()
825 api_checknelems(L, 2); in lua_settable()
826 t = index2value(L, idx); in lua_settable()
827 if (luaV_fastget(L, t, s2v(L->top - 2), slot, luaH_get)) { in lua_settable()
828 luaV_finishfastset(L, t, slot, s2v(L->top - 1)); in lua_settable()
831 luaV_finishset(L, t, s2v(L->top - 2), s2v(L->top - 1), slot); in lua_settable()
832 L->top -= 2; /* pop index and value */ in lua_settable()
833 lua_unlock(L); in lua_settable()
837 LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { in lua_setfield() argument
838 lua_lock(L); /* unlock done in 'auxsetstr' */ in lua_setfield()
839 auxsetstr(L, index2value(L, idx), k); in lua_setfield()
843 LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { in lua_seti() argument
846 lua_lock(L); in lua_seti()
847 api_checknelems(L, 1); in lua_seti()
848 t = index2value(L, idx); in lua_seti()
849 if (luaV_fastgeti(L, t, n, slot)) { in lua_seti()
850 luaV_finishfastset(L, t, slot, s2v(L->top - 1)); in lua_seti()
855 luaV_finishset(L, t, &aux, s2v(L->top - 1), slot); in lua_seti()
857 L->top--; /* pop value */ in lua_seti()
858 lua_unlock(L); in lua_seti()
862 static void aux_rawset (lua_State *L, int idx, TValue *key, int n) { in aux_rawset() argument
865 lua_lock(L); in aux_rawset()
866 api_checknelems(L, n); in aux_rawset()
867 t = gettable(L, idx); in aux_rawset()
868 slot = luaH_set(L, t, key); in aux_rawset()
869 setobj2t(L, slot, s2v(L->top - 1)); in aux_rawset()
871 luaC_barrierback(L, obj2gco(t), s2v(L->top - 1)); in aux_rawset()
872 L->top -= n; in aux_rawset()
873 lua_unlock(L); in aux_rawset()
877 LUA_API void lua_rawset (lua_State *L, int idx) { in lua_rawset() argument
878 aux_rawset(L, idx, s2v(L->top - 2), 2); in lua_rawset()
882 LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { in lua_rawsetp() argument
885 aux_rawset(L, idx, &k, 1); in lua_rawsetp()
889 LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { in lua_rawseti() argument
891 lua_lock(L); in lua_rawseti()
892 api_checknelems(L, 1); in lua_rawseti()
893 t = gettable(L, idx); in lua_rawseti()
894 luaH_setint(L, t, n, s2v(L->top - 1)); in lua_rawseti()
895 luaC_barrierback(L, obj2gco(t), s2v(L->top - 1)); in lua_rawseti()
896 L->top--; in lua_rawseti()
897 lua_unlock(L); in lua_rawseti()
901 LUA_API int lua_setmetatable (lua_State *L, int objindex) { in lua_setmetatable() argument
904 lua_lock(L); in lua_setmetatable()
905 api_checknelems(L, 1); in lua_setmetatable()
906 obj = index2value(L, objindex); in lua_setmetatable()
907 if (ttisnil(s2v(L->top - 1))) in lua_setmetatable()
910 api_check(L, ttistable(s2v(L->top - 1)), "table expected"); in lua_setmetatable()
911 mt = hvalue(s2v(L->top - 1)); in lua_setmetatable()
915 hvalue(obj)->metatable = mt; in lua_setmetatable()
917 luaC_objbarrier(L, gcvalue(obj), mt); in lua_setmetatable()
918 luaC_checkfinalizer(L, gcvalue(obj), mt); in lua_setmetatable()
923 uvalue(obj)->metatable = mt; in lua_setmetatable()
925 luaC_objbarrier(L, uvalue(obj), mt); in lua_setmetatable()
926 luaC_checkfinalizer(L, gcvalue(obj), mt); in lua_setmetatable()
931 G(L)->mt[ttype(obj)] = mt; in lua_setmetatable()
935 L->top--; in lua_setmetatable()
936 lua_unlock(L); in lua_setmetatable()
941 LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) { in lua_setiuservalue() argument
944 lua_lock(L); in lua_setiuservalue()
945 api_checknelems(L, 1); in lua_setiuservalue()
946 o = index2value(L, idx); in lua_setiuservalue()
947 api_check(L, ttisfulluserdata(o), "full userdata expected"); in lua_setiuservalue()
948 if (!(cast_uint(n) - 1u < cast_uint(uvalue(o)->nuvalue))) in lua_setiuservalue()
949 res = 0; /* 'n' not in [1, uvalue(o)->nuvalue] */ in lua_setiuservalue()
951 setobj(L, &uvalue(o)->uv[n - 1].uv, s2v(L->top - 1)); in lua_setiuservalue()
952 luaC_barrierback(L, gcvalue(o), s2v(L->top - 1)); in lua_setiuservalue()
955 L->top--; in lua_setiuservalue()
956 lua_unlock(L); in lua_setiuservalue()
966 #define checkresults(L,na,nr) \ argument
967 api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \
971 LUA_API void lua_callk (lua_State *L, int nargs, int nresults, in lua_callk() argument
974 lua_lock(L); in lua_callk()
975 api_check(L, k == NULL || !isLua(L->ci), in lua_callk()
977 api_checknelems(L, nargs+1); in lua_callk()
978 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); in lua_callk()
979 checkresults(L, nargs, nresults); in lua_callk()
980 func = L->top - (nargs+1); in lua_callk()
981 if (k != NULL && yieldable(L)) { /* need to prepare continuation? */ in lua_callk()
982 L->ci->u.c.k = k; /* save continuation */ in lua_callk()
983 L->ci->u.c.ctx = ctx; /* save context */ in lua_callk()
984 luaD_call(L, func, nresults); /* do the call */ in lua_callk()
987 luaD_callnoyield(L, func, nresults); /* just do the call */ in lua_callk()
988 adjustresults(L, nresults); in lua_callk()
989 lua_unlock(L); in lua_callk()
1003 static void f_call (lua_State *L, void *ud) { in f_call() argument
1005 luaD_callnoyield(L, c->func, c->nresults); in f_call()
1010 LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, in lua_pcallk() argument
1015 lua_lock(L); in lua_pcallk()
1016 api_check(L, k == NULL || !isLua(L->ci), in lua_pcallk()
1018 api_checknelems(L, nargs+1); in lua_pcallk()
1019 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); in lua_pcallk()
1020 checkresults(L, nargs, nresults); in lua_pcallk()
1024 StkId o = index2stack(L, errfunc); in lua_pcallk()
1025 api_check(L, ttisfunction(s2v(o)), "error handler must be a function"); in lua_pcallk()
1026 func = savestack(L, o); in lua_pcallk()
1028 c.func = L->top - (nargs+1); /* function to be called */ in lua_pcallk()
1029 if (k == NULL || !yieldable(L)) { /* no continuation or no yieldable? */ in lua_pcallk()
1031 status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); in lua_pcallk()
1034 CallInfo *ci = L->ci; in lua_pcallk()
1035 ci->u.c.k = k; /* save continuation */ in lua_pcallk()
1036 ci->u.c.ctx = ctx; /* save context */ in lua_pcallk()
1038 ci->u2.funcidx = cast_int(savestack(L, c.func)); in lua_pcallk()
1039 ci->u.c.old_errfunc = L->errfunc; in lua_pcallk()
1040 L->errfunc = func; in lua_pcallk()
1041 setoah(ci->callstatus, L->allowhook); /* save value of 'allowhook' */ in lua_pcallk()
1042 ci->callstatus |= CIST_YPCALL; /* function can do error recovery */ in lua_pcallk()
1043 luaD_call(L, c.func, nresults); /* do the call */ in lua_pcallk()
1044 ci->callstatus &= ~CIST_YPCALL; in lua_pcallk()
1045 L->errfunc = ci->u.c.old_errfunc; in lua_pcallk()
1048 adjustresults(L, nresults); in lua_pcallk()
1049 lua_unlock(L); in lua_pcallk()
1054 LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, in lua_load() argument
1058 lua_lock(L); in lua_load()
1060 luaZ_init(L, &z, reader, data); in lua_load()
1061 status = luaD_protectedparser(L, &z, chunkname, mode); in lua_load()
1063 LClosure *f = clLvalue(s2v(L->top - 1)); /* get newly created function */ in lua_load()
1064 if (f->nupvalues >= 1) { /* does it have an upvalue? */ in lua_load()
1066 Table *reg = hvalue(&G(L)->l_registry); in lua_load()
1069 setobj(L, f->upvals[0]->v, gt); in lua_load()
1070 luaC_barrier(L, f->upvals[0], gt); in lua_load()
1073 lua_unlock(L); in lua_load()
1078 LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) { in lua_dump() argument
1081 lua_lock(L); in lua_dump()
1082 api_checknelems(L, 1); in lua_dump()
1083 o = s2v(L->top - 1); in lua_dump()
1085 status = luaU_dump(L, getproto(o), writer, data, strip); in lua_dump()
1088 lua_unlock(L); in lua_dump()
1093 LUA_API int lua_status (lua_State *L) { in lua_status() argument
1094 return L->status; in lua_status()
1099 ** Garbage-collection function
1101 LUA_API int lua_gc (lua_State *L, int what, ...) { in lua_gc() argument
1105 lua_lock(L); in lua_gc()
1106 g = G(L); in lua_gc()
1110 g->gcrunning = 0; in lua_gc()
1115 g->gcrunning = 1; in lua_gc()
1119 luaC_fullgc(L, 0); in lua_gc()
1134 lu_byte oldrunning = g->gcrunning; in lua_gc()
1135 g->gcrunning = 1; /* allow GC to run */ in lua_gc()
1138 luaC_step(L); in lua_gc()
1141 debt = cast(l_mem, data) * 1024 + g->GCdebt; in lua_gc()
1143 luaC_checkGC(L); in lua_gc()
1145 g->gcrunning = oldrunning; /* restore previous state */ in lua_gc()
1146 if (debt > 0 && g->gcstate == GCSpause) /* end of cycle? */ in lua_gc()
1152 res = getgcparam(g->gcpause); in lua_gc()
1153 setgcparam(g->gcpause, data); in lua_gc()
1158 res = getgcparam(g->gcstepmul); in lua_gc()
1159 setgcparam(g->gcstepmul, data); in lua_gc()
1163 res = g->gcrunning; in lua_gc()
1171 g->genminormul = minormul; in lua_gc()
1173 setgcparam(g->genmajormul, majormul); in lua_gc()
1174 luaC_changemode(L, KGC_GEN); in lua_gc()
1183 setgcparam(g->gcpause, pause); in lua_gc()
1185 setgcparam(g->gcstepmul, stepmul); in lua_gc()
1187 g->gcstepsize = stepsize; in lua_gc()
1188 luaC_changemode(L, KGC_INC); in lua_gc()
1191 default: res = -1; /* invalid option */ in lua_gc()
1194 lua_unlock(L); in lua_gc()
1205 LUA_API int lua_error (lua_State *L) { in lua_error() argument
1207 lua_lock(L); in lua_error()
1208 errobj = s2v(L->top - 1); in lua_error()
1209 api_checknelems(L, 1); in lua_error()
1211 if (ttisshrstring(errobj) && eqshrstr(tsvalue(errobj), G(L)->memerrmsg)) in lua_error()
1212 luaM_error(L); /* raise a memory error */ in lua_error()
1214 luaG_errormsg(L); /* raise a regular error */ in lua_error()
1220 LUA_API int lua_next (lua_State *L, int idx) { in lua_next() argument
1223 lua_lock(L); in lua_next()
1224 api_checknelems(L, 1); in lua_next()
1225 t = gettable(L, idx); in lua_next()
1226 more = luaH_next(L, t, L->top - 1); in lua_next()
1228 api_incr_top(L); in lua_next()
1231 L->top -= 1; /* remove key */ in lua_next()
1232 lua_unlock(L); in lua_next()
1237 LUA_API void lua_toclose (lua_State *L, int idx) { in lua_toclose() argument
1240 lua_lock(L); in lua_toclose()
1241 o = index2stack(L, idx); in lua_toclose()
1242 nresults = L->ci->nresults; in lua_toclose()
1243 api_check(L, L->openupval == NULL || uplevel(L->openupval) <= o, in lua_toclose()
1245 luaF_newtbcupval(L, o); /* create new to-be-closed upvalue */ in lua_toclose()
1247 L->ci->nresults = codeNresults(nresults); /* mark it */ in lua_toclose()
1248 lua_assert(hastocloseCfunc(L->ci->nresults)); in lua_toclose()
1249 lua_unlock(L); in lua_toclose()
1253 LUA_API void lua_concat (lua_State *L, int n) { in lua_concat() argument
1254 lua_lock(L); in lua_concat()
1255 api_checknelems(L, n); in lua_concat()
1257 luaV_concat(L, n); in lua_concat()
1259 setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); /* push empty string */ in lua_concat()
1260 api_incr_top(L); in lua_concat()
1262 luaC_checkGC(L); in lua_concat()
1263 lua_unlock(L); in lua_concat()
1267 LUA_API void lua_len (lua_State *L, int idx) { in lua_len() argument
1269 lua_lock(L); in lua_len()
1270 t = index2value(L, idx); in lua_len()
1271 luaV_objlen(L, L->top, t); in lua_len()
1272 api_incr_top(L); in lua_len()
1273 lua_unlock(L); in lua_len()
1277 LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { in lua_getallocf() argument
1279 lua_lock(L); in lua_getallocf()
1280 if (ud) *ud = G(L)->ud; in lua_getallocf()
1281 f = G(L)->frealloc; in lua_getallocf()
1282 lua_unlock(L); in lua_getallocf()
1287 LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) { in lua_setallocf() argument
1288 lua_lock(L); in lua_setallocf()
1289 G(L)->ud = ud; in lua_setallocf()
1290 G(L)->frealloc = f; in lua_setallocf()
1291 lua_unlock(L); in lua_setallocf()
1295 void lua_setwarnf (lua_State *L, lua_WarnFunction f, void *ud) { in lua_setwarnf() argument
1296 lua_lock(L); in lua_setwarnf()
1297 G(L)->ud_warn = ud; in lua_setwarnf()
1298 G(L)->warnf = f; in lua_setwarnf()
1299 lua_unlock(L); in lua_setwarnf()
1303 void lua_warning (lua_State *L, const char *msg, int tocont) { in lua_warning() argument
1304 lua_lock(L); in lua_warning()
1305 luaE_warning(L, msg, tocont); in lua_warning()
1306 lua_unlock(L); in lua_warning()
1311 LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) { in lua_newuserdatauv() argument
1313 lua_lock(L); in lua_newuserdatauv()
1314 api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, "invalid value"); in lua_newuserdatauv()
1315 u = luaS_newudata(L, size, nuvalue); in lua_newuserdatauv()
1316 setuvalue(L, s2v(L->top), u); in lua_newuserdatauv()
1317 api_incr_top(L); in lua_newuserdatauv()
1318 luaC_checkGC(L); in lua_newuserdatauv()
1319 lua_unlock(L); in lua_newuserdatauv()
1330 if (!(cast_uint(n) - 1u < cast_uint(f->nupvalues))) in aux_upvalue()
1331 return NULL; /* 'n' not in [1, f->nupvalues] */ in aux_upvalue()
1332 *val = &f->upvalue[n-1]; in aux_upvalue()
1339 Proto *p = f->p; in aux_upvalue()
1340 if (!(cast_uint(n) - 1u < cast_uint(p->sizeupvalues))) in aux_upvalue()
1341 return NULL; /* 'n' not in [1, p->sizeupvalues] */ in aux_upvalue()
1342 *val = f->upvals[n-1]->v; in aux_upvalue()
1343 if (owner) *owner = obj2gco(f->upvals[n - 1]); in aux_upvalue()
1344 name = p->upvalues[n-1].name; in aux_upvalue()
1352 LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { in lua_getupvalue() argument
1355 lua_lock(L); in lua_getupvalue()
1356 name = aux_upvalue(index2value(L, funcindex), n, &val, NULL); in lua_getupvalue()
1358 setobj2s(L, L->top, val); in lua_getupvalue()
1359 api_incr_top(L); in lua_getupvalue()
1361 lua_unlock(L); in lua_getupvalue()
1366 LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { in lua_setupvalue() argument
1371 lua_lock(L); in lua_setupvalue()
1372 fi = index2value(L, funcindex); in lua_setupvalue()
1373 api_checknelems(L, 1); in lua_setupvalue()
1376 L->top--; in lua_setupvalue()
1377 setobj(L, val, s2v(L->top)); in lua_setupvalue()
1378 luaC_barrier(L, owner, val); in lua_setupvalue()
1380 lua_unlock(L); in lua_setupvalue()
1385 static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { in getupvalref() argument
1387 TValue *fi = index2value(L, fidx); in getupvalref()
1388 api_check(L, ttisLclosure(fi), "Lua function expected"); in getupvalref()
1390 api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index"); in getupvalref()
1392 return &f->upvals[n - 1]; /* get its upvalue pointer */ in getupvalref()
1396 LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { in lua_upvalueid() argument
1397 TValue *fi = index2value(L, fidx); in lua_upvalueid()
1400 return *getupvalref(L, fidx, n, NULL); in lua_upvalueid()
1404 api_check(L, 1 <= n && n <= f->nupvalues, "invalid upvalue index"); in lua_upvalueid()
1405 return &f->upvalue[n - 1]; in lua_upvalueid()
1408 api_check(L, 0, "closure expected"); in lua_upvalueid()
1415 LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1, in lua_upvaluejoin() argument
1418 UpVal **up1 = getupvalref(L, fidx1, n1, &f1); in lua_upvaluejoin()
1419 UpVal **up2 = getupvalref(L, fidx2, n2, NULL); in lua_upvaluejoin()
1421 luaC_objbarrier(L, f1, *up1); in lua_upvaluejoin()