Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lapi.c File Reference
#include "lprefix.h"
#include <limits.h>
#include <stdarg.h>
#include <string.h>
#include "lua.h"
#include "lapi.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lgc.h"
#include "lmem.h"
#include "lobject.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "lundump.h"
#include "lvm.h"

Go to the source code of this file.

Data Structures

struct  CallS
 

Macros

#define lapi_c
 
#define LUA_CORE
 
#define isvalid(L, o)   (!ttisnil(o) || o != &G(L)->nilvalue)
 
#define ispseudo(i)   ((i) <= LUA_REGISTRYINDEX)
 
#define isupvalue(i)   ((i) < LUA_REGISTRYINDEX)
 
#define getGtable(L)    (&hvalue(&G(L)->l_registry)->array[LUA_RIDX_GLOBALS - 1])
 
#define checkresults(L, na, nr)
 

Functions

static TValueindex2value (lua_State *L, int idx)
 
static StkId index2stack (lua_State *L, int idx)
 
LUA_API int lua_checkstack (lua_State *L, int n)
 
LUA_API void lua_xmove (lua_State *from, lua_State *to, int n)
 
LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf)
 
LUA_API lua_Number lua_version (lua_State *L)
 
LUA_API int lua_absindex (lua_State *L, int idx)
 
LUA_API int lua_gettop (lua_State *L)
 
LUA_API void lua_settop (lua_State *L, int idx)
 
LUA_API void lua_closeslot (lua_State *L, int idx)
 
static void reverse (lua_State *L, StkId from, StkId to)
 
LUA_API void lua_rotate (lua_State *L, int idx, int n)
 
LUA_API void lua_copy (lua_State *L, int fromidx, int toidx)
 
LUA_API void lua_pushvalue (lua_State *L, int idx)
 
LUA_API int lua_type (lua_State *L, int idx)
 
LUA_API const char * lua_typename (lua_State *L, int t)
 
LUA_API int lua_iscfunction (lua_State *L, int idx)
 
LUA_API int lua_isinteger (lua_State *L, int idx)
 
LUA_API int lua_isnumber (lua_State *L, int idx)
 
LUA_API int lua_isstring (lua_State *L, int idx)
 
LUA_API int lua_isuserdata (lua_State *L, int idx)
 
LUA_API int lua_rawequal (lua_State *L, int index1, int index2)
 
LUA_API void lua_arith (lua_State *L, int op)
 
LUA_API int lua_compare (lua_State *L, int index1, int index2, int op)
 
LUA_API size_t lua_stringtonumber (lua_State *L, const char *s)
 
LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum)
 
LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum)
 
LUA_API int lua_toboolean (lua_State *L, int idx)
 
LUA_API const char * lua_tolstring (lua_State *L, int idx, size_t *len)
 
LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx)
 
LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx)
 
static void * touserdata (const TValue *o)
 
LUA_API void * lua_touserdata (lua_State *L, int idx)
 
LUA_API lua_Statelua_tothread (lua_State *L, int idx)
 
LUA_API const void * lua_topointer (lua_State *L, int idx)
 
LUA_API void lua_pushnil (lua_State *L)
 
LUA_API void lua_pushnumber (lua_State *L, lua_Number n)
 
LUA_API void lua_pushinteger (lua_State *L, lua_Integer n)
 
LUA_API const char * lua_pushlstring (lua_State *L, const char *s, size_t len)
 
LUA_API const char * lua_pushstring (lua_State *L, const char *s)
 
LUA_API const char * lua_pushvfstring (lua_State *L, const char *fmt, va_list argp)
 
LUA_API const char * lua_pushfstring (lua_State *L, const char *fmt,...)
 
LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n)
 
LUA_API void lua_pushboolean (lua_State *L, int b)
 
LUA_API void lua_pushlightuserdata (lua_State *L, void *p)
 
LUA_API int lua_pushthread (lua_State *L)
 
static int auxgetstr (lua_State *L, const TValue *t, const char *k)
 
LUA_API int lua_getglobal (lua_State *L, const char *name)
 
LUA_API int lua_gettable (lua_State *L, int idx)
 
LUA_API int lua_getfield (lua_State *L, int idx, const char *k)
 
LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n)
 
static int finishrawget (lua_State *L, const TValue *val)
 
static Tablegettable (lua_State *L, int idx)
 
LUA_API int lua_rawget (lua_State *L, int idx)
 
LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n)
 
LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p)
 
LUA_API void lua_createtable (lua_State *L, int narray, int nrec)
 
LUA_API int lua_getmetatable (lua_State *L, int objindex)
 
LUA_API int lua_getiuservalue (lua_State *L, int idx, int n)
 
static void auxsetstr (lua_State *L, const TValue *t, const char *k)
 
LUA_API void lua_setglobal (lua_State *L, const char *name)
 
LUA_API void lua_settable (lua_State *L, int idx)
 
LUA_API void lua_setfield (lua_State *L, int idx, const char *k)
 
LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n)
 
static void aux_rawset (lua_State *L, int idx, TValue *key, int n)
 
LUA_API void lua_rawset (lua_State *L, int idx)
 
LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p)
 
LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n)
 
LUA_API int lua_setmetatable (lua_State *L, int objindex)
 
LUA_API int lua_setiuservalue (lua_State *L, int idx, int n)
 
LUA_API void lua_callk (lua_State *L, int nargs, int nresults, lua_KContext ctx, lua_KFunction k)
 
static void f_call (lua_State *L, void *ud)
 
LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, lua_KContext ctx, lua_KFunction k)
 
LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, const char *chunkname, const char *mode)
 
LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip)
 
LUA_API int lua_status (lua_State *L)
 
LUA_API int lua_gc (lua_State *L, int what,...)
 
LUA_API int lua_error (lua_State *L)
 
LUA_API int lua_next (lua_State *L, int idx)
 
LUA_API void lua_toclose (lua_State *L, int idx)
 
LUA_API void lua_concat (lua_State *L, int n)
 
LUA_API void lua_len (lua_State *L, int idx)
 
LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud)
 
LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud)
 
void lua_setwarnf (lua_State *L, lua_WarnFunction f, void *ud)
 
void lua_warning (lua_State *L, const char *msg, int tocont)
 
LUA_API void * lua_newuserdatauv (lua_State *L, size_t size, int nuvalue)
 
static const char * aux_upvalue (TValue *fi, int n, TValue **val, GCObject **owner)
 
LUA_API const char * lua_getupvalue (lua_State *L, int funcindex, int n)
 
LUA_API const char * lua_setupvalue (lua_State *L, int funcindex, int n)
 
static UpVal ** getupvalref (lua_State *L, int fidx, int n, LClosure **pf)
 
LUA_API void * lua_upvalueid (lua_State *L, int fidx, int n)
 
LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1, int fidx2, int n2)
 

Variables

const char lua_ident []
 

Macro Definition Documentation

◆ checkresults

#define checkresults ( L,
na,
nr )
Value:
api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \
"results from function overflow current stack size")
#define api_check
#define LUA_MULTRET

Definition at line 992 of file lua-5.4.3/src/lapi.c.

992#define checkresults(L,na,nr) \
993 api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \
994 "results from function overflow current stack size")

Referenced by lua_callk(), and lua_pcallk().

◆ getGtable

#define getGtable ( L)     (&hvalue(&G(L)->l_registry)->array[LUA_RIDX_GLOBALS - 1])

Definition at line 656 of file lua-5.4.3/src/lapi.c.

656#define getGtable(L) \
657 (&hvalue(&G(L)->l_registry)->array[LUA_RIDX_GLOBALS - 1])

Referenced by lua_getglobal(), lua_load(), and lua_setglobal().

◆ ispseudo

#define ispseudo ( i)    ((i) <= LUA_REGISTRYINDEX)

Definition at line 50 of file lua-5.4.3/src/lapi.c.

Referenced by index2stack(), index2value(), and lua_absindex().

◆ isupvalue

#define isupvalue ( i)    ((i) < LUA_REGISTRYINDEX)

Definition at line 53 of file lua-5.4.3/src/lapi.c.

Referenced by lua_copy().

◆ isvalid

#define isvalid ( L,
o )   (!ttisnil(o) || o != &G(L)->nilvalue)

Definition at line 46 of file lua-5.4.3/src/lapi.c.

Referenced by lua_compare(), lua_copy(), lua_rawequal(), and lua_type().

◆ lapi_c

#define lapi_c

Definition at line 7 of file lua-5.4.3/src/lapi.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file lua-5.4.3/src/lapi.c.

Function Documentation

◆ aux_rawset()

static void aux_rawset ( lua_State * L,
int idx,
TValue * key,
int n )
static

Definition at line 890 of file lua-5.4.3/src/lapi.c.

890 {
891 Table *t;
892 lua_lock(L);
893 api_checknelems(L, n);
894 t = gettable(L, idx);
895 luaH_set(L, t, key, s2v(L->top - 1));
897 luaC_barrierback(L, obj2gco(t), s2v(L->top - 1));
898 L->top -= n;
899 lua_unlock(L);
900}
#define api_checknelems(L, n)
#define lua_unlock(L)
#define lua_lock(L)
#define obj2gco(v)
TValue * luaH_set(lua_State *L, Table *t, const TValue *key)
#define luaC_barrierback(L, p, v)
#define invalidateTMcache(t)
static Table * gettable(lua_State *L, int idx)
#define s2v(o)

References api_checknelems, gettable(), invalidateTMcache, lua_lock, lua_unlock, luaC_barrierback, luaH_set(), obj2gco, s2v, and lua_State::top.

Referenced by lua_rawset(), and lua_rawsetp().

◆ aux_upvalue()

static const char * aux_upvalue ( TValue * fi,
int n,
TValue ** val,
GCObject ** owner )
static

Definition at line 1349 of file lua-5.4.3/src/lapi.c.

1350 {
1351 switch (ttypetag(fi)) {
1352 case LUA_VCCL: { /* C closure */
1353 CClosure *f = clCvalue(fi);
1354 if (!(cast_uint(n) - 1u < cast_uint(f->nupvalues)))
1355 return NULL; /* 'n' not in [1, f->nupvalues] */
1356 *val = &f->upvalue[n-1];
1357 if (owner) *owner = obj2gco(f);
1358 return "";
1359 }
1360 case LUA_VLCL: { /* Lua closure */
1361 LClosure *f = clLvalue(fi);
1362 TString *name;
1363 Proto *p = f->p;
1364 if (!(cast_uint(n) - 1u < cast_uint(p->sizeupvalues)))
1365 return NULL; /* 'n' not in [1, p->sizeupvalues] */
1366 *val = f->upvals[n-1]->v;
1367 if (owner) *owner = obj2gco(f->upvals[n - 1]);
1368 name = p->upvalues[n-1].name;
1369 return (name == NULL) ? "(no name)" : getstr(name);
1370 }
1371 default: return NULL; /* not a closure */
1372 }
1373}
pthread_t owner
#define NULL
Definition gmacros.h:924
const char * name
Definition lsqlite3.c:2154
#define getstr(ts)
#define clCvalue(o)
#define clLvalue(o)
#define cast_uint(i)
#define ttypetag(o)
#define LUA_VCCL
#define LUA_VLCL
struct Proto * p
TString ** upvalues

