Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lapi.c File Reference
#include "lprefix.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 NONVALIDVALUE   cast(TValue *, luaO_nilobject)
 
#define isvalid(o)   ((o) != luaO_nilobject)
 
#define ispseudo(i)   ((i) <= LUA_REGISTRYINDEX)
 
#define isupvalue(i)   ((i) < LUA_REGISTRYINDEX)
 
#define isstackindex(i, o)   (isvalid(o) && !ispseudo(i))
 
#define api_checkvalidindex(l, o)   api_check(l, isvalid(o), "invalid index")
 
#define api_checkstackindex(l, i, o)    api_check(l, isstackindex(i, o), "index not in the stack")
 
#define checkresults(L, na, nr)
 

Functions

static TValueindex2addr (lua_State *L, int idx)
 
static void growstack (lua_State *L, void *ud)
 
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 const lua_Numberlua_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)
 
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 size_t lua_rawlen (lua_State *L, int idx)
 
LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx)
 
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)
 
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_getuservalue (lua_State *L, int idx)
 
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)
 
LUA_API void lua_rawset (lua_State *L, int idx)
 
LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n)
 
LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p)
 
LUA_API int lua_setmetatable (lua_State *L, int objindex)
 
LUA_API void lua_setuservalue (lua_State *L, int idx)
 
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, int data)
 
LUA_API int lua_error (lua_State *L)
 
LUA_API int lua_next (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)
 
LUA_API void * lua_newuserdata (lua_State *L, size_t size)
 
static const char * aux_upvalue (StkId fi, int n, TValue **val, CClosure **owner, UpVal **uv)
 
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)
 
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

◆ api_checkstackindex

#define api_checkstackindex ( l,
i,
o )    api_check(l, isstackindex(i, o), "index not in the stack")

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

56#define api_checkstackindex(l, i, o) \
57 api_check(l, isstackindex(i, o), "index not in the stack")

Referenced by lua_pcallk(), and lua_rotate().

◆ api_checkvalidindex

#define api_checkvalidindex ( l,
o )   api_check(l, isvalid(o), "invalid index")

Definition at line 54 of file lua-5.3.6/src/lapi.c.

Referenced by lua_copy().

◆ 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 904 of file lua-5.3.6/src/lapi.c.

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

Referenced by lua_callk(), and lua_pcallk().

◆ ispseudo

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

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

Referenced by index2addr(), and lua_absindex().

◆ isstackindex

#define isstackindex ( i,
o )   (isvalid(o) && !ispseudo(i))

Definition at line 52 of file lua-5.3.6/src/lapi.c.

◆ isupvalue

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

Definition at line 49 of file lua-5.3.6/src/lapi.c.

Referenced by lua_copy().

◆ isvalid

#define isvalid ( o)    ((o) != luaO_nilobject)

Definition at line 43 of file lua-5.3.6/src/lapi.c.

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

◆ lapi_c

#define lapi_c

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

◆ LUA_CORE

#define LUA_CORE

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

◆ NONVALIDVALUE

#define NONVALIDVALUE   cast(TValue *, luaO_nilobject)

Definition at line 40 of file lua-5.3.6/src/lapi.c.

Referenced by index2addr().

Function Documentation

◆ aux_upvalue()

static const char * aux_upvalue ( StkId fi,
int n,
TValue ** val,
CClosure ** owner,
UpVal ** uv )
static

Definition at line 1197 of file lua-5.3.6/src/lapi.c.

1198 {
1199 switch (ttype(fi)) {
1200 case LUA_TCCL: { /* C closure */
1201 CClosure *f = clCvalue(fi);
1202 if (!(1 <= n && n <= f->nupvalues)) return NULL;
1203 *val = &f->upvalue[n-1];
1204 if (owner) *owner = f;
1205 return "";
1206 }
1207 case LUA_TLCL: { /* Lua closure */
1208 LClosure *f = clLvalue(fi);
1209 TString *name;
1210 Proto *p = f->p;
1211 if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
1212 *val = f->upvals[n-1]->v;
1213 if (uv) *uv = f->upvals[n - 1];
1214 name = p->upvalues[n-1].name;
1215 return (name == NULL) ? "(*no name)" : getstr(name);
1216 }
1217 default: return NULL; /* not a closure */
1218 }
1219}
pthread_t owner
#define NULL
Definition gmacros.h:924
const char * name
Definition lsqlite3.c:2154
#define getstr(ts)
#define ttype(o)
#define LUA_TLCL
#define clCvalue(o)
#define LUA_TCCL
#define clLvalue(o)
struct Proto * p
TString ** upvalues

References clCvalue, clLvalue, getstr, LUA_TCCL, LUA_TLCL, name, NULL, owner, LClosure::p, ttype, 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 588 of file lua-5.3.6/src/lapi.c.

588 {
589 const TValue *slot;
590 TString *str = luaS_new(L, k);
591 if (luaV_fastget(L, t, str, slot, luaH_getstr)) {
592 setobj2s(L, L->top, slot);
593 api_incr_top(L);
594 }
595 else {
596 setsvalue2s(L, L->top, str);
597 api_incr_top(L);
598 luaV_finishget(L, t, L->top - 1, L->top - 1, slot);
599 }
600 lua_unlock(L);
601 return ttnov(L->top - 1);
602}
#define api_incr_top(L)
#define lua_unlock(L)
#define setobj2s
#define setsvalue2s
#define luaS_new(L, s)
const TValue * luaH_getstr(Table *t, TString *key)
#define ttnov(o)
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(), setobj2s, setsvalue2s, lua_State::top, and ttnov.

Referenced by lua_getfield(), and lua_getglobal().

◆ auxsetstr()

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

Definition at line 743 of file lua-5.3.6/src/lapi.c.

743 {
744 const TValue *slot;
745 TString *str = luaS_new(L, k);
746 api_checknelems(L, 1);
747 if (luaV_fastset(L, t, str, slot, luaH_getstr, L->top - 1))
748 L->top--; /* pop value */
749 else {
750 setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */
751 api_incr_top(L);
752 luaV_finishset(L, t, L->top - 1, L->top - 2, slot);
753 L->top -= 2; /* pop value and key */
754 }
755 lua_unlock(L); /* lock done by caller */
756}
#define api_checknelems(L, n)
void luaV_finishset(lua_State *L, const TValue *t, TValue *key, StkId val, const TValue *slot)
#define luaV_fastset(L, t, k, slot, f, v)

References api_checknelems, api_incr_top, lua_unlock, luaH_getstr(), luaS_new, luaV_fastset, luaV_finishset(), 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 941 of file lua-5.3.6/src/lapi.c.

941 {
942 struct CallS *c = cast(struct CallS *, ud);
943 luaD_callnoyield(L, c->func, c->nresults);
944}
#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().

◆ getupvalref()

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

Definition at line 1257 of file lua-5.3.6/src/lapi.c.

1257 {
1258 LClosure *f;
1259 StkId fi = index2addr(L, fidx);
1260 api_check(L, ttisLclosure(fi), "Lua function expected");
1261 f = clLvalue(fi);
1262 api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index");
1263 return &f->upvals[n - 1]; /* get its upvalue pointer */
1264}
#define ttisLclosure(o)
static TValue * index2addr(lua_State *L, int idx)

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

