Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lua.h File Reference
#include <stdarg.h>
#include <stddef.h>
#include "luaconf.h"

Go to the source code of this file.

Data Structures

struct  lua_Debug
 

Macros

#define LUA_VERSION_MAJOR   "5"
 
#define LUA_VERSION_MINOR   "2"
 
#define LUA_VERSION_NUM   502
 
#define LUA_VERSION_RELEASE   "4"
 
#define LUA_VERSION   "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
 
#define LUA_RELEASE   LUA_VERSION "." LUA_VERSION_RELEASE
 
#define LUA_COPYRIGHT   LUA_RELEASE " Copyright (C) 1994-2015 Lua.org, PUC-Rio"
 
#define LUA_AUTHORS   "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
 
#define LUA_SIGNATURE   "\033Lua"
 
#define LUA_MULTRET   (-1)
 
#define LUA_REGISTRYINDEX   LUAI_FIRSTPSEUDOIDX
 
#define lua_upvalueindex(i)   (LUA_REGISTRYINDEX - (i))
 
#define LUA_OK   0
 
#define LUA_YIELD   1
 
#define LUA_ERRRUN   2
 
#define LUA_ERRSYNTAX   3
 
#define LUA_ERRMEM   4
 
#define LUA_ERRGCMM   5
 
#define LUA_ERRERR   6
 
#define LUA_TNONE   (-1)
 
#define LUA_TNIL   0
 
#define LUA_TBOOLEAN   1
 
#define LUA_TLIGHTUSERDATA   2
 
#define LUA_TNUMBER   3
 
#define LUA_TSTRING   4
 
#define LUA_TTABLE   5
 
#define LUA_TFUNCTION   6
 
#define LUA_TUSERDATA   7
 
#define LUA_TTHREAD   8
 
#define LUA_NUMTAGS   9
 
#define LUA_MINSTACK   20
 
#define LUA_RIDX_MAINTHREAD   1
 
#define LUA_RIDX_GLOBALS   2
 
#define LUA_RIDX_LAST   LUA_RIDX_GLOBALS
 
#define LUA_OPADD   0 /* ORDER TM */
 
#define LUA_OPSUB   1
 
#define LUA_OPMUL   2
 
#define LUA_OPDIV   3
 
#define LUA_OPMOD   4
 
#define LUA_OPPOW   5
 
#define LUA_OPUNM   6
 
#define LUA_OPEQ   0
 
#define LUA_OPLT   1
 
#define LUA_OPLE   2
 
#define lua_call(L, n, r)   lua_callk(L, (n), (r), 0, NULL)
 
#define lua_pcall(L, n, r, f)   lua_pcallk(L, (n), (r), (f), 0, NULL)
 
#define lua_yield(L, n)   lua_yieldk(L, (n), 0, NULL)
 
#define LUA_GCSTOP   0
 
#define LUA_GCRESTART   1
 
#define LUA_GCCOLLECT   2
 
#define LUA_GCCOUNT   3
 
#define LUA_GCCOUNTB   4
 
#define LUA_GCSTEP   5
 
#define LUA_GCSETPAUSE   6
 
#define LUA_GCSETSTEPMUL   7
 
#define LUA_GCSETMAJORINC   8
 
#define LUA_GCISRUNNING   9
 
#define LUA_GCGEN   10
 
#define LUA_GCINC   11
 
#define lua_tonumber(L, i)   lua_tonumberx(L,i,NULL)
 
#define lua_tointeger(L, i)   lua_tointegerx(L,i,NULL)
 
#define lua_tounsigned(L, i)   lua_tounsignedx(L,i,NULL)
 
#define lua_pop(L, n)   lua_settop(L, -(n)-1)
 
#define lua_newtable(L)   lua_createtable(L, 0, 0)
 
#define lua_register(L, n, f)   (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
 
#define lua_pushcfunction(L, f)   lua_pushcclosure(L, (f), 0)
 
#define lua_isfunction(L, n)   (lua_type(L, (n)) == LUA_TFUNCTION)
 
#define lua_istable(L, n)   (lua_type(L, (n)) == LUA_TTABLE)
 
#define lua_islightuserdata(L, n)   (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
 
#define lua_isnil(L, n)   (lua_type(L, (n)) == LUA_TNIL)
 
#define lua_isboolean(L, n)   (lua_type(L, (n)) == LUA_TBOOLEAN)
 
#define lua_isthread(L, n)   (lua_type(L, (n)) == LUA_TTHREAD)
 
#define lua_isnone(L, n)   (lua_type(L, (n)) == LUA_TNONE)
 
#define lua_isnoneornil(L, n)   (lua_type(L, (n)) <= 0)
 
#define lua_pushliteral(L, s)    lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
 
#define lua_pushglobaltable(L)    lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
 
#define lua_tostring(L, i)   lua_tolstring(L, (i), NULL)
 
#define LUA_HOOKCALL   0
 
#define LUA_HOOKRET   1
 
#define LUA_HOOKLINE   2
 
#define LUA_HOOKCOUNT   3
 
#define LUA_HOOKTAILCALL   4
 
#define LUA_MASKCALL   (1 << LUA_HOOKCALL)
 
#define LUA_MASKRET   (1 << LUA_HOOKRET)
 
#define LUA_MASKLINE   (1 << LUA_HOOKLINE)
 
#define LUA_MASKCOUNT   (1 << LUA_HOOKCOUNT)
 

Typedefs

typedef struct lua_State lua_State
 
typedef int(* lua_CFunction) (lua_State *L)
 
typedef const char *(* lua_Reader) (lua_State *L, void *ud, size_t *sz)
 
typedef int(* lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud)
 
typedef void *(* lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize)
 
typedef LUA_NUMBER lua_Number
 
typedef LUA_INTEGER lua_Integer
 
typedef LUA_UNSIGNED lua_Unsigned
 
typedef struct lua_Debug lua_Debug
 
typedef void(* lua_Hook) (lua_State *L, lua_Debug *ar)
 

Functions

LUA_API lua_Statelua_newstate (lua_Alloc f, void *ud)
 
LUA_API void lua_close (lua_State *L)
 
LUA_API lua_Statelua_newthread (lua_State *L)
 
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_pushvalue (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)
 
LUA_API void lua_replace (lua_State *L, int idx)
 
LUA_API void lua_copy (lua_State *L, int fromidx, int toidx)
 
LUA_API int lua_checkstack (lua_State *L, int sz)
 
LUA_API void lua_xmove (lua_State *from, lua_State *to, int n)
 
LUA_API int lua_isnumber (lua_State *L, int idx)
 
LUA_API int lua_isstring (lua_State *L, int idx)
 
LUA_API int lua_iscfunction (lua_State *L, int idx)
 
LUA_API int lua_isuserdata (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 tp)
 
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_arith (lua_State *L, int op)
 
LUA_API int lua_rawequal (lua_State *L, int idx1, int idx2)
 
LUA_API int lua_compare (lua_State *L, int idx1, int idx2, int op)
 
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 n)
 
LUA_API const char * lua_pushlstring (lua_State *L, const char *s, size_t l)
 
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 narr, int nrec)
 
LUA_API void * lua_newuserdata (lua_State *L, size_t sz)
 
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 void lua_callk (lua_State *L, int nargs, int nresults, int ctx, lua_CFunction k)
 
LUA_API int lua_getctx (lua_State *L, int *ctx)
 
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 *dt, const char *chunkname, const char *mode)
 
LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data)
 
LUA_API int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k)
 
LUA_API int lua_resume (lua_State *L, lua_State *from, int narg)
 
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 int lua_getstack (lua_State *L, int level, lua_Debug *ar)
 
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar)
 
LUA_API const char * lua_getlocal (lua_State *L, const lua_Debug *ar, int n)
 
