Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lapi.c File Reference
#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 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 size)
 
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)
 
LUA_API void lua_remove (lua_State *L, int idx)
 
LUA_API void lua_insert (lua_State *L, int idx)
 
static void moveto (lua_State *L, TValue *fr, int idx)
 
LUA_API void lua_replace (lua_State *L, int idx)
 
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_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 lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum)
 
LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum)
 
LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *isnum)
 
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 void lua_pushunsigned (lua_State *L, lua_Unsigned u)
 
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)
 
LUA_API void lua_getglobal (lua_State *L, const char *var)
 
LUA_API void lua_gettable (lua_State *L, int idx)
 
LUA_API void lua_getfield (lua_State *L, int idx, const char *k)
 
LUA_API void lua_rawget (lua_State *L, int idx)
 
LUA_API void lua_rawgeti (lua_State *L, int idx, int n)
 
LUA_API void 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 void lua_getuservalue (lua_State *L, int idx)
 
LUA_API void lua_setglobal (lua_State *L, const char *var)
 
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_rawset (lua_State *L, int idx)
 
LUA_API void lua_rawseti (lua_State *L, int idx, int 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 int lua_getctx (lua_State *L, int *ctx)
 
LUA_API void lua_callk (lua_State *L, int nargs, int nresults, int ctx, lua_CFunction k)
 
static void f_call (lua_State *L, void *ud)
 
LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, int ctx, lua_CFunction 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)
 
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, 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

◆ api_checkstackindex

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

Definition at line 51 of file lua-5.2.4/src/lapi.c.

51#define api_checkstackindex(L, i, o) \
52 api_check(L, isstackindex(i, o), "index not in the stack")

Referenced by lua_insert(), lua_pcallk(), and lua_remove().

◆ api_checkvalidindex

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

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

Referenced by moveto().

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

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

Referenced by lua_callk(), and lua_pcallk().

◆ ispseudo

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

Definition at line 44 of file lua-5.2.4/src/lapi.c.

Referenced by index2addr(), and lua_absindex().

◆ isstackindex

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

Definition at line 47 of file lua-5.2.4/src/lapi.c.

◆ isvalid

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

Definition at line 41 of file lua-5.2.4/src/lapi.c.

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

◆ lapi_c

#define lapi_c

Definition at line 11 of file lua-5.2.4/src/lapi.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 12 of file lua-5.2.4/src/lapi.c.

◆ NONVALIDVALUE

#define NONVALIDVALUE   cast(TValue *, luaO_nilobject)

Definition at line 38 of file lua-5.2.4/src/lapi.c.

Referenced by index2addr().

Function Documentation

◆ aux_upvalue()

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

Definition at line 1188 of file lua-5.2.4/src/lapi.c.

1189 {
1190 switch (ttype(fi)) {
1191 case LUA_TCCL: { /* C closure */
1192 CClosure *f = clCvalue(fi);
1193 if (!(1 <= n && n <= f->nupvalues)) return NULL;
1194 *val = &f->upvalue[n-1];
1195 if (owner) *owner = obj2gco(f);
1196 return "";
1197 }
1198 case LUA_TLCL: { /* Lua closure */
1199 LClosure *f = clLvalue(fi);
1200 TString *name;
1201 Proto *p = f->p;
1202 if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
1203 *val = f->upvals[n-1]->v;
1204 if (owner) *owner = obj2gco(f->upvals[n - 1]);
1205 name = p->upvalues[n-1].name;
1206 return (name == NULL) ? "" : getstr(name);
1207 }
1208 default: return NULL; /* not a closure */
1209 }
1210}
pthread_t owner
#define NULL
Definition gmacros.h:924
const char * name
Definition lsqlite3.c:2154
#define getstr(ts)
#define ttype(o)
#define obj2gco(v)
#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, obj2gco, owner, LClosure::p, ttype, LClosure::upvals, CClosure::upvalue, Proto::upvalues, and UpVal::v.

Referenced by lua_getupvalue(), and lua_setupvalue().

◆ f_call()

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

Definition at line 921 of file lua-5.2.4/src/lapi.c.

921 {
922 struct CallS *c = cast(struct CallS *, ud);
923 luaD_call(L, c->func, c->nresults, 0);
924}
void luaD_call(lua_State *L, StkId func, int nResults)
#define cast(t, exp)

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

Referenced by lua_pcallk().

◆ getupvalref()

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

Definition at line 1246 of file lua-5.2.4/src/lapi.c.

1246 {
1247 LClosure *f;
1248 StkId fi = index2addr(L, fidx);
1249 api_check(L, ttisLclosure(fi), "Lua function expected");
1250 f = clLvalue(fi);
1251 api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index");
1252 if (pf) *pf = f;
1253 return &f->upvals[n - 1]; /* get its upvalue pointer */
1254}
static TValue * index2addr(lua_State *L, int idx)
#define ttisLclosure(o)

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

86 {
87 int size = *(int *)ud;
88 luaD_growstack(L, size);
89}
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 55 of file lua-5.2.4/src/lapi.c.

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

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_getmetatable(), lua_gettable(), lua_getupvalue(), lua_getuservalue(), lua_insert(), lua_iscfunction(), lua_isnumber(), 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_remove(), lua_setfield(), lua_setmetatable(), lua_settable(), lua_setupvalue(), lua_setuservalue(), lua_toboolean(), lua_tocfunction(), lua_tointegerx(), lua_tolstring(), lua_tonumberx(), lua_topointer(), lua_tothread(), lua_tounsignedx(), lua_touserdata(), lua_type(), lua_upvalueid(), and moveto().

◆ lua_absindex()

LUA_API int lua_absindex ( lua_State * L,
int idx )

Definition at line 153 of file lua-5.2.4/src/lapi.c.

153 {
154 return (idx > 0 || ispseudo(idx))
155 ? idx
156 : cast_int(L->top - L->ci->func + idx);
157}
#define cast_int(i)

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

Referenced by luaL_callmeta(), luaL_getsubtable(), luaL_ref(), and luaL_unref().

◆ lua_arith()

LUA_API void lua_arith ( lua_State * L,
int op )

Definition at line 293 of file lua-5.2.4/src/lapi.c.