Referenced by lua_upvalueid(), and lua_upvaluejoin().

◆ growstack()

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

Definition at line 91 of file lua-5.3.6/src/lapi.c.

91 {
92 int size = *(int *)ud;
93 luaD_growstack(L, size);
94}
void luaD_growstack(lua_State *L, int n)

References luaD_growstack().

Referenced by lua_checkstack().

◆ index2addr()

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

Definition at line 60 of file lua-5.3.6/src/lapi.c.

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

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

Referenced by getupvalref(), lua_compare(), lua_copy(), lua_getfield(), lua_geti(), lua_getmetatable(), lua_gettable(), lua_getupvalue(), lua_getuservalue(), lua_iscfunction(), lua_isinteger(), lua_isnumber(), lua_isstring(), lua_isuserdata(), lua_len(), lua_next(), lua_pcallk(), lua_pushvalue(), lua_rawequal(), lua_rawget(), lua_rawgeti(), lua_rawgetp(), lua_rawlen(), lua_rawset(), lua_rawseti(), lua_rawsetp(), lua_rotate(), lua_setfield(), lua_seti(), lua_setmetatable(), lua_settable(), lua_setupvalue(), lua_setuservalue(), 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 160 of file lua-5.3.6/src/lapi.c.

160 {
161 return (idx > 0 || ispseudo(idx))
162 ? idx
163 : cast_int(L->top - L->ci->func) + idx;
164}
#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 302 of file lua-5.3.6/src/lapi.c.

302 {
303 lua_lock(L);
304 if (op != LUA_OPUNM && op != LUA_OPBNOT)
305 api_checknelems(L, 2); /* all other operations expect two operands */
306 else { /* for unary operations, add fake 2nd operand */
307 api_checknelems(L, 1);
308 setobjs2s(L, L->top, L->top - 1);
309 api_incr_top(L);
310 }
311 /* first operand at top - 2, second at top - 1; result go to top - 2 */
312 luaO_arith(L, op, L->top - 2, L->top - 1, L->top - 2);
313 L->top--; /* remove second operand */
314 lua_unlock(L);
315}
#define lua_lock(L)
#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(), setobjs2s, and lua_State::top.

◆ lua_atpanic()

LUA_API lua_CFunction lua_atpanic ( lua_State * L,
lua_CFunction panicf )

Definition at line 134 of file lua-5.3.6/src/lapi.c.

134 {
135 lua_CFunction old;
136 lua_lock(L);
137 old = G(L)->panic;
138 G(L)->panic = panicf;
139 lua_unlock(L);
140 return old;
141}
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 909 of file lua-5.3.6/src/lapi.c.

910 {
911 StkId func;
912 lua_lock(L);
913 api_check(L, k == NULL || !isLua(L->ci),
914 "cannot use continuations inside hooks");
915 api_checknelems(L, nargs+1);
916 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
917 checkresults(L, nargs, nresults);
918 func = L->top - (nargs+1);
919 if (k != NULL && L->nny == 0) { /* need to prepare continuation? */
920 L->ci->u.c.k = k; /* save continuation */
921 L->ci->u.c.ctx = ctx; /* save context */
922 luaD_call(L, func, nresults); /* do the call */
923 }
924 else /* no continuation or no yieldable */
925 luaD_callnoyield(L, func, nresults); /* just do the call */
926 adjustresults(L, nresults);
927 lua_unlock(L);
928}
#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)
lua_CFunction k
union CallInfo::@64 u
struct CallInfo::@64::@66 c
unsigned short nny

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(), lua_State::nny, NULL, lua_State::status, lua_State::top, and CallInfo::u.

◆ lua_checkstack()

LUA_API int lua_checkstack ( lua_State * L,
int n )

Definition at line 97 of file lua-5.3.6/src/lapi.c.

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

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

◆ lua_compare()

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

Definition at line 318 of file lua-5.3.6/src/lapi.c.

318 {
319 StkId o1, o2;
320 int i = 0;
321 lua_lock(L); /* may call tag method */
322 o1 = index2addr(L, index1);
323 o2 = index2addr(L, index2);
324 if (isvalid(o1) && isvalid(o2)) {
325 switch (op) {
326 case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break;
327 case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;
328 case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;
329 default: api_check(L, 0, "invalid option");
330 }
331 }
332 lua_unlock(L);
333 return i;
334}
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)
#define isvalid(o)
int luaV_equalobj(lua_State *L, const TValue *t1, const TValue *t2)

References api_check, index2addr(), 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 1140 of file lua-5.3.6/src/lapi.c.

1140 {
1141 lua_lock(L);
1142 api_checknelems(L, n);
1143 if (n >= 2) {
1144 luaV_concat(L, n);
1145 }
1146 else if (n == 0) { /* push empty string */
1147 setsvalue2s(L, L->top, luaS_newlstr(L, "", 0));
1148 api_incr_top(L);
1149 }
1150 /* else n == 1; nothing to do */
1151 luaC_checkGC(L);
1152 lua_unlock(L);
1153}
#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 222 of file lua-5.3.6/src/lapi.c.

222 {
223 TValue *fr, *to;
224 lua_lock(L);
225 fr = index2addr(L, fromidx);
226 to = index2addr(L, toidx);
227 api_checkvalidindex(L, to);
228 setobj(L, to, fr);
229 if (isupvalue(toidx)) /* function upvalue? */
230 luaC_barrier(L, clCvalue(L->ci->func), fr);
231 /* LUA_REGISTRYINDEX does not need gc barrier
232 (collector revisits it before finishing collection) */
233 lua_unlock(L);
234}
#define luaC_barrier(L, p, v)
#define setobj(L, obj1, obj2)
#define api_checkvalidindex(l, o)
#define isupvalue(i)

References api_checkvalidindex, lua_State::ci, clCvalue, CallInfo::func, index2addr(), isupvalue, lua_lock, lua_unlock, luaC_barrier, and setobj.

◆ lua_createtable()

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

Definition at line 684 of file lua-5.3.6/src/lapi.c.

684 {
685 Table *t;
686 lua_lock(L);
687 t = luaH_new(L);
688 sethvalue(L, L->top, t);
689 api_incr_top(L);
690 if (narray > 0 || nrec > 0)
691 luaH_resize(L, t, narray, nrec);
692 luaC_checkGC(L);
693 lua_unlock(L);
694}
#define sethvalue(L, obj, x)
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(), sethvalue, and lua_State::top.

◆ lua_dump()

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

Definition at line 1016 of file lua-5.3.6/src/lapi.c.

1016 {
1017 int status;
1018 TValue *o;
1019 lua_lock(L);
1020 api_checknelems(L, 1);
1021 o = L->top - 1;
1022 if (isLfunction(o))
1023 status = luaU_dump(L, getproto(o), writer, data, strip);
1024 else
1025 status = 1;
1026 lua_unlock(L);
1027 return status;
1028}
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(), lua_State::top, and writer().

◆ lua_error()

LUA_API int lua_error ( lua_State * L)