References cast_uint, clCvalue, clLvalue, getstr, LUA_VCCL, LUA_VLCL, name, NULL, obj2gco, owner, LClosure::p, Proto::sizeupvalues, ttypetag, LClosure::upvals, CClosure::upvalue, Proto::upvalues, and UpVal::v.

Referenced by lua_getupvalue(), and lua_setupvalue().

◆ auxgetstr()

static int auxgetstr ( lua_State * L,
const TValue * t,
const char * k )
static

Definition at line 633 of file lua-5.4.3/src/lapi.c.

633 {
634 const TValue *slot;
635 TString *str = luaS_new(L, k);
636 if (luaV_fastget(L, t, str, slot, luaH_getstr)) {
637 setobj2s(L, L->top, slot);
638 api_incr_top(L);
639 }
640 else {
641 setsvalue2s(L, L->top, str);
642 api_incr_top(L);
643 luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot);
644 }
645 lua_unlock(L);
646 return ttype(s2v(L->top - 1));
647}
#define api_incr_top(L)
#define setobj2s
#define setsvalue2s
#define ttype(o)
#define luaS_new(L, s)
const TValue * luaH_getstr(Table *t, TString *key)
void luaV_finishget(lua_State *L, const TValue *t, TValue *key, StkId val, const TValue *slot)
#define luaV_fastget(L, t, k, slot, f)

References api_incr_top, lua_unlock, luaH_getstr(), luaS_new, luaV_fastget, luaV_finishget(), s2v, setobj2s, setsvalue2s, lua_State::top, and ttype.

Referenced by lua_getfield(), and lua_getglobal().

◆ auxsetstr()

static void auxsetstr ( lua_State * L,
const TValue * t,
const char * k )
static

Definition at line 823 of file lua-5.4.3/src/lapi.c.

823 {
824 const TValue *slot;
825 TString *str = luaS_new(L, k);
826 api_checknelems(L, 1);
827 if (luaV_fastget(L, t, str, slot, luaH_getstr)) {
828 luaV_finishfastset(L, t, slot, s2v(L->top - 1));
829 L->top--; /* pop value */
830 }
831 else {
832 setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */
833 api_incr_top(L);
834 luaV_finishset(L, t, s2v(L->top - 1), s2v(L->top - 2), slot);
835 L->top -= 2; /* pop value and key */
836 }
837 lua_unlock(L); /* lock done by caller */
838}
void luaV_finishset(lua_State *L, const TValue *t, TValue *key, StkId val, const TValue *slot)
#define luaV_finishfastset(L, t, slot, v)

References api_checknelems, api_incr_top, lua_unlock, luaH_getstr(), luaS_new, luaV_fastget, luaV_finishfastset, luaV_finishset(), s2v, setsvalue2s, and lua_State::top.

Referenced by lua_setfield(), and lua_setglobal().

◆ f_call()

static void f_call ( lua_State * L,
void * ud )
static

Definition at line 1029 of file lua-5.4.3/src/lapi.c.

1029 {
1030 struct CallS *c = cast(struct CallS *, ud);
1031 luaD_callnoyield(L, c->func, c->nresults);
1032}
#define cast(t, exp)
void luaD_callnoyield(lua_State *L, StkId func, int nResults)

References cast, CallS::func, luaD_callnoyield(), and CallS::nresults.

Referenced by lua_pcallk().

◆ finishrawget()

static int finishrawget ( lua_State * L,
const TValue * val )
static

Definition at line 708 of file lua-5.4.3/src/lapi.c.

708 {
709 if (isempty(val)) /* avoid copying empty items to the stack */
710 setnilvalue(s2v(L->top));
711 else
712 setobj2s(L, L->top, val);
713 api_incr_top(L);
714 lua_unlock(L);
715 return ttype(s2v(L->top - 1));
716}
#define setnilvalue(obj)
#define isempty(v)

References api_incr_top, isempty, lua_unlock, s2v, setnilvalue, setobj2s, lua_State::top, and ttype.

Referenced by lua_rawget(), lua_rawgeti(), and lua_rawgetp().

◆ gettable()

static Table * gettable ( lua_State * L,
int idx )
static

Definition at line 719 of file lua-5.4.3/src/lapi.c.

719 {
720 TValue *t = index2value(L, idx);
721 api_check(L, ttistable(t), "table expected");
722 return hvalue(t);
723}
#define hvalue(o)
#define ttistable(o)
static TValue * index2value(lua_State *L, int idx)

References api_check, hvalue, index2value(), and ttistable.

Referenced by aux_rawset(), lua_next(), lua_rawget(), lua_rawgeti(), lua_rawgetp(), and lua_rawseti().

◆ getupvalref()

static UpVal ** getupvalref ( lua_State * L,
int fidx,
int n,
LClosure ** pf )
static

Definition at line 1409 of file lua-5.4.3/src/lapi.c.

1409 {
1410 static const UpVal *const nullup = NULL;
1411 LClosure *f;
1412 TValue *fi = index2value(L, fidx);
1413 api_check(L, ttisLclosure(fi), "Lua function expected");
1414 f = clLvalue(fi);
1415 if (pf) *pf = f;
1416 if (1 <= n && n <= f->p->sizeupvalues)
1417 return &f->upvals[n - 1]; /* get its upvalue pointer */
1418 else
1419 return (UpVal**)&nullup;
1420}
#define ttisLclosure(o)

References api_check, clLvalue, index2value(), NULL, ttisLclosure, and LClosure::upvals.

Referenced by lua_upvalueid(), and lua_upvaluejoin().

◆ index2stack()

static StkId index2stack ( lua_State * L,
int idx )
static

Definition at line 84 of file lua-5.4.3/src/lapi.c.

84 {
85 CallInfo *ci = L->ci;
86 if (idx > 0) {
87 StkId o = ci->func + idx;
88 api_check(L, o < L->top, "unacceptable index");
89 return o;
90 }
91 else { /* non-positive index */
92 api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
93 api_check(L, !ispseudo(idx), "invalid index");
94 return L->top + idx;
95 }
96}
#define ispseudo(i)

References api_check, lua_State::ci, CallInfo::func, ispseudo, and lua_State::top.

Referenced by lua_closeslot(), lua_pcallk(), lua_rotate(), and lua_toclose().

◆ index2value()

static TValue * index2value ( lua_State * L,
int idx )
static

Definition at line 56 of file lua-5.4.3/src/lapi.c.

56 {
57 CallInfo *ci = L->ci;
58 if (idx > 0) {
59 StkId o = ci->func + idx;
60 api_check(L, idx <= L->ci->top - (ci->func + 1), "unacceptable index");
61 if (o >= L->top) return &G(L)->nilvalue;
62 else return s2v(o);
63 }
64 else if (!ispseudo(idx)) { /* negative index */
65 api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
66 return s2v(L->top + idx);
67 }
68 else if (idx == LUA_REGISTRYINDEX)
69 return &G(L)->l_registry;
70 else { /* upvalues */
71 idx = LUA_REGISTRYINDEX - idx;
72 api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large");
73 if (ttislcf(s2v(ci->func))) /* light C function? */
74 return &G(L)->nilvalue; /* it has no upvalues */
75 else {
76 CClosure *func = clCvalue(s2v(ci->func));
77 return (idx <= func->nupvalues) ? &func->upvalue[idx-1]
78 : &G(L)->nilvalue;
79 }
80 }
81}
#define G(L)
#define LUA_REGISTRYINDEX
#define MAXUPVAL
#define ttislcf(o)

References api_check, lua_State::ci, clCvalue, CallInfo::func, G, ispseudo, LUA_REGISTRYINDEX, MAXUPVAL, s2v, CallInfo::top, lua_State::top, ttislcf, and CClosure::upvalue.

Referenced by gettable(), getupvalref(), lua_compare(), lua_copy(), lua_getfield(), lua_geti(), lua_getiuservalue(), lua_getmetatable(), lua_gettable(), lua_getupvalue(), lua_iscfunction(), lua_isinteger(), lua_isnumber(), lua_isstring(), lua_isuserdata(), lua_len(), lua_pushvalue(), lua_rawequal(), lua_rawlen(), lua_setfield(), lua_seti(), lua_setiuservalue(), lua_setmetatable(), lua_settable(), lua_setupvalue(), lua_toboolean(), lua_tocfunction(), lua_tointegerx(), lua_tolstring(), lua_tonumberx(), lua_topointer(), lua_tothread(), lua_touserdata(), lua_type(), and lua_upvalueid().

◆ lua_absindex()

LUA_API int lua_absindex ( lua_State * L,
int idx )

Definition at line 162 of file lua-5.4.3/src/lapi.c.

162 {
163 return (idx > 0 || ispseudo(idx))
164 ? idx
165 : cast_int(L->top - L->ci->func) + idx;
166}
#define cast_int(i)

References cast_int, lua_State::ci, CallInfo::func, ispseudo, and lua_State::top.

◆ lua_arith()

LUA_API void lua_arith ( lua_State * L,
int op )

Definition at line 329 of file lua-5.4.3/src/lapi.c.

329 {
330 lua_lock(L);
331 if (op != LUA_OPUNM && op != LUA_OPBNOT)
332 api_checknelems(L, 2); /* all other operations expect two operands */
333 else { /* for unary operations, add fake 2nd operand */
334 api_checknelems(L, 1);
335 setobjs2s(L, L->top, L->top - 1);
336 api_incr_top(L);
337 }
338 /* first operand at top - 2, second at top - 1; result go to top - 2 */
339 luaO_arith(L, op, s2v(L->top - 2), s2v(L->top - 1), L->top - 2);
340 L->top--; /* remove second operand */
341 lua_unlock(L);
342}
#define setobjs2s
lua_Number luaO_arith(int op, lua_Number v1, lua_Number v2)
#define LUA_OPUNM
#define LUA_OPBNOT

References api_checknelems, api_incr_top, lua_lock, LUA_OPBNOT, LUA_OPUNM, lua_unlock, luaO_arith(), s2v, setobjs2s, and lua_State::top.

◆ lua_atpanic()