293 {
294 StkId o1; /* 1st operand */
295 StkId o2; /* 2nd operand */
296 lua_lock(L);
297 if (op != LUA_OPUNM) /* all other operations expect two operands */
298 api_checknelems(L, 2);
299 else { /* for unary minus, add fake 2nd operand */
300 api_checknelems(L, 1);
301 setobjs2s(L, L->top, L->top - 1);
302 L->top++;
303 }
304 o1 = L->top - 2;
305 o2 = L->top - 1;
306 if (ttisnumber(o1) && ttisnumber(o2)) {
307 setnvalue(o1, luaO_arith(op, nvalue(o1), nvalue(o2)));
308 }
309 else
310 luaV_arith(L, o1, o1, o2, cast(TMS, op - LUA_OPADD + TM_ADD));
311 L->top--;
312 lua_unlock(L);
313}
#define api_checknelems(L, n)
#define lua_unlock(L)
#define lua_lock(L)
#define nvalue(o)
#define setobjs2s
#define setnvalue(obj, x)
#define ttisnumber(o)
@ TM_ADD
lua_Number luaO_arith(int op, lua_Number v1, lua_Number v2)
#define LUA_OPADD
#define LUA_OPUNM
void luaV_arith(lua_State *L, StkId ra, const TValue *rb, const TValue *rc, TMS op)

References api_checknelems, cast, lua_lock, LUA_OPADD, LUA_OPUNM, lua_unlock, luaO_arith(), luaV_arith(), nvalue, setnvalue, setobjs2s, TM_ADD, lua_State::top, and ttisnumber.

Referenced by arith().

◆ lua_atpanic()

LUA_API lua_CFunction lua_atpanic ( lua_State * L,
lua_CFunction panicf )

Definition at line 127 of file lua-5.2.4/src/lapi.c.

127 {
128 lua_CFunction old;
129 lua_lock(L);
130 old = G(L)->panic;
131 G(L)->panic = panicf;
132 lua_unlock(L);
133 return old;
134}
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,
int ctx,
lua_CFunction k )

Definition at line 889 of file lua-5.2.4/src/lapi.c.

890 {
891 StkId func;
892 lua_lock(L);
893 api_check(L, k == NULL || !isLua(L->ci),
894 "cannot use continuations inside hooks");
895 api_checknelems(L, nargs+1);
896 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
897 checkresults(L, nargs, nresults);
898 func = L->top - (nargs+1);
899 if (k != NULL && L->nny == 0) { /* need to prepare continuation? */
900 L->ci->u.c.k = k; /* save continuation */
901 L->ci->u.c.ctx = ctx; /* save context */
902 luaD_call(L, func, nresults, 1); /* do the call */
903 }
904 else /* no continuation or no yieldable */
905 luaD_call(L, func, nresults, 0); /* just do the call */
906 adjustresults(L, nresults);
907 lua_unlock(L);
908}
#define adjustresults(L, nres)
#define isLua(ci)
#define checkresults(L, na, nr)
#define LUA_OK
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(), lua_State::nny, NULL, lua_State::status, lua_State::top, and CallInfo::u.

Referenced by luaB_dofile(), luaB_dofile(), and luaB_dofile().

◆ lua_checkstack()

LUA_API int lua_checkstack ( lua_State * L,
int size )

Definition at line 92 of file lua-5.2.4/src/lapi.c.

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

References 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 316 of file lua-5.2.4/src/lapi.c.

316 {
317 StkId o1, o2;
318 int i = 0;
319 lua_lock(L); /* may call tag method */
320 o1 = index2addr(L, index1);
321 o2 = index2addr(L, index2);
322 if (isvalid(o1) && isvalid(o2)) {
323 switch (op) {
324 case LUA_OPEQ: i = equalobj(L, o1, o2); break;
325 case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;
326 case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;
327 default: api_check(L, 0, "invalid option");
328 }
329 }
330 lua_unlock(L);
331 return i;
332}
int luaV_lessthan(lua_State *L, const TValue *l, const TValue *r)
#define equalobj(L, o1, o2)
#define isvalid(o)
#define LUA_OPLT
#define LUA_OPLE
#define LUA_OPEQ
int luaV_lessequal(lua_State *L, const TValue *l, const TValue *r)

References api_check, equalobj, index2addr(), isvalid, lua_lock, LUA_OPEQ, LUA_OPLE, LUA_OPLT, lua_unlock, luaV_lessequal(), and luaV_lessthan().

Referenced by math_max(), math_max(), math_min(), math_min(), sort_comp(), sort_comp(), sort_comp(), tmove(), and tmove().

◆ lua_concat()

LUA_API void lua_concat ( lua_State * L,
int n )

Definition at line 1131 of file lua-5.2.4/src/lapi.c.

1131 {
1132 lua_lock(L);
1133 api_checknelems(L, n);
1134 if (n >= 2) {
1135 luaC_checkGC(L);
1136 luaV_concat(L, n);
1137 }
1138 else if (n == 0) { /* push empty string */
1139 setsvalue2s(L, L->top, luaS_newlstr(L, "", 0));
1140 api_incr_top(L);
1141 }
1142 /* else n == 1; nothing to do */
1143 lua_unlock(L);
1144}
#define api_incr_top(L)
#define luaC_checkGC(L)
#define setsvalue2s
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 226 of file lua-5.2.4/src/lapi.c.

226 {
227 TValue *fr;
228 lua_lock(L);
229 fr = index2addr(L, fromidx);
230 moveto(L, fr, toidx);
231 lua_unlock(L);
232}
static void moveto(lua_State *L, TValue *fr, int idx)

References index2addr(), lua_lock, lua_unlock, and moveto().

Referenced by ll_require(), luaB_xpcall(), pushglobalfuncname(), pushglobalfuncname(), and pushglobalfuncname().

◆ lua_createtable()

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

Definition at line 673 of file lua-5.2.4/src/lapi.c.

673 {
674 Table *t;
675 lua_lock(L);
676 luaC_checkGC(L);
677 t = luaH_new(L);
678 sethvalue(L, L->top, t);
679 api_incr_top(L);
680 if (narray > 0 || nrec > 0)
681 luaH_resize(L, t, narray, nrec);
682 lua_unlock(L);
683}
#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 )

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

997 {
998 int status;
999 TValue *o;
1000 lua_lock(L);
1001 api_checknelems(L, 1);
1002 o = L->top - 1;
1003 if (isLfunction(o))
1004 status = luaU_dump(L, getproto(o), writer, data, 0);
1005 else
1006 status = 1;
1007 lua_unlock(L);
1008 return status;
1009}
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 1105 of file lua-5.2.4/src/lapi.c.

1105 {
1106 lua_lock(L);
1107 api_checknelems(L, 1);
1108 luaG_errormsg(L);
1109 /* code unreachable; will unlock when control actually leaves the kernel */
1110 return 0; /* to avoid warnings */
1111}
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 1021 of file lua-5.2.4/src/lapi.c.