Definition at line 1114 of file lua-5.3.6/src/lapi.c.

1114 {
1115 lua_lock(L);
1116 api_checknelems(L, 1);
1117 luaG_errormsg(L);
1118 /* code unreachable; will unlock when control actually leaves the kernel */
1119 return 0; /* to avoid warnings */
1120}
void luaG_errormsg(lua_State *L)

References api_checknelems, lua_lock, and luaG_errormsg().

◆ lua_gc()

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

Definition at line 1040 of file lua-5.3.6/src/lapi.c.

1040 {
1041 int res = 0;
1042 global_State *g;
1043 lua_lock(L);
1044 g = G(L);
1045 switch (what) {
1046 case LUA_GCSTOP: {
1047 g->gcrunning = 0;
1048 break;
1049 }
1050 case LUA_GCRESTART: {
1051 luaE_setdebt(g, 0);
1052 g->gcrunning = 1;
1053 break;
1054 }
1055 case LUA_GCCOLLECT: {
1056 luaC_fullgc(L, 0);
1057 break;
1058 }
1059 case LUA_GCCOUNT: {
1060 /* GC values are expressed in Kbytes: #bytes/2^10 */
1061 res = cast_int(gettotalbytes(g) >> 10);
1062 break;
1063 }
1064 case LUA_GCCOUNTB: {
1065 res = cast_int(gettotalbytes(g) & 0x3ff);
1066 break;
1067 }
1068 case LUA_GCSTEP: {
1069 l_mem debt = 1; /* =1 to signal that it did an actual step */
1070 lu_byte oldrunning = g->gcrunning;
1071 g->gcrunning = 1; /* allow GC to run */
1072 if (data == 0) {
1073 luaE_setdebt(g, -GCSTEPSIZE); /* to do a "small" step */
1074 luaC_step(L);
1075 }
1076 else { /* add 'data' to total debt */
1077 debt = cast(l_mem, data) * 1024 + g->GCdebt;
1078 luaE_setdebt(g, debt);
1079 luaC_checkGC(L);
1080 }
1081 g->gcrunning = oldrunning; /* restore previous state */
1082 if (debt > 0 && g->gcstate == GCSpause) /* end of cycle? */
1083 res = 1; /* signal it */
1084 break;
1085 }
1086 case LUA_GCSETPAUSE: {
1087 res = g->gcpause;
1088 g->gcpause = data;
1089 break;
1090 }
1091 case LUA_GCSETSTEPMUL: {
1092 res = g->gcstepmul;
1093 if (data < 40) data = 40; /* avoid ridiculous low values (and 0) */
1094 g->gcstepmul = data;
1095 break;
1096 }
1097 case LUA_GCISRUNNING: {
1098 res = g->gcrunning;
1099 break;
1100 }
1101 default: res = -1; /* invalid option */
1102 }
1103 lua_unlock(L);
1104 return res;
1105}
void luaC_fullgc(lua_State *L)
void luaC_step(lua_State *L)
#define GCSTEPSIZE
#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 luaE_setdebt(global_State *g, l_mem debt)
#define gettotalbytes(g)
#define LUA_GCISRUNNING

References cast, cast_int, G, global_State::GCdebt, global_State::gcpause, global_State::gcrunning, GCSpause, global_State::gcstate, global_State::gcstepmul, GCSTEPSIZE, gettotalbytes, LUA_GCCOLLECT, LUA_GCCOUNT, LUA_GCCOUNTB, LUA_GCISRUNNING, LUA_GCRESTART, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL, LUA_GCSTEP, LUA_GCSTOP, lua_lock, lua_unlock, luaC_checkGC, luaC_fullgc(), luaC_step(), and luaE_setdebt().

◆ lua_getallocf()

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

Definition at line 1166 of file lua-5.3.6/src/lapi.c.

1166 {
1167 lua_Alloc f;
1168 lua_lock(L);
1169 if (ud) *ud = G(L)->ud;
1170 f = G(L)->frealloc;
1171 lua_unlock(L);
1172 return f;
1173}
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 622 of file lua-5.3.6/src/lapi.c.

622 {
623 lua_lock(L);
624 return auxgetstr(L, index2addr(L, idx), k);
625}
static int auxgetstr(lua_State *L, const TValue *t, const char *k)

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

◆ lua_getglobal()

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

Definition at line 605 of file lua-5.3.6/src/lapi.c.

605 {
606 Table *reg = hvalue(&G(L)->l_registry);
607 lua_lock(L);
608 return auxgetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);
609}
#define hvalue(o)
const TValue * luaH_getint(Table *t, int key)
#define LUA_RIDX_GLOBALS

References auxgetstr(), G, hvalue, lua_lock, LUA_RIDX_GLOBALS, luaH_getint(), and name.

◆ lua_geti()

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

Definition at line 628 of file lua-5.3.6/src/lapi.c.

628 {
629 StkId t;
630 const TValue *slot;
631 lua_lock(L);
632 t = index2addr(L, idx);
633 if (luaV_fastget(L, t, n, slot, luaH_getint)) {
634 setobj2s(L, L->top, slot);
635 api_incr_top(L);
636 }
637 else {
638 setivalue(L->top, n);
639 api_incr_top(L);
640 luaV_finishget(L, t, L->top - 1, L->top - 1, slot);
641 }
642 lua_unlock(L);
643 return ttnov(L->top - 1);
644}
#define setivalue(obj, x)

References api_incr_top, index2addr(), lua_lock, lua_unlock, luaH_getint(), luaV_fastget, luaV_finishget(), setivalue, setobj2s, lua_State::top, and ttnov.

Referenced by addfield(), addfield(), auxsort(), auxsort(), ipairsaux(), ipairsaux(), partition(), partition(), tinsert(), tinsert(), tmove(), tmove(), tremove(), tremove(), tunpack(), and unpack().

◆ lua_getmetatable()

LUA_API int lua_getmetatable ( lua_State * L,
int objindex )

Definition at line 697 of file lua-5.3.6/src/lapi.c.

697 {
698 const TValue *obj;
699 Table *mt;
700 int res = 0;
701 lua_lock(L);
702 obj = index2addr(L, objindex);
703 switch (ttnov(obj)) {
704 case LUA_TTABLE:
705 mt = hvalue(obj)->metatable;
706 break;
707 case LUA_TUSERDATA:
708 mt = uvalue(obj)->metatable;
709 break;
710 default:
711 mt = G(L)->mt[ttnov(obj)];
712 break;
713 }
714 if (mt != NULL) {
715 sethvalue(L, L->top, mt);
716 api_incr_top(L);
717 res = 1;
718 }
719 lua_unlock(L);
720 return res;
721}
#define uvalue(o)
#define LUA_TTABLE
#define LUA_TUSERDATA
struct Table * metatable

References api_incr_top, G, hvalue, index2addr(), lua_lock, LUA_TTABLE, LUA_TUSERDATA, lua_unlock, Table::metatable, NULL, sethvalue, lua_State::top, ttnov, and uvalue.

◆ lua_gettable()

LUA_API int lua_gettable ( lua_State * L,
int idx )