LUA_API lua_CFunction lua_atpanic ( lua_State * L,
lua_CFunction panicf )

Definition at line 137 of file lua-5.4.3/src/lapi.c.

137 {
138 lua_CFunction old;
139 lua_lock(L);
140 old = G(L)->panic;
141 G(L)->panic = panicf;
142 lua_unlock(L);
143 return old;
144}
int(* lua_CFunction)(lua_State *L)

References G, lua_lock, and lua_unlock.

◆ lua_callk()

LUA_API void lua_callk ( lua_State * L,
int nargs,
int nresults,
lua_KContext ctx,
lua_KFunction k )

Definition at line 997 of file lua-5.4.3/src/lapi.c.

998 {
999 StkId func;
1000 lua_lock(L);
1001 api_check(L, k == NULL || !isLua(L->ci),
1002 "cannot use continuations inside hooks");
1003 api_checknelems(L, nargs+1);
1004 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
1005 checkresults(L, nargs, nresults);
1006 func = L->top - (nargs+1);
1007 if (k != NULL && yieldable(L)) { /* need to prepare continuation? */
1008 L->ci->u.c.k = k; /* save continuation */
1009 L->ci->u.c.ctx = ctx; /* save context */
1010 luaD_call(L, func, nresults); /* do the call */
1011 }
1012 else /* no continuation or no yieldable */
1013 luaD_callnoyield(L, func, nresults); /* just do the call */
1014 adjustresults(L, nresults);
1015 lua_unlock(L);
1016}
#define adjustresults(L, nres)
void luaD_call(lua_State *L, StkId func, int nResults)
#define isLua(ci)
#define LUA_OK
#define checkresults(L, na, nr)
#define yieldable(L)
lua_CFunction k
union CallInfo::@64 u
struct CallInfo::@64::@66 c

References adjustresults, api_check, api_checknelems, CallInfo::c, checkresults, lua_State::ci, CallInfo::ctx, isLua, CallInfo::k, lua_lock, LUA_OK, lua_unlock, luaD_call(), luaD_callnoyield(), NULL, lua_State::status, lua_State::top, CallInfo::u, and yieldable.

◆ lua_checkstack()

LUA_API int lua_checkstack ( lua_State * L,
int n )

Definition at line 99 of file lua-5.4.3/src/lapi.c.

99 {
100 int res;
101 CallInfo *ci;
102 lua_lock(L);
103 ci = L->ci;
104 api_check(L, n >= 0, "negative 'n'");
105 if (L->stack_last - L->top > n) /* stack large enough? */
106 res = 1; /* yes; check is OK */
107 else { /* no; need to grow stack */
108 int inuse = cast_int(L->top - L->stack) + EXTRA_STACK;
109 if (inuse > LUAI_MAXSTACK - n) /* can grow without overflow? */
110 res = 0; /* no */
111 else /* try to grow stack */
112 res = luaD_growstack(L, n, 0);
113 }
114 if (res && ci->top < L->top + n)
115 ci->top = L->top + n; /* adjust frame top */
116 lua_unlock(L);
117 return res;
118}
void luaD_growstack(lua_State *L, int n)
#define EXTRA_STACK
#define LUAI_MAXSTACK

References api_check, cast_int, lua_State::ci, EXTRA_STACK, lua_lock, lua_unlock, luaD_growstack(), LUAI_MAXSTACK, lua_State::stack, lua_State::stack_last, CallInfo::top, and lua_State::top.

◆ lua_closeslot()

LUA_API void lua_closeslot ( lua_State * L,
int idx )

Definition at line 202 of file lua-5.4.3/src/lapi.c.

202 {
203 StkId level;
204 lua_lock(L);
205 level = index2stack(L, idx);
206 api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist == level,
207 "no variable to close at given level");
208 luaF_close(L, level, CLOSEKTOP, 0);
209 level = index2stack(L, idx); /* stack may be moved */
210 setnilvalue(s2v(level));
211 lua_unlock(L);
212}
void luaF_close(lua_State *L, StkId level)
static StkId index2stack(lua_State *L, int idx)
#define hastocloseCfunc(n)
#define CLOSEKTOP

References api_check, lua_State::ci, CLOSEKTOP, hastocloseCfunc, index2stack(), lua_lock, lua_unlock, luaF_close(), CallInfo::nresults, s2v, setnilvalue, and lua_State::tbclist.

Referenced by luaL_pushresult().

◆ lua_compare()

LUA_API int lua_compare ( lua_State * L,
int index1,
int index2,
int op )

Definition at line 345 of file lua-5.4.3/src/lapi.c.

345 {
346 const TValue *o1;
347 const TValue *o2;
348 int i = 0;
349 lua_lock(L); /* may call tag method */
350 o1 = index2value(L, index1);
351 o2 = index2value(L, index2);
352 if (isvalid(L, o1) && isvalid(L, o2)) {
353 switch (op) {
354 case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break;
355 case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;
356 case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;
357 default: api_check(L, 0, "invalid option");
358 }
359 }
360 lua_unlock(L);
361 return i;
362}
int luaV_lessthan(lua_State *L, const TValue *l, const TValue *r)
#define LUA_OPLT
#define LUA_OPLE
#define LUA_OPEQ
int luaV_lessequal(lua_State *L, const TValue *l, const TValue *r)
int luaV_equalobj(lua_State *L, const TValue *t1, const TValue *t2)
#define isvalid(L, o)

References api_check, index2value(), isvalid, lua_lock, LUA_OPEQ, LUA_OPLE, LUA_OPLT, lua_unlock, luaV_equalobj(), luaV_lessequal(), and luaV_lessthan().

◆ lua_concat()

LUA_API void lua_concat ( lua_State * L,
int n )

Definition at line 1277 of file lua-5.4.3/src/lapi.c.

1277 {
1278 lua_lock(L);
1279 api_checknelems(L, n);
1280 if (n > 0)
1281 luaV_concat(L, n);
1282 else { /* nothing to concatenate */
1283 setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); /* push empty string */
1284 api_incr_top(L);
1285 }
1286 luaC_checkGC(L);
1287 lua_unlock(L);
1288}
#define luaC_checkGC(L)
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)
void luaV_concat(lua_State *L, int total, int last)

References api_checknelems, api_incr_top, lua_lock, lua_unlock, luaC_checkGC, luaS_newlstr(), luaV_concat(), setsvalue2s, and lua_State::top.

◆ lua_copy()

LUA_API void lua_copy ( lua_State * L,
int fromidx,
int toidx )

Definition at line 249 of file lua-5.4.3/src/lapi.c.

249 {
250 TValue *fr, *to;
251 lua_lock(L);
252 fr = index2value(L, fromidx);
253 to = index2value(L, toidx);
254 api_check(L, isvalid(L, to), "invalid index");
255 setobj(L, to, fr);
256 if (isupvalue(toidx)) /* function upvalue? */
257 luaC_barrier(L, clCvalue(s2v(L->ci->func)), fr);
258 /* LUA_REGISTRYINDEX does not need gc barrier
259 (collector revisits it before finishing collection) */
260 lua_unlock(L);
261}
#define luaC_barrier(L, p, v)
#define setobj(L, obj1, obj2)
#define isupvalue(i)

References api_check, lua_State::ci, clCvalue, CallInfo::func, index2value(), isupvalue, isvalid, lua_lock, lua_unlock, luaC_barrier, s2v, and setobj.

◆ lua_createtable()

LUA_API void lua_createtable ( lua_State * L,
int narray,
int nrec )

Definition at line 756 of file lua-5.4.3/src/lapi.c.

756 {
757 Table *t;
758 lua_lock(L);
759 t = luaH_new(L);
760 sethvalue2s(L, L->top, t);
761 api_incr_top(L);
762 if (narray > 0 || nrec > 0)
763 luaH_resize(L, t, narray, nrec);
764 luaC_checkGC(L);
765 lua_unlock(L);
766}
#define sethvalue2s
Table * luaH_new(lua_State *L, int narray, int nhash)
void luaH_resize(lua_State *L, Table *t, int nasize, int nhsize)

References api_incr_top, lua_lock, lua_unlock, luaC_checkGC, luaH_new(), luaH_resize(), sethvalue2s, and lua_State::top.

◆ lua_dump()

LUA_API int lua_dump ( lua_State * L,
lua_Writer writer,
void * data,
int strip )

Definition at line 1103 of file lua-5.4.3/src/lapi.c.

1103 {
1104 int status;
1105 TValue *o;
1106 lua_lock(L);
1107 api_checknelems(L, 1);
1108 o = s2v(L->top - 1);
1109 if (isLfunction(o))
1110 status = luaU_dump(L, getproto(o), writer, data, strip);
1111 else
1112 status = 1;
1113 lua_unlock(L);
1114 return status;
1115}
int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, int strip)
#define isLfunction(o)
static int writer(lua_State *L, const void *b, size_t size, void *B)
#define getproto(o)

References api_checknelems, getproto, isLfunction, lua_lock, lua_unlock, luaU_dump(), s2v, lua_State::top, and writer().

◆ lua_error()

LUA_API int lua_error ( lua_State * L)

Definition at line 1230 of file lua-5.4.3/src/lapi.c.

1230 {
1231 TValue *errobj;
1232 lua_lock(L);
1233 errobj = s2v(L->top - 1);
1234 api_checknelems(L, 1);
1235 /* error object is the memory error message? */
1236 if (ttisshrstring(errobj) && eqshrstr(tsvalue(errobj), G(L)->memerrmsg))
1237 luaM_error(L); /* raise a memory error */
1238 else
1239 luaG_errormsg(L); /* raise a regular error */
1240 /* code unreachable; will unlock when control actually leaves the kernel */
1241 return 0; /* to avoid warnings */
1242}
void luaG_errormsg(lua_State *L)
#define tsvalue(o)
#define ttisshrstring(o)
#define eqshrstr(a, b)
#define luaM_error(L)

References api_checknelems, eqshrstr, G, lua_lock, luaG_errormsg(), luaM_error, s2v, lua_State::top, tsvalue, and ttisshrstring.

◆ lua_gc()

LUA_API int lua_gc ( lua_State * L,
int what,
... )

Definition at line 1126 of file lua-5.4.3/src/lapi.c.