LUA_API const char * lua_setlocal (lua_State *L, const lua_Debug *ar, int n)
 
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)
 
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)
 
LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count)
 
LUA_API lua_Hook lua_gethook (lua_State *L)
 
LUA_API int lua_gethookmask (lua_State *L)
 
LUA_API int lua_gethookcount (lua_State *L)
 

Variables

const char lua_ident []
 

Macro Definition Documentation

◆ LUA_AUTHORS

#define LUA_AUTHORS   "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"

Definition at line 27 of file lua-5.2.4/src/lua.h.

◆ lua_call

◆ LUA_COPYRIGHT

#define LUA_COPYRIGHT   LUA_RELEASE " Copyright (C) 1994-2015 Lua.org, PUC-Rio"

Definition at line 26 of file lua-5.2.4/src/lua.h.

◆ LUA_ERRERR

#define LUA_ERRERR   6

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

◆ LUA_ERRGCMM

#define LUA_ERRGCMM   5

Definition at line 50 of file lua-5.2.4/src/lua.h.

Referenced by GCTM(), and GCTM().

◆ LUA_ERRMEM

#define LUA_ERRMEM   4

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

◆ LUA_ERRRUN

#define LUA_ERRRUN   2

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

◆ LUA_ERRSYNTAX

#define LUA_ERRSYNTAX   3

Definition at line 48 of file lua-5.2.4/src/lua.h.

◆ LUA_GCCOLLECT

#define LUA_GCCOLLECT   2

Definition at line 283 of file lua-5.2.4/src/lua.h.

◆ LUA_GCCOUNT

#define LUA_GCCOUNT   3

Definition at line 284 of file lua-5.2.4/src/lua.h.

◆ LUA_GCCOUNTB

#define LUA_GCCOUNTB   4

Definition at line 285 of file lua-5.2.4/src/lua.h.

◆ LUA_GCGEN

#define LUA_GCGEN   10

Definition at line 291 of file lua-5.2.4/src/lua.h.

Referenced by lua_gc(), lua_gc(), luaB_collectgarbage(), luaB_collectgarbage(), and pmain().

◆ LUA_GCINC

#define LUA_GCINC   11

◆ LUA_GCISRUNNING

#define LUA_GCISRUNNING   9

◆ LUA_GCRESTART

#define LUA_GCRESTART   1

Definition at line 282 of file lua-5.2.4/src/lua.h.

◆ LUA_GCSETMAJORINC

#define LUA_GCSETMAJORINC   8

Definition at line 289 of file lua-5.2.4/src/lua.h.

Referenced by lua_gc(), and luaB_collectgarbage().

◆ LUA_GCSETPAUSE

#define LUA_GCSETPAUSE   6

Definition at line 287 of file lua-5.2.4/src/lua.h.

◆ LUA_GCSETSTEPMUL

#define LUA_GCSETSTEPMUL   7

Definition at line 288 of file lua-5.2.4/src/lua.h.

◆ LUA_GCSTEP

#define LUA_GCSTEP   5

Definition at line 286 of file lua-5.2.4/src/lua.h.

◆ LUA_GCSTOP

#define LUA_GCSTOP   0

Definition at line 281 of file lua-5.2.4/src/lua.h.

◆ LUA_HOOKCALL

#define LUA_HOOKCALL   0

Definition at line 360 of file lua-5.2.4/src/lua.h.

◆ LUA_HOOKCOUNT

#define LUA_HOOKCOUNT   3

Definition at line 363 of file lua-5.2.4/src/lua.h.

◆ LUA_HOOKLINE

#define LUA_HOOKLINE   2

Definition at line 362 of file lua-5.2.4/src/lua.h.

◆ LUA_HOOKRET

#define LUA_HOOKRET   1

Definition at line 361 of file lua-5.2.4/src/lua.h.

◆ LUA_HOOKTAILCALL

#define LUA_HOOKTAILCALL   4

Definition at line 364 of file lua-5.2.4/src/lua.h.

Referenced by callhook(), callhook(), and luaD_hookcall().

◆ lua_isboolean

#define lua_isboolean ( L,
n )   (lua_type(L, (n)) == LUA_TBOOLEAN)

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

◆ lua_isfunction

#define lua_isfunction ( L,
n )   (lua_type(L, (n)) == LUA_TFUNCTION)

Definition at line 331 of file lua-5.2.4/src/lua.h.

◆ lua_islightuserdata

#define lua_islightuserdata ( L,
n )   (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)

Definition at line 333 of file lua-5.2.4/src/lua.h.

◆ lua_isnil

#define lua_isnil ( L,
n )   (lua_type(L, (n)) == LUA_TNIL)

Definition at line 334 of file lua-5.2.4/src/lua.h.

◆ lua_isnone

#define lua_isnone ( L,
n )   (lua_type(L, (n)) == LUA_TNONE)

Definition at line 337 of file lua-5.2.4/src/lua.h.

◆ lua_isnoneornil

#define lua_isnoneornil ( L,
n )   (lua_type(L, (n)) <= 0)

Definition at line 338 of file lua-5.2.4/src/lua.h.

◆ lua_istable

#define lua_istable ( L,
n )   (lua_type(L, (n)) == LUA_TTABLE)

Definition at line 332 of file lua-5.2.4/src/lua.h.

◆ lua_isthread

#define lua_isthread ( L,
n )   (lua_type(L, (n)) == LUA_TTHREAD)

Definition at line 336 of file lua-5.2.4/src/lua.h.

◆ LUA_MASKCALL

#define LUA_MASKCALL   (1 << LUA_HOOKCALL)

Definition at line 370 of file lua-5.2.4/src/lua.h.

◆ LUA_MASKCOUNT

#define LUA_MASKCOUNT   (1 << LUA_HOOKCOUNT)

Definition at line 373 of file lua-5.2.4/src/lua.h.

◆ LUA_MASKLINE

#define LUA_MASKLINE   (1 << LUA_HOOKLINE)

Definition at line 372 of file lua-5.2.4/src/lua.h.

◆ LUA_MASKRET

#define LUA_MASKRET   (1 << LUA_HOOKRET)

Definition at line 371 of file lua-5.2.4/src/lua.h.

◆ LUA_MINSTACK

#define LUA_MINSTACK   20

Definition at line 93 of file lua-5.2.4/src/lua.h.

◆ LUA_MULTRET

#define LUA_MULTRET   (-1)

Definition at line 34 of file lua-5.2.4/src/lua.h.

◆ lua_newtable

#define lua_newtable ( L)    lua_createtable(L, 0, 0)

Definition at line 325 of file lua-5.2.4/src/lua.h.

◆ LUA_NUMTAGS

#define LUA_NUMTAGS   9

Definition at line 88 of file lua-5.2.4/src/lua.h.

Referenced by lua_newstate(), lua_typename(), markmt(), markmt(), and markmt().

◆ LUA_OK

◆ LUA_OPADD

#define LUA_OPADD   0 /* ORDER TM */

◆ LUA_OPDIV

#define LUA_OPDIV   3

◆ LUA_OPEQ

#define LUA_OPEQ   0

Definition at line 194 of file lua-5.2.4/src/lua.h.

Referenced by lua_compare(), tmove(), and tmove().

◆ LUA_OPLE

#define LUA_OPLE   2

Definition at line 196 of file lua-5.2.4/src/lua.h.

Referenced by lua_compare().

◆ LUA_OPLT

#define LUA_OPLT   1

◆ LUA_OPMOD

#define LUA_OPMOD   4

◆ LUA_OPMUL

#define LUA_OPMUL   2

Definition at line 186 of file lua-5.2.4/src/lua.h.

Referenced by arith_mul(), intarith(), intarith(), luaO_arith(), numarith(), and numarith().

◆ LUA_OPPOW

#define LUA_OPPOW   5

◆ LUA_OPSUB

#define LUA_OPSUB   1