Definition at line 612 of file lua-5.3.6/src/lapi.c.

612 {
613 StkId t;
614 lua_lock(L);
615 t = index2addr(L, idx);
616 luaV_gettable(L, t, L->top - 1, L->top - 1);
617 lua_unlock(L);
618 return ttnov(L->top - 1);
619}
#define luaV_gettable(L, t, k, v)

References index2addr(), lua_lock, lua_unlock, luaV_gettable, lua_State::top, and ttnov.

◆ lua_gettop()

LUA_API int lua_gettop ( lua_State * L)

Definition at line 167 of file lua-5.3.6/src/lapi.c.

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

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 1222 of file lua-5.3.6/src/lapi.c.

1222 {
1223 const char *name;
1224 TValue *val = NULL; /* to avoid warnings */
1225 lua_lock(L);
1226 name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL, NULL);
1227 if (name) {
1228 setobj2s(L, L->top, val);
1229 api_incr_top(L);
1230 }
1231 lua_unlock(L);
1232 return name;
1233}
static const char * aux_upvalue(StkId fi, int n, TValue **val, CClosure **owner, UpVal **uv)

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

◆ lua_getuservalue()

LUA_API int lua_getuservalue ( lua_State * L,
int idx )

Definition at line 724 of file lua-5.3.6/src/lapi.c.

724 {
725 StkId o;
726 lua_lock(L);
727 o = index2addr(L, idx);
728 api_check(L, ttisfulluserdata(o), "full userdata expected");
729 getuservalue(L, uvalue(o), L->top);
730 api_incr_top(L);
731 lua_unlock(L);
732 return ttnov(L->top - 1);
733}
#define getuservalue(L, u, o)
#define ttisfulluserdata(o)

References api_check, api_incr_top, getuservalue, index2addr(), lua_lock, lua_unlock, lua_State::top, ttisfulluserdata, ttnov, and uvalue.

◆ lua_iscfunction()

LUA_API int lua_iscfunction ( lua_State * L,
int idx )

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

264 {
265 StkId o = index2addr(L, idx);
266 return (ttislcf(o) || (ttisCclosure(o)));
267}
#define ttisCclosure(o)

References index2addr(), ttisCclosure, and ttislcf.

◆ lua_isinteger()

◆ lua_isnumber()

LUA_API int lua_isnumber ( lua_State * L,
int idx )

Definition at line 276 of file lua-5.3.6/src/lapi.c.

276 {
277 lua_Number n;
278 const TValue *o = index2addr(L, idx);
279 return tonumber(o, &n);
280}
LUA_NUMBER lua_Number
#define tonumber(o, n)

References index2addr(), and tonumber.

◆ lua_isstring()

LUA_API int lua_isstring ( lua_State * L,
int idx )

Definition at line 283 of file lua-5.3.6/src/lapi.c.

283 {
284 const TValue *o = index2addr(L, idx);
285 return (ttisstring(o) || cvt2str(o));
286}
#define ttisstring(o)
#define cvt2str(o)

References cvt2str, index2addr(), and ttisstring.

◆ lua_isuserdata()

LUA_API int lua_isuserdata ( lua_State * L,
int idx )

Definition at line 289 of file lua-5.3.6/src/lapi.c.

289 {
290 const TValue *o = index2addr(L, idx);
291 return (ttisfulluserdata(o) || ttislightuserdata(o));
292}
#define ttislightuserdata(o)

References index2addr(), ttisfulluserdata, and ttislightuserdata.

◆ lua_len()

LUA_API void lua_len ( lua_State * L,
int idx )

Definition at line 1156 of file lua-5.3.6/src/lapi.c.

1156 {
1157 StkId t;
1158 lua_lock(L);
1159 t = index2addr(L, idx);
1160 luaV_objlen(L, L->top, t);
1161 api_incr_top(L);
1162 lua_unlock(L);
1163}
void luaV_objlen(lua_State *L, StkId ra, const TValue *rb)

References api_incr_top, index2addr(), 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 992 of file lua-5.3.6/src/lapi.c.

993 {
994 ZIO z;
995 int status;
996 lua_lock(L);
997 if (!chunkname) chunkname = "?";
998 luaZ_init(L, &z, reader, data);
999 status = luaD_protectedparser(L, &z, chunkname, mode);
1000 if (status == LUA_OK) { /* no errors? */
1001 LClosure *f = clLvalue(L->top - 1); /* get newly created function */
1002 if (f->nupvalues >= 1) { /* does it have an upvalue? */
1003 /* get global table from registry */
1004 Table *reg = hvalue(&G(L)->l_registry);
1005 const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
1006 /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
1007 setobj(L, f->upvals[0]->v, gt);
1008 luaC_upvalbarrier(L, f->upvals[0]);
1009 }
1010 }
1011 lua_unlock(L);
1012 return status;
1013}
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)
#define luaC_upvalbarrier(L, uv)

References clLvalue, G, gt, hvalue, lua_lock, LUA_OK, LUA_RIDX_GLOBALS, lua_unlock, luaC_upvalbarrier, luaD_protectedparser(), luaH_getint(), luaZ_init(), reader(), setobj, lua_State::top, LClosure::upvals, and UpVal::v.

◆ lua_newuserdata()

LUA_API void * lua_newuserdata ( lua_State * L,
size_t size )

Definition at line 1184 of file lua-5.3.6/src/lapi.c.

1184 {
1185 Udata *u;
1186 lua_lock(L);
1187 u = luaS_newudata(L, size);
1188 setuvalue(L, L->top, u);
1189 api_incr_top(L);
1190 luaC_checkGC(L);
1191 lua_unlock(L);
1192 return getudatamem(u);
1193}
#define setuvalue(L, obj, x)
Udata * luaS_newudata(lua_State *L, size_t s, Table *e)
#define getudatamem(u)

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

◆ lua_next()

LUA_API int lua_next ( lua_State * L,
int idx )

Definition at line 1123 of file lua-5.3.6/src/lapi.c.

1123 {
1124 StkId t;
1125 int more;
1126 lua_lock(L);
1127 t = index2addr(L, idx);
1128 api_check(L, ttistable(t), "table expected");
1129 more = luaH_next(L, hvalue(t), L->top - 1);
1130 if (more) {
1131 api_incr_top(L);
1132 }
1133 else /* no more elements */
1134 L->top -= 1; /* remove key */
1135 lua_unlock(L);
1136 return more;
1137}
#define ttistable(o)
int luaH_next(lua_State *L, Table *t, StkId key)

References api_check, api_incr_top, hvalue, index2addr(), lua_lock, lua_unlock, luaH_next(), lua_State::top, and ttistable.

◆ 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 948 of file lua-5.3.6/src/lapi.c.