1126 {
1127 va_list argp;
1128 int res = 0;
1129 global_State *g;
1130 lua_lock(L);
1131 g = G(L);
1132 va_start(argp, what);
1133 switch (what) {
1134 case LUA_GCSTOP: {
1135 g->gcrunning = 0;
1136 break;
1137 }
1138 case LUA_GCRESTART: {
1139 luaE_setdebt(g, 0);
1140 g->gcrunning = 1;
1141 break;
1142 }
1143 case LUA_GCCOLLECT: {
1144 luaC_fullgc(L, 0);
1145 break;
1146 }
1147 case LUA_GCCOUNT: {
1148 /* GC values are expressed in Kbytes: #bytes/2^10 */
1149 res = cast_int(gettotalbytes(g) >> 10);
1150 break;
1151 }
1152 case LUA_GCCOUNTB: {
1153 res = cast_int(gettotalbytes(g) & 0x3ff);
1154 break;
1155 }
1156 case LUA_GCSTEP: {
1157 int data = va_arg(argp, int);
1158 l_mem debt = 1; /* =1 to signal that it did an actual step */
1159 lu_byte oldrunning = g->gcrunning;
1160 g->gcrunning = 1; /* allow GC to run */
1161 if (data == 0) {
1162 luaE_setdebt(g, 0); /* do a basic step */
1163 luaC_step(L);
1164 }
1165 else { /* add 'data' to total debt */
1166 debt = cast(l_mem, data) * 1024 + g->GCdebt;
1167 luaE_setdebt(g, debt);
1168 luaC_checkGC(L);
1169 }
1170 g->gcrunning = oldrunning; /* restore previous state */
1171 if (debt > 0 && g->gcstate == GCSpause) /* end of cycle? */
1172 res = 1; /* signal it */
1173 break;
1174 }
1175 case LUA_GCSETPAUSE: {
1176 int data = va_arg(argp, int);
1177 res = getgcparam(g->gcpause);
1178 setgcparam(g->gcpause, data);
1179 break;
1180 }
1181 case LUA_GCSETSTEPMUL: {
1182 int data = va_arg(argp, int);
1183 res = getgcparam(g->gcstepmul);
1184 setgcparam(g->gcstepmul, data);
1185 break;
1186 }
1187 case LUA_GCISRUNNING: {
1188 res = g->gcrunning;
1189 break;
1190 }
1191 case LUA_GCGEN: {
1192 int minormul = va_arg(argp, int);
1193 int majormul = va_arg(argp, int);
1194 res = isdecGCmodegen(g) ? LUA_GCGEN : LUA_GCINC;
1195 if (minormul != 0)
1196 g->genminormul = minormul;
1197 if (majormul != 0)
1198 setgcparam(g->genmajormul, majormul);
1200 break;
1201 }
1202 case LUA_GCINC: {
1203 int pause = va_arg(argp, int);
1204 int stepmul = va_arg(argp, int);
1205 int stepsize = va_arg(argp, int);
1206 res = isdecGCmodegen(g) ? LUA_GCGEN : LUA_GCINC;
1207 if (pause != 0)
1208 setgcparam(g->gcpause, pause);
1209 if (stepmul != 0)
1210 setgcparam(g->gcstepmul, stepmul);
1211 if (stepsize != 0)
1212 g->gcstepsize = stepsize;
1214 break;
1215 }
1216 default: res = -1; /* invalid option */
1217 }
1218 va_end(argp);
1219 lua_unlock(L);
1220 return res;
1221}
void luaC_fullgc(lua_State *L)
void luaC_step(lua_State *L)
#define GCSpause
LUAI_MEM l_mem
unsigned char lu_byte
#define LUA_GCSETPAUSE
#define LUA_GCCOUNT
#define LUA_GCCOLLECT
#define LUA_GCSTOP
#define LUA_GCRESTART
#define LUA_GCCOUNTB
#define LUA_GCSTEP
#define LUA_GCSETSTEPMUL
void luaC_changemode(lua_State *L, int mode)
void luaE_setdebt(global_State *g, l_mem debt)
#define gettotalbytes(g)
#define KGC_GEN
#define LUA_GCGEN
#define LUA_GCINC
#define LUA_GCISRUNNING
#define getgcparam(p)
#define isdecGCmodegen(g)
#define setgcparam(p, v)
#define KGC_INC

References cast, cast_int, G, global_State::GCdebt, global_State::gcpause, global_State::gcrunning, GCSpause, global_State::gcstate, global_State::gcstepmul, global_State::gcstepsize, global_State::genmajormul, global_State::genminormul, getgcparam, gettotalbytes, isdecGCmodegen, KGC_GEN, KGC_INC, LUA_GCCOLLECT, LUA_GCCOUNT, LUA_GCCOUNTB, LUA_GCGEN, LUA_GCINC, LUA_GCISRUNNING, LUA_GCRESTART, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL, LUA_GCSTEP, LUA_GCSTOP, lua_lock, lua_unlock, luaC_changemode(), luaC_checkGC, luaC_fullgc(), luaC_step(), luaE_setdebt(), and setgcparam.

◆ lua_getallocf()

LUA_API lua_Alloc lua_getallocf ( lua_State * L,
void ** ud )

Definition at line 1301 of file lua-5.4.3/src/lapi.c.

1301 {
1302 lua_Alloc f;
1303 lua_lock(L);
1304 if (ud) *ud = G(L)->ud;
1305 f = G(L)->frealloc;
1306 lua_unlock(L);
1307 return f;
1308}
void *(* lua_Alloc)(void *ud, void *ptr, size_t osize, size_t nsize)

References G, lua_lock, and lua_unlock.

◆ lua_getfield()

LUA_API int lua_getfield ( lua_State * L,
int idx,
const char * k )

Definition at line 683 of file lua-5.4.3/src/lapi.c.

683 {
684 lua_lock(L);
685 return auxgetstr(L, index2value(L, idx), k);
686}
static int auxgetstr(lua_State *L, const TValue *t, const char *k)

References auxgetstr(), index2value(), and lua_lock.

◆ lua_getglobal()

LUA_API int lua_getglobal ( lua_State * L,
const char * name )

Definition at line 660 of file lua-5.4.3/src/lapi.c.

660 {
661 const TValue *G;
662 lua_lock(L);
663 G = getGtable(L);
664 return auxgetstr(L, G, name);
665}
#define getGtable(L)

References auxgetstr(), G, getGtable, lua_lock, and name.

◆ lua_geti()

LUA_API int lua_geti ( lua_State * L,
int idx,
lua_Integer n )

Definition at line 689 of file lua-5.4.3/src/lapi.c.

689 {
690 TValue *t;
691 const TValue *slot;
692 lua_lock(L);
693 t = index2value(L, idx);
694 if (luaV_fastgeti(L, t, n, slot)) {
695 setobj2s(L, L->top, slot);
696 }
697 else {
698 TValue aux;
699 setivalue(&aux, n);
700 luaV_finishget(L, t, &aux, L->top, slot);
701 }
702 api_incr_top(L);
703 lua_unlock(L);
704 return ttype(s2v(L->top - 1));
705}
#define setivalue(obj, x)
#define luaV_fastgeti(L, t, k, slot)

References api_incr_top, index2value(), lua_lock, lua_unlock, luaV_fastgeti, luaV_finishget(), s2v, setivalue, setobj2s, lua_State::top, and ttype.

◆ lua_getiuservalue()

LUA_API int lua_getiuservalue ( lua_State * L,
int idx,
int n )

Definition at line 796 of file lua-5.4.3/src/lapi.c.

796 {
797 TValue *o;
798 int t;
799 lua_lock(L);
800 o = index2value(L, idx);
801 api_check(L, ttisfulluserdata(o), "full userdata expected");
802 if (n <= 0 || n > uvalue(o)->nuvalue) {
803 setnilvalue(s2v(L->top));
804 t = LUA_TNONE;
805 }
806 else {
807 setobj2s(L, L->top, &uvalue(o)->uv[n - 1].uv);
808 t = ttype(s2v(L->top));
809 }
810 api_incr_top(L);
811 lua_unlock(L);
812 return t;
813}
#define uvalue(o)
#define LUA_TNONE
#define ttisfulluserdata(o)

References api_check, api_incr_top, index2value(), lua_lock, LUA_TNONE, lua_unlock, s2v, setnilvalue, setobj2s, lua_State::top, ttisfulluserdata, ttype, and uvalue.

Referenced by db_getuservalue().

◆ lua_getmetatable()

LUA_API int lua_getmetatable ( lua_State * L,
int objindex )

Definition at line 769 of file lua-5.4.3/src/lapi.c.

769 {
770 const TValue *obj;
771 Table *mt;
772 int res = 0;
773 lua_lock(L);
774 obj = index2value(L, objindex);
775 switch (ttype(obj)) {
776 case LUA_TTABLE:
777 mt = hvalue(obj)->metatable;
778 break;
779 case LUA_TUSERDATA:
780 mt = uvalue(obj)->metatable;
781 break;
782 default:
783 mt = G(L)->mt[ttype(obj)];
784 break;
785 }
786 if (mt != NULL) {
787 sethvalue2s(L, L->top, mt);
788 api_incr_top(L);
789 res = 1;
790 }
791 lua_unlock(L);
792 return res;
793}
#define LUA_TTABLE
#define LUA_TUSERDATA
struct Table * metatable

References api_incr_top, G, hvalue, index2value(), lua_lock, LUA_TTABLE, LUA_TUSERDATA, lua_unlock, Table::metatable, NULL, sethvalue2s, lua_State::top, ttype, and uvalue.

◆ lua_gettable()

LUA_API int lua_gettable ( lua_State * L,
int idx )

Definition at line 668 of file lua-5.4.3/src/lapi.c.

668 {
669 const TValue *slot;
670 TValue *t;
671 lua_lock(L);
672 t = index2value(L, idx);
673 if (luaV_fastget(L, t, s2v(L->top - 1), slot, luaH_get)) {
674 setobj2s(L, L->top - 1, slot);
675 }
676 else
677 luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot);
678 lua_unlock(L);
679 return ttype(s2v(L->top - 1));
680}
const TValue * luaH_get(Table *t, const TValue *key)

References index2value(), lua_lock, lua_unlock, luaH_get(), luaV_fastget, luaV_finishget(), s2v, setobj2s, lua_State::top, and ttype.

◆ lua_gettop()

LUA_API int lua_gettop ( lua_State * L)

Definition at line 169 of file lua-5.4.3/src/lapi.c.

169 {
170 return cast_int(L->top - (L->ci->func + 1));
171}

References cast_int, lua_State::ci, CallInfo::func, and lua_State::top.

◆ lua_getupvalue()

LUA_API const char * lua_getupvalue ( lua_State * L,
int funcindex,
int n )

Definition at line 1376 of file lua-5.4.3/src/lapi.c.

1376 {
1377 const char *name;
1378 TValue *val = NULL; /* to avoid warnings */
1379 lua_lock(L);
1380 name = aux_upvalue(index2value(L, funcindex), n, &val, NULL);
1381 if (name) {
1382 setobj2s(L, L->top, val);
1383 api_incr_top(L);
1384 }
1385 lua_unlock(L);
1386 return name;
1387}
static const char * aux_upvalue(TValue *fi, int n, TValue **val, GCObject **owner)

