Last edit: 07.02.2010 Lua 5.1 C API
Last edit: 07.02.2010
Push data lua_pushboolean lua_pushinteger lua_pushnumber
lua_pushliteral lua_pushstring lua_pushlstring lua_pushfstring lua_pushvfstring lua_pushcfunction lua_pushcclosure
R
P1
P2
P3
P4
L
bool
L
n
L
n
L
pc
L
pc
L
pc
len
pc
L
fmt
...
pc
L
fmt
va_list
L
cf
L
cf
n
lua_pushlightuserdata lua_pushthread lua_pushnil
L
data
L
L
Check data lua_isboolean lua_isnumber lua_isstring lua_istable lua_isfunction lua_iscfunction lua_islightuserdata lua_isuserdata lua_isoneornil lua_isnone lua_isnil lua_isthread
R ok ok ok ok ok ok ok ok ok ok ok ok
P1 L L L L L L L L L L L L
P2 n n n n n n n n n n n n
P3
P4
Get data checked luaL_checkany luaL_checkinteger luaL_checkint luaL_checklong luaL_checkstring luaL_checklstring luaL_checknumber luaL_checktype luaL_checkudata luaL_checkoption
R
P1
L
integer L
int
L
long L
pc
L
pc
L
number L
L
data L
index L
P2 n n n n n n n n n n
P3
P4
plen
t
name
pc
ppc
Get data converted lua_toboolean lua_tocfunction lua_tointeger lua_tostring lua_tolstring lua_tonumber lua_topointer lua_tothread lua_touserdata
R
P1
P2
P3
P4
bool L
n
cf
L
n
int
L
n
pc
L
n
pc
L
n
plen
number L
n
data L
n
thread L
n
ud
L
n
Get data with defaults luaL_optint luaL_optinteger luaL_optlong luaL_optnumber luaL_optlstring luaL_optstring
R
P1
int
L
integer L
long L
number L
string L
string L
P2 n n n n n n
P3 d d d d pc pc
P4 len
POP 0 0 0 0 0 0 0 0 0 -n
0 0 0
POP 0 0 0 0 0 0 0 0 0 0 0 0
POP 0 0 0 0 0 0 0 0 0 0
POP 0 0 0 0 0 0 0 0 0
POP 0 0 0 0 0 0
Stack IN
-1: upvalue 1 -n: upvalue n
Stack IN -n: value -n: value -n: value -n: value -n: value -n: value -n: value -n: value -n: value -n: value -n: value -n: value
Stack IN -n: value -n: value -n: value -n: value -n: value -n: value -n: value -n: value -n: value -n: value
Stack IN -n: value -n: value -n: value -n: value -n: value -n: value -n: value -n: value -n: value
Stack IN -n: value -n: value -n: value -n: value -n: value -n: value
PUSH +1 +1 +1 +1 +1 +1 +1 +1 +1 +1
+1 +1 +1
PUSH 0 0 0 0 0 0 0 0 0 0 0 0
PUSH 0 0 0 0 0 0 0 0 0 0
PUSH 0 0 0 0 0 0 0 0 0
PUSH 0 0 0 0 0 0
Lua 5.1 C API
Stack OUT -1: bool -1: num -1: num -1: string -1: string -1: string -1: string -1: data -1: func -1: func
? Ewald Arnold 1/7
Error -
m m m m m
Remark push a boolean value push integer push Lua number (double)
push string literal push C string push string of given length push a sprintf() formatted string and return also pointer to result push a vsprintf() formatted string and return also pointer to result push a C function push a C closure with n upvalues (value 1 being pushed first)
-1: data -1: thread -1: nil
- push light user data - push the thread of the current stack, return 1 for main thread - push nil
Stack OUT
Error -
Remark return true if value at position n is a boolean return true if value at position n is a number return true if value at position n is a string return true if value at position n is a table return true if value at position n is a Lua function return true if value at position n is a C function return true if value at position n is a light user data return true if value at position n is a light/full user data return true if value at position n is nil or outside current stack return true if value at position n is outside current stack return true if value at position n is nil return true if value at position n is a thread
Stack OUT
Error v v v v v v v v v v
Remark check if value at position n is a valid value check for integer and return int at position n check for number and return int at position n check for number and return long at position n check for string and return string at position n check for string and return string at position n and actual length check for number and return int at position n check for Lua type t at position n check for userdata name and return its pointer at position n search index of n (or pc) in list ppc
Stack OUT
Error -
Remark convert value at position n to bool convert value at position n to a C function convert value at position n to integer convert value at position n to C string, return pointer convert value at position n to C string, return pointer and actual length convert value at position n to a Lua number convert value at position n to pointer convert value at position n to thread convert value at position n to light userdata
Stack OUT
Error m m m m m m
Remark check for number at position n, return n if number or d otherwise check for number at position n, return n if number or d otherwise check for number at position n, return n if number or d otherwise check for number at position n, return n if integer or d otherwise check for string at position n, return n if string or pc with len otherwise check for string at position n, return n if string or pc otherwise
Last edit: 07.02.2010
Stack operator lua_gettop lua_settop lua_insert lua_pop lua_pushvalue lua_remove lua_replace lua_xmove
R size
Value operator lua_equal
R eq
lua_lessthan
eq
lua_rawequal
eq
luaL_gsub lua_concat
P1 L L L L L L L L1
P2
n n n n n n L2
P1
P2
L
n1
L
n1
L
n1
L
pc
n
P3
P4
n
P3
P4
n2
n2
n2
patt rep
POP 0 ? -1 -n 0 -1 -1 -n
POP 0
0
0
0 -n
Table lua_createtable lua_newtable lua_getfield lua_setfield
lua_rawget
lua_rawset
R
P1
P2
P3
L
narr
nrec
L
L
n
name
L
n
name
L
n
L
n
P4 POP 0 0 0 -1
-1
-2
lua_rawgeti lua_rawseti
lua_gettable
lua_settable
L
n
k
0
L
n
k
-1
L
n
-1
L
n
-2
lua_getmetatable lua_setmetatable
LuaL_newmetatable lualL_getmetatable lua_next
lua_objlen luaL_getmetafield
Global data lua_setglobal lua_getglobal lua_setfenv
lua_getfenv lua_register luaL_register
ok
L
n
L
n
created L
L
ok
L
name name n
size
L
n
ok
L
n
name
R
P1
P2
P3
L
name
L
name
L
n
L
n
L
name func
L
name list
0 -1
0 0 -1
0 0
P4 POP -1 0 -1
0 0 -0, -1
Stack IN
-1: value
-n: value -n: value -1: value
Stack IN -n1: value 1 -n2: value 2 -n1: value 1 -n2: value 2 -n1: value 1 -n2: value 2
-1: value 1 -n: value n
Stack IN
-n: table -1: key -n: table -1 field -n: table -1: value -2: key -n: table -n: table -1: value -n: table -1: field -n: table -1: value -2: key -n: table -1: value -1: value -n: table
-1: key
-n: value -n: value
Stack IN -1 value
-1: table -n: table
-1: table
PUSH 0 ? +1 0 +1 0 0 +n
PUSH 0
0
+1 +1
Lua 5.1 C API
Stack OUT
-(n-1): value -1: value
-(n-1): value
Error -
return the current size of the stack set stack size to n moves top element to position n pop n values from stack push value at position n remove value at position n pop value and replace value at position n pop n values from L1, push to L2
? Ewald Arnold 2/7 Remark
Stack OUT
Error
Remark
e return true if values at position n1 and n2 are equal
e return true if value at position n1 is smaller than value at position n2
0x
- return true if value at position n1 is smaller than value at position n2 (without metamethods)
-1: string -1: string
m push copy of pc with all patt replaced by rep pop n values and push concatenated strings 1 .. n
PUSH +1 +1 +1
Stack OUT -1: table -1: table -1: value
+1
-1 value
0
Error m m e e
Remark create and push a new table with pre-allocated space create and push a new empty table push value of table at position n with field name pop value and store in table at position n with field key
e push value of table at position n with field at top (without metamethods)
e pop value and store in table at position n with field key (without metamethods)
+1
-1: value
+1
-1: value
0
- push value of table at position n with field at index k pop value and store in table at position n with field at index k
e push value of table at position n with field at top
e pop value and store in table at position n with field key
+0, +1 0
+1 +1 +0, +2
0 +0, +1
PUSH 0 +1 0
+1 0 +1
-1: table
-1: table -1: table -1: value -2: key -1: value Stack OUT -1: value
-1: env -1: table
push metatable of value at position n if possible - pop value and store as metatable for value at position n
m push metatable name in registry, create if necessary - push metatable name from registry e pop key and push next pair of table at position n, (push nil at start, pop 1 value in each iteration
- return size of value at position n v push metafield of value at position n with given name if possible
Error e e -
store a global value push a global value
set environment table of value at position n
Remark
- push environment table of value at position n - register C function in global table with name m open library with list elements in table on stack, if name is != 0 create and push new table
Last edit: 07.02.2010
Call function
R
lua_call
lua_pcall
error
lua_cpcall luaL_callmeta
Load or call Lua code lua_load luaL_loadbuffer luaL_dofile luaL_dostring luaL_loadfile luaL_loadstring
Debugging lua_gethook lua_gethookcount lua_gethookmask lua_sethook lua_getinfo lua_getlocal lua_setlocal lua_getupvalue lua_setupvalue lua_dump lua_error lua_getstack lua_checkstack lua_type lua_typename lua_atpanic luaL_argcheck luaL_argerror luaL_typerror luaL_error luaL_checkstack luaL_where
Buffer luaL_buffinit luaL_prepbuffer luaL_addvalue luaL_addchar luaL_addlstring luaL_addstring luaL_addsize luaL_pushresult
Thread lua_yield lua_resume lua_status
error ok
R error error ok ok error error
R cf n n
n name name name name error
ok n t name cf
R
data
R
error error
P1
P2
P3
L
ni
no
P4 POP -(ni+1)
L
ni
no
lf
-(ni+1)
cf
ud
L
n
name
P1 L L L L L L
P2 reader pc file pc file pc
P3 data len
P4 name name
P1 L L L L L L L L L L L L L L L fn L L L L L L
P2
cf what ar ar f f writer
n n n t
cond n n fmt n n
P3
P4
mask ar n n n n data
count
ar
n
msg
msg
name
...
msg
P1
P2
P3
P4
L
B
B
B
B
c
B
pc
len
B
pc
B
n
B
P1 L L L
P2 n n
P3
P4
0 0
POP 0 0 0 0 0 0
POP 0 0 0 0
0, -1 0
-0, -1 0
0, -1 0 -1 0 0 0 0 0 0 0 0 0 0 0
POP 0 0 -1 0 0 0 0 0
POP -n -n 0
Stack IN -1: value ni -2: value 1
-(ni+1): func -1: value ni -2: value 1
-(ni+1): func -1: ud -n: value
Stack IN
Stack IN
-1: func -1: value -1: func -1: func -1: message -n: value
Stack IN -1: value
Stack IN
PUSH +no
+no, +1
+0, +1 0, +1
PUSH +1 +1 ? ? +1 +1
PUSH 0 0 0 0
+(0,1,2) +0, +1
0 +0, +1
0 0 0 0 0 0 0 0 0 0 0 0 0 +1
PUSH 0 0 0 0 0 0 0 +1
PUSH +n +n 0
Lua 5.1 C API
Stack OUT -1: value 1 -n: value n
? Ewald Arnold 3/7
Error
Remark
e call Lua function func with ni input values and no expected return values
-1: value | errobj -n: value n
- call Lua function func in protected mode, if f != 0 call function at position f
-1: errobj -1: value
- call C function in protected mode, if error != 0 return errobj e call metatable of value at position n with field name if possible: v = n.__call(n)
Stack OUT -1: func -1: func -?: value ? -?: value ? -1: func -1: func
Error m m m m m
Remark load a Lua chunk name by repeatedly calling reader(data), push the resulting function load a Lua chunk with name at given buffer and length, push the resulting function load and run Lua file, push return values load and run Lua chunk in memory, push return values load a Lua file, push the resulting function load a Lua chunk in memory, push the resulting function
Stack OUT -1: value -1: value
-1: string
Error m m v v m m m
Remark return hook function return hook count return hook mask set hook function, mask and count return specific information, see manual for details get information for local variable pop and store as value of local variable n get information for upvalue n in function at position f pop and store as value of upvalue n in function at position f dump function as binary data to writer generates a Lua error, never returns get information of runtime stack at level n ensure remaining stack space of at least n values return Lua type of value at position n return typename of type number t set panic function and return previous one If cond is not true: raise argument error with text based on n and msg raise argument error with text based on n and msg raise type error with text based on n and name raise error with a sprintf() formatted message ensure remaining stack space of at least n values, raise error with text including msg push a string describing the current programm position
Stack OUT -1: value
Error m m m m m m
initialise a buffer return intermediate space pop value and copy resulting string to buffer add character c to buffer add string with len l to buffer add C string to buffer add intermediate space with given size to buffer finish buffer and push result
Remark
Stack OUT
Error -
suspend a coroutine resume a coroutine return status of thread L
Remark
Last edit: 07.02.2010
Library lua_close luaopen_base luaopen_debug luaopen_io luaopen_math luaopen_os luaopen_package luaopen_string luaopen_table luaL_openlibs
R
P1
P2
P3
P4 POP
L
0
L
0
L
0
L
0
L
0
L
0
L
0
L
0
L
0
L
0
Misc lua_newthread lua_newuserdata lua_newstate luaL_newstate lua_gc lua_getallocf lua_setallocf luaL_ref
R
state state error alloc
key
P1
P2
P3
L
L
size
alloc ud
L
what data
L
pud
L
func
ud
L
n
P4 POP 0 0 0 0 0 0 0 -1
luaL_unref
L
n
key
0
Stack IN
Stack IN
-1: value -n: table -n: table
luaL_findtable luaL_setn luaL_getn luaL_openlib
deprecated function values popped in call values remaining in call
Basic types LUA_TNONE LUA_TNIL LUA_TBOOLEAN LUA_TLIGHTUSERDATA LUA_TNUMBER LUA_TSTRING LUA_TTABLE LUA_TFUNCTION LUA_TUSERDATA LUA_TTHREAD
Value (-1) 0 1 2 3 4 5 6 7 8
Type name
nil boolean
number string table
function
thread
Thread status
LUA_YIELD
1
LUA_ERRRUN
2
LUA_ERRSYNTAX
3
LUA_ERRMEM
4
LUA_ERRERR
5
Pseudo indices LUA_REGISTRYINDEX LUA_ENVIRONINDEX LUA_GLOBALSINDEX lua_upvalueindex(i)
(-10000) (-10001) (-10002) (LUA_GLOBALSINDEX-(i))
PUSH 0 0 0 0 0 0 0 0 0 0
PUSH +1 +1 0 0 0 0 0 0
0
Lua 5.1 C API
Stack OUT
Error -
close Lua library open base library open debug library open io library open math library open os library open package library open string library open table library open all the above standard libraries
? Ewald Arnold 4/7 Remark
Stack OUT -1: table -1: table
Error m m e m
Remark create and push a new thread allocate and push user data with given size create a new Lua state with given allocator and user data create a new Lua state with defaults control garbage collector get memory allocator and user data set memory allocator and user data create unique key in table at position n
- release key in table at position n
deprecated: ? deprecated: set table size, see table.setn() deprecated: get table size, see table.getn() open library
Name Remark cf c function lf Lua function ud light userdata ni number input args no number output args k field index n Stack element at index n n1 Stack element 1 at index n1 n2 Stack element 2 at index n2
value Lua value fmt format string, see fprintf() data pointer to raw data number Lua number ar Pointer to debug structure L, L1, L2 Lua state B Lua buffer integer Lua integer
t lua type
ok 1=success error error code, 0=ok
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- where are programming languages going
- lex yacc epaperpress
- complete guide for rf 433mhz transmitter receiver module
- syhunt catarinka lua library
- an intermediate representation for structured input lua
- seminar configurable systems
- scripting home iho
- jan schwinghammer december 5 2005 n ramsey
- gpu computing with pycuda
- luatex a user s perspective tug