Definition at line 185 of file lua-5.2.4/src/lua.h.

Referenced by arith_sub(), intarith(), intarith(), luaO_arith(), numarith(), and numarith().

◆ LUA_OPUNM

#define LUA_OPUNM   6

◆ lua_pcall

◆ lua_pop

#define lua_pop ( L,
n )   lua_settop(L, -(n)-1)

Definition at line 323 of file lua-5.2.4/src/lua.h.

◆ lua_pushcfunction

#define lua_pushcfunction ( L,
f )   lua_pushcclosure(L, (f), 0)

Definition at line 329 of file lua-5.2.4/src/lua.h.

◆ lua_pushglobaltable

#define lua_pushglobaltable ( L)     lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)

Definition at line 343 of file lua-5.2.4/src/lua.h.

343#define lua_pushglobaltable(L) \
344 lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)

Referenced by luaopen_base(), luaopen_package(), and pushglobalfuncname().

◆ lua_pushliteral

#define lua_pushliteral ( L,
s )    lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)

Definition at line 340 of file lua-5.2.4/src/lua.h.

340#define lua_pushliteral(L, s) \
341 lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)

◆ lua_register

#define lua_register ( L,
n,
f )   (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))

Definition at line 327 of file lua-5.2.4/src/lua.h.

◆ LUA_REGISTRYINDEX

#define LUA_REGISTRYINDEX   LUAI_FIRSTPSEUDOIDX

Definition at line 40 of file lua-5.2.4/src/lua.h.

◆ LUA_RELEASE

#define LUA_RELEASE   LUA_VERSION "." LUA_VERSION_RELEASE

Definition at line 25 of file lua-5.2.4/src/lua.h.

◆ LUA_RIDX_GLOBALS

#define LUA_RIDX_GLOBALS   2

◆ LUA_RIDX_LAST

#define LUA_RIDX_LAST   LUA_RIDX_GLOBALS

Definition at line 99 of file lua-5.2.4/src/lua.h.

Referenced by init_registry(), init_registry(), and init_registry().

◆ LUA_RIDX_MAINTHREAD

#define LUA_RIDX_MAINTHREAD   1

Definition at line 97 of file lua-5.2.4/src/lua.h.

Referenced by init_registry(), init_registry(), and init_registry().

◆ LUA_SIGNATURE

#define LUA_SIGNATURE   "\033Lua"

Definition at line 31 of file lua-5.2.4/src/lua.h.

◆ LUA_TBOOLEAN

#define LUA_TBOOLEAN   1

Definition at line 79 of file lua-5.2.4/src/lua.h.

◆ LUA_TFUNCTION

#define LUA_TFUNCTION   6

Definition at line 84 of file lua-5.2.4/src/lua.h.

◆ LUA_TLIGHTUSERDATA

#define LUA_TLIGHTUSERDATA   2

Definition at line 80 of file lua-5.2.4/src/lua.h.

◆ LUA_TNIL

#define LUA_TNIL   0

Definition at line 78 of file lua-5.2.4/src/lua.h.

◆ LUA_TNONE

#define LUA_TNONE   (-1)

Definition at line 76 of file lua-5.2.4/src/lua.h.

◆ LUA_TNUMBER

#define LUA_TNUMBER   3

Definition at line 81 of file lua-5.2.4/src/lua.h.

◆ lua_tointeger

◆ lua_tonumber

◆ lua_tostring

#define lua_tostring ( L,
i )   lua_tolstring(L, (i), NULL)

Definition at line 346 of file lua-5.2.4/src/lua.h.

◆ lua_tounsigned

#define lua_tounsigned ( L,
i )   lua_tounsignedx(L,i,NULL)

Definition at line 321 of file lua-5.2.4/src/lua.h.

Referenced by luaL_checkversion_().

◆ LUA_TSTRING

#define LUA_TSTRING   4

Definition at line 82 of file lua-5.2.4/src/lua.h.

◆ LUA_TTABLE

#define LUA_TTABLE   5

Definition at line 83 of file lua-5.2.4/src/lua.h.

◆ LUA_TTHREAD

#define LUA_TTHREAD   8

Definition at line 86 of file lua-5.2.4/src/lua.h.

◆ LUA_TUSERDATA

#define LUA_TUSERDATA   7

Definition at line 85 of file lua-5.2.4/src/lua.h.

◆ lua_upvalueindex

#define lua_upvalueindex ( i)    (LUA_REGISTRYINDEX - (i))

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

◆ LUA_VERSION

#define LUA_VERSION   "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR

Definition at line 24 of file lua-5.2.4/src/lua.h.

◆ LUA_VERSION_MAJOR

#define LUA_VERSION_MAJOR   "5"

Definition at line 19 of file lua-5.2.4/src/lua.h.

◆ LUA_VERSION_MINOR

#define LUA_VERSION_MINOR   "2"

Definition at line 20 of file lua-5.2.4/src/lua.h.

◆ LUA_VERSION_NUM

#define LUA_VERSION_NUM   502

Definition at line 21 of file lua-5.2.4/src/lua.h.

◆ LUA_VERSION_RELEASE

#define LUA_VERSION_RELEASE   "4"

Definition at line 22 of file lua-5.2.4/src/lua.h.

◆ LUA_YIELD

#define LUA_YIELD   1

Definition at line 46 of file lua-5.2.4/src/lua.h.

◆ lua_yield

#define lua_yield ( L,
n )   lua_yieldk(L, (n), 0, NULL)

Definition at line 273 of file lua-5.2.4/src/lua.h.

Referenced by luaB_yield(), luaB_yield(), luaB_yield(), and luaB_yield().

Typedef Documentation

◆ lua_Alloc

typedef void *(* lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize)

Definition at line 70 of file lua-5.2.4/src/lua.h.

◆ lua_CFunction

typedef int(* lua_CFunction) (lua_State *L)

Definition at line 56 of file lua-5.2.4/src/lua.h.

◆ lua_Debug

typedef struct lua_Debug lua_Debug

Definition at line 375 of file lua-5.2.4/src/lua.h.

◆ lua_Hook

typedef void(* lua_Hook) (lua_State *L, lua_Debug *ar)

Definition at line 379 of file lua-5.2.4/src/lua.h.

◆ lua_Integer

Definition at line 107 of file lua-5.2.4/src/lua.h.

◆ lua_Number

Definition at line 103 of file lua-5.2.4/src/lua.h.

◆ lua_Reader

typedef const char *(* lua_Reader) (lua_State *L, void *ud, size_t *sz)

Definition at line 62 of file lua-5.2.4/src/lua.h.

◆ lua_State

typedef struct lua_State lua_State

Definition at line 54 of file lua-5.2.4/src/lua.h.

◆ lua_Unsigned

Definition at line 110 of file lua-5.2.4/src/lua.h.

◆ lua_Writer

typedef int(* lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud)

Definition at line 64 of file lua-5.2.4/src/lua.h.

Function Documentation

◆ 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)
#define ispseudo(i)

◆ 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 cast(t, exp)
#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)

◆ lua_atpanic()

LUA_API lua_CFunction lua_atpanic ( lua_State * L,
lua_CFunction panicf )

Definition at line 130 of file lua-5.1.5/src/lapi.c.

130 {
131 lua_CFunction old;
132 lua_lock(L);
133 old = G(L)->panic;
134 G(L)->panic = panicf;
135 lua_unlock(L);
136 return old;
137}
#define G(L)
int(* lua_CFunction)(lua_State *L)

◆ 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 NULL
Definition gmacros.h:924
#define adjustresults(L, nres)
void luaD_call(lua_State *L, StkId func, int nResults)
#define api_check
#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 sz )

Definition at line 95 of file lua-5.1.5/src/lapi.c.