References api_incr_top, aux_upvalue(), index2value(), lua_lock, lua_unlock, name, NULL, setobj2s, and lua_State::top.

◆ lua_iscfunction()

LUA_API int lua_iscfunction ( lua_State * L,
int idx )

Definition at line 291 of file lua-5.4.3/src/lapi.c.

291 {
292 const TValue *o = index2value(L, idx);
293 return (ttislcf(o) || (ttisCclosure(o)));
294}
#define ttisCclosure(o)

References index2value(), ttisCclosure, and ttislcf.

◆ lua_isinteger()

LUA_API int lua_isinteger ( lua_State * L,
int idx )

Definition at line 297 of file lua-5.4.3/src/lapi.c.

297 {
298 const TValue *o = index2value(L, idx);
299 return ttisinteger(o);
300}
#define ttisinteger(o)

References index2value(), and ttisinteger.

◆ lua_isnumber()

LUA_API int lua_isnumber ( lua_State * L,
int idx )

Definition at line 303 of file lua-5.4.3/src/lapi.c.

303 {
304 lua_Number n;
305 const TValue *o = index2value(L, idx);
306 return tonumber(o, &n);
307}
LUA_NUMBER lua_Number
#define tonumber(o, n)

References index2value(), and tonumber.

◆ lua_isstring()

LUA_API int lua_isstring ( lua_State * L,
int idx )

Definition at line 310 of file lua-5.4.3/src/lapi.c.

310 {
311 const TValue *o = index2value(L, idx);
312 return (ttisstring(o) || cvt2str(o));
313}
#define ttisstring(o)
#define cvt2str(o)

References cvt2str, index2value(), and ttisstring.

◆ lua_isuserdata()

LUA_API int lua_isuserdata ( lua_State * L,
int idx )

Definition at line 316 of file lua-5.4.3/src/lapi.c.

316 {
317 const TValue *o = index2value(L, idx);
318 return (ttisfulluserdata(o) || ttislightuserdata(o));
319}
#define ttislightuserdata(o)

References index2value(), ttisfulluserdata, and ttislightuserdata.

◆ lua_len()

LUA_API void lua_len ( lua_State * L,
int idx )

Definition at line 1291 of file lua-5.4.3/src/lapi.c.

1291 {
1292 TValue *t;
1293 lua_lock(L);
1294 t = index2value(L, idx);
1295 luaV_objlen(L, L->top, t);
1296 api_incr_top(L);
1297 lua_unlock(L);
1298}
void luaV_objlen(lua_State *L, StkId ra, const TValue *rb)

References api_incr_top, index2value(), lua_lock, lua_unlock, luaV_objlen(), and lua_State::top.

◆ lua_load()

LUA_API int lua_load ( lua_State * L,
lua_Reader reader,
void * data,
const char * chunkname,
const char * mode )

Definition at line 1080 of file lua-5.4.3/src/lapi.c.

1081 {
1082 ZIO z;
1083 int status;
1084 lua_lock(L);
1085 if (!chunkname) chunkname = "?";
1086 luaZ_init(L, &z, reader, data);
1087 status = luaD_protectedparser(L, &z, chunkname, mode);
1088 if (status == LUA_OK) { /* no errors? */
1089 LClosure *f = clLvalue(s2v(L->top - 1)); /* get newly created function */
1090 if (f->nupvalues >= 1) { /* does it have an upvalue? */
1091 /* get global table from registry */
1092 const TValue *gt = getGtable(L);
1093 /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
1094 setobj(L, f->upvals[0]->v, gt);
1095 luaC_barrier(L, f->upvals[0], gt);
1096 }
1097 }
1098 lua_unlock(L);
1099 return status;
1100}
int luaD_protectedparser(lua_State *L, ZIO *z, const char *name)
#define gt(L)
void luaZ_init(lua_State *L, ZIO *z, lua_Reader reader, void *data)
static const char * reader(lua_State *L, void *ud, size_t *size)

References clLvalue, getGtable, gt, lua_lock, LUA_OK, lua_unlock, luaC_barrier, luaD_protectedparser(), luaZ_init(), reader(), s2v, setobj, lua_State::top, LClosure::upvals, and UpVal::v.

◆ lua_newuserdatauv()

LUA_API void * lua_newuserdatauv ( lua_State * L,
size_t size,
int nuvalue )

Definition at line 1335 of file lua-5.4.3/src/lapi.c.

1335 {
1336 Udata *u;
1337 lua_lock(L);
1338 api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, "invalid value");
1339 u = luaS_newudata(L, size, nuvalue);
1340 setuvalue(L, s2v(L->top), u);
1341 api_incr_top(L);
1342 luaC_checkGC(L);
1343 lua_unlock(L);
1344 return getudatamem(u);
1345}
#define setuvalue(L, obj, x)
Udata * luaS_newudata(lua_State *L, size_t s, Table *e)
#define getudatamem(u)

References api_check, api_incr_top, getudatamem, lua_lock, lua_unlock, luaC_checkGC, luaS_newudata(), s2v, setuvalue, and lua_State::top.

Referenced by gmatch(), newbox(), newprefile(), and setrandfunc().

◆ lua_next()

LUA_API int lua_next ( lua_State * L,
int idx )

Definition at line 1245 of file lua-5.4.3/src/lapi.c.

1245 {
1246 Table *t;
1247 int more;
1248 lua_lock(L);
1249 api_checknelems(L, 1);
1250 t = gettable(L, idx);
1251 more = luaH_next(L, t, L->top - 1);
1252 if (more) {
1253 api_incr_top(L);
1254 }
1255 else /* no more elements */
1256 L->top -= 1; /* remove key */
1257 lua_unlock(L);
1258 return more;
1259}
int luaH_next(lua_State *L, Table *t, StkId key)

References api_checknelems, api_incr_top, gettable(), lua_lock, lua_unlock, luaH_next(), and lua_State::top.

◆ lua_pcallk()

LUA_API int lua_pcallk ( lua_State * L,
int nargs,
int nresults,
int errfunc,
lua_KContext ctx,
lua_KFunction k )

Definition at line 1036 of file lua-5.4.3/src/lapi.c.

1037 {
1038 struct CallS c;
1039 int status;
1040 ptrdiff_t func;
1041 lua_lock(L);
1042 api_check(L, k == NULL || !isLua(L->ci),
1043 "cannot use continuations inside hooks");
1044 api_checknelems(L, nargs+1);
1045 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
1046 checkresults(L, nargs, nresults);
1047 if (errfunc == 0)
1048 func = 0;
1049 else {
1050 StkId o = index2stack(L, errfunc);
1051 api_check(L, ttisfunction(s2v(o)), "error handler must be a function");
1052 func = savestack(L, o);
1053 }
1054 c.func = L->top - (nargs+1); /* function to be called */
1055 if (k == NULL || !yieldable(L)) { /* no continuation or no yieldable? */
1056 c.nresults = nresults; /* do a 'conventional' protected call */
1057 status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
1058 }
1059 else { /* prepare continuation (call is already protected by 'resume') */
1060 CallInfo *ci = L->ci;
1061 ci->u.c.k = k; /* save continuation */
1062 ci->u.c.ctx = ctx; /* save context */
1063 /* save information for error recovery */
1064 ci->u2.funcidx = cast_int(savestack(L, c.func));
1065 ci->u.c.old_errfunc = L->errfunc;
1066 L->errfunc = func;
1067 setoah(ci->callstatus, L->allowhook); /* save value of 'allowhook' */
1068 ci->callstatus |= CIST_YPCALL; /* function can do error recovery */
1069 luaD_call(L, c.func, nresults); /* do the call */
1070 ci->callstatus &= ~CIST_YPCALL;
1071 L->errfunc = ci->u.c.old_errfunc;
1072 status = LUA_OK; /* if it is here, there were no errors */
1073 }
1075 lua_unlock(L);
1076 return status;
1077}
int luaD_pcall(lua_State *L, Pfunc func, void *u, ptrdiff_t old_top, ptrdiff_t ef)
#define savestack(L, p)
#define ttisfunction(o)
#define CIST_YPCALL
#define setoah(st, v)
static void f_call(lua_State *L, void *ud)
union CallInfo::@95 u2
ptrdiff_t old_errfunc

References adjustresults, lua_State::allowhook, api_check, api_checknelems, CallInfo::c, CallInfo::callstatus, cast_int, checkresults, lua_State::ci, CIST_YPCALL, CallInfo::ctx, lua_State::errfunc, f_call(), CallS::func, CallInfo::funcidx, index2stack(), isLua, CallInfo::k, lua_lock, LUA_OK, lua_unlock, luaD_call(), luaD_pcall(), CallS::nresults, NULL, CallInfo::old_errfunc, s2v, savestack, setoah, lua_State::status, lua_State::top, ttisfunction, CallInfo::u, CallInfo::u2, and yieldable.

◆ lua_pushboolean()

LUA_API void lua_pushboolean ( lua_State * L,
int b )

Definition at line 599 of file lua-5.4.3/src/lapi.c.

599 {
600 lua_lock(L);
601 if (b)
602 setbtvalue(s2v(L->top));
603 else
604 setbfvalue(s2v(L->top));
605 api_incr_top(L);
606 lua_unlock(L);
607}
#define setbtvalue(obj)
#define setbfvalue(obj)

References api_incr_top, lua_lock, lua_unlock, s2v, setbfvalue, setbtvalue, and lua_State::top.

◆ lua_pushcclosure()

LUA_API void lua_pushcclosure ( lua_State * L,
lua_CFunction fn,
int n )

Definition at line 573 of file lua-5.4.3/src/lapi.c.

573 {
574 lua_lock(L);
575 if (n == 0) {
576 setfvalue(s2v(L->top), fn);
577 api_incr_top(L);
578 }
579 else {
580 CClosure *cl;
581 api_checknelems(L, n);
582 api_check(L, n <= MAXUPVAL, "upvalue index too large");
583 cl = luaF_newCclosure(L, n);
584 cl->f = fn;
585 L->top -= n;
586 while (n--) {
587 setobj2n(L, &cl->upvalue[n], s2v(L->top + n));
588 /* does not need barrier because closure is white */
589 lua_assert(iswhite(cl));
590 }
591 setclCvalue(L, s2v(L->top), cl);
592 api_incr_top(L);
593 luaC_checkGC(L);
594 }
595 lua_unlock(L);
596}
Closure * luaF_newCclosure(lua_State *L, int nelems, Table *e)
#define iswhite(x)
#define lua_assert(c)
#define setobj2n
#define setfvalue(obj, x)
#define setclCvalue(L, obj, x)
lua_CFunction f