1021 {
1022 int res = 0;
1023 global_State *g;
1024 lua_lock(L);
1025 g = G(L);
1026 switch (what) {
1027 case LUA_GCSTOP: {
1028 g->gcrunning = 0;
1029 break;
1030 }
1031 case LUA_GCRESTART: {
1032 luaE_setdebt(g, 0);
1033 g->gcrunning = 1;
1034 break;
1035 }
1036 case LUA_GCCOLLECT: {
1037 luaC_fullgc(L, 0);
1038 break;
1039 }
1040 case LUA_GCCOUNT: {
1041 /* GC values are expressed in Kbytes: #bytes/2^10 */
1042 res = cast_int(gettotalbytes(g) >> 10);
1043 break;
1044 }
1045 case LUA_GCCOUNTB: {
1046 res = cast_int(gettotalbytes(g) & 0x3ff);
1047 break;
1048 }
1049 case LUA_GCSTEP: {
1050 if (g->gckind == KGC_GEN) { /* generational mode? */
1051 res = (g->GCestimate == 0); /* true if it will do major collection */
1052 luaC_forcestep(L); /* do a single step */
1053 }
1054 else {
1055 lu_mem debt = cast(lu_mem, data) * 1024 - GCSTEPSIZE;
1056 if (g->gcrunning)
1057 debt += g->GCdebt; /* include current debt */
1058 luaE_setdebt(g, debt);
1059 luaC_forcestep(L);
1060 if (g->gcstate == GCSpause) /* end of cycle? */
1061 res = 1; /* signal it */
1062 }
1063 break;
1064 }
1065 case LUA_GCSETPAUSE: {
1066 res = g->gcpause;
1067 g->gcpause = data;
1068 break;
1069 }
1070 case LUA_GCSETMAJORINC: {
1071 res = g->gcmajorinc;
1072 g->gcmajorinc = data;
1073 break;
1074 }
1075 case LUA_GCSETSTEPMUL: {
1076 res = g->gcstepmul;
1077 g->gcstepmul = data;
1078 break;
1079 }
1080 case LUA_GCISRUNNING: {
1081 res = g->gcrunning;
1082 break;
1083 }
1084 case LUA_GCGEN: { /* change collector to generational mode */
1086 break;
1087 }
1088 case LUA_GCINC: { /* change collector to incremental mode */
1090 break;
1091 }
1092 default: res = -1; /* invalid option */
1093 }
1094 lua_unlock(L);
1095 return res;
1096}
void luaC_fullgc(lua_State *L)
#define GCSTEPSIZE
#define GCSpause
LUAI_UMEM lu_mem
#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_forcestep(lua_State *L)
void luaC_changemode(lua_State *L, int mode)
void luaE_setdebt(global_State *g, l_mem debt)
#define gettotalbytes(g)
#define KGC_GEN
#define KGC_NORMAL
#define LUA_GCGEN
#define LUA_GCSETMAJORINC
#define LUA_GCINC
#define LUA_GCISRUNNING

References cast, cast_int, G, global_State::GCdebt, global_State::GCestimate, global_State::gckind, global_State::gcmajorinc, global_State::gcpause, global_State::gcrunning, GCSpause, global_State::gcstate, global_State::gcstepmul, GCSTEPSIZE, gettotalbytes, KGC_GEN, KGC_NORMAL, LUA_GCCOLLECT, LUA_GCCOUNT, LUA_GCCOUNTB, LUA_GCGEN, LUA_GCINC, LUA_GCISRUNNING, LUA_GCRESTART, LUA_GCSETMAJORINC, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL, LUA_GCSTEP, LUA_GCSTOP, lua_lock, lua_unlock, luaC_changemode(), luaC_forcestep(), luaC_fullgc(), and luaE_setdebt().

◆ lua_getallocf()

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

Definition at line 1157 of file lua-5.2.4/src/lapi.c.

1157 {
1158 lua_Alloc f;
1159 lua_lock(L);
1160 if (ud) *ud = G(L)->ud;
1161 f = G(L)->frealloc;
1162 lua_unlock(L);
1163 return f;
1164}
void *(* lua_Alloc)(void *ud, void *ptr, size_t osize, size_t nsize)

References G, lua_lock, and lua_unlock.

◆ lua_getctx()

LUA_API int lua_getctx ( lua_State * L,
int * ctx )

Definition at line 880 of file lua-5.2.4/src/lapi.c.

880 {
881 if (L->ci->callstatus & CIST_YIELDED) {
882 if (ctx) *ctx = L->ci->u.c.ctx;
883 return L->ci->u.c.status;
884 }
885 else return LUA_OK;
886}
#define CIST_YIELDED

References CallInfo::c, CallInfo::callstatus, lua_State::ci, CIST_YIELDED, CallInfo::ctx, LUA_OK, CallInfo::status, and CallInfo::u.

Referenced by pcallcont().

◆ lua_getfield()

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

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

628 {
629 StkId t;
630 lua_lock(L);
631 t = index2addr(L, idx);
632 setsvalue2s(L, L->top, luaS_new(L, k));
633 api_incr_top(L);
634 luaV_gettable(L, t, L->top - 1, L->top - 1);
635 lua_unlock(L);
636}
#define luaS_new(L, s)
#define luaV_gettable(L, t, k, v)

References api_incr_top, index2addr(), lua_lock, lua_unlock, luaS_new, luaV_gettable, setsvalue2s, and lua_State::top.

◆ lua_getglobal()

LUA_API void lua_getglobal ( lua_State * L,
const char * var )

Definition at line 608 of file lua-5.2.4/src/lapi.c.

608 {
609 Table *reg = hvalue(&G(L)->l_registry);
610 const TValue *gt; /* global table */
611 lua_lock(L);
613 setsvalue2s(L, L->top++, luaS_new(L, var));
614 luaV_gettable(L, gt, L->top - 1, L->top - 1);
615 lua_unlock(L);
616}
#define hvalue(o)
#define gt(L)
const TValue * luaH_getint(Table *t, int key)
#define LUA_RIDX_GLOBALS

References G, gt, hvalue, lua_lock, LUA_RIDX_GLOBALS, lua_unlock, luaH_getint(), luaS_new, luaV_gettable, setsvalue2s, and lua_State::top.

◆ lua_getmetatable()

LUA_API int lua_getmetatable ( lua_State * L,
int objindex )

Definition at line 686 of file lua-5.2.4/src/lapi.c.

686 {
687 const TValue *obj;
688 Table *mt = NULL;
689 int res;
690 lua_lock(L);
691 obj = index2addr(L, objindex);
692 switch (ttypenv(obj)) {
693 case LUA_TTABLE:
694 mt = hvalue(obj)->metatable;
695 break;
696 case LUA_TUSERDATA:
697 mt = uvalue(obj)->metatable;
698 break;
699 default:
700 mt = G(L)->mt[ttypenv(obj)];
701 break;
702 }
703 if (mt == NULL)
704 res = 0;
705 else {
706 sethvalue(L, L->top, mt);
707 api_incr_top(L);
708 res = 1;
709 }
710 lua_unlock(L);
711 return res;
712}
#define uvalue(o)
#define LUA_TTABLE
#define LUA_TUSERDATA
#define ttypenv(o)
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, ttypenv, and uvalue.