95 {
96 int res = 1;
97 lua_lock(L);
98 if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK)
99 res = 0; /* stack overflow */
100 else if (size > 0) {
101 luaD_checkstack(L, size);
102 if (L->ci->top < L->top + size)
103 L->ci->top = L->top + size;
104 }
105 lua_unlock(L);
106 return res;
107}
#define luaD_checkstack(L, n)
#define LUAI_MAXCSTACK

◆ lua_close()

LUA_API void lua_close ( lua_State * L)

Definition at line 199 of file lua-5.1.5/src/lstate.c.

199 {
200 L = G(L)->mainthread; /* only the main thread can be closed */
201 lua_lock(L);
202 luaF_close(L, L->stack); /* close all upvalues for this thread */
203 luaC_separateudata(L, 1); /* separate udata that have GC metamethods */
204 L->errfunc = 0; /* no error function during GC metamethods */
205 do { /* repeat until no more errors */
206 L->ci = L->base_ci;
207 L->base = L->top = L->ci->base;
208 L->nCcalls = L->baseCcalls = 0;
209 } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
210 lua_assert(G(L)->tmudata == NULL);
212 close_state(L);
213}
int luaD_rawrunprotected(lua_State *L, Pfunc f, void *ud)
void luaF_close(lua_State *L, StkId level)
size_t luaC_separateudata(lua_State *L, int all)
#define lua_assert(c)
static void close_state(lua_State *L)
static void callallgcTM(lua_State *L, void *ud)
#define luai_userstateclose(L)
unsigned short nCcalls
unsigned short baseCcalls

◆ lua_compare()

LUA_API int lua_compare ( lua_State * L,
int idx1,
int idx2,
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)
static TValue * index2addr(lua_State *L, int idx)
#define LUA_OPLT
#define LUA_OPLE
#define LUA_OPEQ
int luaV_lessequal(lua_State *L, const TValue *l, const TValue *r)

◆ lua_concat()

LUA_API void lua_concat ( lua_State * L,
int n )

Definition at line 990 of file lua-5.1.5/src/lapi.c.

990 {
991 lua_lock(L);
992 api_checknelems(L, n);
993 if (n >= 2) {
994 luaC_checkGC(L);
995 luaV_concat(L, n, cast_int(L->top - L->base) - 1);
996 L->top -= (n-1);
997 }
998 else if (n == 0) { /* push empty string */
999 setsvalue2s(L, L->top, luaS_newlstr(L, "", 0));
1000 api_incr_top(L);
1001 }
1002 /* else n == 1; nothing to do */
1003 lua_unlock(L);
1004}
#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)

◆ 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)

◆ lua_createtable()

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

Definition at line 578 of file lua-5.1.5/src/lapi.c.

578 {
579 lua_lock(L);
580 luaC_checkGC(L);
581 sethvalue(L, L->top, luaH_new(L, narray, nrec));
582 api_incr_top(L);
583 lua_unlock(L);
584}
#define sethvalue(L, obj, x)
Table * luaH_new(lua_State *L, int narray, int nhash)

◆ lua_dump()

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

Definition at line 875 of file lua-5.1.5/src/lapi.c.

875 {
876 int status;
877 TValue *o;
878 lua_lock(L);
879 api_checknelems(L, 1);
880 o = L->top - 1;
881 if (isLfunction(o))
882 status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0);
883 else
884 status = 1;
885 lua_unlock(L);
886 return status;
887}
int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, int strip)
#define clvalue(o)
#define isLfunction(o)
static int writer(lua_State *L, const void *b, size_t size, void *B)

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

Referenced by str_dump(), str_dump(), str_dump(), and str_dump().

◆ lua_error()

LUA_API int lua_error ( lua_State * L)

Definition at line 964 of file lua-5.1.5/src/lapi.c.

964 {
965 lua_lock(L);
966 api_checknelems(L, 1);
967 luaG_errormsg(L);
968 lua_unlock(L);
969 return 0; /* to avoid warnings */
970}
void luaG_errormsg(lua_State *L)

◆ lua_gc()

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

Definition at line 899 of file lua-5.1.5/src/lapi.c.

899 {
900 int res = 0;
901 global_State *g;
902 lua_lock(L);
903 g = G(L);
904 switch (what) {
905 case LUA_GCSTOP: {
907 break;
908 }
909 case LUA_GCRESTART: {
910 g->GCthreshold = g->totalbytes;
911 break;
912 }
913 case LUA_GCCOLLECT: {
914 luaC_fullgc(L);
915 break;
916 }
917 case LUA_GCCOUNT: {
918 /* GC values are expressed in Kbytes: #bytes/2^10 */
919 res = cast_int(g->totalbytes >> 10);
920 break;
921 }
922 case LUA_GCCOUNTB: {
923 res = cast_int(g->totalbytes & 0x3ff);
924 break;
925 }
926 case LUA_GCSTEP: {
927 lu_mem a = (cast(lu_mem, data) << 10);
928 if (a <= g->totalbytes)
929 g->GCthreshold = g->totalbytes - a;
930 else
931 g->GCthreshold = 0;
932 while (g->GCthreshold <= g->totalbytes) {
933 luaC_step(L);
934 if (g->gcstate == GCSpause) { /* end of cycle? */
935 res = 1; /* signal it */
936 break;
937 }
938 }
939 break;
940 }
941 case LUA_GCSETPAUSE: {
942 res = g->gcpause;
943 g->gcpause = data;
944 break;
945 }
946 case LUA_GCSETSTEPMUL: {
947 res = g->gcstepmul;
948 g->gcstepmul = data;
949 break;
950 }
951 default: res = -1; /* invalid option */
952 }
953 lua_unlock(L);
954 return res;
955}
void luaC_fullgc(lua_State *L)
void luaC_step(lua_State *L)
#define GCSpause
LUAI_UMEM lu_mem
#define MAX_LUMEM
#define LUA_GCSETPAUSE
#define LUA_GCCOUNT
#define LUA_GCCOLLECT
#define LUA_GCSTOP
#define LUA_GCRESTART
#define LUA_GCCOUNTB
#define LUA_GCSTEP
#define LUA_GCSETSTEPMUL

◆ lua_getallocf()

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

Definition at line 1007 of file lua-5.1.5/src/lapi.c.

1007 {
1008 lua_Alloc f;
1009 lua_lock(L);
1010 if (ud) *ud = G(L)->ud;
1011 f = G(L)->frealloc;
1012 lua_unlock(L);
1013 return f;
1014}
void *(* lua_Alloc)(void *ud, void *ptr, size_t osize, size_t nsize)

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

544 {
545 StkId t;
546 TValue key;
547 lua_lock(L);
548 t = index2adr(L, idx);
550 setsvalue(L, &key, luaS_new(L, k));
551 luaV_gettable(L, t, &key, L->top);
552 api_incr_top(L);
553 lua_unlock(L);
554}
#define api_checkvalidindex(L, i)
static TValue * index2adr(lua_State *L, int idx)
#define setsvalue(L, obj, x)
#define luaS_new(L, s)
#define luaV_gettable(L, t, k, v)

◆ 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

◆ lua_gethook()

LUA_API lua_Hook lua_gethook ( lua_State * L)

Definition at line 69 of file lua-5.1.5/src/ldebug.c.

69 {
70 return L->hook;
71}

◆ lua_gethookcount()

LUA_API int lua_gethookcount ( lua_State * L)

Definition at line 79 of file lua-5.1.5/src/ldebug.c.

79 {
80 return L->basehookcount;
81}

◆ lua_gethookmask()

LUA_API int lua_gethookmask ( lua_State * L)

Definition at line 74 of file lua-5.1.5/src/ldebug.c.

74 {
75 return L->hookmask;
76}

◆ lua_getinfo()

LUA_API int lua_getinfo ( lua_State * L,
const char * what,
lua_Debug * ar )

Definition at line 232 of file lua-5.1.5/src/ldebug.c.