949 {
950 struct CallS c;
951 int status;
952 ptrdiff_t func;
953 lua_lock(L);
954 api_check(L, k == NULL || !isLua(L->ci),
955 "cannot use continuations inside hooks");
956 api_checknelems(L, nargs+1);
957 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
958 checkresults(L, nargs, nresults);
959 if (errfunc == 0)
960 func = 0;
961 else {
962 StkId o = index2addr(L, errfunc);
963 api_checkstackindex(L, errfunc, o);
964 func = savestack(L, o);
965 }
966 c.func = L->top - (nargs+1); /* function to be called */
967 if (k == NULL || L->nny > 0) { /* no continuation or no yieldable? */
968 c.nresults = nresults; /* do a 'conventional' protected call */
969 status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
970 }
971 else { /* prepare continuation (call is already protected by 'resume') */
972 CallInfo *ci = L->ci;
973 ci->u.c.k = k; /* save continuation */
974 ci->u.c.ctx = ctx; /* save context */
975 /* save information for error recovery */
976 ci->extra = savestack(L, c.func);
977 ci->u.c.old_errfunc = L->errfunc;
978 L->errfunc = func;
979 setoah(ci->callstatus, L->allowhook); /* save value of 'allowhook' */
980 ci->callstatus |= CIST_YPCALL; /* function can do error recovery */
981 luaD_call(L, c.func, nresults); /* do the call */
982 ci->callstatus &= ~CIST_YPCALL;
983 L->errfunc = ci->u.c.old_errfunc;
984 status = LUA_OK; /* if it is here, there were no errors */
985 }
987 lua_unlock(L);
988 return status;
989}
int luaD_pcall(lua_State *L, Pfunc func, void *u, ptrdiff_t old_top, ptrdiff_t ef)
#define savestack(L, p)
#define CIST_YPCALL
#define api_checkstackindex(l, i, o)
static void f_call(lua_State *L, void *ud)
#define setoah(st, v)
ptrdiff_t old_errfunc

References adjustresults, lua_State::allowhook, api_check, api_checknelems, api_checkstackindex, CallInfo::c, CallInfo::callstatus, checkresults, lua_State::ci, CIST_YPCALL, CallInfo::ctx, lua_State::errfunc, CallInfo::extra, f_call(), CallS::func, index2addr(), isLua, CallInfo::k, lua_lock, LUA_OK, lua_unlock, luaD_call(), luaD_pcall(), lua_State::nny, CallS::nresults, NULL, CallInfo::old_errfunc, savestack, setoah, lua_State::status, lua_State::top, and CallInfo::u.

◆ lua_pushboolean()

LUA_API void lua_pushboolean ( lua_State * L,
int b )

Definition at line 557 of file lua-5.3.6/src/lapi.c.

557 {
558 lua_lock(L);
559 setbvalue(L->top, (b != 0)); /* ensure that true is 1 */
560 api_incr_top(L);
561 lua_unlock(L);
562}
#define setbvalue(obj, x)

References api_incr_top, lua_lock, lua_unlock, setbvalue, and lua_State::top.

◆ lua_pushcclosure()

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

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

532 {
533 lua_lock(L);
534 if (n == 0) {
535 setfvalue(L->top, fn);
536 api_incr_top(L);
537 }
538 else {
539 CClosure *cl;
540 api_checknelems(L, n);
541 api_check(L, n <= MAXUPVAL, "upvalue index too large");
542 cl = luaF_newCclosure(L, n);
543 cl->f = fn;
544 L->top -= n;
545 while (n--) {
546 setobj2n(L, &cl->upvalue[n], L->top + n);
547 /* does not need barrier because closure is white */
548 }
549 setclCvalue(L, L->top, cl);
550 api_incr_top(L);
551 luaC_checkGC(L);
552 }
553 lua_unlock(L);
554}
Closure * luaF_newCclosure(lua_State *L, int nelems, Table *e)
#define setobj2n
#define setfvalue(obj, x)
#define setclCvalue(L, obj, x)
lua_CFunction f

References api_check, api_checknelems, api_incr_top, CClosure::f, lua_lock, lua_unlock, luaC_checkGC, luaF_newCclosure(), MAXUPVAL, 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 519 of file lua-5.3.6/src/lapi.c.

519 {
520 const char *ret;
521 va_list argp;
522 lua_lock(L);
523 va_start(argp, fmt);
524 ret = luaO_pushvfstring(L, fmt, argp);
525 va_end(argp);
526 luaC_checkGC(L);
527 lua_unlock(L);
528 return ret;
529}
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 466 of file lua-5.3.6/src/lapi.c.

466 {
467 lua_lock(L);
468 setivalue(L->top, n);
469 api_incr_top(L);
470 lua_unlock(L);
471}

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

◆ lua_pushlightuserdata()

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

Definition at line 565 of file lua-5.3.6/src/lapi.c.

565 {
566 lua_lock(L);
567 setpvalue(L->top, p);
568 api_incr_top(L);
569 lua_unlock(L);
570}
#define setpvalue(obj, x)

References api_incr_top, lua_lock, lua_unlock, 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 479 of file lua-5.3.6/src/lapi.c.

479 {
480 TString *ts;
481 lua_lock(L);
482 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len);
483 setsvalue2s(L, L->top, ts);
484 api_incr_top(L);
485 luaC_checkGC(L);
486 lua_unlock(L);
487 return getstr(ts);
488}
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 450 of file lua-5.3.6/src/lapi.c.

450 {
451 lua_lock(L);
452 setnilvalue(L->top);
453 api_incr_top(L);
454 lua_unlock(L);
455}
#define setnilvalue(obj)

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

◆ lua_pushnumber()

LUA_API void lua_pushnumber ( lua_State * L,
lua_Number n )

Definition at line 458 of file lua-5.3.6/src/lapi.c.

458 {
459 lua_lock(L);
460 setfltvalue(L->top, n);
461 api_incr_top(L);
462 lua_unlock(L);
463}
#define setfltvalue(obj, x)

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

◆ lua_pushstring()

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

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

491 {
492 lua_lock(L);
493 if (s == NULL)
494 setnilvalue(L->top);
495 else {
496 TString *ts;
497 ts = luaS_new(L, s);
498 setsvalue2s(L, L->top, ts);
499 s = getstr(ts); /* internal copy's address */
500 }
501 api_incr_top(L);
502 luaC_checkGC(L);
503 lua_unlock(L);
504 return s;
505}

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

◆ lua_pushthread()

LUA_API int lua_pushthread ( lua_State * L)

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

573 {
574 lua_lock(L);
575 setthvalue(L, L->top, L);
576 api_incr_top(L);
577 lua_unlock(L);
578 return (G(L)->mainthread == L);
579}
#define setthvalue(L, obj, x)

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

◆ lua_pushvalue()

LUA_API void lua_pushvalue ( lua_State * L,
int idx )

Definition at line 237 of file lua-5.3.6/src/lapi.c.

237 {
238 lua_lock(L);
239 setobj2s(L, L->top, index2addr(L, idx));
240 api_incr_top(L);
241 lua_unlock(L);
242}

References api_incr_top, index2addr(), 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 508 of file lua-5.3.6/src/lapi.c.

509 {
510 const char *ret;
511 lua_lock(L);
512 ret = luaO_pushvfstring(L, fmt, argp);
513 luaC_checkGC(L);
514 lua_unlock(L);
515 return ret;
516}

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 295 of file lua-5.3.6/src/lapi.c.

