Professional Documents
Culture Documents
www.lua.org
\0
luaconf.h
LUA_32BITS
0/0
a.name
a["name"]
i
a[i]
a[j]
1.0 == 1
a[2.0] = true
2
type
var
_ENV.var
_ENV
_ENV
_ENV
_ENV
_ENV
_ENV
_G
_G
_ENV
load
load
loadfile
lua
error
pcall
xpcall
lua_pcall
xpcall
__add
"add"
getmetatable
setmetatable
__
__add
obj
rawget(getmetatable(obj) or {}, "__" .. event_name)
+
__add
*
/
%
^
//
&
|
~
~
<<
>>
..
==
<
<=
__le
__lt
a <= b
table[key]
not (b < a)
table
table
table
key
table
key
key
table
table
table[key] = value
table
key
table
key
value
rawset
func(args)
func
func
func
args
lua_gc
collectgarbage
__gc
__gc
__gc
__gc
lua_close
__mode
k
__mode
__mode
v
coroutine.create
create
coroutine.resume
coroutine.resume
coroutine.create
coroutine.resume
coroutine.resume
coroutine.resume
coroutine.yield
coroutine.resume
coroutine.resume
coroutine.yield
coroutine.yield
coroutine.resume
coroutine.create
coroutine.wrap
coroutine.resume
coroutine.resume
coroutine.resume
coroutine.wrap
coroutine.wrap
co-body 1
foo
2
main true
co-body r
main true
co-body x
main true
main false
coroutine.resume(co,
coroutine.resume(co,
coroutine.resume(co,
coroutine.resume(co,
1, 10))
"r"))
"x", "y"))
"x", "y"))
10
4
11
-9
y
10
end
cannot resume dead coroutine
lua_newthread
lua_resume
lua_yield
and
false
local
then
break
do
else
elseif end
for
function goto
if
in
nil
not
or
repeat return
true
until
while
and
And
AND
_VERSION
+
&
==
(
;
*
/
%
^
#
~
|
<< >> //
~= <= >= <
>
)
{
}
[
]
::
:
,
.
.. ...
\a
\r
\b
\f
\t
\"
\v
\'
\z
\n
\\
\0
\xXX
\ddd
\u{XXX}
[[
[=[
]====]
a
1
a = 'alo\n123"'
a = "alo\n123\""
a = '\97lo\10\04923"'
a = [[alo
123"]]
a = [==[
alo
123"]==]
e
0X
p
0x
345
0xff
0xBEBADA
3.0
3.1416
314.16e-2
0.31416E1
34e1
0x0.1E 0xA23p-4 0X1.921FB54442D18P+1
--
--
var.Name
var["Name"]
_ENV.x
_ENV
stat ::= ;
a=b+c
(print or io.write)('done')
a = b + c(print or io.write)('done')
a = b + c; (print or io.write)('done')
;(print or io.write)('done')
_ENV
_ENV
luac
string.dump
load
i=3
i, a[i] = i+1, 20
a[3]
a[4]
a[i]
x, y = y, x
x
x, y, z = y, z, x
x y
z
t[i]
= val
settable_event
x = val
settable_event(t,i,val)
_ENV.x = val
do
local var, limit, step = tonumber(e1), tonumber(e2), tonumber(e3
if not (var and limit and step) then error() end
var = var - step
while true do
var = var + step
if (step >= 0 and var > limit) or (step < 0 and var < limit) then
break
end
local v = var
block
end
end
var
limit
step
do
local f, s, var = explist
while true do
local var_1, , var_n = f(s, var)
if var_1 == nil then break end
var = var_1
block
end
end
explist
f
var
var_i
...
f()
-- 0
g(f(), x)
-- f()
g(x, f())
-- g x f()
a,b,c = f(), x
-- f() 1 c nil
a,b = ...
-- a
-- b
-- a b nil
a,b,c = x, f()
-- f() 2
a,b,c = f()
-- f() 3
return f()
-- f()
return ...
-- parameters
return x,y,f()
-- x, y, f()
{f()}
-- f()
{...}
--
{f(), nil}
-- f()
(f(x,y,z))
(f(x,y,z))
f
f
f
*
/
//
%
^
-
/
pow
//
&
|
~
>>
<<
~
format
string.format
==
~=
<
>
<=
>=
==
"0"==0
t[0]
~=
t["0"]
==
a>b
b<a
a >= b
10 or 20
--> 10
10 or error()
--> 10
nil or "a"
--> "a"
nil and 10
--> nil
false and error() --> false
false and nil
--> false
false or nil
--> nil
10 and 20
--> 20
-->
b <= a
..
__concat
__len
__len
or
and
<
>
<= >= ~=
|
~
&
<< >>
..
+
*
/
// %
unary operators (not #
^
==
~)
..
exp1
["name"] = exp
i
do
local t = {}
t[f(1)] = g
t[1] = "x"
t[2] = "y"
t.x = 1
t[3] = f(x)
t[30] = 23
t[4] = 45
a=t
end
-- 1st exp
-- 2nd exp
-- t["x"] = 1
-- 3rd exp
-- 4th exp
exp
f"string"
return functioncall
return (f(x))
return 2 * f(x)
return x, f(x)
f(x); return
return x or f(x)
--
--
--
--
f[[string]]
CALL
PARAMETERS
f(3)
f(3, 4)
f(3, 4, 5)
f(r(), 10)
f(r())
a=3, b=nil
a=3, b=4
a=3, b=4
a=1, b=10
a=1, b=2
g(3)
a=3, b=nil, ... --> (nothing)
g(3, 4)
a=3, b=4, ... --> (nothing)
g(3, 4, 5, 8) a=3, b=4, ... --> 5 8
g(5, r())
a=5, b=1, ... --> 2 3
self
function t.a.b.c:f (params) body end
x = 10
--
do
--
local x = x
-- 'x', 10
print(x)
--> 10
x = x+1
do
--
local x = x+1
-- 'x'
print(x)
--> 12
end
print(x)
--> 11
end
print(x)
--> 10
local x = x
x
x
a = {}
local x = 20
for i=1,10 do
local y = 0
a[i] = function () y=y+1; return x+y end
end
y
lua.h
LUA_USE_APICHECK
lua_CFunction
lua_checkstack
LUA_MINSTACK
LUA_MINSTACK
lua_call
lua_checkstack
1
abs(index) top
LUA_TNONE
lua_pushcclosure
lua_upvalueindex
lua_upvalueindex(1)
lua_upvalueindex(n)
LUA_REGISTRYINDEX
luaL_ref
lua.h
LUA_RIDX_MAINTHREAD
LUA_RIDX_GLOBALS
longjmp
LUAI_THROW
setjmp
lua_atpanic
abort
lua_error
longjmp
foo
longjmp
foo
lua_yieldk
lua_yieldk
lua_callk
lua_callk
k
lua_pcallk
lua_pcallk
k
lua_KFunction
lua_pcall
lua_pcall
lua_pcall
k
lua_pcallk
lua_pcallk
lua_callk
lua_pcallk
ctx
lua_pcallk
lua_pcallk
LUA_YIELD
lua_yieldk
LUA_YIELD
LUA_OK
lua_callk
lua_callk
lua_yieldk
lua_yieldk
LUA_OK
lua_callk
o
p
x|y
x
e
lua_absindex
int lua_absindex (lua_State *L, int idx);
idx
lua_Alloc
typedef void * (*lua_Alloc) (void *ud,
void *ptr,
size_t osize,
size_t nsize);
realloc
lua_newstate
ud
ptr
osize
nsize
ptr
ptr
NULL
NULL
osize
ptr
osize
osize
nsize
free
nsize
NULL
luaL_newstate
osize
NULL
realloc
osize >= nsize
realloc(NULL,size)
malloc(size)
realloc
lua_arith
void lua_arith (lua_State *L, int op);
op
LUA_OPADD
LUA_OPSUB
LUA_OPMUL
LUA_OPDIV
LUA_OPIDIV
LUA_OPMOD
LUA_OPPOW
LUA_OPUNM
LUA_OPBNOT
LUA_OPBAND
LUA_OPBOR
LUA_OPBXOR
LUA_OPSHL
LUA_OPSHR
lua_atpanic
+
*
/
//
%
^
~
&
|
~
<<
>>
lua_call
void lua_call (lua_State *L, int nargs, int nresults);
lua_call
nargs
nresults
nresults
LUA_MULTRET
longjmp
lua_getglobal(L, "f");
/* function to be called */
lua_pushliteral(L, "how");
/* 1st argument */
lua_getglobal(L, "t");
/* table to be indexed */
lua_getfield(L, -1, "x");
/* push result of t.x (2nd arg) */
lua_remove(L, -2);
/* remove 't' from the stack */
lua_pushinteger(L, 14);
/* 3rd argument */
lua_call(L, 3, 1);
/* call 'f' with 3 arguments and 1 result */
lua_setglobal(L, "a");
/* set global 'a' */
lua_callk
void lua_callk (lua_State *L,
int nargs,
int nresults,
lua_KContext ctx,
lua_KFunction k);
lua_call
lua_CFunction
typedef int (*lua_CFunction) (lua_State *L);
lua_gettop(L)
lua_gettop(L)
lua_checkstack
int lua_checkstack (lua_State *L, int n);
n
lua_close
void lua_close (lua_State *L);
lua_compare
int lua_compare (lua_State *L, int index1, int index2, int op);
index1
op
index2
op
LUA_OPEQ
LUA_OPLT
LUA_OPLE
==
<
<=
lua_concat
void lua_concat (lua_State *L, int n);
n
n
n
lua_copy
void lua_copy (lua_State *L, int fromidx, int toidx);
fromidx
toidx
lua_createtable
void lua_createtable (lua_State *L, int narr, int nrec);
narr
nrec
lua_newtable
lua_dump
int lua_dump (lua_State *L,
lua_Writer writer,
void *data,
int strip);
writer
writer
lua_dump
data
lua_Writer
strip
writer
lua_error
int lua_error (lua_State *L);
luaL_error
lua_gc
int lua_gc (lua_State *L, int what, int data);
what
LUA_GCSTOP
LUA_GCRESTART
LUA_GCCOLLECT
LUA_GCCOUNT
LUA_GCCOUNTB
LUA_GCSTEP
LUA_GCSETPAUSE
LUA_GCSETSTEPMUL
data
data
LUA_GCISRUNNING
collectgarbage
lua_getallocf
lua_Alloc lua_getallocf (lua_State *L, void **ud);
ud
NULL
*ud
lua_getfield
int lua_getfield (lua_State *L, int index, const char *k);
t[k]
lua_getextraspace
void *lua_getextraspace (lua_State *L);
luaconf.h
LUA_EXTRASPACE
lua_getglobal
lua_geti
int lua_geti (lua_State *L, int index, lua_Integer i);
t[i]
lua_getmetatable
int lua_getmetatable (lua_State *L, int index);
lua_gettable
int lua_gettable (lua_State *L, int index);
t[k]
lua_gettop
int lua_gettop (lua_State *L);
lua_getuservalue
int lua_getuservalue (lua_State *L, int index);
lua_insert
void lua_insert (lua_State *L, int index);
lua_Integer
typedef ... lua_Integer;
long long
long
int
luaconf.h
LUA_INT
LUA_MININTEGER
LUA_MAXINTEGER
lua_isboolean
int lua_isboolean (lua_State *L, int index);
lua_iscfunction
int lua_iscfunction (lua_State *L, int index);
lua_isfunction
int lua_isfunction (lua_State *L, int index);
lua_isinteger
int lua_isinteger (lua_State *L, int index);
lua_islightuserdata
int lua_islightuserdata (lua_State *L, int index);
lua_isnil
int lua_isnil (lua_State *L, int index);
lua_isnone
int lua_isnone (lua_State *L, int index);
lua_isnoneornil
int lua_isnoneornil (lua_State *L, int index);
lua_isnumber
int lua_isnumber (lua_State *L, int index);
lua_isstring
int lua_isstring (lua_State *L, int index);
lua_istable
int lua_istable (lua_State *L, int index);
lua_isthread
lua_isuserdata
int lua_isuserdata (lua_State *L, int index);
lua_isyieldable
int lua_isyieldable (lua_State *L);
lua_KContext
typedef ... lua_KContext;
intptr_t
intptr_t
ptrdiff_t
lua_KFunction
typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);
lua_len
void lua_len (lua_State *L, int index);
#
lua_load
int lua_load (lua_State *L,
lua_Reader reader,
void *data,
const char *chunkname,
const char *mode);
lua_load
lua_load
LUA_OK
LUA_ERRSYNTAX
LUA_ERRMEM
LUA_ERRGCMM
lua_load
lua_Reader
__gc
reader
reader
data
chunkname
lua_load
luac
mode
NULL
load
bt
lua_load
LUA_RIDX_GLOBALS
_ENV
lua_newstate
lua_State *lua_newstate (lua_Alloc f, void *ud);
NULL
f
ud
lua_newtable
void lua_newtable (lua_State *L);
lua_createtable(L, 0, 0)
lua_newthread
lua_newuserdata
void *lua_newuserdata (lua_State *L, size_t size);
lua_next
int lua_next (lua_State *L, int index);
lua_next
/* 't' */
lua_pushnil(L); /* */
while (lua_next(L, t) != 0) {
/* '' -2 '' -1 */
printf("%s - %s\n",
lua_typename(L, lua_type(L, -2)),
lua_typename(L, lua_type(L, -1)));
/* '' '' */
lua_pop(L, 1);
}
lua_tolstring
lua_tolstring
lua_next
next
lua_Number
typedef double lua_Number;
luaconf.h
LUA_REAL
lua_numbertointeger
int lua_numbertointeger (lua_Number n, lua_Integer *p);
n
*p
lua_pcall
int lua_pcall (lua_State *L, int nargs, int nresults, int msgh);
nargs
nresults
lua_pcall
lua_pcall
lua_call
lua_call
lua_call
lua_pcall
msgh
msgh
lua_pcall
lua_pcall
lua_pcall
LUA_OK
LUA_ERRRUN
LUA_ERRMEM
LUA_ERRERR
lua.h
LUA_ERRGCMM
__gc
lua_pcallk
int lua_pcallk (lua_State *L,
int nargs,
int nresults,
int msgh,
lua_KContext ctx,
lua_KFunction k);
lua_pcall
lua_pop
void lua_pop (lua_State *L, int n);
n
lua_pushboolean
void lua_pushboolean (lua_State *L, int b);
b
lua_pushcclosure
void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
lua_pushcclosure
n
lua_pushcclosure
n
n
lua_pushcfunction
void lua_pushcfunction (lua_State *L, lua_CFunction f);
function
lua_CFunction
lua_pushcfunction
#define lua_pushcfunction(L,f) lua_pushcclosure(L,f,0)
lua_pushfstring
const char *lua_pushfstring (lua_State *L, const char *fmt, ...);
sprintf
%%
%
%f
lua_Integer
%d
%U
%s
lua_Number
%p
int
%c
int
long int
lua_pushglobaltable
void lua_pushglobaltable (lua_State *L);
lua_pushinteger
void lua_pushinteger (lua_State *L, lua_Integer n);
n
lua_pushlightuserdata
%L
void*
lua_pushliteral
const char *lua_pushliteral (lua_State *L, const char *s);
lua_pushlstring
lua_pushlstring
const char *lua_pushlstring (lua_State *L, const char *s, size_t len);
s
len
s
lua_pushnil
void lua_pushnil (lua_State *L);
lua_pushnumber
void lua_pushnumber (lua_State *L, lua_Number n);
n
lua_pushstring
const char *lua_pushstring (lua_State *L, const char *s);
s
NULL
NULL
lua_pushthread
int lua_pushthread (lua_State *L);
L
lua_pushvalue
void lua_pushvalue (lua_State *L, int index);
lua_pushvfstring
const char *lua_pushvfstring (lua_State *L,
const char *fmt,
va_list argp);
lua_pushfstring
va_list
lua_rawequal
int lua_rawequal (lua_State *L, int index1, int index2);
index1
index2
lua_rawget
int lua_rawget (lua_State *L, int index);
lua_gettable
lua_rawgeti
int lua_rawgeti (lua_State *L, int index, lua_Integer n);
t[n]
lua_rawgetp
int lua_rawgetp (lua_State *L, int index, const void *p);
t[k]
lua_rawlen
size_t lua_rawlen (lua_State *L, int index);
#
lua_rawset
void lua_rawset (lua_State *L, int index);
lua_settable
lua_rawseti
void lua_rawseti (lua_State *L, int index, lua_Integer i);
t[i] = v
lua_rawsetp
void lua_rawsetp (lua_State *L, int index, const void *p);
t[k] = v
lua_Reader
typedef const char * (*lua_Reader) (lua_State *L,
void *data,
size_t *size);
lua_load
lua_load
data
size
NULL
size
lua_register
void lua_register (lua_State *L, const char *name, lua_CFunction f);
f
name
#define lua_register(L,n,f) \
(lua_pushcfunction(L, f), lua_setglobal(L, n))
lua_remove
void lua_remove (lua_State *L, int index);
lua_replace
void lua_replace (lua_State *L, int index);
lua_resume
int lua_resume (lua_State *L, lua_State *from, int nargs);
lua_resume
lua_yield
lua_resume
nargs
LUA_YIELD
lua_pcall
lua_yield
lua_resume
yield
from
L
NULL
lua_rotate
void lua_rotate (lua_State *L, int idx, int n);
idx
n
-n
lua_setallocf
void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
ud
lua_setfield
void lua_setfield (lua_State *L, int index, const char *k);
t[k] = v
lua_setglobal
void lua_setglobal (lua_State *L, const char *name);
name
lua_seti
void lua_seti (lua_State *L, int index, lua_Integer n);
t[n] = v
lua_setmetatable
void lua_setmetatable (lua_State *L, int index);
lua_settable
void lua_settable (lua_State *L, int index);
t[k] = v
lua_settop
void lua_settop (lua_State *L, int index);
index
lua_setuservalue
void lua_setuservalue (lua_State *L, int index);
lua_State
typedef struct lua_State lua_State;
lua_newstate
lua_status
int lua_status (lua_State *L);
L
LUA_OK
lua_resume
LUA_YIELD
LUA_OK
LUA_OK
LUA_YIELD
lua_stringtonumber
size_t lua_stringtonumber (lua_State *L, const char *s);
s
lua_toboolean
int lua_toboolean (lua_State *L, int index);
lua_toboolean
lua_isboolean
lua_tocfunction
lua_CFunction lua_tocfunction (lua_State *L, int index);
NULL
lua_tointeger
lua_Integer lua_tointeger (lua_State *L, int index);
lua_tointegerx
isnum
NULL
lua_tointegerx
lua_Integer lua_tointegerx (lua_State *L, int index, int *isnum);
lua_Integer
lua_tointegerx
isnum
NULL
*isnum
lua_tolstring
const char *lua_tolstring (lua_State *L, int index, size_t *len);
len
*len
NULL
NULL
lua_tolstring
lua_tolstring
lua_next
lua_tolstring
lua_tolstring
lua_tonumber
lua_Number lua_tonumber (lua_State *L, int index);
lua_tonumberx
isnum
NULL
lua_tonumberx
lua_Number lua_tonumberx (lua_State *L, int index, int *isnum);
lua_Number
lua_tonumberx
isnum
NULL
*isnum
lua_topointer
const void *lua_topointer (lua_State *L, int index);
void*
lua_topointer
NULL
lua_tostring
const char *lua_tostring (lua_State *L, int index);
lua_tolstring
len
NULL
lua_tothread
lua_State *lua_tothread (lua_State *L, int index);
lua_State*
NULL
lua_touserdata
void *lua_touserdata (lua_State *L, int index);
NULL
lua_type
int lua_type (lua_State *L, int index);
LUA_TNONE
lua_type
lua.h
LUA_TNIL
LUA_TNUMBER
LUA_TBOOLEAN
LUA_TSTRING
LUA_TTABLE
LUA_TFUNCTION
LUA_TUSERDATA LUA_TTHREAD LUA_TLIGHTUSERDATA
lua_typename
const char *lua_typename (lua_State *L, int tp);
tp
tp
lua_type
lua_Unsigned
typedef ... lua_Unsigned;
lua_Integer
lua_upvalueindex
int lua_upvalueindex (int i);
i
lua_version
const lua_Number *lua_version (lua_State *L);
lua_State
NULL
lua_Writer
typedef int (*lua_Writer) (lua_State *L,
const void* p,
size_t sz,
void* ud);
lua_dump
lua_dump
lua_dump
p
sz
data
lua_dump
lua_xmove
void lua_xmove (lua_State *from, lua_State *to, int n);
from
to
lua_yield
int lua_yield (lua_State *L, int nresults);
lua_yieldk
lua_yield
lua_yieldk
int lua_yieldk (lua_State *L,
int nresults,
lua_KContext ctx,
lua_KFunction k);
lua_yieldk
lua_resume
nresults
lua_resume
k
n
lua_yieldk
lua_resume
ctx
lua_yieldk
lua_yield
lua_Debug
} lua_Debug;
lua_getstack
lua_getinfo
lua_Debug
lua_Debug
source
source
@
source
source
short_src
linedefined
lastlinedefined
what
source
"Lua"
"C"
"main"
currentline
currentline
name
lua_getinfo
name
NULL
namewhat
name
namewhat
"global" "local" "method" "field" "upvalue"
""
istailcall
nups
nparams
isvararg
lua_gethook
lua_Hook lua_gethook (lua_State *L);
lua_gethookcount
int lua_gethookcount (lua_State *L);
lua_gethookmask
int lua_gethookmask (lua_State *L);
lua_getinfo
int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
ar
lua_getstack
lua_Hook
what
>
lua_getinfo
f
lua_Debug ar;
lua_getglobal(L, "f"); /* 'f' */
lua_getinfo(L, ">S", &ar);
printf("%d\n", ar.linedefined);
what
ar
n
S
l
t
u
f
L
name
namewhat
source
short_src
linedefined
what
currentline
istailcall
nups nparams
isvararg
lastlinedefined
f
what
lua_getlocal
const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
ar
lua_getstack
n
debug.getlocal
lua_Hook
lua_getlocal
ar
NULL
NULL
lua_getstack
int lua_getstack (lua_State *L, int level, lua_Debug *ar);
lua_Debug
lua_getstack
lua_getupvalue
const char *lua_getupvalue (lua_State *L, int funcindex, int n);
lua_getupvalue
funcindex
NULL
""
lua_Hook
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
ar
event
LUA_HOOKCALL LUA_HOOKRET
LUA_HOOKTAILCALL LUA_HOOKLINE
currentline
lua_getinfo
event
LUA_HOOKTAILCALL
LUA_HOOKCOUNT
ar
LUA_HOOKCALL
k
lua_pcallk
lua_callk
lua_yield
nresults
lua_yieldk
lua_sethook
void lua_sethook (lua_State *L, lua_Hook f, int mask, int count);
mask
LUA_MASKCALL
LUA_MASKCOUNT
LUA_MASKCOUNT
LUA_MASKRET
count
LUA_MASKLINE
count
mask
lua_setlocal
const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
lua_getlocal
ar
lua_setlocal
lua_getlocal
NULL
lua_setupvalue
const char *lua_setupvalue (lua_State *L, int funcindex, int n);
funcindex
lua_getupvalue
lua_getupvalue
NULL
lua_upvalueid
void *lua_upvalueid (lua_State *L, int funcindex, int n);
funcindex
funcindex
n
lua_getupvalue
n
lua_getupvalue
n
lua_upvaluejoin
void lua_upvaluejoin (lua_State *L, int funcindex1, int n1,
int funcindex2, int n2);
funcindex1
funcindex2
n1
n2
lauxlib.h
luaL_
bad argument #1
luaL_check*
luaL_addchar
void luaL_addchar (luaL_Buffer *B, char c);
B
luaL_Buffer
luaL_addlstring
void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);
B
luaL_Buffer
luaL_addsize
void luaL_addsize (luaL_Buffer *B, size_t n);
B
luaL_Buffer
luaL_prepbuffer
n
luaL_addstring
void luaL_addstring (luaL_Buffer *B, const char *s);
B
luaL_Buffer
luaL_addvalue
void luaL_addvalue (luaL_Buffer *B);
B
luaL_Buffer
luaL_argcheck
void luaL_argcheck (lua_State *L,
int cond,
int arg,
luaL_argerror
int luaL_argerror (lua_State *L, int arg, const char *extramsg);
arg
extramsg
bad argument #arg to 'funcname' (extramsg)
luaL_Buffer
typedef struct luaL_Buffer luaL_Buffer;
luaL_Buffer
luaL_buffinit(L, &b)
luaL_add*
luaL_pushresult(&b)
luaL_Buffer
b
luaL_buffinitsize(L, &b, sz)
luaL_pushresultsize(&b, sz)
luaL_addvalue
sz
sz
luaL_pushresult
luaL_buffinit
void luaL_buffinit (lua_State *L, luaL_Buffer *B);
B
luaL_Buffer
luaL_buffinitsize
char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz);
luaL_buffinit
luaL_prepbuffsize
luaL_callmeta
int luaL_callmeta (lua_State *L, int obj, const char *e);
obj
luaL_checkany
void luaL_checkany (lua_State *L, int arg);
arg
luaL_checkinteger
lua_Integer luaL_checkinteger (lua_State *L, int arg);
arg
lua_Integer
luaL_checklstring
const char *luaL_checklstring (lua_State *L, int arg, size_t *l);
arg
NULL
l
*l
lua_tolstring
luaL_checknumber
lua_Number luaL_checknumber (lua_State *L, int arg);
arg
luaL_checkoption
int luaL_checkoption (lua_State *L,
int arg,
const char *def,
const char *const lst[]);
arg
def
NULL
lst
def
arg
luaL_checkstack
void luaL_checkstack (lua_State *L, int sz, const char *msg);
top + sz
msg
NULL
luaL_checkstring
const char *luaL_checkstring (lua_State *L, int arg);
arg
lua_tolstring
luaL_checktype
void luaL_checktype (lua_State *L, int arg, int t);
arg
lua_type
luaL_checkudata
void *luaL_checkudata (lua_State *L, int arg, const char *tname);
arg
luaL_newmetatable
lua_touserdata
tname
luaL_checkversion
void luaL_checkversion (lua_State *L);
luaL_dofile
int luaL_dofile (lua_State *L, const char *filename);
luaL_dostring
int luaL_dostring (lua_State *L, const char *str);
luaL_error
int luaL_error (lua_State *L, const char *fmt, ...);
fmt
lua_pushfstring
return
luaL_error(args)
luaL_execresult
int luaL_execresult (lua_State *L, int stat);
os.execute
io.close
luaL_fileresult
int luaL_fileresult (lua_State *L, int stat, const char *fname);
io.open
os.rename
file:seek
luaL_getmetafield
int luaL_getmetafield (lua_State *L, int obj, const char *e);
obj
e
LUA_TNIL
luaL_getmetatable
int luaL_getmetatable (lua_State *L, const char *tname);
tname
tname
luaL_newmetatable
luaL_getsubtable
int luaL_getsubtable (lua_State *L, int idx, const char *fname);
t[fname]
idx
luaL_gsub
const char *luaL_gsub (lua_State *L,
const char *s,
const char *p,
const char *r);
s
luaL_len
lua_Integer luaL_len (lua_State *L, int index);
#
luaL_loadbuffer
int luaL_loadbuffer (lua_State *L,
const char *buff,
size_t sz,
const char *name);
luaL_loadbufferx
mode
NULL
luaL_loadbufferx
int luaL_loadbufferx (lua_State *L,
const char *buff,
size_t sz,
const char *name,
const char *mode);
lua_load
buff
sz
lua_load
mode
name
lua_load
luaL_loadfile
int luaL_loadfile (lua_State *L, const char *filename);
luaL_loadfilex
mode
NULL
luaL_loadfilex
int luaL_loadfilex (lua_State *L, const char *filename,
const char *mode);
filename
#
lua_load
filename
NULL
mode
lua_load
lua_load
LUA_ERRFILE
lua_load
luaL_loadstring
int luaL_loadstring (lua_State *L, const char *s);
lua_load
s
lua_load
lua_load
luaL_newlib
void luaL_newlib (lua_State *L, const luaL_Reg l[]);
l
(luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
l
luaL_newlibtable
void luaL_newlibtable (lua_State *L, const luaL_Reg l[]);
l
luaL_newlib
luaL_setfuncs
l
luaL_newmetatable
int luaL_newmetatable (lua_State *L, const char *tname);
tname
__name = tname
[tname]
= new table
__name
tname
luaL_newstate
lua_State *luaL_newstate (void);
realloc
lua_newstate
NULL
luaL_openlibs
void luaL_openlibs (lua_State *L);
luaL_optinteger
lua_Integer luaL_optinteger (lua_State *L,
int arg,
lua_Integer d);
arg
d
luaL_optlstring
const char *luaL_optlstring (lua_State *L,
int arg,
const char *d,
size_t *l);
arg
d
l
NULL
*l
luaL_optnumber
lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number d);
arg
d
luaL_optstring
const char *luaL_optstring (lua_State *L,
int arg,
const char *d);
arg
d
luaL_prepbuffer
char *luaL_prepbuffer (luaL_Buffer *B);
luaL_prepbuffsize
LUAL_BUFFERSIZE
luaL_prepbuffsize
char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz);
sz
luaL_Buffer
luaL_addsize
luaL_pushresult
void luaL_pushresult (luaL_Buffer *B);
B
luaL_pushresultsize
void luaL_pushresultsize (luaL_Buffer *B, size_t sz);
luaL_addsize luaL_pushresult
luaL_ref
int luaL_ref (lua_State *L, int t);
t
luaL_ref
lua_rawgeti(L, t, r)
LUA_NOREF
luaL_unref
luaL_ref
luaL_ref
LUA_REFNIL
luaL_Reg
typedef struct luaL_Reg {
const char *name;
lua_CFunction func;
} luaL_Reg;
luaL_setfuncs
luaL_Reg
name
name
func
func
NULL
luaL_requiref
void luaL_requiref (lua_State *L, const char *modname,
lua_CFunction openf, int glb);
modname
package.loaded
modname
package.loaded[modname]
glb
openf
require
modname
luaL_setfuncs
void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);
l
nup
luaL_Reg
nup
luaL_setmetatable
void luaL_setmetatable (lua_State *L, const char *tname);
tname
luaL_newmetatable
luaL_Stream
typedef struct luaL_Stream {
FILE *f;
lua_CFunction closef;
} luaL_Stream;
LUA_FILEHANDLE
LUA_FILEHANDLE
luaL_newmetatable
luaL_Stream
f
NULL
closef
NULL
luaL_testudata
void *luaL_testudata (lua_State *L, int arg, const char *tname);
luaL_checkudata
NULL
luaL_tolstring
const char *luaL_tolstring (lua_State *L, int idx, size_t *len);
len
NULL
*len
"__tostring"
luaL_tolstring
luaL_traceback
void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
int level);
L1
msg
NULL
level
luaL_typename
const char *luaL_typename (lua_State *L, int index);
luaL_unref
void luaL_unref (lua_State *L, int t, int ref);
t
ref
ref
LUA_NOREF
luaL_ref
ref
LUA_REFNIL
luaL_unref
luaL_where
void luaL_where (lua_State *L, int lvl);
lvl
chunkname:currentline:
type
table.sort
getmetatable
luaL_openlibs
luaL_requiref
luaopen_package
luaopen_string
luaopen_table
luaopen_io
luaopen_debug
luaopen_base
luaopen_coroutine
luaopen_utf8
luaopen_math
luaopen_os
lualib.h
assert (v [, message])
v
error
message
assertion failed!
collect
stop
restart
count
step
arg
setpause
arg
setstepmul
arg
isrunning
dofile ([filename])
dofile
stdin
dofile
dofile
error
level
error
error
_G
getmetatable (object)
object
"__metatable"
error
ipairs (t)
t
for i,v in ipairs(t) do body end
1,t[1]
2,t[2]
chunk
load
chunk
chunk
env
_ENV
string.dump
chunkname
chunk
chunk
=(load)
mode
b
bt
bt
filename
next
next
next
next(t)
next
pairs (t)
t
__pairs
next
pcall (f [, arg1, ])
f
pcall
pcall
pcall
print ()
stdout
print
string.format
io.write
tostring
v1
v2
table
index
rawlen (v)
v
value table
value
table
select (index, )
index
index
index
"#"
select
tonumber (e [, base])
base
tonumber
tonumber
base
tostring (v)
string.format
v
"__tostring"
tostring
type (v)
table
number
string
thread
userdata
function
nil
boolean
_VERSION
Lua 5.3
msgh
coroutine
coroutine.create (f)
f
f
"thread"
coroutine.isyieldable ()
val1
resume
yield
resume
coroutine.running ()
coroutine.status (co)
status
co
"running"
"suspended"
"normal"
"dead"
yield
coroutine.wrap (f)
f
resume
f
resume
coroutine.yield ()
yield
require
resume
package
require (modname)
package.loaded
require
modname
package.loaded[modname]
require
package.searchers
require
package.searchers
require
package.preload[modname]
require
package.path
package.cpath
package.searchers
require
modname
require
package.loaded[modname]
package.loaded[modname] require
require
package.loaded[modname]
require
package.config
\
/
;
?
!
luaopen_
-
package.cpath
require
package.path
LUA_CPATH_5_3
luaconf.h
package.cpath
LUA_CPATH
package.loaded
require
package.loaded[modname]
modname
require
require
*
funcname
funcname
lua_CFunction
lua_CFunction
require
libname
funcname
dlfcn
package.path
require
LUA_PATH_5_3
luaconf.h
;;
package.preload
require
LUA_PATH
require
package.searchers
require
require
require
package.preload
package.path
package.searchpath
package.cpath
package.searchpath
"./?.so;./?.dll;/usr/local/?/init.so"
foo
/usr/local/foo/init.so
./foo.so ./foo.dll
luaopen_
a.b.c-v2.1
luaopen_a_b_c
a.b.c
luaopen_a_b_c
package.searchpath
name
name
sep
rep
"./?.lua;./?.lc;/usr/local/?/init.lua"
foo.a
/usr/local/foo/a/init.lua
./foo/a.lua
./foo/a.lc
string
__index
string.byte(s,i)
s:byte(i)
string.byte (s [, i [, j]])
s[i]
j
s[i+1]
i
string.char ()
s[j]
string.sub
pattern
s
init
plain
pattern
init
plain
string.format (formatstring, )
sprintf
* h L l n p
a
c d i o u X
s
E e f G
x
g
q
s
tostring
s
pattern
s
s = "hello world from Lua"
for w in string.gmatch(s, "%a+") do
print(w)
end
key=value
t = {}
s = "from=world, to=Lua"
for k, v in string.gmatch(s, "(%w+)=(%w+)") do
t[k] = v
end
^
n
repl
pattern
repl
gsub
gsub
repl
%
repl
%d
%0
repl
repl
%%
string.len (s)
""
"a\000bc\000"
string.lower (s)
pattern
match
pattern
pattern
init
v1 v2
fmt
string.packsize (fmt)
string.pack
s
z
sep
sep
string.reverse (s)
s
j
string.sub(s,1,j)
-i)
i
j
s
string.sub(s,
j
j
string.pack
string.upper (s)
^$()%.[]*+-?
.
%a
%c
%d
%g
%l
%p
%s
%u
%w
%x
%x
%
[set]
%
[%w_]
[0-7]
-
[_%w]
[0-7%l%-]
[%a-z]
[^set]
%a %c
%S
[a-z]
%l
[a-%%]
*
+
-
?
%n
%bxy
%b()
%f[set]
\0
^
$
^
"(a*(.)
%w(%s*))"
"a*(.)%w(%s*)"
.
%s*
()
"()aa()"
"flaaap"
string.pack
<
>
=
![n]
b
B
h
H
l
L
j
J
T
i[n]
I[n]
f
d
n
cn n
z
s[n]
size_t
x
Xop
string.packsize
n
char
char
short
short
long
long
lua_Integer
lua_Unsigned
size_t
n
n
float
double
lua_Number
int
int
op
[n]
<=>!
string.unpack
!n
string.unpack
sn
xX
string.pack
in In n
string.pack
string.unpack
!1=
c
z
string.pack
string.unpack
utf8
utf8.char ()
utf8.charpattern
[\0-\x7F\xC2-\xF4][\x80-\xBF]*
utf8.codes (s)
utf8.codepoint (s [, i [, j]])
s
i
i
j
utf8.len (s [, i [, j]])
n
n
i
i
#s + 1
n
utf8.offset(s, -n)
table
__len
sep
j
value
list[pos],
pos
t
#list+1
a2
a1
table.pack ()
n
list[#list]
#list
pos
list[pos+1], list[pos+2],
pos
#list + 1
list[pos]
table.remove(l)
list[#list]
not
comp(list[i+1],list[i])
comp
<
#list
math
integer/float
math.ceil math.floor math.modf
math.abs (x)
math.acos (x)
x
math.asin (x)
x
math.atan (y [, x])
y/x
x
x
math.atan(y)
math.ceil (x)
x
math.cos (x)
x
math.deg (x)
x
math.exp (x)
e
math.floor (x)
x
math.fmod (x, y)
x
math.huge
HUGE_VAL
math.log (x [, base])
x
base
math.max (x, )
<
math.maxinteger
math.min (x, )
<
math.mininteger
math.modf (x)
x
math.pi
math.rad (x)
x
math.random
math.random(n)
math.randomseed (x)
math.random(1,n)
math.sin (x)
x
math.sqrt (x)
x
x^0.5
math.tan (x)
x
math.tointeger (x)
x
math.type (x)
x
integer
float
math.ult (m, n)
m
io
io.open
io
io.stdout
io.stdin
io.stderr
errno
io.close ([file])
file:close()
file
io.flush ()
io.output():flush()
io.input ([file])
io.lines ([filename ])
file:lines()
io.lines()
io.input():lines("*l")
mode
r
w
a
r+
w+
a+
mode
io.output ([file])
io.input
mode
"w"
mode
prog
"r"
io.read ()
io.input():read()
io.tmpfile ()
io.type (obj)
obj
obj
"file"
"closed file"
obj
obj
io.write ()
io.output():write()
file:close ()
file
io.popen
os.execute
file:close
file:flush ()
file
file:lines ()
l
for c in file:lines(1) do body end
io.lines
file:read ()
file
0x
i
a
l
L
number
3.4e-
offset
whence
whence
set
cur
end
seek
seek
whence
"cur"
offset
file:seek()
file:seek("set")
file:seek("end")
no
full
flush
line
io.flush
size
file:write ()
file
file
os
os.clock ()
format
time
date
format
os.time
!
format
*t
month
sec
min
yday
format
strftime
*t
date
year
hour
day
wday
isdst
date
date
os.date()
os.date("%c")
gmtime
localtime
t2
os.time
t2
t1
os.execute ([command])
system
command
exit
signal
os.execute
code
code
EXIT_FAILURE
code
code
close
os.getenv (varname)
varname
os.remove (filename)
newname
"all"
"numeric"
"collate"
"time"
setlocale
os.time ([table])
year month
hour
isdst
min
day
sec
os.date
time
os.date
os.difftime
os.tmpname ()
io.tmpfile
debug
debug.debug ()
cont
debug.debug
debug.gethook ([thread])
debug.sethook
f
getinfo
getinfo
f
getinfo
what
lua_getinfo
what
f
func
activelines
debug.getinfo(1,"n")
debug.getinfo(print)
local
debug.getinfo
getlocal
debug.getmetatable (value)
value
debug.getregistry ()
up
debug.getuservalue (u)
u
count
c
r
l
count
count
debug.sethook
"call"
call"
"return"
"line"
"count"
getinfo
getinfo
level
local
level
debug.getinfo
debug.getlocal
table
value
up
"tail
udata
udata
udata
level
traceback
debug.upvalueid (f, n)
n
n1
lua
lua [options] [script [args]]
-e stat
-l mod
-i
-v
-E
f2
n2
--
stdin
lua
stdin
lua
lua -v -i
lua -
-E
LUA_INIT_5_3
@filename
LUA_PATH
package.cpath
-i
lua
-E
LUA_CPATH
LUA_INIT
lua
LUA_INIT
package.path
luaconf.h
-E
script.lua
$
lua
arg
$ lua -e "print(arg[1])"
-e
arg[1]
arg[#arg]
__tostring
lua_close
os.exit
chmod +x
#!
#!/usr/local/bin/lua
lua
PATH
#!/usr/bin/env lua
luaconf.h
.0
x = x + 0.0
.0
2.0
bit32
bit32
ipairs
io.read
__ipairs
*
atan2
cosh
sinh tanh
pow
frexp
ldexp
x^y
math.pow(x,y) math.atan math.atan2
x * 2.0^exp
math.ldexp(x,exp)
Lua
require C
Lua 5.2
lua_getctx
lua_getctx
lua_dump strip
0
lua_pushunsigned
lua_tounsigned lua_tounsignedx luaL_checkunsigned
luaL_optunsigned
luaL_checkint luaL_optint
luaL_checklong luaL_optlong
lua_Integer
lua_Integer