232 {
233 int status;
234 Closure *f = NULL;
235 CallInfo *ci = NULL;
236 lua_lock(L);
237 if (*what == '>') {
238 StkId func = L->top - 1;
239 luai_apicheck(L, ttisfunction(func));
240 what++; /* skip the '>' */
241 f = clvalue(func);
242 L->top--; /* pop function */
243 }
244 else if (ar->i_ci != 0) { /* no tail call? */
245 ci = L->base_ci + ar->i_ci;
247 f = clvalue(ci->func);
248 }
249 status = auxgetinfo(L, what, ar, f, ci);
250 if (strchr(what, 'f')) {
251 if (f == NULL) setnilvalue(L->top);
252 else setclvalue(L, L->top, f);
253 incr_top(L);
254 }
255 if (strchr(what, 'L'))
256 collectvalidlines(L, f);
257 lua_unlock(L);
258 return status;
259}
static void collectvalidlines(lua_State *L, Closure *f)
static int auxgetinfo(lua_State *L, const char *what, lua_Debug *ar, Closure *f, CallInfo *ci)
#define incr_top(L)
#define ttisfunction(o)
#define setclvalue(L, obj, x)
#define setnilvalue(obj)
#define luai_apicheck(L, o)

◆ lua_getlocal()

LUA_API const char * lua_getlocal ( lua_State * L,
const lua_Debug * ar,
int n )

Definition at line 127 of file lua-5.1.5/src/ldebug.c.

127 {
128 CallInfo *ci = L->base_ci + ar->i_ci;
129 const char *name = findlocal(L, ci, n);
130 lua_lock(L);
131 if (name)
132 luaA_pushobject(L, ci->base + (n - 1));
133 lua_unlock(L);
134 return name;
135}
const char * name
Definition lsqlite3.c:2154
void luaA_pushobject(lua_State *L, const TValue *o)
static const char * findlocal(lua_State *L, CallInfo *ci, int n)

◆ lua_getmetatable()

LUA_API int lua_getmetatable ( lua_State * L,
int objindex )

Definition at line 587 of file lua-5.1.5/src/lapi.c.

587 {
588 const TValue *obj;
589 Table *mt = NULL;
590 int res;
591 lua_lock(L);
592 obj = index2adr(L, objindex);
593 switch (ttype(obj)) {
594 case LUA_TTABLE:
595 mt = hvalue(obj)->metatable;
596 break;
597 case LUA_TUSERDATA:
598 mt = uvalue(obj)->metatable;
599 break;
600 default:
601 mt = G(L)->mt[ttype(obj)];
602 break;
603 }
604 if (mt == NULL)
605 res = 0;
606 else {
607 sethvalue(L, L->top, mt);
608 api_incr_top(L);
609 res = 1;
610 }
611 lua_unlock(L);
612 return res;
613}
#define uvalue(o)
#define ttype(o)
#define LUA_TTABLE
#define LUA_TUSERDATA
struct Table * metatable

◆ lua_getstack()

LUA_API int lua_getstack ( lua_State * L,
int level,
lua_Debug * ar )

Definition at line 84 of file lua-5.1.5/src/ldebug.c.

84 {
85 int status;
86 CallInfo *ci;
87 lua_lock(L);
88 for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) {
89 level--;
90 if (f_isLua(ci)) /* Lua function? */
91 level -= ci->tailcalls; /* skip lost tail calls */
92 }
93 if (level == 0 && ci > L->base_ci) { /* level found? */
94 status = 1;
95 ar->i_ci = cast_int(ci - L->base_ci);
96 }
97 else if (level < 0) { /* level is of a lost tail call? */
98 status = 1;
99 ar->i_ci = 0;
100 }
101 else status = 0; /* no such level */
102 lua_unlock(L);
103 return status;
104}
#define f_isLua(ci)

◆ lua_gettable()

LUA_API void lua_gettable ( lua_State * L,
int idx )

Definition at line 534 of file lua-5.1.5/src/lapi.c.

534 {
535 StkId t;
536 lua_lock(L);
537 t = index2adr(L, idx);
539 luaV_gettable(L, t, L->top - 1, L->top - 1);
540 lua_unlock(L);
541}

◆ lua_gettop()

LUA_API int lua_gettop ( lua_State * L)

Definition at line 159 of file lua-5.1.5/src/lapi.c.

159 {
160 return cast_int(L->top - L->base);
161}

◆ lua_getupvalue()

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

Definition at line 1057 of file lua-5.1.5/src/lapi.c.

1057 {
1058 const char *name;
1059 TValue *val;
1060 lua_lock(L);
1061 name = aux_upvalue(index2adr(L, funcindex), n, &val);
1062 if (name) {
1063 setobj2s(L, L->top, val);
1064 api_incr_top(L);
1065 }
1066 lua_unlock(L);
1067 return name;
1068}
static const char * aux_upvalue(StkId fi, int n, TValue **val)
#define setobj2s

◆ 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 ttisuserdata(o)

◆ lua_insert()

LUA_API void lua_insert ( lua_State * L,
int idx )

Definition at line 191 of file lua-5.1.5/src/lapi.c.

191 {
192 StkId p;
193 StkId q;
194 lua_lock(L);
195 p = index2adr(L, idx);
197 for (q = L->top; q>p; q--) setobjs2s(L, q, q-1);
198 setobjs2s(L, p, L->top);
199 lua_unlock(L);
200}

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

◆ lua_iscfunction()

LUA_API int lua_iscfunction ( lua_State * L,
int idx )

Definition at line 254 of file lua-5.1.5/src/lapi.c.

254 {
255 StkId o = index2adr(L, idx);
256 return iscfunction(o);
257}
#define iscfunction(o)

◆ lua_isnumber()

LUA_API int lua_isnumber ( lua_State * L,
int idx )

Definition at line 260 of file lua-5.1.5/src/lapi.c.

260 {
261 TValue n;
262 const TValue *o = index2adr(L, idx);
263 return tonumber(o, &n);
264}
#define tonumber(o, n)

◆ lua_isstring()

LUA_API int lua_isstring ( lua_State * L,
int idx )

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

267 {
268 int t = lua_type(L, idx);
269 return (t == LUA_TSTRING || t == LUA_TNUMBER);
270}
LUA_API int lua_type(lua_State *L, int idx)
#define LUA_TSTRING
#define LUA_TNUMBER

◆ lua_isuserdata()

LUA_API int lua_isuserdata ( lua_State * L,
int idx )

Definition at line 273 of file lua-5.1.5/src/lapi.c.

273 {
274 const TValue *o = index2adr(L, idx);
275 return (ttisuserdata(o) || ttislightuserdata(o));
276}
#define ttislightuserdata(o)

◆ 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)

◆ lua_load()

LUA_API int lua_load ( lua_State * L,
lua_Reader reader,
void * dt,
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)
#define clLvalue(o)
static const char * reader(lua_State *L, void *ud, size_t *size)

◆ lua_newstate()

LUA_API lua_State * lua_newstate ( lua_Alloc f,
void * ud )

Definition at line 143 of file lua-5.1.5/src/lstate.c.