295 {
296 StkId o1 = index2addr(L, index1);
297 StkId o2 = index2addr(L, index2);
298 return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0;
299}
#define luaV_rawequalobj(o1, o2)

References index2addr(), isvalid, and luaV_rawequalobj.

◆ lua_rawget()

LUA_API int lua_rawget ( lua_State * L,
int idx )

Definition at line 647 of file lua-5.3.6/src/lapi.c.

647 {
648 StkId t;
649 lua_lock(L);
650 t = index2addr(L, idx);
651 api_check(L, ttistable(t), "table expected");
652 setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
653 lua_unlock(L);
654 return ttnov(L->top - 1);
655}
const TValue * luaH_get(Table *t, const TValue *key)

References api_check, hvalue, index2addr(), lua_lock, lua_unlock, luaH_get(), setobj2s, lua_State::top, ttistable, and ttnov.

◆ lua_rawgeti()

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

Definition at line 658 of file lua-5.3.6/src/lapi.c.

658 {
659 StkId t;
660 lua_lock(L);
661 t = index2addr(L, idx);
662 api_check(L, ttistable(t), "table expected");
663 setobj2s(L, L->top, luaH_getint(hvalue(t), n));
664 api_incr_top(L);
665 lua_unlock(L);
666 return ttnov(L->top - 1);
667}

References api_check, api_incr_top, hvalue, index2addr(), lua_lock, lua_unlock, luaH_getint(), setobj2s, lua_State::top, ttistable, and ttnov.

◆ lua_rawgetp()

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

Definition at line 670 of file lua-5.3.6/src/lapi.c.

670 {
671 StkId t;
672 TValue k;
673 lua_lock(L);
674 t = index2addr(L, idx);
675 api_check(L, ttistable(t), "table expected");
676 setpvalue(&k, cast(void *, p));
677 setobj2s(L, L->top, luaH_get(hvalue(t), &k));
678 api_incr_top(L);
679 lua_unlock(L);
680 return ttnov(L->top - 1);
681}

References api_check, api_incr_top, cast, hvalue, index2addr(), lua_lock, lua_unlock, luaH_get(), setobj2s, setpvalue, lua_State::top, ttistable, and ttnov.

◆ lua_rawlen()

LUA_API size_t lua_rawlen ( lua_State * L,
int idx )

Definition at line 392 of file lua-5.3.6/src/lapi.c.

392 {
393 StkId o = index2addr(L, idx);
394 switch (ttype(o)) {
395 case LUA_TSHRSTR: return tsvalue(o)->shrlen;
396 case LUA_TLNGSTR: return tsvalue(o)->u.lnglen;
397 case LUA_TUSERDATA: return uvalue(o)->len;
398 case LUA_TTABLE: return luaH_getn(hvalue(o));
399 default: return 0;
400 }
401}
#define tsvalue(o)
int luaH_getn(Table *t)
#define LUA_TSHRSTR
#define LUA_TLNGSTR

References hvalue, index2addr(), LUA_TLNGSTR, LUA_TSHRSTR, LUA_TTABLE, LUA_TUSERDATA, luaH_getn(), tsvalue, ttype, and uvalue.

◆ lua_rawset()

LUA_API void lua_rawset ( lua_State * L,
int idx )

Definition at line 801 of file lua-5.3.6/src/lapi.c.

801 {
802 StkId o;
803 TValue *slot;
804 lua_lock(L);
805 api_checknelems(L, 2);
806 o = index2addr(L, idx);
807 api_check(L, ttistable(o), "table expected");
808 slot = luaH_set(L, hvalue(o), L->top - 2);
809 setobj2t(L, slot, L->top - 1);
811 luaC_barrierback(L, hvalue(o), L->top-1);
812 L->top -= 2;
813 lua_unlock(L);
814}
#define setobj2t
TValue * luaH_set(lua_State *L, Table *t, const TValue *key)
#define luaC_barrierback(L, p, v)
#define invalidateTMcache(t)

References api_check, api_checknelems, hvalue, index2addr(), invalidateTMcache, lua_lock, lua_unlock, luaC_barrierback, luaH_set(), setobj2t, lua_State::top, and ttistable.

◆ lua_rawseti()

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

Definition at line 817 of file lua-5.3.6/src/lapi.c.

817 {
818 StkId o;
819 lua_lock(L);
820 api_checknelems(L, 1);
821 o = index2addr(L, idx);
822 api_check(L, ttistable(o), "table expected");
823 luaH_setint(L, hvalue(o), n, L->top - 1);
824 luaC_barrierback(L, hvalue(o), L->top-1);
825 L->top--;
826 lua_unlock(L);
827}
void luaH_setint(lua_State *L, Table *t, int key, TValue *value)

References api_check, api_checknelems, hvalue, index2addr(), lua_lock, lua_unlock, luaC_barrierback, luaH_setint(), lua_State::top, and ttistable.

◆ lua_rawsetp()

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

Definition at line 830 of file lua-5.3.6/src/lapi.c.

830 {
831 StkId o;
832 TValue k, *slot;
833 lua_lock(L);
834 api_checknelems(L, 1);
835 o = index2addr(L, idx);
836 api_check(L, ttistable(o), "table expected");
837 setpvalue(&k, cast(void *, p));
838 slot = luaH_set(L, hvalue(o), &k);
839 setobj2t(L, slot, L->top - 1);
840 luaC_barrierback(L, hvalue(o), L->top - 1);
841 L->top--;
842 lua_unlock(L);
843}

References api_check, api_checknelems, cast, hvalue, index2addr(), lua_lock, lua_unlock, luaC_barrierback, luaH_set(), setobj2t, setpvalue, lua_State::top, and ttistable.

◆ lua_rotate()

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

Definition at line 207 of file lua-5.3.6/src/lapi.c.

207 {
208 StkId p, t, m;
209 lua_lock(L);
210 t = L->top - 1; /* end of stack segment being rotated */
211 p = index2addr(L, idx); /* start of segment */
212 api_checkstackindex(L, idx, p);
213 api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'");
214 m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */
215 reverse(L, p, m); /* reverse the prefix with length 'n' */
216 reverse(L, m + 1, t); /* reverse the suffix */
217 reverse(L, p, t); /* reverse the entire segment */
218 lua_unlock(L);
219}
static void reverse(lua_State *L, StkId from, StkId to)

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

Referenced by aux_lines(), aux_lines(), db_getlocal(), db_getlocal(), ll_require(), luaB_xpcall(), luaB_xpcall(), treatstackoption(), and treatstackoption().

◆ lua_setallocf()

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

Definition at line 1176 of file lua-5.3.6/src/lapi.c.

1176 {
1177 lua_lock(L);
1178 G(L)->ud = ud;
1179 G(L)->frealloc = f;
1180 lua_unlock(L);
1181}

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 777 of file lua-5.3.6/src/lapi.c.

777 {
778 lua_lock(L); /* unlock done in 'auxsetstr' */
779 auxsetstr(L, index2addr(L, idx), k);
780}
static void auxsetstr(lua_State *L, const TValue *t, const char *k)

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

◆ lua_setglobal()

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

Definition at line 759 of file lua-5.3.6/src/lapi.c.