◆ lua_gettable()

LUA_API void lua_gettable ( lua_State * L,
int idx )

Definition at line 619 of file lua-5.2.4/src/lapi.c.

619 {
620 StkId t;
621 lua_lock(L);
622 t = index2addr(L, idx);
623 luaV_gettable(L, t, L->top - 1, L->top - 1);
624 lua_unlock(L);
625}

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

◆ lua_gettop()

LUA_API int lua_gettop ( lua_State * L)

Definition at line 160 of file lua-5.2.4/src/lapi.c.

160 {
161 return cast_int(L->top - (L->ci->func + 1));
162}

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

1213 {
1214 const char *name;
1215 TValue *val = NULL; /* to avoid warnings */
1216 lua_lock(L);
1217 name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL);
1218 if (name) {
1219 setobj2s(L, L->top, val);
1220 api_incr_top(L);
1221 }
1222 lua_unlock(L);
1223 return name;
1224}
#define setobj2s
static const char * aux_upvalue(StkId fi, int n, TValue **val, GCObject **owner)

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

◆ lua_getuservalue()

LUA_API void lua_getuservalue ( lua_State * L,
int idx )

Definition at line 715 of file lua-5.2.4/src/lapi.c.

715 {
716 StkId o;
717 lua_lock(L);
718 o = index2addr(L, idx);
719 api_check(L, ttisuserdata(o), "userdata expected");
720 if (uvalue(o)->env) {
721 sethvalue(L, L->top, uvalue(o)->env);
722 } else
723 setnilvalue(L->top);
724 api_incr_top(L);
725 lua_unlock(L);
726}
#define setnilvalue(obj)
#define ttisuserdata(o)

References api_check, api_incr_top, index2addr(), lua_lock, lua_unlock, sethvalue, setnilvalue, lua_State::top, ttisuserdata, and uvalue.

◆ lua_insert()

LUA_API void lua_insert ( lua_State * L,
int idx )

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

193 {
194 StkId p;
195 StkId q;
196 lua_lock(L);
197 p = index2addr(L, idx);
198 api_checkstackindex(L, idx, p);
199 for (q = L->top; q > p; q--) /* use L->top as a temporary */
200 setobjs2s(L, q, q - 1);
201 setobjs2s(L, p, L->top);
202 lua_unlock(L);
203}
#define api_checkstackindex(L, i, o)

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

◆ lua_iscfunction()

LUA_API int lua_iscfunction ( lua_State * L,
int idx )

Definition at line 261 of file lua-5.2.4/src/lapi.c.

261 {
262 StkId o = index2addr(L, idx);
263 return (ttislcf(o) || (ttisCclosure(o)));
264}
#define ttisCclosure(o)

References index2addr(), ttisCclosure, and ttislcf.

◆ lua_isnumber()

LUA_API int lua_isnumber ( lua_State * L,
int idx )

Definition at line 267 of file lua-5.2.4/src/lapi.c.

267 {
268 TValue n;
269 const TValue *o = index2addr(L, idx);
270 return tonumber(o, &n);
271}
#define tonumber(o, n)

References index2addr(), and tonumber.

◆ lua_isstring()

LUA_API int lua_isstring ( lua_State * L,
int idx )

Definition at line 274 of file lua-5.2.4/src/lapi.c.

274 {
275 int t = lua_type(L, idx);
276 return (t == LUA_TSTRING || t == LUA_TNUMBER);
277}
#define LUA_TSTRING
#define LUA_TNUMBER
LUA_API int lua_type(lua_State *L, int idx)

References LUA_TNUMBER, LUA_TSTRING, and lua_type().

◆ lua_isuserdata()

LUA_API int lua_isuserdata ( lua_State * L,
int idx )

Definition at line 280 of file lua-5.2.4/src/lapi.c.

280 {
281 const TValue *o = index2addr(L, idx);
282 return (ttisuserdata(o) || ttislightuserdata(o));
283}
#define ttislightuserdata(o)

References index2addr(), ttislightuserdata, and ttisuserdata.

◆ lua_len()

LUA_API void lua_len ( lua_State * L,
int idx )

Definition at line 1147 of file lua-5.2.4/src/lapi.c.

1147 {
1148 StkId t;
1149 lua_lock(L);
1150 t = index2addr(L, idx);
1151 luaV_objlen(L, L->top, t);
1152 api_incr_top(L);
1153 lua_unlock(L);
1154}
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.

Referenced by luaL_len().

◆ lua_load()

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

Definition at line 973 of file lua-5.2.4/src/lapi.c.

974 {
975 ZIO z;
976 int status;
977 lua_lock(L);
978 if (!chunkname) chunkname = "?";
979 luaZ_init(L, &z, reader, data);
980 status = luaD_protectedparser(L, &z, chunkname, mode);
981 if (status == LUA_OK) { /* no errors? */
982 LClosure *f = clLvalue(L->top - 1); /* get newly created function */
983 if (f->nupvalues == 1) { /* does it have one upvalue? */
984 /* get global table from registry */
985 Table *reg = hvalue(&G(L)->l_registry);
986 const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
987 /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
988 setobj(L, f->upvals[0]->v, gt);
989 luaC_barrier(L, f->upvals[0], gt);
990 }
991 }
992 lua_unlock(L);
993 return status;
994}
int luaD_protectedparser(lua_State *L, ZIO *z, const char *name)
#define luaC_barrier(L, p, v)
#define setobj(L, obj1, obj2)
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, G, gt, hvalue, lua_lock, LUA_OK, LUA_RIDX_GLOBALS, lua_unlock, luaC_barrier, 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 1175 of file lua-5.2.4/src/lapi.c.

1175 {
1176 Udata *u;
1177 lua_lock(L);
1178 luaC_checkGC(L);
1179 u = luaS_newudata(L, size, NULL);
1180 setuvalue(L, L->top, u);
1181 api_incr_top(L);
1182 lua_unlock(L);
1183 return u + 1;
1184}
#define setuvalue(L, obj, x)
Udata * luaS_newudata(lua_State *L, size_t s, Table *e)

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

◆ lua_next()

LUA_API int lua_next ( lua_State * L,
int idx )

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

1114 {
1115 StkId t;
1116 int more;
1117 lua_lock(L);
1118 t = index2addr(L, idx);
1119 api_check(L, ttistable(t), "table expected");
1120 more = luaH_next(L, hvalue(t), L->top - 1);
1121 if (more) {
1122 api_incr_top(L);
1123 }
1124 else /* no more elements */
1125 L->top -= 1; /* remove key */
1126 lua_unlock(L);
1127 return more;
1128}
#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,
int ctx,
lua_CFunction k )