References api_check, api_checknelems, api_incr_top, CClosure::f, iswhite, lua_assert, lua_lock, lua_unlock, luaC_checkGC, luaF_newCclosure(), MAXUPVAL, s2v, setclCvalue, setfvalue, setobj2n, lua_State::top, and CClosure::upvalue.

◆ lua_pushfstring()

LUA_API const char * lua_pushfstring ( lua_State * L,
const char * fmt,
... )

Definition at line 560 of file lua-5.4.3/src/lapi.c.

560 {
561 const char *ret;
562 va_list argp;
563 lua_lock(L);
564 va_start(argp, fmt);
565 ret = luaO_pushvfstring(L, fmt, argp);
566 va_end(argp);
567 luaC_checkGC(L);
568 lua_unlock(L);
569 return ret;
570}
const char * luaO_pushvfstring(lua_State *L, const char *fmt, va_list argp)

References lua_lock, lua_unlock, luaC_checkGC, and luaO_pushvfstring().

◆ lua_pushinteger()

LUA_API void lua_pushinteger ( lua_State * L,
lua_Integer n )

Definition at line 507 of file lua-5.4.3/src/lapi.c.

507 {
508 lua_lock(L);
509 setivalue(s2v(L->top), n);
510 api_incr_top(L);
511 lua_unlock(L);
512}

References api_incr_top, lua_lock, lua_unlock, s2v, setivalue, and lua_State::top.

◆ lua_pushlightuserdata()

LUA_API void lua_pushlightuserdata ( lua_State * L,
void * p )

Definition at line 610 of file lua-5.4.3/src/lapi.c.

610 {
611 lua_lock(L);
612 setpvalue(s2v(L->top), p);
613 api_incr_top(L);
614 lua_unlock(L);
615}
#define setpvalue(obj, x)

References api_incr_top, lua_lock, lua_unlock, s2v, setpvalue, and lua_State::top.

◆ lua_pushlstring()

LUA_API const char * lua_pushlstring ( lua_State * L,
const char * s,
size_t len )

Definition at line 520 of file lua-5.4.3/src/lapi.c.

520 {
521 TString *ts;
522 lua_lock(L);
523 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len);
524 setsvalue2s(L, L->top, ts);
525 api_incr_top(L);
526 luaC_checkGC(L);
527 lua_unlock(L);
528 return getstr(ts);
529}
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References api_incr_top, getstr, lua_lock, lua_unlock, luaC_checkGC, luaS_new, luaS_newlstr(), s, setsvalue2s, and lua_State::top.

◆ lua_pushnil()

LUA_API void lua_pushnil ( lua_State * L)

Definition at line 491 of file lua-5.4.3/src/lapi.c.

491 {
492 lua_lock(L);
493 setnilvalue(s2v(L->top));
494 api_incr_top(L);
495 lua_unlock(L);
496}

References api_incr_top, lua_lock, lua_unlock, s2v, setnilvalue, and lua_State::top.

◆ lua_pushnumber()

LUA_API void lua_pushnumber ( lua_State * L,
lua_Number n )

Definition at line 499 of file lua-5.4.3/src/lapi.c.

499 {
500 lua_lock(L);
501 setfltvalue(s2v(L->top), n);
502 api_incr_top(L);
503 lua_unlock(L);
504}
#define setfltvalue(obj, x)

References api_incr_top, lua_lock, lua_unlock, s2v, setfltvalue, and lua_State::top.

◆ lua_pushstring()

LUA_API const char * lua_pushstring ( lua_State * L,
const char * s )

Definition at line 532 of file lua-5.4.3/src/lapi.c.

532 {
533 lua_lock(L);
534 if (s == NULL)
535 setnilvalue(s2v(L->top));
536 else {
537 TString *ts;
538 ts = luaS_new(L, s);
539 setsvalue2s(L, L->top, ts);
540 s = getstr(ts); /* internal copy's address */
541 }
542 api_incr_top(L);
543 luaC_checkGC(L);
544 lua_unlock(L);
545 return s;
546}

References api_incr_top, getstr, lua_lock, lua_unlock, luaC_checkGC, luaS_new, NULL, s, s2v, setnilvalue, setsvalue2s, and lua_State::top.

◆ lua_pushthread()

LUA_API int lua_pushthread ( lua_State * L)

Definition at line 618 of file lua-5.4.3/src/lapi.c.

618 {
619 lua_lock(L);
620 setthvalue(L, s2v(L->top), L);
621 api_incr_top(L);
622 lua_unlock(L);
623 return (G(L)->mainthread == L);
624}
#define setthvalue(L, obj, x)

References api_incr_top, G, lua_lock, lua_unlock, s2v, setthvalue, and lua_State::top.

◆ lua_pushvalue()

LUA_API void lua_pushvalue ( lua_State * L,
int idx )

Definition at line 264 of file lua-5.4.3/src/lapi.c.

264 {
265 lua_lock(L);
266 setobj2s(L, L->top, index2value(L, idx));
267 api_incr_top(L);
268 lua_unlock(L);
269}

References api_incr_top, index2value(), lua_lock, lua_unlock, setobj2s, and lua_State::top.

◆ lua_pushvfstring()

LUA_API const char * lua_pushvfstring ( lua_State * L,
const char * fmt,
va_list argp )

Definition at line 549 of file lua-5.4.3/src/lapi.c.

550 {
551 const char *ret;
552 lua_lock(L);
553 ret = luaO_pushvfstring(L, fmt, argp);
554 luaC_checkGC(L);
555 lua_unlock(L);
556 return ret;
557}

References lua_lock, lua_unlock, luaC_checkGC, and luaO_pushvfstring().

◆ lua_rawequal()

LUA_API int lua_rawequal ( lua_State * L,
int index1,
int index2 )

Definition at line 322 of file lua-5.4.3/src/lapi.c.

322 {
323 const TValue *o1 = index2value(L, index1);
324 const TValue *o2 = index2value(L, index2);
325 return (isvalid(L, o1) && isvalid(L, o2)) ? luaV_rawequalobj(o1, o2) : 0;
326}
#define luaV_rawequalobj(o1, o2)

References index2value(), isvalid, and luaV_rawequalobj.

◆ lua_rawget()

LUA_API int lua_rawget ( lua_State * L,
int idx )

Definition at line 726 of file lua-5.4.3/src/lapi.c.

726 {
727 Table *t;
728 const TValue *val;
729 lua_lock(L);
730 api_checknelems(L, 1);
731 t = gettable(L, idx);
732 val = luaH_get(t, s2v(L->top - 1));
733 L->top--; /* remove key */
734 return finishrawget(L, val);
735}
static int finishrawget(lua_State *L, const TValue *val)

References api_checknelems, finishrawget(), gettable(), lua_lock, luaH_get(), s2v, and lua_State::top.

◆ lua_rawgeti()

LUA_API int lua_rawgeti ( lua_State * L,
int idx,
lua_Integer n )

Definition at line 738 of file lua-5.4.3/src/lapi.c.

738 {
739 Table *t;
740 lua_lock(L);
741 t = gettable(L, idx);
742 return finishrawget(L, luaH_getint(t, n));
743}
const TValue * luaH_getint(Table *t, int key)

References finishrawget(), gettable(), lua_lock, and luaH_getint().

◆ lua_rawgetp()

LUA_API int lua_rawgetp ( lua_State * L,
int idx,
const void * p )

Definition at line 746 of file lua-5.4.3/src/lapi.c.

746 {
747 Table *t;
748 TValue k;
749 lua_lock(L);
750 t = gettable(L, idx);
751 setpvalue(&k, cast_voidp(p));
752 return finishrawget(L, luaH_get(t, &k));
753}
#define cast_voidp(i)

References cast_voidp, finishrawget(), gettable(), lua_lock, luaH_get(), and setpvalue.

◆ lua_rawlen()

LUA_API lua_Unsigned lua_rawlen ( lua_State * L,
int idx )

Definition at line 420 of file lua-5.4.3/src/lapi.c.

420 {
421 const TValue *o = index2value(L, idx);
422 switch (ttypetag(o)) {
423 case LUA_VSHRSTR: return tsvalue(o)->shrlen;
424 case LUA_VLNGSTR: return tsvalue(o)->u.lnglen;
425 case LUA_VUSERDATA: return uvalue(o)->len;
426 case LUA_VTABLE: return luaH_getn(hvalue(o));
427 default: return 0;
428 }
429}
int luaH_getn(Table *t)
#define LUA_VLNGSTR
#define LUA_VSHRSTR
#define LUA_VUSERDATA
#define LUA_VTABLE

References hvalue, index2value(), LUA_VLNGSTR, LUA_VSHRSTR, LUA_VTABLE, LUA_VUSERDATA, luaH_getn(), tsvalue, ttypetag, and uvalue.

◆ lua_rawset()

LUA_API void lua_rawset ( lua_State * L,
int idx )

Definition at line 903 of file lua-5.4.3/src/lapi.c.

903 {
904 aux_rawset(L, idx, s2v(L->top - 2), 2);
905}
static void aux_rawset(lua_State *L, int idx, TValue *key, int n)

References aux_rawset(), s2v, and lua_State::top.

◆ lua_rawseti()

LUA_API void lua_rawseti ( lua_State * L,
int idx,
lua_Integer n )

Definition at line 915 of file lua-5.4.3/src/lapi.c.

915 {
916 Table *t;
917 lua_lock(L);
918 api_checknelems(L, 1);
919 t = gettable(L, idx);
920 luaH_setint(L, t, n, s2v(L->top - 1));
921 luaC_barrierback(L, obj2gco(t), s2v(L->top - 1));
922 L->top--;
923 lua_unlock(L);
924}
void luaH_setint(lua_State *L, Table *t, int key, TValue *value)

References api_checknelems, gettable(), lua_lock, lua_unlock, luaC_barrierback, luaH_setint(), obj2gco, s2v, and lua_State::top.

◆ lua_rawsetp()

LUA_API void lua_rawsetp ( lua_State * L,
int idx,
const void * p )

Definition at line 908 of file lua-5.4.3/src/lapi.c.

908 {
909 TValue k;
910 setpvalue(&k, cast_voidp(p));
911 aux_rawset(L, idx, &k, 1);
912}

References aux_rawset(), cast_voidp, and setpvalue.

◆ lua_rotate()

LUA_API void lua_rotate ( lua_State * L,
int idx,
int n )

Definition at line 235 of file lua-5.4.3/src/lapi.c.