759 {
760 Table *reg = hvalue(&G(L)->l_registry);
761 lua_lock(L); /* unlock done in 'auxsetstr' */
763}

References auxsetstr(), G, hvalue, lua_lock, LUA_RIDX_GLOBALS, luaH_getint(), and name.

◆ lua_seti()

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

Definition at line 783 of file lua-5.3.6/src/lapi.c.

783 {
784 StkId t;
785 const TValue *slot;
786 lua_lock(L);
787 api_checknelems(L, 1);
788 t = index2addr(L, idx);
789 if (luaV_fastset(L, t, n, slot, luaH_getint, L->top - 1))
790 L->top--; /* pop value */
791 else {
792 setivalue(L->top, n);
793 api_incr_top(L);
794 luaV_finishset(L, t, L->top - 1, L->top - 2, slot);
795 L->top -= 2; /* pop value and key */
796 }
797 lua_unlock(L);
798}

References api_checknelems, api_incr_top, index2addr(), lua_lock, lua_unlock, luaH_getint(), luaV_fastset, luaV_finishset(), setivalue, and lua_State::top.

Referenced by pack(), set2(), set2(), tinsert(), tinsert(), tmove(), tmove(), tpack(), tremove(), and tremove().

◆ lua_setmetatable()

LUA_API int lua_setmetatable ( lua_State * L,
int objindex )

Definition at line 846 of file lua-5.3.6/src/lapi.c.

846 {
847 TValue *obj;
848 Table *mt;
849 lua_lock(L);
850 api_checknelems(L, 1);
851 obj = index2addr(L, objindex);
852 if (ttisnil(L->top - 1))
853 mt = NULL;
854 else {
855 api_check(L, ttistable(L->top - 1), "table expected");
856 mt = hvalue(L->top - 1);
857 }
858 switch (ttnov(obj)) {
859 case LUA_TTABLE: {
860 hvalue(obj)->metatable = mt;
861 if (mt) {
862 luaC_objbarrier(L, gcvalue(obj), mt);
863 luaC_checkfinalizer(L, gcvalue(obj), mt);
864 }
865 break;
866 }
867 case LUA_TUSERDATA: {
868 uvalue(obj)->metatable = mt;
869 if (mt) {
870 luaC_objbarrier(L, uvalue(obj), mt);
871 luaC_checkfinalizer(L, gcvalue(obj), mt);
872 }
873 break;
874 }
875 default: {
876 G(L)->mt[ttnov(obj)] = mt;
877 break;
878 }
879 }
880 L->top--;
881 lua_unlock(L);
882 return 1;
883}
#define luaC_objbarrier(L, p, o)
#define gcvalue(o)
#define ttisnil(o)
void luaC_checkfinalizer(lua_State *L, GCObject *o, Table *mt)

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

◆ lua_settable()

LUA_API void lua_settable ( lua_State * L,
int idx )

Definition at line 766 of file lua-5.3.6/src/lapi.c.

766 {
767 StkId t;
768 lua_lock(L);
769 api_checknelems(L, 2);
770 t = index2addr(L, idx);
771 luaV_settable(L, t, L->top - 2, L->top - 1);
772 L->top -= 2; /* pop index and value */
773 lua_unlock(L);
774}
#define luaV_settable(L, t, k, v)

References api_checknelems, index2addr(), lua_lock, lua_unlock, luaV_settable, and lua_State::top.

◆ lua_settop()

LUA_API void lua_settop ( lua_State * L,
int idx )

Definition at line 172 of file lua-5.3.6/src/lapi.c.

172 {
173 StkId func = L->ci->func;
174 lua_lock(L);
175 if (idx >= 0) {
176 api_check(L, idx <= L->stack_last - (func + 1), "new top too large");
177 while (L->top < (func + 1) + idx)
178 setnilvalue(L->top++);
179 L->top = (func + 1) + idx;
180 }
181 else {
182 api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top");
183 L->top += idx+1; /* 'subtract' index (index is negative) */
184 }
185 lua_unlock(L);
186}

References api_check, lua_State::ci, CallInfo::func, lua_lock, lua_unlock, setnilvalue, and lua_State::top.

◆ lua_setupvalue()

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

Definition at line 1236 of file lua-5.3.6/src/lapi.c.

1236 {
1237 const char *name;
1238 TValue *val = NULL; /* to avoid warnings */
1239 CClosure *owner = NULL;
1240 UpVal *uv = NULL;
1241 StkId fi;
1242 lua_lock(L);
1243 fi = index2addr(L, funcindex);
1244 api_checknelems(L, 1);
1245 name = aux_upvalue(fi, n, &val, &owner, &uv);
1246 if (name) {
1247 L->top--;
1248 setobj(L, val, L->top);
1249 if (owner) { luaC_barrier(L, owner, L->top); }
1250 else if (uv) { luaC_upvalbarrier(L, uv); }
1251 }
1252 lua_unlock(L);
1253 return name;
1254}

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

◆ lua_setuservalue()

LUA_API void lua_setuservalue ( lua_State * L,
int idx )

Definition at line 886 of file lua-5.3.6/src/lapi.c.

886 {
887 StkId o;
888 lua_lock(L);
889 api_checknelems(L, 1);
890 o = index2addr(L, idx);
891 api_check(L, ttisfulluserdata(o), "full userdata expected");
892 setuservalue(L, uvalue(o), L->top - 1);
893 luaC_barrier(L, gcvalue(o), L->top - 1);
894 L->top--;
895 lua_unlock(L);
896}
#define setuservalue(L, u, o)

References api_check, api_checknelems, gcvalue, index2addr(), lua_lock, lua_unlock, luaC_barrier, setuservalue, lua_State::top, ttisfulluserdata, and uvalue.

◆ lua_status()

LUA_API int lua_status ( lua_State * L)

Definition at line 1031 of file lua-5.3.6/src/lapi.c.

1031 {
1032 return L->status;
1033}

References lua_State::status.

◆ lua_stringtonumber()

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

Definition at line 337 of file lua-5.3.6/src/lapi.c.

337 {
338 size_t sz = luaO_str2num(s, L->top);
339 if (sz != 0)
340 api_incr_top(L);
341 return sz;
342}
size_t luaO_str2num(const char *s, TValue *o)

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

Referenced by luaB_tonumber(), luaB_tonumber(), read_number(), read_number(), and tonum().

◆ lua_toboolean()

LUA_API int lua_toboolean ( lua_State * L,
int idx )

Definition at line 367 of file lua-5.3.6/src/lapi.c.

367 {
368 const TValue *o = index2addr(L, idx);
369 return !l_isfalse(o);
370}
#define l_isfalse(o)

References index2addr(), and l_isfalse.

◆ lua_tocfunction()

LUA_API lua_CFunction lua_tocfunction ( lua_State * L,
int idx )

Definition at line 404 of file lua-5.3.6/src/lapi.c.

404 {
405 StkId o = index2addr(L, idx);
406 if (ttislcf(o)) return fvalue(o);
407 else if (ttisCclosure(o))
408 return clCvalue(o)->f;
409 else return NULL; /* not a C function */
410}
#define fvalue(o)

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