143 {
144 int i;
145 lua_State *L;
146 global_State *g;
147 void *l = (*f)(ud, NULL, 0, state_size(LG));
148 if (l == NULL) return NULL;
149 L = tostate(l);
150 g = &((LG *)L)->g;
151 L->next = NULL;
152 L->tt = LUA_TTHREAD;
154 L->marked = luaC_white(g);
155 set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
156 preinit_state(L, g);
157 g->frealloc = f;
158 g->ud = ud;
159 g->mainthread = L;
160 g->uvhead.u.l.prev = &g->uvhead;
161 g->uvhead.u.l.next = &g->uvhead;
162 g->GCthreshold = 0; /* mark it as unfinished state */
163 g->strt.size = 0;
164 g->strt.nuse = 0;
165 g->strt.hash = NULL;
167 luaZ_initbuffer(L, &g->buff);
168 g->panic = NULL;
169 g->gcstate = GCSpause;
170 g->rootgc = obj2gco(L);
171 g->sweepstrgc = 0;
172 g->sweepgc = &g->rootgc;
173 g->gray = NULL;
174 g->grayagain = NULL;
175 g->weak = NULL;
176 g->tmudata = NULL;
177 g->totalbytes = sizeof(LG);
180 g->gcdept = 0;
181 for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
182 if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
183 /* memory allocation error: free partial state */
184 close_state(L);
185 L = NULL;
186 }
187 else
189 return L;
190}
#define bit2mask(b1, b2)
#define WHITE0BIT
#define FIXEDBIT
#define SFIXEDBIT
#define set2bits(x, b1, b2)
#define luaC_white(g)
#define NUM_TAGS
#define state_size(x)
#define tostate(l)
static void f_luaopen(lua_State *L, void *ud)
static void preinit_state(lua_State *L, global_State *g)
struct LG LG
#define obj2gco(v)
#define registry(L)
#define LUA_TTHREAD
#define luai_userstateopen(L)
#define LUAI_GCPAUSE
#define LUAI_GCMUL
#define luaZ_initbuffer(L, buff)
struct UpVal * prev
union UpVal::@48 u
struct UpVal * next
struct UpVal::@48::@49 l
struct lua_State * mainthread
lua_CFunction panic
struct Table * mt[NUM_TAGS]

◆ lua_newthread()

LUA_API lua_State * lua_newthread ( lua_State * L)

Definition at line 140 of file lua-5.1.5/src/lapi.c.

140 {
141 lua_State *L1;
142 lua_lock(L);
143 luaC_checkGC(L);
144 L1 = luaE_newthread(L);
145 setthvalue(L, L->top, L1);
146 api_incr_top(L);
147 lua_unlock(L);
149 return L1;
150}
#define setthvalue(L, obj, x)
lua_State * luaE_newthread(lua_State *L)
#define luai_userstatethread(L, L1)

◆ lua_newuserdata()

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

Definition at line 1025 of file lua-5.1.5/src/lapi.c.

1025 {
1026 Udata *u;
1027 lua_lock(L);
1028 luaC_checkGC(L);
1029 u = luaS_newudata(L, size, getcurrenv(L));
1030 setuvalue(L, L->top, u);
1031 api_incr_top(L);
1032 lua_unlock(L);
1033 return u + 1;
1034}
static Table * getcurrenv(lua_State *L)
#define setuvalue(L, obj, x)
Udata * luaS_newudata(lua_State *L, size_t s, Table *e)

◆ lua_next()

LUA_API int lua_next ( lua_State * L,
int idx )

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

973 {
974 StkId t;
975 int more;
976 lua_lock(L);
977 t = index2adr(L, idx);
978 api_check(L, ttistable(t));
979 more = luaH_next(L, hvalue(t), L->top - 1);
980 if (more) {
981 api_incr_top(L);
982 }
983 else /* no more elements */
984 L->top -= 1; /* remove key */
985 lua_unlock(L);
986 return more;
987}
#define ttistable(o)
int luaH_next(lua_State *L, Table *t, StkId key)

◆ 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 api_checkstackindex(L, i, o)
#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 503 of file lua-5.1.5/src/lapi.c.

503 {
504 lua_lock(L);
505 setbvalue(L->top, (b != 0)); /* ensure that true is 1 */
506 api_incr_top(L);
507 lua_unlock(L);
508}
#define setbvalue(obj, x)

◆ lua_pushcclosure()

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

Definition at line 486 of file lua-5.1.5/src/lapi.c.

486 {
487 Closure *cl;
488 lua_lock(L);
489 luaC_checkGC(L);
490 api_checknelems(L, n);
491 cl = luaF_newCclosure(L, n, getcurrenv(L));
492 cl->c.f = fn;
493 L->top -= n;
494 while (n--)
495 setobj2n(L, &cl->c.upvalue[n], L->top+n);
496 setclvalue(L, L->top, cl);
498 api_incr_top(L);
499 lua_unlock(L);
500}
Closure * luaF_newCclosure(lua_State *L, int nelems, Table *e)
#define iswhite(x)
#define setobj2n
lua_CFunction f

◆ lua_pushfstring()

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

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

473 {
474 const char *ret;
475 va_list argp;
476 lua_lock(L);
477 luaC_checkGC(L);
478 va_start(argp, fmt);
479 ret = luaO_pushvfstring(L, fmt, argp);
480 va_end(argp);
481 lua_unlock(L);
482 return ret;
483}
const char * luaO_pushvfstring(lua_State *L, const char *fmt, va_list argp)

◆ lua_pushinteger()

LUA_API void lua_pushinteger ( lua_State * L,
lua_Integer n )

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

437 {
438 lua_lock(L);
439 setnvalue(L->top, cast_num(n));
440 api_incr_top(L);
441 lua_unlock(L);
442}
#define cast_num(i)

◆ lua_pushlightuserdata()

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

Definition at line 511 of file lua-5.1.5/src/lapi.c.

511 {
512 lua_lock(L);
513 setpvalue(L->top, p);
514 api_incr_top(L);
515 lua_unlock(L);
516}
#define setpvalue(obj, x)

◆ lua_pushlstring()

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

Definition at line 445 of file lua-5.1.5/src/lapi.c.

445 {
446 lua_lock(L);
447 luaC_checkGC(L);
448 setsvalue2s(L, L->top, luaS_newlstr(L, s, len));
449 api_incr_top(L);
450 lua_unlock(L);
451}
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

◆ lua_pushnil()

LUA_API void lua_pushnil ( lua_State * L)

Definition at line 421 of file lua-5.1.5/src/lapi.c.

421 {
422 lua_lock(L);
423 setnilvalue(L->top);
424 api_incr_top(L);
425 lua_unlock(L);
426}

◆ lua_pushnumber()

LUA_API void lua_pushnumber ( lua_State * L,
lua_Number n )

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

429 {
430 lua_lock(L);
431 setnvalue(L->top, n);
432 api_incr_top(L);
433 lua_unlock(L);
434}

◆ lua_pushstring()

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

Definition at line 454 of file lua-5.1.5/src/lapi.c.

454 {
455 if (s == NULL)
456 lua_pushnil(L);
457 else
458 lua_pushlstring(L, s, strlen(s));
459}
LUA_API void lua_pushnil(lua_State *L)
LUA_API void lua_pushlstring(lua_State *L, const char *s, size_t len)

◆ lua_pushthread()

LUA_API int lua_pushthread ( lua_State * L)

Definition at line 519 of file lua-5.1.5/src/lapi.c.

519 {
520 lua_lock(L);
521 setthvalue(L, L->top, L);
522 api_incr_top(L);
523 lua_unlock(L);
524 return (G(L)->mainthread == L);
525}

◆ lua_pushunsigned()

LUA_API void lua_pushunsigned ( lua_State * L,
lua_Unsigned n )

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

228 {
229 lua_lock(L);
230 setobj2s(L, L->top, index2adr(L, idx));
231 api_incr_top(L);
232 lua_unlock(L);
233}

◆ lua_pushvfstring()

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

Definition at line 462 of file lua-5.1.5/src/lapi.c.

463 {
464 const char *ret;
465 lua_lock(L);
466 luaC_checkGC(L);
467 ret = luaO_pushvfstring(L, fmt, argp);
468 lua_unlock(L);
469 return ret;
470}

◆ lua_rawequal()

LUA_API int lua_rawequal ( lua_State * L,
int idx1,
int idx2 )

Definition at line 279 of file lua-5.1.5/src/lapi.c.