235 {
236 StkId p, t, m;
237 lua_lock(L);
238 t = L->top - 1; /* end of stack segment being rotated */
239 p = index2stack(L, idx); /* start of segment */
240 api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'");
241 m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */
242 reverse(L, p, m); /* reverse the prefix with length 'n' */
243 reverse(L, m + 1, t); /* reverse the suffix */
244 reverse(L, p, t); /* reverse the entire segment */
245 lua_unlock(L);
246}
static void reverse(lua_State *L, StkId from, StkId to)

References api_check, index2stack(), lua_lock, lua_unlock, reverse(), and lua_State::top.

◆ lua_setallocf()

LUA_API void lua_setallocf ( lua_State * L,
lua_Alloc f,
void * ud )

Definition at line 1311 of file lua-5.4.3/src/lapi.c.

1311 {
1312 lua_lock(L);
1313 G(L)->ud = ud;
1314 G(L)->frealloc = f;
1315 lua_unlock(L);
1316}

References G, lua_lock, and lua_unlock.

◆ lua_setfield()

LUA_API void lua_setfield ( lua_State * L,
int idx,
const char * k )

Definition at line 865 of file lua-5.4.3/src/lapi.c.

865 {
866 lua_lock(L); /* unlock done in 'auxsetstr' */
867 auxsetstr(L, index2value(L, idx), k);
868}
static void auxsetstr(lua_State *L, const TValue *t, const char *k)

References auxsetstr(), index2value(), and lua_lock.

◆ lua_setglobal()

LUA_API void lua_setglobal ( lua_State * L,
const char * name )

Definition at line 841 of file lua-5.4.3/src/lapi.c.

841 {
842 const TValue *G;
843 lua_lock(L); /* unlock done in 'auxsetstr' */
844 G = getGtable(L);
845 auxsetstr(L, G, name);
846}

References auxsetstr(), G, getGtable, lua_lock, and name.

◆ lua_seti()

LUA_API void lua_seti ( lua_State * L,
int idx,
lua_Integer n )

Definition at line 871 of file lua-5.4.3/src/lapi.c.

871 {
872 TValue *t;
873 const TValue *slot;
874 lua_lock(L);
875 api_checknelems(L, 1);
876 t = index2value(L, idx);
877 if (luaV_fastgeti(L, t, n, slot)) {
878 luaV_finishfastset(L, t, slot, s2v(L->top - 1));
879 }
880 else {
881 TValue aux;
882 setivalue(&aux, n);
883 luaV_finishset(L, t, &aux, s2v(L->top - 1), slot);
884 }
885 L->top--; /* pop value */
886 lua_unlock(L);
887}

References api_checknelems, index2value(), lua_lock, lua_unlock, luaV_fastgeti, luaV_finishfastset, luaV_finishset(), s2v, setivalue, and lua_State::top.

◆ lua_setiuservalue()

LUA_API int lua_setiuservalue ( lua_State * L,
int idx,
int n )

Definition at line 967 of file lua-5.4.3/src/lapi.c.

967 {
968 TValue *o;
969 int res;
970 lua_lock(L);
971 api_checknelems(L, 1);
972 o = index2value(L, idx);
973 api_check(L, ttisfulluserdata(o), "full userdata expected");
974 if (!(cast_uint(n) - 1u < cast_uint(uvalue(o)->nuvalue)))
975 res = 0; /* 'n' not in [1, uvalue(o)->nuvalue] */
976 else {
977 setobj(L, &uvalue(o)->uv[n - 1].uv, s2v(L->top - 1));
978 luaC_barrierback(L, gcvalue(o), s2v(L->top - 1));
979 res = 1;
980 }
981 L->top--;
982 lua_unlock(L);
983 return res;
984}
#define gcvalue(o)

References api_check, api_checknelems, cast_uint, gcvalue, index2value(), lua_lock, lua_unlock, luaC_barrierback, s2v, setobj, lua_State::top, ttisfulluserdata, and uvalue.

Referenced by db_setuservalue().

◆ lua_setmetatable()

LUA_API int lua_setmetatable ( lua_State * L,
int objindex )

Definition at line 927 of file lua-5.4.3/src/lapi.c.

927 {
928 TValue *obj;
929 Table *mt;
930 lua_lock(L);
931 api_checknelems(L, 1);
932 obj = index2value(L, objindex);
933 if (ttisnil(s2v(L->top - 1)))
934 mt = NULL;
935 else {
936 api_check(L, ttistable(s2v(L->top - 1)), "table expected");
937 mt = hvalue(s2v(L->top - 1));
938 }
939 switch (ttype(obj)) {
940 case LUA_TTABLE: {
941 hvalue(obj)->metatable = mt;
942 if (mt) {
943 luaC_objbarrier(L, gcvalue(obj), mt);
944 luaC_checkfinalizer(L, gcvalue(obj), mt);
945 }
946 break;
947 }
948 case LUA_TUSERDATA: {
949 uvalue(obj)->metatable = mt;
950 if (mt) {
951 luaC_objbarrier(L, uvalue(obj), mt);
952 luaC_checkfinalizer(L, gcvalue(obj), mt);
953 }
954 break;
955 }
956 default: {
957 G(L)->mt[ttype(obj)] = mt;
958 break;
959 }
960 }
961 L->top--;
962 lua_unlock(L);
963 return 1;
964}
#define luaC_objbarrier(L, p, o)
#define ttisnil(o)
void luaC_checkfinalizer(lua_State *L, GCObject *o, Table *mt)

References api_check, api_checknelems, G, gcvalue, hvalue, index2value(), lua_lock, LUA_TTABLE, LUA_TUSERDATA, lua_unlock, luaC_checkfinalizer(), luaC_objbarrier, NULL, s2v, lua_State::top, ttisnil, ttistable, ttype, and uvalue.

◆ lua_settable()

LUA_API void lua_settable ( lua_State * L,
int idx )

Definition at line 849 of file lua-5.4.3/src/lapi.c.

849 {
850 TValue *t;
851 const TValue *slot;
852 lua_lock(L);
853 api_checknelems(L, 2);
854 t = index2value(L, idx);
855 if (luaV_fastget(L, t, s2v(L->top - 2), slot, luaH_get)) {
856 luaV_finishfastset(L, t, slot, s2v(L->top - 1));
857 }
858 else
859 luaV_finishset(L, t, s2v(L->top - 2), s2v(L->top - 1), slot);
860 L->top -= 2; /* pop index and value */
861 lua_unlock(L);
862}

References api_checknelems, index2value(), lua_lock, lua_unlock, luaH_get(), luaV_fastget, luaV_finishfastset, luaV_finishset(), s2v, and lua_State::top.

◆ lua_settop()

LUA_API void lua_settop ( lua_State * L,
int idx )

Definition at line 174 of file lua-5.4.3/src/lapi.c.

174 {
175 CallInfo *ci;
176 StkId func, newtop;
177 ptrdiff_t diff; /* difference for new top */
178 lua_lock(L);
179 ci = L->ci;
180 func = ci->func;
181 if (idx >= 0) {
182 api_check(L, idx <= ci->top - (func + 1), "new top too large");
183 diff = ((func + 1) + idx) - L->top;
184 for (; diff > 0; diff--)
185 setnilvalue(s2v(L->top++)); /* clear new slots */
186 }
187 else {
188 api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top");
189 diff = idx + 1; /* will "subtract" index (as it is negative) */
190 }
191 api_check(L, L->tbclist < L->top, "previous pop of an unclosed slot");
192 newtop = L->top + diff;
193 if (diff < 0 && L->tbclist >= newtop) {
195 luaF_close(L, newtop, CLOSEKTOP, 0);
196 }
197 L->top = newtop; /* correct top only after closing any upvalue */
198 lua_unlock(L);
199}

References api_check, lua_State::ci, CLOSEKTOP, CallInfo::func, hastocloseCfunc, lua_assert, lua_lock, lua_unlock, luaF_close(), CallInfo::nresults, s2v, setnilvalue, lua_State::tbclist, and lua_State::top.

◆ lua_setupvalue()

LUA_API const char * lua_setupvalue ( lua_State * L,
int funcindex,
int n )

Definition at line 1390 of file lua-5.4.3/src/lapi.c.

1390 {
1391 const char *name;
1392 TValue *val = NULL; /* to avoid warnings */
1393 GCObject *owner = NULL; /* to avoid warnings */
1394 TValue *fi;
1395 lua_lock(L);
1396 fi = index2value(L, funcindex);
1397 api_checknelems(L, 1);
1398 name = aux_upvalue(fi, n, &val, &owner);
1399 if (name) {
1400 L->top--;
1401 setobj(L, val, s2v(L->top));
1402 luaC_barrier(L, owner, val);
1403 }
1404 lua_unlock(L);
1405 return name;
1406}

References api_checknelems, aux_upvalue(), index2value(), lua_lock, lua_unlock, luaC_barrier, name, NULL, owner, s2v, setobj, and lua_State::top.

◆ lua_setwarnf()

void lua_setwarnf ( lua_State * L,
lua_WarnFunction f,
void * ud )

Definition at line 1319 of file lua-5.4.3/src/lapi.c.

1319 {
1320 lua_lock(L);
1321 G(L)->ud_warn = ud;
1322 G(L)->warnf = f;
1323 lua_unlock(L);
1324}

References G, lua_lock, and lua_unlock.

Referenced by checkcontrol(), luaL_newstate(), and warnfcont().

◆ lua_status()

LUA_API int lua_status ( lua_State * L)

Definition at line 1118 of file lua-5.4.3/src/lapi.c.

1118 {
1119 return L->status;
1120}

References lua_State::status.

◆ lua_stringtonumber()

LUA_API size_t lua_stringtonumber ( lua_State * L,
const char * s )

Definition at line 365 of file lua-5.4.3/src/lapi.c.

365 {
366 size_t sz = luaO_str2num(s, s2v(L->top));
367 if (sz != 0)
368 api_incr_top(L);
369 return sz;
370}
size_t luaO_str2num(const char *s, TValue *o)

References api_incr_top, luaO_str2num(), s, s2v, and lua_State::top.

◆ lua_toboolean()

LUA_API int lua_toboolean ( lua_State * L,
int idx )

Definition at line 393 of file lua-5.4.3/src/lapi.c.

393 {
394 const TValue *o = index2value(L, idx);
395 return !l_isfalse(o);
396}
#define l_isfalse(o)

References index2value(), and l_isfalse.

◆ lua_tocfunction()

LUA_API lua_CFunction lua_tocfunction ( lua_State * L,
int idx )

Definition at line 432 of file lua-5.4.3/src/lapi.c.

432 {
433 const TValue *o = index2value(L, idx);
434 if (ttislcf(o)) return fvalue(o);
435 else if (ttisCclosure(o))
436 return clCvalue(o)->f;
437 else return NULL; /* not a C function */
438}
#define fvalue(o)