◆ lua_tointegerx()

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

Definition at line 356 of file lua-5.3.6/src/lapi.c.

356 {
357 lua_Integer res;
358 const TValue *o = index2addr(L, idx);
359 int isnum = tointeger(o, &res);
360 if (!isnum)
361 res = 0; /* call to 'tointeger' may change 'n' even if it fails */
362 if (pisnum) *pisnum = isnum;
363 return res;
364}
LUA_INTEGER lua_Integer
#define tointeger(o, i)

References index2addr(), and tointeger.

◆ lua_tolstring()

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

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

373 {
374 StkId o = index2addr(L, idx);
375 if (!ttisstring(o)) {
376 if (!cvt2str(o)) { /* not convertible? */
377 if (len != NULL) *len = 0;
378 return NULL;
379 }
380 lua_lock(L); /* 'luaO_tostring' may create a new string */
381 luaO_tostring(L, o);
382 luaC_checkGC(L);
383 o = index2addr(L, idx); /* previous call may reallocate the stack */
384 lua_unlock(L);
385 }
386 if (len != NULL)
387 *len = vslen(o);
388 return svalue(o);
389}
#define svalue(o)
void luaO_tostring(lua_State *L, StkId obj)
#define vslen(o)

References cvt2str, index2addr(), 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 345 of file lua-5.3.6/src/lapi.c.

345 {
346 lua_Number n;
347 const TValue *o = index2addr(L, idx);
348 int isnum = tonumber(o, &n);
349 if (!isnum)
350 n = 0; /* call to 'tonumber' may change 'n' even if it fails */
351 if (pisnum) *pisnum = isnum;
352 return n;
353}

References index2addr(), and tonumber.

◆ lua_topointer()

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

Definition at line 429 of file lua-5.3.6/src/lapi.c.

429 {
430 StkId o = index2addr(L, idx);
431 switch (ttype(o)) {
432 case LUA_TTABLE: return hvalue(o);
433 case LUA_TLCL: return clLvalue(o);
434 case LUA_TCCL: return clCvalue(o);
435 case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));
436 case LUA_TTHREAD: return thvalue(o);
437 case LUA_TUSERDATA: return getudatamem(uvalue(o));
438 case LUA_TLIGHTUSERDATA: return pvalue(o);
439 default: return NULL;
440 }
441}
#define pvalue(o)
#define thvalue(o)
#define LUA_TTHREAD
#define LUA_TLIGHTUSERDATA
#define LUA_TLCF

References cast, clCvalue, clLvalue, fvalue, getudatamem, hvalue, index2addr(), LUA_TCCL, LUA_TLCF, LUA_TLCL, LUA_TLIGHTUSERDATA, LUA_TTABLE, LUA_TTHREAD, LUA_TUSERDATA, NULL, pvalue, thvalue, ttype, and uvalue.

◆ lua_tothread()

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

Definition at line 423 of file lua-5.3.6/src/lapi.c.

423 {
424 StkId o = index2addr(L, idx);
425 return (!ttisthread(o)) ? NULL : thvalue(o);
426}
#define ttisthread(o)

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

◆ lua_touserdata()

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

Definition at line 413 of file lua-5.3.6/src/lapi.c.

413 {
414 StkId o = index2addr(L, idx);
415 switch (ttnov(o)) {
416 case LUA_TUSERDATA: return getudatamem(uvalue(o));
417 case LUA_TLIGHTUSERDATA: return pvalue(o);
418 default: return NULL;
419 }
420}

References getudatamem, index2addr(), LUA_TLIGHTUSERDATA, LUA_TUSERDATA, NULL, pvalue, ttnov, and uvalue.

◆ lua_type()

LUA_API int lua_type ( lua_State * L,
int idx )

Definition at line 251 of file lua-5.3.6/src/lapi.c.

251 {
252 StkId o = index2addr(L, idx);
253 return (isvalid(o) ? ttnov(o) : LUA_TNONE);
254}
#define LUA_TNONE

References index2addr(), isvalid, LUA_TNONE, and ttnov.

◆ lua_typename()

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

Definition at line 257 of file lua-5.3.6/src/lapi.c.

257 {
258 UNUSED(L);
259 api_check(L, LUA_TNONE <= t && t < LUA_NUMTAGS, "invalid tag");
260 return ttypename(t);
261}
#define UNUSED(x)
#define ttypename(x)
#define LUA_NUMTAGS

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

◆ lua_upvalueid()

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

Definition at line 1267 of file lua-5.3.6/src/lapi.c.

1267 {
1268 StkId fi = index2addr(L, fidx);
1269 switch (ttype(fi)) {
1270 case LUA_TLCL: { /* lua closure */
1271 return *getupvalref(L, fidx, n);
1272 }
1273 case LUA_TCCL: { /* C closure */
1274 CClosure *f = clCvalue(fi);
1275 api_check(L, 1 <= n && n <= f->nupvalues, "invalid upvalue index");
1276 return &f->upvalue[n - 1];
1277 }
1278 default: {
1279 api_check(L, 0, "closure expected");
1280 return NULL;
1281 }
1282 }
1283}
static UpVal ** getupvalref(lua_State *L, int fidx, int n)

References api_check, clCvalue, getupvalref(), index2addr(), LUA_TCCL, LUA_TLCL, NULL, ttype, and CClosure::upvalue.

◆ lua_upvaluejoin()

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

Definition at line 1286 of file lua-5.3.6/src/lapi.c.

1287 {
1288 UpVal **up1 = getupvalref(L, fidx1, n1);
1289 UpVal **up2 = getupvalref(L, fidx2, n2);
1290 if (*up1 == *up2)
1291 return;
1292 luaC_upvdeccount(L, *up1);
1293 *up1 = *up2;
1294 (*up1)->refcount++;
1295 if (upisopen(*up1)) (*up1)->u.open.touched = 1;
1296 luaC_upvalbarrier(L, *up1);
1297}
#define upisopen(up)
void luaC_upvdeccount(lua_State *L, UpVal *uv)
lu_mem refcount

References getupvalref(), luaC_upvalbarrier, luaC_upvdeccount(), UpVal::refcount, and upisopen.

◆ lua_version()

LUA_API const lua_Number * lua_version ( lua_State * L)

Definition at line 144 of file lua-5.3.6/src/lapi.c.

144 {
145 static const lua_Number version = LUA_VERSION_NUM;
146 if (L == NULL) return &version;
147 else return G(L)->version;
148}
#define LUA_VERSION_NUM

References G, LUA_VERSION_NUM, and NULL.

◆ lua_xmove()

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

Definition at line 118 of file lua-5.3.6/src/lapi.c.

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

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

◆ reverse()

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

Definition at line 193 of file lua-5.3.6/src/lapi.c.

193 {
194 for (; from < to; from++, to--) {
195 TValue temp;
196 setobj(L, &temp, from);
197 setobjs2s(L, from, to);
198 setobj2s(L, to, &temp);
199 }
200}

References setobj, setobj2s, and setobjs2s.

Referenced by lua_rotate().

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 34 of file lua-5.3.6/src/lapi.c.