Definition at line 928 of file lua-5.2.4/src/lapi.c.

929 {
930 struct CallS c;
931 int status;
932 ptrdiff_t func;
933 lua_lock(L);
934 api_check(L, k == NULL || !isLua(L->ci),
935 "cannot use continuations inside hooks");
936 api_checknelems(L, nargs+1);
937 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
938 checkresults(L, nargs, nresults);
939 if (errfunc == 0)
940 func = 0;
941 else {
942 StkId o = index2addr(L, errfunc);
943 api_checkstackindex(L, errfunc, o);
944 func = savestack(L, o);
945 }
946 c.func = L->top - (nargs+1); /* function to be called */
947 if (k == NULL || L->nny > 0) { /* no continuation or no yieldable? */
948 c.nresults = nresults; /* do a 'conventional' protected call */
949 status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
950 }
951 else { /* prepare continuation (call is already protected by 'resume') */
952 CallInfo *ci = L->ci;
953 ci->u.c.k = k; /* save continuation */
954 ci->u.c.ctx = ctx; /* save context */
955 /* save information for error recovery */
956 ci->extra = savestack(L, c.func);
957 ci->u.c.old_allowhook = L->allowhook;
958 ci->u.c.old_errfunc = L->errfunc;
959 L->errfunc = func;
960 /* mark that function may do error recovery */
961 ci->callstatus |= CIST_YPCALL;
962 luaD_call(L, c.func, nresults, 1); /* do the call */
963 ci->callstatus &= ~CIST_YPCALL;
964 L->errfunc = ci->u.c.old_errfunc;
965 status = LUA_OK; /* if it is here, there were no errors */
966 }
968 lua_unlock(L);
969 return status;
970}
int luaD_pcall(lua_State *L, Pfunc func, void *u, ptrdiff_t old_top, ptrdiff_t ef)
#define savestack(L, p)
static void f_call(lua_State *L, void *ud)
#define CIST_YPCALL
ptrdiff_t old_errfunc
lu_byte old_allowhook

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_allowhook, CallInfo::old_errfunc, savestack, lua_State::status, lua_State::top, and CallInfo::u.

Referenced by luaB_pcall(), luaB_pcall(), luaB_pcall(), luaB_xpcall(), luaB_xpcall(), and luaB_xpcall().

◆ lua_pushboolean()

LUA_API void lua_pushboolean ( lua_State * L,
int b )

Definition at line 577 of file lua-5.2.4/src/lapi.c.

577 {
578 lua_lock(L);
579 setbvalue(L->top, (b != 0)); /* ensure that true is 1 */
580 api_incr_top(L);
581 lua_unlock(L);
582}
#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 555 of file lua-5.2.4/src/lapi.c.

555 {
556 lua_lock(L);
557 if (n == 0) {
558 setfvalue(L->top, fn);
559 }
560 else {
561 Closure *cl;
562 api_checknelems(L, n);
563 api_check(L, n <= MAXUPVAL, "upvalue index too large");
564 luaC_checkGC(L);
565 cl = luaF_newCclosure(L, n);
566 cl->c.f = fn;
567 L->top -= n;
568 while (n--)
569 setobj2n(L, &cl->c.upvalue[n], L->top + n);
570 setclCvalue(L, L->top, cl);
571 }
572 api_incr_top(L);
573 lua_unlock(L);
574}
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, Closure::c, 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 542 of file lua-5.2.4/src/lapi.c.

542 {
543 const char *ret;
544 va_list argp;
545 lua_lock(L);
546 luaC_checkGC(L);
547 va_start(argp, fmt);
548 ret = luaO_pushvfstring(L, fmt, argp);
549 va_end(argp);
550 lua_unlock(L);
551 return ret;
552}
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 483 of file lua-5.2.4/src/lapi.c.

483 {
484 lua_lock(L);
485 setnvalue(L->top, cast_num(n));
486 api_incr_top(L);
487 lua_unlock(L);
488}
#define cast_num(i)

References api_incr_top, cast_num, lua_lock, lua_unlock, setnvalue, and lua_State::top.

◆ lua_pushlightuserdata()

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

Definition at line 585 of file lua-5.2.4/src/lapi.c.

585 {
586 lua_lock(L);
587 setpvalue(L->top, p);
588 api_incr_top(L);
589 lua_unlock(L);
590}
#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 501 of file lua-5.2.4/src/lapi.c.

501 {
502 TString *ts;
503 lua_lock(L);
504 luaC_checkGC(L);
505 ts = luaS_newlstr(L, s, len);
506 setsvalue2s(L, L->top, ts);
507 api_incr_top(L);
508 lua_unlock(L);
509 return getstr(ts);
510}
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

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

◆ lua_pushnil()

LUA_API void lua_pushnil ( lua_State * L)

Definition at line 465 of file lua-5.2.4/src/lapi.c.

465 {
466 lua_lock(L);
467 setnilvalue(L->top);
468 api_incr_top(L);
469 lua_unlock(L);
470}

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

Referenced by lua_pushstring().

◆ lua_pushnumber()

LUA_API void lua_pushnumber ( lua_State * L,
lua_Number n )

Definition at line 473 of file lua-5.2.4/src/lapi.c.

473 {
474 lua_lock(L);
475 setnvalue(L->top, n);
476 luai_checknum(L, L->top,
477 luaG_runerror(L, "C API - attempt to push a signaling NaN"));
478 api_incr_top(L);
479 lua_unlock(L);
480}
void luaG_runerror(lua_State *L, const char *fmt,...)
#define luai_checknum(L, o, c)

References api_incr_top, lua_lock, lua_unlock, luaG_runerror(), luai_checknum, setnvalue, and lua_State::top.

◆ lua_pushstring()

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

Definition at line 513 of file lua-5.2.4/src/lapi.c.

513 {
514 if (s == NULL) {
515 lua_pushnil(L);
516 return NULL;
517 }
518 else {
519 TString *ts;
520 lua_lock(L);
521 luaC_checkGC(L);
522 ts = luaS_new(L, s);
523 setsvalue2s(L, L->top, ts);
524 api_incr_top(L);
525 lua_unlock(L);
526 return getstr(ts);
527 }
528}
LUA_API void lua_pushnil(lua_State *L)

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

◆ lua_pushthread()

LUA_API int lua_pushthread ( lua_State * L)

Definition at line 593 of file lua-5.2.4/src/lapi.c.

593 {
594 lua_lock(L);
595 setthvalue(L, L->top, L);
596 api_incr_top(L);
597 lua_unlock(L);
598 return (G(L)->mainthread == L);
599}
#define setthvalue(L, obj, x)

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

◆ lua_pushunsigned()