279 {
280 StkId o1 = index2adr(L, index1);
281 StkId o2 = index2adr(L, index2);
282 return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
283 : luaO_rawequalObj(o1, o2);
284}
int luaO_rawequalObj(const TValue *t1, const TValue *t2)
#define luaO_nilobject

◆ lua_rawget()

LUA_API void lua_rawget ( lua_State * L,
int idx )

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

557 {
558 StkId t;
559 lua_lock(L);
560 t = index2adr(L, idx);
561 api_check(L, ttistable(t));
562 setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
563 lua_unlock(L);
564}
const TValue * luaH_get(Table *t, const TValue *key)

◆ lua_rawgeti()

◆ 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}

◆ 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)
#define ttypenv(o)

◆ lua_rawset()

LUA_API void lua_rawset ( lua_State * L,
int idx )

Definition at line 671 of file lua-5.1.5/src/lapi.c.

671 {
672 StkId t;
673 lua_lock(L);
674 api_checknelems(L, 2);
675 t = index2adr(L, idx);
676 api_check(L, ttistable(t));
677 setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
678 luaC_barriert(L, hvalue(t), L->top-1);
679 L->top -= 2;
680 lua_unlock(L);
681}
#define luaC_barriert(L, t, v)
#define setobj2t
TValue * luaH_set(lua_State *L, Table *t, const TValue *key)

◆ lua_rawseti()

◆ 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}
#define gcvalue(o)
#define luaC_barrierback(L, p, v)

◆ lua_remove()

LUA_API void lua_remove ( lua_State * L,
int idx )

Definition at line 180 of file lua-5.1.5/src/lapi.c.

180 {
181 StkId p;
182 lua_lock(L);
183 p = index2adr(L, idx);
185 while (++p < L->top) setobjs2s(L, p-1, p);
186 L->top--;
187 lua_unlock(L);
188}

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

◆ lua_replace()

LUA_API void lua_replace ( lua_State * L,
int idx )

Definition at line 203 of file lua-5.1.5/src/lapi.c.

203 {
204 StkId o;
205 lua_lock(L);
206 /* explicit test for incompatible code */
207 if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci)
208 luaG_runerror(L, "no calling environment");
209 api_checknelems(L, 1);
210 o = index2adr(L, idx);
212 if (idx == LUA_ENVIRONINDEX) {
213 Closure *func = curr_func(L);
214 api_check(L, ttistable(L->top - 1));
215 func->c.env = hvalue(L->top - 1);
216 luaC_barrier(L, func, L->top - 1);
217 }
218 else {
219 setobj(L, o, L->top - 1);
220 if (idx < LUA_GLOBALSINDEX) /* function upvalue? */
221 luaC_barrier(L, curr_func(L), L->top - 1);
222 }
223 L->top--;
224 lua_unlock(L);
225}
void luaG_runerror(lua_State *L, const char *fmt,...)
#define curr_func(L)
#define LUA_ENVIRONINDEX
#define LUA_GLOBALSINDEX

References api_check, api_checknelems, api_checkvalidindex, lua_State::base_ci, Closure::c, lua_State::ci, curr_func, hvalue, index2adr(), LUA_ENVIRONINDEX, LUA_GLOBALSINDEX, lua_lock, lua_unlock, luaC_barrier, luaG_runerror(), moveto(), setobj, lua_State::top, and ttistable.

◆ lua_resume()

LUA_API int lua_resume ( lua_State * L,
lua_State * from,
int narg )

Definition at line 535 of file lua-5.2.4/src/ldo.c.

535 {
536 int status;
537 int oldnny = L->nny; /* save 'nny' */
538 lua_lock(L);
539 luai_userstateresume(L, nargs);
540 L->nCcalls = (from) ? from->nCcalls + 1 : 1;
541 L->nny = 0; /* allow yields */
542 api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);
543 status = luaD_rawrunprotected(L, resume, L->top - nargs);
544 if (status == -1) /* error calling 'lua_resume'? */
545 status = LUA_ERRRUN;
546 else { /* yield or regular error */
547 while (status != LUA_OK && status != LUA_YIELD) { /* error? */
548 if (recover(L, status)) /* recover point? */
549 status = luaD_rawrunprotected(L, unroll, NULL); /* run continuation */
550 else { /* unrecoverable error */
551 L->status = cast_byte(status); /* mark thread as `dead' */
552 seterrorobj(L, status, L->top);
553 L->ci->top = L->top;
554 break;
555 }
556 }
557 lua_assert(status == L->status);
558 }
559 L->nny = oldnny; /* restore 'nny' */
560 L->nCcalls--;
561 lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0));
562 lua_unlock(L);
563 return status;
564}
#define cast_byte(i)
#define LUA_YIELD
#define LUA_ERRRUN
#define luai_userstateresume(L, n)
static void unroll(lua_State *L, void *ud)
static int recover(lua_State *L, int status)
int luaD_rawrunprotected(lua_State *L, Pfunc f, void *ud)
static void resume(lua_State *L, void *ud)
static void seterrorobj(lua_State *L, int errcode, StkId oldtop)

◆ lua_setallocf()

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

Definition at line 1017 of file lua-5.1.5/src/lapi.c.

1017 {
1018 lua_lock(L);
1019 G(L)->ud = ud;
1020 G(L)->frealloc = f;
1021 lua_unlock(L);
1022}

◆ lua_setfield()

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

Definition at line 657 of file lua-5.1.5/src/lapi.c.

657 {
658 StkId t;
659 TValue key;
660 lua_lock(L);
661 api_checknelems(L, 1);
662 t = index2adr(L, idx);
664 setsvalue(L, &key, luaS_new(L, k));
665 luaV_settable(L, t, &key, L->top - 1);
666 L->top--; /* pop value */
667 lua_unlock(L);
668}
#define luaV_settable(L, t, k, v)

◆ 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}

◆ lua_sethook()

LUA_API int lua_sethook ( lua_State * L,
lua_Hook func,
int mask,
int count )

Definition at line 56 of file lua-5.1.5/src/ldebug.c.

56 {
57 if (func == NULL || mask == 0) { /* turn off hooks? */
58 mask = 0;
59 func = NULL;
60 }
61 L->hook = func;
62 L->basehookcount = count;
65 return 1;
66}
#define resethookcount(L)
#define mask(n)

◆ lua_setlocal()

LUA_API const char * lua_setlocal ( lua_State * L,
const lua_Debug * ar,
int n )

Definition at line 138 of file lua-5.1.5/src/ldebug.c.

138 {
139 CallInfo *ci = L->base_ci + ar->i_ci;
140 const char *name = findlocal(L, ci, n);
141 lua_lock(L);
142 if (name)
143 setobjs2s(L, ci->base + (n - 1), L->top - 1);
144 L->top--; /* pop value */
145 lua_unlock(L);
146 return name;
147}

◆ lua_setmetatable()

LUA_API int lua_setmetatable ( lua_State * L,
int objindex )

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

697 {
698 TValue *obj;
699 Table *mt;
700 lua_lock(L);
701 api_checknelems(L, 1);
702 obj = index2adr(L, objindex);
703 api_checkvalidindex(L, obj);
704 if (ttisnil(L->top - 1))
705 mt = NULL;
706 else {
707 api_check(L, ttistable(L->top - 1));
708 mt = hvalue(L->top - 1);
709 }
710 switch (ttype(obj)) {
711 case LUA_TTABLE: {
712 hvalue(obj)->metatable = mt;
713 if (mt)
714 luaC_objbarriert(L, hvalue(obj), mt);
715 break;
716 }
717 case LUA_TUSERDATA: {
718 uvalue(obj)->metatable = mt;
719 if (mt)
720 luaC_objbarrier(L, rawuvalue(obj), mt);
721 break;
722 }
723 default: {
724 G(L)->mt[ttype(obj)] = mt;
725 break;
726 }
727 }
728 L->top--;
729 lua_unlock(L);
730 return 1;
731}
#define luaC_objbarriert(L, t, o)
#define luaC_objbarrier(L, p, o)
#define ttisnil(o)
#define rawuvalue(o)