References clCvalue, fvalue, index2value(), NULL, ttisCclosure, and ttislcf.

◆ lua_toclose()

LUA_API void lua_toclose ( lua_State * L,
int idx )

Definition at line 1262 of file lua-5.4.3/src/lapi.c.

1262 {
1263 int nresults;
1264 StkId o;
1265 lua_lock(L);
1266 o = index2stack(L, idx);
1267 nresults = L->ci->nresults;
1268 api_check(L, L->tbclist < o, "given index below or equal a marked one");
1269 luaF_newtbcupval(L, o); /* create new to-be-closed upvalue */
1270 if (!hastocloseCfunc(nresults)) /* function not marked yet? */
1271 L->ci->nresults = codeNresults(nresults); /* mark it */
1273 lua_unlock(L);
1274}
#define codeNresults(n)
void luaF_newtbcupval(lua_State *L, StkId level)

References api_check, lua_State::ci, codeNresults, hastocloseCfunc, index2stack(), lua_assert, lua_lock, lua_unlock, luaF_newtbcupval(), CallS::nresults, CallInfo::nresults, and lua_State::tbclist.

Referenced by prepbuffsize().

◆ lua_tointegerx()

LUA_API lua_Integer lua_tointegerx ( lua_State * L,
int idx,
int * pisnum )

Definition at line 383 of file lua-5.4.3/src/lapi.c.

383 {
384 lua_Integer res = 0;
385 const TValue *o = index2value(L, idx);
386 int isnum = tointeger(o, &res);
387 if (pisnum)
388 *pisnum = isnum;
389 return res;
390}
LUA_INTEGER lua_Integer
#define tointeger(o, i)

References index2value(), and tointeger.

◆ lua_tolstring()

LUA_API const char * lua_tolstring ( lua_State * L,
int idx,
size_t * len )

Definition at line 399 of file lua-5.4.3/src/lapi.c.

399 {
400 TValue *o;
401 lua_lock(L);
402 o = index2value(L, idx);
403 if (!ttisstring(o)) {
404 if (!cvt2str(o)) { /* not convertible? */
405 if (len != NULL) *len = 0;
406 lua_unlock(L);
407 return NULL;
408 }
409 luaO_tostring(L, o);
410 luaC_checkGC(L);
411 o = index2value(L, idx); /* previous call may reallocate the stack */
412 }
413 if (len != NULL)
414 *len = vslen(o);
415 lua_unlock(L);
416 return svalue(o);
417}
#define svalue(o)
void luaO_tostring(lua_State *L, StkId obj)
#define vslen(o)

References cvt2str, index2value(), lua_lock, lua_unlock, luaC_checkGC, luaO_tostring(), NULL, svalue, ttisstring, and vslen.

◆ lua_tonumberx()

LUA_API lua_Number lua_tonumberx ( lua_State * L,
int idx,
int * pisnum )

Definition at line 373 of file lua-5.4.3/src/lapi.c.

373 {
374 lua_Number n = 0;
375 const TValue *o = index2value(L, idx);
376 int isnum = tonumber(o, &n);
377 if (pisnum)
378 *pisnum = isnum;
379 return n;
380}

References index2value(), and tonumber.

◆ lua_topointer()

LUA_API const void * lua_topointer ( lua_State * L,
int idx )

Definition at line 469 of file lua-5.4.3/src/lapi.c.

469 {
470 const TValue *o = index2value(L, idx);
471 switch (ttypetag(o)) {
472 case LUA_VLCF: return cast_voidp(cast_sizet(fvalue(o)));
474 return touserdata(o);
475 default: {
476 if (iscollectable(o))
477 return gcvalue(o);
478 else
479 return NULL;
480 }
481 }
482}
#define iscollectable(o)
static void * touserdata(const TValue *o)
#define cast_sizet(i)
#define LUA_VLIGHTUSERDATA
#define LUA_VLCF

References cast_sizet, cast_voidp, fvalue, gcvalue, index2value(), iscollectable, LUA_VLCF, LUA_VLIGHTUSERDATA, LUA_VUSERDATA, NULL, touserdata(), and ttypetag.

◆ lua_tothread()

LUA_API lua_State * lua_tothread ( lua_State * L,
int idx )

Definition at line 456 of file lua-5.4.3/src/lapi.c.

456 {
457 const TValue *o = index2value(L, idx);
458 return (!ttisthread(o)) ? NULL : thvalue(o);
459}
#define thvalue(o)
#define ttisthread(o)

References index2value(), NULL, thvalue, and ttisthread.

◆ lua_touserdata()

LUA_API void * lua_touserdata ( lua_State * L,
int idx )

Definition at line 450 of file lua-5.4.3/src/lapi.c.

450 {
451 const TValue *o = index2value(L, idx);
452 return touserdata(o);
453}

References index2value(), and touserdata().

◆ lua_type()

LUA_API int lua_type ( lua_State * L,
int idx )

Definition at line 278 of file lua-5.4.3/src/lapi.c.

278 {
279 const TValue *o = index2value(L, idx);
280 return (isvalid(L, o) ? ttype(o) : LUA_TNONE);
281}

References index2value(), isvalid, LUA_TNONE, and ttype.

◆ lua_typename()

LUA_API const char * lua_typename ( lua_State * L,
int t )

Definition at line 284 of file lua-5.4.3/src/lapi.c.

284 {
285 UNUSED(L);
286 api_check(L, LUA_TNONE <= t && t < LUA_NUMTYPES, "invalid type");
287 return ttypename(t);
288}
#define UNUSED(x)
#define ttypename(x)
#define LUA_NUMTYPES

References api_check, LUA_NUMTYPES, LUA_TNONE, ttypename, and UNUSED.

◆ lua_upvalueid()

LUA_API void * lua_upvalueid ( lua_State * L,
int fidx,
int n )

Definition at line 1423 of file lua-5.4.3/src/lapi.c.

1423 {
1424 TValue *fi = index2value(L, fidx);
1425 switch (ttypetag(fi)) {
1426 case LUA_VLCL: { /* lua closure */
1427 return *getupvalref(L, fidx, n, NULL);
1428 }
1429 case LUA_VCCL: { /* C closure */
1430 CClosure *f = clCvalue(fi);
1431 if (1 <= n && n <= f->nupvalues)
1432 return &f->upvalue[n - 1];
1433 /* else */
1434 } /* FALLTHROUGH */
1435 case LUA_VLCF:
1436 return NULL; /* light C functions have no upvalues */
1437 default: {
1438 api_check(L, 0, "function expected");
1439 return NULL;
1440 }
1441 }
1442}
static UpVal ** getupvalref(lua_State *L, int fidx, int n, LClosure **pf)

References api_check, clCvalue, getupvalref(), index2value(), LUA_VCCL, LUA_VLCF, LUA_VLCL, NULL, ttypetag, and CClosure::upvalue.

◆ lua_upvaluejoin()

LUA_API void lua_upvaluejoin ( lua_State * L,
int fidx1,
int n1,
int fidx2,
int n2 )

Definition at line 1445 of file lua-5.4.3/src/lapi.c.

1446 {
1447 LClosure *f1;
1448 UpVal **up1 = getupvalref(L, fidx1, n1, &f1);
1449 UpVal **up2 = getupvalref(L, fidx2, n2, NULL);
1450 api_check(L, *up1 != NULL && *up2 != NULL, "invalid upvalue index");
1451 *up1 = *up2;
1452 luaC_objbarrier(L, f1, *up1);
1453}

References api_check, getupvalref(), luaC_objbarrier, and NULL.

◆ lua_version()

LUA_API lua_Number lua_version ( lua_State * L)

Definition at line 147 of file lua-5.4.3/src/lapi.c.

147 {
148 UNUSED(L);
149 return LUA_VERSION_NUM;
150}
#define LUA_VERSION_NUM

References LUA_VERSION_NUM, and UNUSED.

◆ lua_warning()

void lua_warning ( lua_State * L,
const char * msg,
int tocont )

Definition at line 1327 of file lua-5.4.3/src/lapi.c.

1327 {
1328 lua_lock(L);
1329 luaE_warning(L, msg, tocont);
1330 lua_unlock(L);
1331}
void luaE_warning(lua_State *L, const char *msg, int tocont)

References lua_lock, lua_unlock, and luaE_warning().

Referenced by luaB_warn(), and runargs().

◆ lua_xmove()

LUA_API void lua_xmove ( lua_State * from,
lua_State * to,
int n )

Definition at line 121 of file lua-5.4.3/src/lapi.c.

121 {
122 int i;
123 if (from == to) return;
124 lua_lock(to);
125 api_checknelems(from, n);
126 api_check(from, G(from) == G(to), "moving among independent states");
127 api_check(from, to->ci->top - to->top >= n, "stack overflow");
128 from->top -= n;
129 for (i = 0; i < n; i++) {
130 setobjs2s(to, to->top, from->top + i);
131 to->top++; /* stack already checked by previous 'api_check' */
132 }
133 lua_unlock(to);
134}

References api_check, api_checknelems, lua_State::ci, G, lua_lock, lua_unlock, setobjs2s, CallInfo::top, and lua_State::top.

◆ reverse()

static void reverse ( lua_State * L,
StkId from,
StkId to )
static

Definition at line 221 of file lua-5.4.3/src/lapi.c.

221 {
222 for (; from < to; from++, to--) {
223 TValue temp;
224 setobj(L, &temp, s2v(from));
225 setobjs2s(L, from, to);
226 setobj2s(L, to, &temp);
227 }
228}

References s2v, setobj, setobj2s, and setobjs2s.

Referenced by lua_rotate().

◆ touserdata()

static void * touserdata ( const TValue * o)
static

Definition at line 441 of file lua-5.4.3/src/lapi.c.

441 {
442 switch (ttype(o)) {
443 case LUA_TUSERDATA: return getudatamem(uvalue(o));
444 case LUA_TLIGHTUSERDATA: return pvalue(o);
445 default: return NULL;
446 }
447}
#define pvalue(o)
#define LUA_TLIGHTUSERDATA

References getudatamem, LUA_TLIGHTUSERDATA, LUA_TUSERDATA, NULL, pvalue, ttype, and uvalue.

Referenced by lua_topointer(), and lua_touserdata().

Variable Documentation

◆ lua_ident

const char lua_ident[]
Initial value:
=
"$LuaVersion: " LUA_COPYRIGHT " $"
"$LuaAuthors: " LUA_AUTHORS " $"
#define LUA_COPYRIGHT
#define LUA_AUTHORS

Definition at line 35 of file lua-5.4.3/src/lapi.c.