LUA_API void lua_pushunsigned ( lua_State * L,
lua_Unsigned u )

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

491 {
492 lua_Number n;
493 lua_lock(L);
494 n = lua_unsigned2number(u);
495 setnvalue(L->top, n);
496 api_incr_top(L);
497 lua_unlock(L);
498}
LUA_NUMBER lua_Number
#define lua_unsigned2number(u)

References api_incr_top, lua_lock, lua_unlock, lua_unsigned2number, setnvalue, and lua_State::top.

Referenced by b_and(), b_arshift(), b_extract(), b_not(), b_or(), b_replace(), b_rot(), b_shift(), and b_xor().

◆ lua_pushvalue()

LUA_API void lua_pushvalue ( lua_State * L,
int idx )

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

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

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

532 {
533 const char *ret;
534 lua_lock(L);
535 luaC_checkGC(L);
536 ret = luaO_pushvfstring(L, fmt, argp);
537 lua_unlock(L);
538 return ret;
539}

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

286 {
287 StkId o1 = index2addr(L, index1);
288 StkId o2 = index2addr(L, index2);
289 return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0;
290}
#define luaV_rawequalobj(o1, o2)

References index2addr(), isvalid, and luaV_rawequalobj.

◆ lua_rawget()

LUA_API void lua_rawget ( lua_State * L,
int idx )

Definition at line 639 of file lua-5.2.4/src/lapi.c.

639 {
640 StkId t;
641 lua_lock(L);
642 t = index2addr(L, idx);
643 api_check(L, ttistable(t), "table expected");
644 setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
645 lua_unlock(L);
646}
const TValue * luaH_get(Table *t, const TValue *key)

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

◆ lua_rawgeti()

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

Definition at line 649 of file lua-5.2.4/src/lapi.c.

649 {
650 StkId t;
651 lua_lock(L);
652 t = index2addr(L, idx);
653 api_check(L, ttistable(t), "table expected");
654 setobj2s(L, L->top, luaH_getint(hvalue(t), n));
655 api_incr_top(L);
656 lua_unlock(L);
657}

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

◆ lua_rawgetp()

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

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

660 {
661 StkId t;
662 TValue k;
663 lua_lock(L);
664 t = index2addr(L, idx);
665 api_check(L, ttistable(t), "table expected");
666 setpvalue(&k, cast(void *, p));
667 setobj2s(L, L->top, luaH_get(hvalue(t), &k));
668 api_incr_top(L);
669 lua_unlock(L);
670}

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

Referenced by addtoclib(), checkclib(), db_gethook(), db_sethook(), and hookf().

◆ lua_rawlen()

LUA_API size_t lua_rawlen ( lua_State * L,
int idx )

Definition at line 407 of file lua-5.2.4/src/lapi.c.

407 {
408 StkId o = index2addr(L, idx);
409 switch (ttypenv(o)) {
410 case LUA_TSTRING: return tsvalue(o)->len;
411 case LUA_TUSERDATA: return uvalue(o)->len;
412 case LUA_TTABLE: return luaH_getn(hvalue(o));
413 default: return 0;
414 }
415}
#define tsvalue(o)
int luaH_getn(Table *t)

References hvalue, index2addr(), LUA_TSTRING, LUA_TTABLE, LUA_TUSERDATA, luaH_getn(), tsvalue, ttypenv, and uvalue.

◆ lua_rawset()

LUA_API void lua_rawset ( lua_State * L,
int idx )

Definition at line 770 of file lua-5.2.4/src/lapi.c.

770 {
771 StkId t;
772 lua_lock(L);
773 api_checknelems(L, 2);
774 t = index2addr(L, idx);
775 api_check(L, ttistable(t), "table expected");
776 setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
778 luaC_barrierback(L, gcvalue(t), L->top-1);
779 L->top -= 2;
780 lua_unlock(L);
781}
#define gcvalue(o)
#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, gcvalue, 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,
int n )

Definition at line 784 of file lua-5.2.4/src/lapi.c.

784 {
785 StkId t;
786 lua_lock(L);
787 api_checknelems(L, 1);
788 t = index2addr(L, idx);
789 api_check(L, ttistable(t), "table expected");
790 luaH_setint(L, hvalue(t), n, L->top - 1);
791 luaC_barrierback(L, gcvalue(t), L->top-1);
792 L->top--;
793 lua_unlock(L);
794}
void luaH_setint(lua_State *L, Table *t, int key, TValue *value)

References api_check, api_checknelems, gcvalue, 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 797 of file lua-5.2.4/src/lapi.c.

797 {
798 StkId t;
799 TValue k;
800 lua_lock(L);
801 api_checknelems(L, 1);
802 t = index2addr(L, idx);
803 api_check(L, ttistable(t), "table expected");
804 setpvalue(&k, cast(void *, p));
805 setobj2t(L, luaH_set(L, hvalue(t), &k), L->top - 1);
806 luaC_barrierback(L, gcvalue(t), L->top - 1);
807 L->top--;
808 lua_unlock(L);
809}

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

Referenced by createclibstable(), and db_sethook().

◆ lua_remove()

LUA_API void lua_remove ( lua_State * L,
int idx )

Definition at line 182 of file lua-5.2.4/src/lapi.c.

182 {
183 StkId p;
184 lua_lock(L);
185 p = index2addr(L, idx);
186 api_checkstackindex(L, idx, p);
187 while (++p < L->top) setobjs2s(L, p-1, p);
188 L->top--;
189 lua_unlock(L);
190}

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

◆ lua_replace()

LUA_API void lua_replace ( lua_State * L,
int idx )

Definition at line 217 of file lua-5.2.4/src/lapi.c.

217 {
218 lua_lock(L);
219 api_checknelems(L, 1);
220 moveto(L, L->top - 1, idx);
221 L->top--;
222 lua_unlock(L);
223}

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

◆ lua_setallocf()

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

Definition at line 1167 of file lua-5.2.4/src/lapi.c.

1167 {
1168 lua_lock(L);
1169 G(L)->ud = ud;
1170 G(L)->frealloc = f;
1171 lua_unlock(L);
1172}

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

758 {
759 StkId t;
760 lua_lock(L);
761 api_checknelems(L, 1);
762 t = index2addr(L, idx);
763 setsvalue2s(L, L->top++, luaS_new(L, k));
764 luaV_settable(L, t, L->top - 1, L->top - 2);
765 L->top -= 2; /* pop value and key */
766 lua_unlock(L);
767}
#define luaV_settable(L, t, k, v)

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

◆ lua_setglobal()

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

Definition at line 734 of file lua-5.2.4/src/lapi.c.