◆ lua_settable()

LUA_API void lua_settable ( lua_State * L,
int idx )

Definition at line 645 of file lua-5.1.5/src/lapi.c.

645 {
646 StkId t;
647 lua_lock(L);
648 api_checknelems(L, 2);
649 t = index2adr(L, idx);
651 luaV_settable(L, t, L->top - 2, L->top - 1);
652 L->top -= 2; /* pop index and value */
653 lua_unlock(L);
654}

◆ lua_settop()

LUA_API void lua_settop ( lua_State * L,
int idx )

Definition at line 164 of file lua-5.1.5/src/lapi.c.

164 {
165 lua_lock(L);
166 if (idx >= 0) {
167 api_check(L, idx <= L->stack_last - L->base);
168 while (L->top < L->base + idx)
169 setnilvalue(L->top++);
170 L->top = L->base + idx;
171 }
172 else {
173 api_check(L, -(idx+1) <= (L->top - L->base));
174 L->top += idx+1; /* `subtract' index (index is negative) */
175 }
176 lua_unlock(L);
177}

◆ lua_setupvalue()

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

Definition at line 1071 of file lua-5.1.5/src/lapi.c.

1071 {
1072 const char *name;
1073 TValue *val;
1074 StkId fi;
1075 lua_lock(L);
1076 fi = index2adr(L, funcindex);
1077 api_checknelems(L, 1);
1078 name = aux_upvalue(fi, n, &val);
1079 if (name) {
1080 L->top--;
1081 setobj(L, val, L->top);
1082 luaC_barrier(L, clvalue(fi), L->top);
1083 }
1084 lua_unlock(L);
1085 return name;
1086}

◆ 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}

◆ lua_status()

LUA_API int lua_status ( lua_State * L)

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

890 {
891 return L->status;
892}

◆ lua_toboolean()

LUA_API int lua_toboolean ( lua_State * L,
int idx )

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

337 {
338 const TValue *o = index2adr(L, idx);
339 return !l_isfalse(o);
340}
#define l_isfalse(o)

◆ lua_tocfunction()

LUA_API lua_CFunction lua_tocfunction ( lua_State * L,
int idx )

Definition at line 379 of file lua-5.1.5/src/lapi.c.

379 {
380 StkId o = index2adr(L, idx);
381 return (!iscfunction(o)) ? NULL : clvalue(o)->c.f;
382}

◆ 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)

◆ lua_tolstring()

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

Definition at line 343 of file lua-5.1.5/src/lapi.c.

343 {
344 StkId o = index2adr(L, idx);
345 if (!ttisstring(o)) {
346 lua_lock(L); /* `luaV_tostring' may create a new string */
347 if (!luaV_tostring(L, o)) { /* conversion failed? */
348 if (len != NULL) *len = 0;
349 lua_unlock(L);
350 return NULL;
351 }
352 luaC_checkGC(L);
353 o = index2adr(L, idx); /* previous call may reallocate the stack */
354 lua_unlock(L);
355 }
356 if (len != NULL) *len = tsvalue(o)->len;
357 return svalue(o);
358}
#define ttisstring(o)
#define svalue(o)
int luaV_tostring(lua_State *L, StkId obj)

◆ 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}

◆ lua_topointer()

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

Definition at line 401 of file lua-5.1.5/src/lapi.c.

401 {
402 StkId o = index2adr(L, idx);
403 switch (ttype(o)) {
404 case LUA_TTABLE: return hvalue(o);
405 case LUA_TFUNCTION: return clvalue(o);
406 case LUA_TTHREAD: return thvalue(o);
407 case LUA_TUSERDATA:
409 return lua_touserdata(L, idx);
410 default: return NULL;
411 }
412}
LUA_API void * lua_touserdata(lua_State *L, int idx)
#define thvalue(o)
#define LUA_TLIGHTUSERDATA
#define LUA_TFUNCTION

◆ lua_tothread()

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

Definition at line 395 of file lua-5.1.5/src/lapi.c.

395 {
396 StkId o = index2adr(L, idx);
397 return (!ttisthread(o)) ? NULL : thvalue(o);
398}
#define ttisthread(o)

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

385 {
386 StkId o = index2adr(L, idx);
387 switch (ttype(o)) {
388 case LUA_TUSERDATA: return (rawuvalue(o) + 1);
389 case LUA_TLIGHTUSERDATA: return pvalue(o);
390 default: return NULL;
391 }
392}
#define pvalue(o)

◆ lua_type()

LUA_API int lua_type ( lua_State * L,
int idx )

Definition at line 242 of file lua-5.1.5/src/lapi.c.

242 {
243 StkId o = index2adr(L, idx);
244 return (o == luaO_nilobject) ? LUA_TNONE : ttype(o);
245}
#define LUA_TNONE

◆ lua_typename()

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

Definition at line 248 of file lua-5.1.5/src/lapi.c.

248 {
249 UNUSED(L);
250 return (t == LUA_TNONE) ? "no value" : luaT_typenames[t];
251}
#define UNUSED(x)
const char *const luaT_typenames[]

◆ 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)
#define LUA_TLCL
#define clCvalue(o)
#define LUA_TCCL

◆ 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}

◆ 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

◆ lua_xmove()

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

Definition at line 110 of file lua-5.1.5/src/lapi.c.

110 {
111 int i;
112 if (from == to) return;
113 lua_lock(to);
114 api_checknelems(from, n);
115 api_check(from, G(from) == G(to));
116 api_check(from, to->ci->top - to->top >= n);
117 from->top -= n;
118 for (i = 0; i < n; i++) {
119 setobj2s(to, to->top++, from->top + i);
120 }
121 lua_unlock(to);
122}

◆ lua_yieldk()

LUA_API int lua_yieldk ( lua_State * L,
int nresults,
int ctx,
lua_CFunction k )

Definition at line 567 of file lua-5.2.4/src/ldo.c.

567 {
568 CallInfo *ci = L->ci;
569 luai_userstateyield(L, nresults);
570 lua_lock(L);
571 api_checknelems(L, nresults);
572 if (L->nny > 0) {
573 if (L != G(L)->mainthread)
574 luaG_runerror(L, "attempt to yield across a C-call boundary");
575 else
576 luaG_runerror(L, "attempt to yield from outside a coroutine");
577 }
578 L->status = LUA_YIELD;
579 ci->extra = savestack(L, ci->func); /* save current 'func' */
580 if (isLua(ci)) { /* inside a hook? */
581 api_check(L, k == NULL, "hooks cannot continue after yielding");
582 }
583 else {
584 if ((ci->u.c.k = k) != NULL) /* is there a continuation? */
585 ci->u.c.ctx = ctx; /* save context */
586 ci->func = L->top - nresults - 1; /* protect stack below results */
588 }
589 lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */
590 lua_unlock(L);
591 return 0; /* return to 'luaD_hook' */
592}
#define luai_userstateyield(L, n)
l_noret luaD_throw(lua_State *L, int errcode)
#define CIST_HOOKED

References api_check, api_checknelems, CallInfo::c, CallInfo::callstatus, lua_State::ci, CIST_HOOKED, CallInfo::ctx, CallInfo::extra, CallInfo::func, G, isLua, CallInfo::k, lua_assert, lua_lock, lua_unlock, LUA_YIELD, luaD_throw(), luaG_runerror(), luai_userstateyield, lua_State::nny, NULL, savestack, lua_State::status, lua_State::top, and CallInfo::u.

Variable Documentation

◆ lua_ident

const char lua_ident[]
extern

Definition at line 34 of file lua-5.1.5/src/lapi.c.