734 {
735 Table *reg = hvalue(&G(L)->l_registry);
736 const TValue *gt; /* global table */
737 lua_lock(L);
738 api_checknelems(L, 1);
740 setsvalue2s(L, L->top++, luaS_new(L, var));
741 luaV_settable(L, gt, L->top - 1, L->top - 2);
742 L->top -= 2; /* pop value and key */
743 lua_unlock(L);
744}

References api_checknelems, G, gt, hvalue, lua_lock, LUA_RIDX_GLOBALS, lua_unlock, luaH_getint(), luaS_new, luaV_settable, setsvalue2s, and lua_State::top.

◆ lua_setmetatable()

LUA_API int lua_setmetatable ( lua_State * L,
int objindex )

Definition at line 812 of file lua-5.2.4/src/lapi.c.

812 {
813 TValue *obj;
814 Table *mt;
815 lua_lock(L);
816 api_checknelems(L, 1);
817 obj = index2addr(L, objindex);
818 if (ttisnil(L->top - 1))
819 mt = NULL;
820 else {
821 api_check(L, ttistable(L->top - 1), "table expected");
822 mt = hvalue(L->top - 1);
823 }
824 switch (ttypenv(obj)) {
825 case LUA_TTABLE: {
826 hvalue(obj)->metatable = mt;
827 if (mt) {
828 luaC_objbarrierback(L, gcvalue(obj), mt);
829 luaC_checkfinalizer(L, gcvalue(obj), mt);
830 }
831 break;
832 }
833 case LUA_TUSERDATA: {
834 uvalue(obj)->metatable = mt;
835 if (mt) {
836 luaC_objbarrier(L, rawuvalue(obj), mt);
837 luaC_checkfinalizer(L, gcvalue(obj), mt);
838 }
839 break;
840 }
841 default: {
842 G(L)->mt[ttypenv(obj)] = mt;
843 break;
844 }
845 }
846 L->top--;
847 lua_unlock(L);
848 return 1;
849}
#define luaC_objbarrier(L, p, o)
#define ttisnil(o)
#define rawuvalue(o)
void luaC_checkfinalizer(lua_State *L, GCObject *o, Table *mt)
#define luaC_objbarrierback(L, p, o)

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

◆ lua_settable()

LUA_API void lua_settable ( lua_State * L,
int idx )

Definition at line 747 of file lua-5.2.4/src/lapi.c.

747 {
748 StkId t;
749 lua_lock(L);
750 api_checknelems(L, 2);
751 t = index2addr(L, idx);
752 luaV_settable(L, t, L->top - 2, L->top - 1);
753 L->top -= 2; /* pop index and value */
754 lua_unlock(L);
755}

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

165 {
166 StkId func = L->ci->func;
167 lua_lock(L);
168 if (idx >= 0) {
169 api_check(L, idx <= L->stack_last - (func + 1), "new top too large");
170 while (L->top < (func + 1) + idx)
171 setnilvalue(L->top++);
172 L->top = (func + 1) + idx;
173 }
174 else {
175 api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top");
176 L->top += idx+1; /* `subtract' index (index is negative) */
177 }
178 lua_unlock(L);
179}

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

1227 {
1228 const char *name;
1229 TValue *val = NULL; /* to avoid warnings */
1230 GCObject *owner = NULL; /* to avoid warnings */
1231 StkId fi;
1232 lua_lock(L);
1233 fi = index2addr(L, funcindex);
1234 api_checknelems(L, 1);
1235 name = aux_upvalue(fi, n, &val, &owner);
1236 if (name) {
1237 L->top--;
1238 setobj(L, val, L->top);
1239 luaC_barrier(L, owner, L->top);
1240 }
1241 lua_unlock(L);
1242 return name;
1243}

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

◆ lua_setuservalue()

LUA_API void lua_setuservalue ( lua_State * L,
int idx )

Definition at line 852 of file lua-5.2.4/src/lapi.c.

852 {
853 StkId o;
854 lua_lock(L);
855 api_checknelems(L, 1);
856 o = index2addr(L, idx);
857 api_check(L, ttisuserdata(o), "userdata expected");
858 if (ttisnil(L->top - 1))
859 uvalue(o)->env = NULL;
860 else {
861 api_check(L, ttistable(L->top - 1), "table expected");
862 uvalue(o)->env = hvalue(L->top - 1);
863 luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
864 }
865 L->top--;
866 lua_unlock(L);
867}

References api_check, api_checknelems, gcvalue, hvalue, index2addr(), lua_lock, lua_unlock, luaC_objbarrier, NULL, lua_State::top, ttisnil, ttistable, ttisuserdata, and uvalue.

◆ lua_status()

LUA_API int lua_status ( lua_State * L)

Definition at line 1012 of file lua-5.2.4/src/lapi.c.

1012 {
1013 return L->status;
1014}

References lua_State::status.

◆ lua_toboolean()

LUA_API int lua_toboolean ( lua_State * L,
int idx )

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

383 {
384 const TValue *o = index2addr(L, idx);
385 return !l_isfalse(o);
386}
#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 418 of file lua-5.2.4/src/lapi.c.

418 {
419 StkId o = index2addr(L, idx);
420 if (ttislcf(o)) return fvalue(o);
421 else if (ttisCclosure(o))
422 return clCvalue(o)->f;
423 else return NULL; /* not a C function */
424}
#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 * isnum )

Definition at line 349 of file lua-5.2.4/src/lapi.c.

349 {
350 TValue n;
351 const TValue *o = index2addr(L, idx);
352 if (tonumber(o, &n)) {
353 lua_Integer res;
354 lua_Number num = nvalue(o);
355 lua_number2integer(res, num);
356 if (isnum) *isnum = 1;
357 return res;
358 }
359 else {
360 if (isnum) *isnum = 0;
361 return 0;
362 }
363}
LUA_INTEGER lua_Integer
#define lua_number2integer(i, d)

References index2addr(), lua_number2integer, nvalue, and tonumber.

Referenced by getfield(), getfield(), getfield(), luaL_checkinteger(), luaL_checkinteger(), luaL_len(), math_toint(), and math_toint().

◆ lua_tolstring()

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

Definition at line 389 of file lua-5.2.4/src/lapi.c.

389 {
390 StkId o = index2addr(L, idx);
391 if (!ttisstring(o)) {
392 lua_lock(L); /* `luaV_tostring' may create a new string */
393 if (!luaV_tostring(L, o)) { /* conversion failed? */
394 if (len != NULL) *len = 0;
395 lua_unlock(L);
396 return NULL;
397 }
398 luaC_checkGC(L);
399 o = index2addr(L, idx); /* previous call may reallocate the stack */
400 lua_unlock(L);
401 }
402 if (len != NULL) *len = tsvalue(o)->len;
403 return svalue(o);
404}
#define ttisstring(o)
#define svalue(o)
int luaV_tostring(lua_State *L, StkId obj)

References index2addr(), lua_lock, lua_unlock, luaC_checkGC, luaV_tostring(), NULL, svalue, tsvalue, and ttisstring.

◆ lua_tonumberx()

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

Definition at line 335 of file lua-5.2.4/src/lapi.c.

335 {
336 TValue n;
337 const TValue *o = index2addr(L, idx);
338 if (tonumber(o, &n)) {
339 if (isnum) *isnum = 1;
340 return nvalue(o);
341 }
342 else {
343 if (isnum) *isnum = 0;
344 return 0;
345 }
346}

References index2addr(), nvalue, and tonumber.

Referenced by luaB_tonumber(), luaL_checknumber(), and luaL_checknumber().

◆ lua_topointer()

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

Definition at line 443 of file lua-5.2.4/src/lapi.c.

443 {
444 StkId o = index2addr(L, idx);
445 switch (ttype(o)) {
446 case LUA_TTABLE: return hvalue(o);
447 case LUA_TLCL: return clLvalue(o);
448 case LUA_TCCL: return clCvalue(o);
449 case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));
450 case LUA_TTHREAD: return thvalue(o);
451 case LUA_TUSERDATA:
453 return lua_touserdata(L, idx);
454 default: return NULL;
455 }
456}
#define thvalue(o)
#define LUA_TTHREAD
#define LUA_TLIGHTUSERDATA
LUA_API void * lua_touserdata(lua_State *L, int idx)
#define LUA_TLCF

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

◆ lua_tothread()

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

Definition at line 437 of file lua-5.2.4/src/lapi.c.

437 {
438 StkId o = index2addr(L, idx);
439 return (!ttisthread(o)) ? NULL : thvalue(o);
440}
#define ttisthread(o)

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

◆ lua_tounsignedx()

LUA_API lua_Unsigned lua_tounsignedx ( lua_State * L,
int idx,
int * isnum )

Definition at line 366 of file lua-5.2.4/src/lapi.c.

366 {
367 TValue n;
368 const TValue *o = index2addr(L, idx);
369 if (tonumber(o, &n)) {
370 lua_Unsigned res;
371 lua_Number num = nvalue(o);
372 lua_number2unsigned(res, num);
373 if (isnum) *isnum = 1;
374 return res;
375 }
376 else {
377 if (isnum) *isnum = 0;
378 return 0;
379 }
380}
#define lua_number2unsigned(i, n)
LUA_UNSIGNED lua_Unsigned

References index2addr(), lua_number2unsigned, nvalue, and tonumber.

Referenced by luaL_checkunsigned().

◆ lua_touserdata()

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

Definition at line 427 of file lua-5.2.4/src/lapi.c.

427 {
428 StkId o = index2addr(L, idx);
429 switch (ttypenv(o)) {
430 case LUA_TUSERDATA: return (rawuvalue(o) + 1);
431 case LUA_TLIGHTUSERDATA: return pvalue(o);
432 default: return NULL;
433 }
434}
#define pvalue(o)

References index2addr(), LUA_TLIGHTUSERDATA, LUA_TUSERDATA, NULL, pvalue, rawuvalue, and ttypenv.

Referenced by lua_topointer().

◆ lua_type()

LUA_API int lua_type ( lua_State * L,
int idx )

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

249 {
250 StkId o = index2addr(L, idx);
251 return (isvalid(o) ? ttypenv(o) : LUA_TNONE);
252}
#define LUA_TNONE

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

Referenced by lua_isstring().

◆ lua_typename()

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

Definition at line 255 of file lua-5.2.4/src/lapi.c.

255 {
256 UNUSED(L);
257 return ttypename(t);
258}
#define UNUSED(x)
#define ttypename(x)

References ttypename, and UNUSED.

◆ lua_upvalueid()

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

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

1257 {
1258 StkId fi = index2addr(L, fidx);
1259 switch (ttype(fi)) {
1260 case LUA_TLCL: { /* lua closure */
1261 return *getupvalref(L, fidx, n, NULL);
1262 }
1263 case LUA_TCCL: { /* C closure */
1264 CClosure *f = clCvalue(fi);
1265 api_check(L, 1 <= n && n <= f->nupvalues, "invalid upvalue index");
1266 return &f->upvalue[n - 1];
1267 }
1268 default: {
1269 api_check(L, 0, "closure expected");
1270 return NULL;
1271 }
1272 }
1273}
static UpVal ** getupvalref(lua_State *L, int fidx, int n, LClosure **pf)

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

Referenced by checkupval(), db_upvalueid(), and db_upvalueid().

◆ lua_upvaluejoin()

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

Definition at line 1276 of file lua-5.2.4/src/lapi.c.

1277 {
1278 LClosure *f1;
1279 UpVal **up1 = getupvalref(L, fidx1, n1, &f1);
1280 UpVal **up2 = getupvalref(L, fidx2, n2, NULL);
1281 *up1 = *up2;
1282 luaC_objbarrier(L, f1, *up2);
1283}

References getupvalref(), luaC_objbarrier, and NULL.

Referenced by db_upvaluejoin(), db_upvaluejoin(), and db_upvaluejoin().

◆ lua_version()

LUA_API const lua_Number * lua_version ( lua_State * L)

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

137 {
138 static const lua_Number version = LUA_VERSION_NUM;
139 if (L == NULL) return &version;
140 else return G(L)->version;
141}
#define LUA_VERSION_NUM

References G, LUA_VERSION_NUM, and NULL.

Referenced by f_luaopen(), f_luaopen(), luaL_checkversion_(), and luaL_checkversion_().

◆ lua_xmove()

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

Definition at line 112 of file lua-5.2.4/src/lapi.c.

112 {
113 int i;
114 if (from == to) return;
115 lua_lock(to);
116 api_checknelems(from, n);
117 api_check(from, G(from) == G(to), "moving among independent states");
118 api_check(from, to->ci->top - to->top >= n, "not enough elements to move");
119 from->top -= n;
120 for (i = 0; i < n; i++) {
121 setobj2s(to, to->top++, from->top + i);
122 }
123 lua_unlock(to);
124}

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

◆ moveto()

static void moveto ( lua_State * L,
TValue * fr,
int idx )
static

Definition at line 206 of file lua-5.2.4/src/lapi.c.

206 {
207 TValue *to = index2addr(L, idx);
208 api_checkvalidindex(L, to);
209 setobj(L, to, fr);
210 if (idx < LUA_REGISTRYINDEX) /* function upvalue? */
211 luaC_barrier(L, clCvalue(L->ci->func), fr);
212 /* LUA_REGISTRYINDEX does not need gc barrier
213 (collector revisits it before finishing collection) */
214}
#define api_checkvalidindex(L, o)

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

Referenced by lua_copy(), and lua_replace().

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