You are on page 1of 121

lua

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

2

type

var
_ENV.var

j

_ENV _ENV _ENV _ENV _ENV _ENV _G _G _ENV load load loadfile lua error pcall xpcall lua_pcall xpcall .

event_name) .__add "add" getmetatable setmetatable __ __add obj rawget(getmetatable(obj) or {}.. "__" .

.+ __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 .

yield coroutine.resume coroutine.resume coroutine.wrap .create coroutine.resume coroutine.resume coroutine.yield coroutine.create create coroutine.create coroutine.resume coroutine.resume coroutine.yield coroutine.coroutine.resume coroutine.resume coroutine.

r) local r. s) return b. a.resume(co.create(function (a. a) return coroutine.wrap coroutine. s = coroutine. a-b) print("co-body". b) local r = foo(a+1) print("co-body". "y")) 10 4 11 -9 y 10 end cannot resume dead coroutine lua_newthread lua_resume lua_yield .b) print("co-body".resume(co. "y")) "x". print("main". print("main". coroutine.resume coroutine.resume(co. 1.resume coroutine.coroutine. coroutine. co-body 1 foo 2 main true co-body r main true co-body x main true main false coroutine.yield(2*a) end co = coroutine. coroutine. "end" end) print("main".wrap function foo (a) print("foo". r. print("main".yield(a+b. 10)) "r")) "x".resume(co.resume coroutine.

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

E

0X
p

P

0x

3

345

0xff

0xBEBADA

3.0
3.1416
314.16e-2
0.31416E1
34e1
0x0.1E 0xA23p-4 0X1.921FB54442D18P+1
--

--

var ::= Name

var ::= prefixexp ‘[’ exp ‘]’
t[i]
gettable_event(t,i)
gettable_event

var.Name

var["Name"]

(print or io.’ Name x _ENV.write)('done') a = b + c(print or io.(print or io.write)('done') .’ a=b+c (print or io.write)('done') stat ::= do block end .write)('done') a = b + c.x _ENV block ::= {stat} stat ::= ‘.var ::= prefixexp ‘.

20 a[3] a[4] a[i] i .’ var} explist ::= exp {‘. a[i] = i+1.chunk ::= block _ENV _ENV luac string.’ exp} i=3 i.dump load stat ::= varlist ‘=’ explist varlist ::= var {‘.

val) _ENV.x. x x y z t[i] = val settable_event x = val settable_event(t. z = y. x x y x. y.i. y = y. z.x = val stat ::= while exp do block end stat ::= repeat block until exp stat ::= if exp then block {elseif exp then block} [else block] stat ::= goto Name stat ::= label label ::= ‘::’ Name ‘::’ .

step while true do var = var + step if (step >= 0 and var > limit) or (step < 0 and var < limit) then break . e3 do block end do local var.stat ::= break stat ::= return [explist] [‘.’] do return end stat ::= for Name ‘=’ exp ‘. step = tonumber(e1).’ exp] do block end for v = e1. tonumber(e3 if not (var and limit and step) then error() end var = var . limit. e2.’ exp [‘. tonumber(e2).

···. ···. var) if var_1 == nil then break end var = var_1 block end end explist f s var .’ Name} for var_1. s.end local v = var block end end var limit step v stat ::= for namelist in explist do block end namelist ::= Name {‘. var = explist while true do local var_1. var_n = f(s. var_n in explist do block end do local f.

..var_i stat ::= functioncall stat ::= local namelist [‘=’ explist] exp ::= prefixexp exp ::= nil | false | true exp ::= Numeral exp ::= LiteralString exp ::= functiondef exp ::= tableconstructor exp ::= ‘.’ exp ::= exp binop exp exp ::= unop exp prefixexp ::= var | functioncall | ‘(’ exp ‘)’ .

f() -.f() 被调整为 1 个结果 (c 收到 nil) a.返回从可变参数列表中接收到的所有参数parameters return x.c = f() -. -.b.a 收到可变参数列表的第一个参数, -.没有实际的参数,a 和 b 都会收到 nil) a.f() 被调整为 3 个结果 return f() -.用可变参数中的所有值创建一个列表 {f(). y.c = f()..c = x.z)) f + f f .y. x) -.g 收到 x 以及 f() 返回的所有结果 a.z)) (f(x...y.调整为 0 个结果 g(f(). f() -..f() 被调整为 2 个结果 a. f()) -. x -.. -.b 收到第二个参数(如果可变参数列表中 -....b. 以及 f() 的所有返回值 {f()} -..b = .f() 会被调整为一个结果 g(x.y.} -.f() 被调整为一个结果 (f(x.返回 f() 的所有返回结果 return . nil} -.b. f() -.用 f() 的所有返回值创建一个列表 {.返回 x.

* / // % ^ - / pow // & | ~ >> << ~ .

format == ~= < > <= >= == .format string.

"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 .

^ . + * / // % unary operators (not # ^ 3 == - ~) ... __concat # __len __len t {10. 20.. nil. 40} 4 or and < > <= >= ~= | ~ & << >> ..

"y". [30] = 23.4th exp exp functioncall ::= prefixexp args .x = 1 t[3] = f(x) t[30] = 23 t[4] = 45 a=t end -. f(x).3rd exp -. 45 } do local t = {} t[f(1)] = g t[1] = "x" t[2] = "y" t.t["x"] = 1 -. "x".’ [exp1] = exp2 exp2 name = exp exp [i] = exp exp1 ["name"] = exp i a = { [f(1)] = g.2nd exp -.1st exp -.tableconstructor ::= ‘{’ [fieldlist] ‘}’ fieldlist ::= field {fieldsep field} [fieldsep] field ::= ‘[’ exp ‘]’ ‘=’ exp | Name ‘=’ exp | exp fieldsep ::= ‘.’ | ‘. x = 1.

返回值全部被舍弃 -. return return x or f(x) -. f(x) f(x).args) v args ::= ‘(’ [explist] ‘)’ args ::= tableconstructor args ::= LiteralString f{fields} f({fields}) f'string' f('string') f"string" return functioncall return (f(x)) return 2 * f(x) return x.返回值被调整为一个 functiondef ::= function funcbody funcbody ::= ‘(’ [parlist] ‘)’ block end f[[string]] .返回值被调整为一个 -.functioncall ::= prefixexp ‘:’ Name args v:name(args) v.name(v.追加若干返回值 -.

..’ .a.c. f = function () body end local f = function () body end f parlist ::= namelist [‘.f () body end t.b...stat ::= function funcname funcbody stat ::= local function Name funcbody funcname ::= Name {‘.f = function () body end local function f () body end local f.a.’ Name} [‘:’ Name] function f () body end f = function () body end function t.’ ‘. ...c.b.’] | ‘.

. 4. --> (nothing) g(3.3 end CALL PARAMETERS f(3) f(3.. 4) a=3. . --> (nothing) g(3..c.2. b=nil a=3. b=2 g(3) a=3. 8) a=3. b=4. b) end function g(a.. --> 5 8 g(5. b. . b=nil.. 5.function f(a. . . b=4 a=3. 4. 4) f(3. 10) f(r()) a=3.. 5) f(r().. b=1. r()) a=5. --> 2 3 self function t.f = function (self..b.b. b=4.. .a. b=10 a=1. b=4 a=1.c:f (params) body end t.) end function r() return 1. params) body end ..a.

h .10 do local y = 0 a[i] = function () y=y+1.新的语句块 local x = x -.x = 10 -.又一个 'x' print(x) --> 12 end print(x) --> 11 end print(x) --> 10 (取到的是全局的那一个) local x = x x x a = {} local x = 20 for i=1.新的一个 'x'. return x+y end end y x lua.全局变量 do -.另一个语句块 local x = x+1 -. 它的值现在是 10 print(x) --> 10 x = x+1 do -.

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 .

m.longjmp foo longjmp foo lua_yieldk lua_yieldk lua_callk lua_callk k lua_pcallk lua_pcallk int original_function (lua_State *L) { . lua_KContext ctx) { ... /* code 1 */ status = lua_pcall(L. h)... h). n. lua_pcall(L. ctx)... /* code 1 */ return k(L. } . /* calls Lua */ . /* code 2 */ } lua_pcall int k (lua_State *L.. /* code 2 */ } int original_function (lua_State *L) { . m.. n. int status.

ctx1). h. lua_pcallk(L.. n. k). m. ctx2.k lua_KFunction lua_pcall lua_pcall lua_pcall k lua_pcallk int original_function (lua_State *L) { .. } 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 . /* code 1 */ return k(L.

idx lua_Alloc typedef void * (*lua_Alloc) (void *ud. size_t nsize). int idx). void *ptr. size_t osize.x y ? x e v lua_absindex int lua_absindex (lua_State *L. realloc lua_newstate ud ptr osize nsize ptr ptr NULL NULL osize ptr osize osize LUA_TSTRING LUA_TTABLE LUA_TFUNCTION LUA_TUSERDATA LUA_TTHREAD nsize free nsize NULL luaL_newstate osize NULL realloc osize >= nsize .

size_t osize. } else return realloc(ptr. /* not used */ if (nsize == 0) { free(ptr). 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 + * / // % ^ ~ & | ~ << >> . } free(NULL) realloc(NULL. size_t nsize) { (void)ud. (void)osize. return NULL.static void *l_alloc (void *ud. int op). nsize). void *ptr.size) malloc(size) realloc lua_arith void lua_arith (lua_State *L.

t.x. -2). int nresults. lua_CFunction panicf). "x").x (2nd arg) */ lua_remove(L. lua_call nargs nresults nresults LUA_MULTRET longjmp a = f("how". -1. /* 1st argument */ lua_getglobal(L. 3. 14). "how"). /* function to be called */ lua_pushliteral(L. 1). int nargs. /* table to be indexed */ lua_getfield(L.lua_CFunction lua_atpanic (lua_State *L. int nresults). /* set global 'a' */ lua_callk void lua_callk (lua_State *L. "f"). "a"). "t"). int nargs. lua_call void lua_call (lua_State *L. /* call 'f' with 3 arguments and 1 result */ lua_setglobal(L. /* push result of t. 14) lua_getglobal(L. . /* remove 't' from the stack */ lua_pushinteger(L. /* 3rd argument */ lua_call(L.

sum/n). for (i = 1. } lua_pushnumber(L. /* 第一个返回值 */ lua_pushnumber(L. n . lua_call lua_CFunction typedef int (*lua_CFunction) (lua_State *L). "incorrect argument"). sum). i++) { if (!lua_isnumber(L. int n). lua_gettop(L) lua_gettop(L) static int foo (lua_State *L) { int n = lua_gettop(L). lua_error(L).lua_KContext ctx. lua_KFunction k). /* 第二个返回值 */ return 2. i)) { lua_pushliteral(L.0. /* 返回值的个数 */ } lua_checkstack int lua_checkstack (lua_State *L. i). /* 参数的个数 */ lua_Number sum = 0. i <= n. } sum += lua_tonumber(L. int i.

int fromidx. n n n lua_copy void lua_copy (lua_State *L. int op). int toidx).lua_close void lua_close (lua_State *L). int index2. fromidx toidx . int n). int index1. index1 op index2 op LUA_OPEQ LUA_OPLT LUA_OPLE == < <= lua_concat void lua_concat (lua_State *L. lua_compare int lua_compare (lua_State *L.

lua_createtable void lua_createtable (lua_State *L. int strip). narr nrec lua_newtable lua_dump int lua_dump (lua_State *L. writer writer lua_dump data lua_Writer strip writer lua_error int lua_error (lua_State *L). lua_Writer writer. void *data. luaL_error lua_gc int lua_gc (lua_State *L. int narr. int nrec). what LUA_GCSTOP . int data). int what.

ud NULL *ud lua_getfield int lua_getfield (lua_State *L. const char *k). t[k] t lua_getextraspace void *lua_getextraspace (lua_State *L).h LUA_EXTRASPACE lua_getglobal . void **ud). luaconf. int index.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.

lua_getuservalue int lua_getuservalue (lua_State *L. int index.int lua_getglobal (lua_State *L. int index). . lua_Integer i). lua_geti int lua_geti (lua_State *L. const char *name). int index). int index). t[k] t k lua_gettop int lua_gettop (lua_State *L). t[i] t lua_getmetatable int lua_getmetatable (lua_State *L. lua_gettable int lua_gettable (lua_State *L.

lua_Integer. int index)..h LUA_INT LUA_MININTEGER LUA_MAXINTEGER lua_isboolean int lua_isboolean (lua_State *L. lua_isinteger int lua_isinteger (lua_State *L. . lua_iscfunction int lua_iscfunction (lua_State *L. int index). int index). int index). lua_isfunction int lua_isfunction (lua_State *L.lua_insert void lua_insert (lua_State *L. lua_Integer typedef . int index).. long long long int luaconf.

lua_islightuserdata int lua_islightuserdata (lua_State *L. lua_istable int lua_istable (lua_State *L. int index). lua_isnone int lua_isnone (lua_State *L. lua_isnumber int lua_isnumber (lua_State *L. lua_isnoneornil int lua_isnoneornil (lua_State *L. int index). lua_isthread . int index). int index). int index). lua_isnil int lua_isnil (lua_State *L. int index). lua_isstring int lua_isstring (lua_State *L. int index).

int lua_isthread (lua_State *L. . lua_len void lua_len (lua_State *L.. lua_KContext ctx). lua_isuserdata int lua_isuserdata (lua_State *L. int index). lua_KContext. int index). int index). intptr_t intptr_t ptrdiff_t lua_KFunction typedef int (*lua_KFunction) (lua_State *L. lua_isyieldable int lua_isyieldable (lua_State *L). void *data. lua_Reader reader. # lua_load int lua_load (lua_State *L. const char *mode).. lua_KContext typedef . const char *chunkname. int status.

0. NULL f ud lua_newtable void lua_newtable (lua_State *L). void *ud). lua_createtable(L. 0) lua_newthread .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.

lua_State *lua_newthread (lua_State *L). -2)). t) != 0) { /* 使用 '键' (在索引 -2 处) 和 '值' (在索引 -1 处)*/ printf("%s . /* 第一个键 */ while (lua_next(L. . lua_State lua_newuserdata void *lua_newuserdata (lua_State *L. lua_next /* 表放在索引 't' 处 */ lua_pushnil(L). size_t size). /* 移除 '值' ;保留 '键' 做下一次迭代 */ lua_pop(L. lua_type(L. lua_typename(L. lua_typename(L.%s\n". } lua_tolstring lua_tolstring lua_next next lua_Number typedef double lua_Number. lua_next int lua_next (lua_State *L. -1))). int index). 1). lua_type(L.

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. lua_Integer *p). int nresults.luaconf.h LUA_REAL lua_numbertointeger int lua_numbertointeger (lua_Number n. n *p lua_pcall int lua_pcall (lua_State *L. int nargs.h . int msgh).

lua_pushcclosure n lua_pushcclosure n n . int nresults. lua_CFunction fn.LUA_ERRGCMM __gc lua_pcallk int lua_pcallk (lua_State *L. int b). int n). int msgh. n lua_pushboolean void lua_pushboolean (lua_State *L. b lua_pushcclosure void lua_pushcclosure (lua_State *L. lua_KContext ctx. lua_pcall lua_pop void lua_pop (lua_State *L. int n). lua_KFunction k). int nargs.

n lua_pushlightuserdata %L . sprintf %% % %f lua_Integer %d %U %s lua_Number %p int %c int long int lua_pushglobaltable void lua_pushglobaltable (lua_State *L).lua_pushcfunction void lua_pushcfunction (lua_State *L. function lua_CFunction lua_pushcfunction #define lua_pushcfunction(L. lua_pushinteger void lua_pushinteger (lua_State *L.).f) lua_pushcclosure(L..f. lua_Integer n). const char *fmt. .0) lua_pushfstring const char *lua_pushfstring (lua_State *L.. lua_CFunction f).

s .void lua_pushlightuserdata (lua_State *L. void* lua_pushliteral const char *lua_pushliteral (lua_State *L. lua_pushlstring s lua_pushlstring const char *lua_pushlstring (lua_State *L. void *p). const char *s). const char *s). lua_Number n). const char *s. size_t len). n lua_pushstring const char *lua_pushstring (lua_State *L. lua_pushnumber void lua_pushnumber (lua_State *L. s len s lua_pushnil void lua_pushnil (lua_State *L).

int index). index1 index2 lua_rawget int lua_rawget (lua_State *L. int index). lua_pushvfstring const char *lua_pushvfstring (lua_State *L. lua_pushfstring va_list lua_rawequal int lua_rawequal (lua_State *L. t[n] t . int index. lua_gettable lua_rawgeti int lua_rawgeti (lua_State *L.s NULL NULL lua_pushthread int lua_pushthread (lua_State *L). lua_Integer n). L lua_pushvalue void lua_pushvalue (lua_State *L. int index1. va_list argp). const char *fmt. int index2).

int index). lua_Integer i). lua_settable lua_rawseti void lua_rawseti (lua_State *L. int index. t[k] = v t k v lua_Reader typedef const char * (*lua_Reader) (lua_State *L. t[i] = v t v lua_rawsetp void lua_rawsetp (lua_State *L. const void *p). t[k] t k p lua_rawlen size_t lua_rawlen (lua_State *L. const void *p). # lua_rawset void lua_rawset (lua_State *L. int index.lua_rawgetp int lua_rawgetp (lua_State *L. int index). p . int index.

lua_replace void lua_replace (lua_State *L. lua_CFunction f). lua_resume lua_yield lua_resume nargs LUA_YIELD .f) \ (lua_pushcfunction(L. size_t *size). lua_State *from. int index).n. int nargs). f name #define lua_register(L.void *data. int index). f). lua_resume int lua_resume (lua_State *L. lua_setglobal(L. const char *name. n)) lua_remove void lua_remove (lua_State *L. lua_load lua_load data size NULL size lua_register void lua_register (lua_State *L.

const char *k).lua_pcall lua_yield lua_resume yield from L NULL lua_rotate void lua_rotate (lua_State *L. const char *name). t[k] = v t v lua_setglobal void lua_setglobal (lua_State *L. name lua_seti void lua_seti (lua_State *L. int idx. idx n n -n n n lua_setallocf void lua_setallocf (lua_State *L. lua_Alloc f. int index. int n). void *ud). int index. t[n] = v t v . lua_Integer n). ud f lua_setfield void lua_setfield (lua_State *L.

int index).lua_setmetatable void lua_setmetatable (lua_State *L. int index). index lua_setuservalue void lua_setuservalue (lua_State *L. int index). lua_newstate . int index). t[k] = v t v k lua_settop void lua_settop (lua_State *L. lua_State typedef struct lua_State lua_State. lua_settable void lua_settable (lua_State *L.

int index). L LUA_OK lua_resume LUA_YIELD LUA_OK LUA_OK LUA_YIELD lua_stringtonumber size_t lua_stringtonumber (lua_State *L. NULL lua_tointeger lua_Integer lua_tointeger (lua_State *L. lua_toboolean lua_isboolean lua_tocfunction lua_CFunction lua_tocfunction (lua_State *L. . const char *s). int index). int index). s lua_toboolean int lua_toboolean (lua_State *L.lua_status int lua_status (lua_State *L).

len *len NULL NULL lua_tolstring lua_tolstring lua_next lua_tolstring lua_tolstring lua_tonumber lua_Number lua_tonumber (lua_State *L. lua_Number lua_tonumberx isnum NULL *isnum .lua_tointegerx isnum NULL lua_tointegerx lua_Integer lua_tointegerx (lua_State *L. int index). int *isnum). size_t *len). int index. lua_Integer lua_tointegerx isnum NULL *isnum lua_tolstring const char *lua_tolstring (lua_State *L. int *isnum). lua_tonumberx isnum NULL lua_tonumberx lua_Number lua_tonumberx (lua_State *L. int index. int index.

lua_State* NULL lua_touserdata void *lua_touserdata (lua_State *L. int index). . int index). lua_tolstring len NULL lua_tothread lua_State *lua_tothread (lua_State *L. int index). int index). int index). LUA_TNONE lua_type lua. void* lua_topointer NULL lua_tostring const char *lua_tostring (lua_State *L.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).lua_topointer const void *lua_topointer (lua_State *L. NULL lua_type int lua_type (lua_State *L.

.. lua_Unsigned. lua_dump lua_dump lua_dump p sz data lua_dump lua_xmove void lua_xmove (lua_State *from. void* ud). lua_Integer lua_upvalueindex int lua_upvalueindex (int i). lua_State *to.tp tp lua_type lua_Unsigned typedef . i lua_version const lua_Number *lua_version (lua_State *L). lua_State NULL lua_Writer typedef int (*lua_Writer) (lua_State *L. size_t sz. from n to . int n). const void* p.

lua_KFunction k). lua_KContext ctx. int nresults). lua_yieldk lua_resume nresults lua_resume k n lua_yieldk lua_resume ctx lua_yieldk lua_yield lua_Debug .lua_yield int lua_yield (lua_State *L. lua_yieldk lua_yield lua_yieldk int lua_yieldk (lua_State *L. int nresults.

/* (u) */ char istailcall. 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" "" . /* (t) */ char short_src[LUA_IDSIZE]. /* (S) */ const char *source.typedef struct lua_Debug { int event. /* (l) */ int linedefined. /* (n) */ const char *what. /* (n) */ const char *namewhat. /* (S) */ int lastlinedefined. /* (S) */ unsigned char nups. /* (S) */ /* 私有部分 */ 其它域 } lua_Debug. /* (u) 上值的数量 */ unsigned char nparams. /* (S) */ int currentline. const char *name. /* (u) 参数的数量 */ char isvararg.

/* 取得全局变量 'f' */ lua_getinfo(L. ar lua_getstack lua_Hook what > lua_getinfo f lua_Debug ar. lua_gethookcount int lua_gethookcount (lua_State *L). lua_getinfo int lua_getinfo (lua_State *L. lua_getglobal(L. &ar). printf("%d\n". const char *what. . "f").linedefined). ar.istailcall nups nparams isvararg lua_gethook lua_Hook lua_gethook (lua_State *L). lua_Debug *ar). lua_gethookmask int lua_gethookmask (lua_State *L). ">S".

int level.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. lua_Debug . lua_Debug *ar).getlocal lua_Hook lua_getlocal ar NULL NULL lua_getstack int lua_getstack (lua_State *L. int n). const lua_Debug *ar. ar lua_getstack n debug.

int funcindex.lua_getstack lua_getupvalue const char *lua_getupvalue (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 . int n). lua_getupvalue funcindex n NULL "" lua_Hook typedef void (*lua_Hook) (lua_State *L.

funcindex lua_getupvalue n lua_getupvalue NULL . f mask LUA_MASKCALL LUA_MASKCOUNT LUA_MASKCOUNT LUA_MASKRET count LUA_MASKLINE count mask lua_setlocal const char *lua_setlocal (lua_State *L. int count). int n).lua_sethook void lua_sethook (lua_State *L. int mask. const lua_Debug *ar. lua_getlocal ar lua_setlocal n lua_getlocal NULL lua_setupvalue const char *lua_setupvalue (lua_State *L. int funcindex. lua_Hook f. int n).

funcindex1 funcindex2 n1 n2 lauxlib.h luaL_ bad argument #1 luaL_check* . int n2). int funcindex1. funcindex funcindex n lua_getupvalue n lua_getupvalue n lua_upvaluejoin void lua_upvaluejoin (lua_State *L. int funcindex2.lua_upvalueid void *lua_upvalueid (lua_State *L. int funcindex. int n1. int n).

size_t l). B luaL_Buffer luaL_argcheck void luaL_argcheck (lua_State *L.luaL_addchar void luaL_addchar (luaL_Buffer *B. const char *s. B luaL_Buffer luaL_prepbuffer n luaL_addstring void luaL_addstring (luaL_Buffer *B. int arg. char c). s . size_t n). B luaL_Buffer luaL_addvalue void luaL_addvalue (luaL_Buffer *B). int cond. B luaL_Buffer l s luaL_addsize void luaL_addsize (luaL_Buffer *B. B luaL_Buffer c luaL_addlstring void luaL_addlstring (luaL_Buffer *B. const char *s).

const char *extramsg);
cond
luaL_argerror

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)

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

e

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

t

lua_type

t

const char *tname).. filename) || lua_pcall(L.).luaL_checkudata void *luaL_checkudata (lua_State *L. 0)) luaL_dostring int luaL_dostring (lua_State *L. arg luaL_newmetatable lua_touserdata tname luaL_checkversion void luaL_checkversion (lua_State *L). const char *filename). fmt lua_pushfstring return luaL_error(args) . LUA_MULTRET. 0. int arg. (luaL_loadstring(L. (luaL_loadfile(L. 0)) luaL_error int luaL_error (lua_State *L. 0.. const char *str). luaL_dofile int luaL_dofile (lua_State *L. const char *fmt. LUA_MULTRET. str) || lua_pcall(L. .

const char *fname).open os. t[fname] t idx luaL_gsub const char *luaL_gsub (lua_State *L. int stat). s p r . int idx. const char *fname).close luaL_fileresult int luaL_fileresult (lua_State *L. io. os.rename file:seek luaL_getmetafield int luaL_getmetafield (lua_State *L. int stat. const char *e).luaL_execresult int luaL_execresult (lua_State *L. const char *tname). obj e LUA_TNIL luaL_getmetatable int luaL_getmetatable (lua_State *L. const char *p.execute io. int obj. const char *r). tname tname luaL_newmetatable luaL_getsubtable int luaL_getsubtable (lua_State *L. const char *s.

lua_load buff sz lua_load mode name lua_load luaL_loadfile int luaL_loadfile (lua_State *L. const char *buff. const char *filename). const char *filename. luaL_loadfilex mode NULL luaL_loadfilex int luaL_loadfilex (lua_State *L. const char *mode). const char *name. size_t sz. # luaL_loadbuffer int luaL_loadbuffer (lua_State *L. size_t sz. const char *buff.luaL_len lua_Integer luaL_len (lua_State *L. luaL_loadbufferx mode NULL luaL_loadbufferx int luaL_loadbufferx (lua_State *L. const char *name). const char *mode). filename # lua_load filename NULL . int index).

0)) l luaL_newlibtable void luaL_newlibtable (lua_State *L.l. const luaL_Reg l[]). lua_load s lua_load lua_load luaL_newlib void luaL_newlib (lua_State *L. const luaL_Reg l[]). l luaL_newlib luaL_setfuncs l luaL_newmetatable int luaL_newmetatable (lua_State *L. tname __name = tname [tname] . luaL_setfuncs(L.mode lua_load lua_load LUA_ERRFILE lua_load luaL_loadstring int luaL_loadstring (lua_State *L. l (luaL_newlibtable(L.l). const char *tname). const char *s).

= new table __name tname luaL_newstate lua_State *luaL_newstate (void). int arg. int arg. size_t *l). realloc lua_newstate NULL luaL_openlibs void luaL_openlibs (lua_State *L). arg d luaL_optlstring const char *luaL_optlstring (lua_State *L. int arg. lua_Integer d). . const char *d. luaL_optinteger lua_Integer luaL_optinteger (lua_State *L. arg d l NULL *l luaL_optnumber lua_Number luaL_optnumber (lua_State *L. lua_Number d).

arg d luaL_prepbuffer char *luaL_prepbuffer (luaL_Buffer *B). const char *d).arg d luaL_optstring const char *luaL_optstring (lua_State *L. int t). int arg. sz luaL_Buffer luaL_addsize B luaL_pushresult void luaL_pushresult (luaL_Buffer *B). luaL_addsize luaL_pushresult luaL_ref int luaL_ref (lua_State *L. luaL_prepbuffsize LUAL_BUFFERSIZE luaL_prepbuffsize char *luaL_prepbuffsize (luaL_Buffer *B. size_t sz). t t . size_t sz). B luaL_pushresultsize void luaL_pushresultsize (luaL_Buffer *B.

l nup luaL_Reg nup luaL_setmetatable void luaL_setmetatable (lua_State *L. int nup). } luaL_Reg. int glb).luaL_ref lua_rawgeti(L. t. .loaded[modname] glb openf require modname luaL_setfuncs void luaL_setfuncs (lua_State *L. const char *modname. modname package. const char *tname). lua_CFunction openf. lua_CFunction func. luaL_setfuncs luaL_Reg name name func func NULL luaL_requiref void luaL_requiref (lua_State *L. const luaL_Reg *l.loaded modname package. r) LUA_NOREF r luaL_unref luaL_ref luaL_ref LUA_REFNIL luaL_Reg typedef struct luaL_Reg { const char *name.

tname luaL_newmetatable luaL_Stream typedef struct luaL_Stream { FILE *f. const char *msg. . size_t *len). len NULL *len "__tostring" luaL_tolstring luaL_traceback void luaL_traceback (lua_State *L. int level). } luaL_Stream. LUA_FILEHANDLE LUA_FILEHANDLE luaL_newmetatable luaL_Stream f NULL closef NULL luaL_testudata void *luaL_testudata (lua_State *L. luaL_checkudata NULL luaL_tolstring const char *luaL_tolstring (lua_State *L. lua_State *L1. int idx. lua_CFunction closef. int arg. const char *tname).

luaL_unref void luaL_unref (lua_State *L.L1 msg NULL level luaL_typename const char *luaL_typename (lua_State *L. int ref). t ref ref LUA_NOREF luaL_ref ref LUA_REFNIL luaL_unref luaL_where void luaL_where (lua_State *L. int t.sort getmetatable . lvl chunkname:currentline: type table. int index). int lvl).

message]) v error message assertion failed! collectgarbage ([opt [.h assert (v [. arg]]) opt collect stop .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.

level]) message error level error error _G getmetatable (object) object "__metatable" error .restart count step arg setpause arg setstepmul arg isrunning dofile ([filename]) dofile stdin dofile dofile error (message [.

chunkname [. mode [.t[2] load (chunk [.t[1] 2. mode [.dump chunkname chunk chunk =(load) mode b t bt bt loadfile ([filename [. env]]]) chunk load chunk chunk env _ENV string. env]]]) load filename next (table [.ipairs (t) t for i.v in ipairs(t) do body end 1. index]) .

arg1.next next next next(t) next pairs (t) t __pairs t next t for k.write rawequal (v1.v in pairs(t) do body end t next pcall (f [. ···]) f f pcall pcall pcall print (···) stdout print string. v2) tostring .format io.

index) table[index] table index rawlen (v) v v rawset (table.v1 v2 rawget (table. base]) base tonumber tonumber . index. metatable) metatable "__metatable" table tonumber (e [. ···) index index index "#" select setmetatable (table. value) table[index] index value table value table select (index.

isyieldable () . arg1.format v "__tostring" tostring v type (v) table number string thread userdata function nil boolean _VERSION Lua 5.base e A B Z e tostring (v) string.3 xpcall (f.create (f) f f "thread" coroutine. ···]) pcall msgh coroutine coroutine. msgh [.

coroutine. ···]) co val1 resume val1 resume yield resume coroutine.resume (co [.wrap (f) f resume f resume coroutine.running () coroutine.yield (···) yield require resume package . val1.status (co) status co "running" "suspended" "normal" "dead" yield coroutine.

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

package.loadlib (libname, funcname)
libname
funcname

*
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

a

rep]]) path name name sep rep ". j]]) s[i] j s[i+1] i string.byte(s.searchpath (name.package.lc string __index string.i) s:byte(i) string.a /usr/local/foo/a/init.lua ..lua. sep [.lc.sub i ./?.lua" foo.lua ./foo/a./foo/a. path [.byte (s [./?. i [.char (···) s[j] string./usr/local/?/init.

strip]) load strip string.string. 'a string with "quotes" and \n new line') "a string with \"quotes\" and \ new line" A a c d i o u X s E e f G x g q s .format (formatstring.format('%q'. plain]]) s find pattern s init plain pattern init plain string. init [.dump (function [. pattern [. ···) sprintf * h L l n p q q string.find (s.

to=Lua" for k.gmatch(s.gsub (s. n]) s n repl n pattern repl gsub gsub repl % repl %d %0 repl repl %% % . repl [. pattern) pattern pattern s pattern s s = "hello world from Lua" for w in string.gmatch(s. v in string. "%a+") do print(w) end key=value t = {} s = "from=world.tostring string.gmatch (s. "(%w+)=(%w+)") do t[k] = v end ^ string. pattern.

pattern [. ···) . os.-)%$". "%$(%w+)". "(%w+)".pack (fmt. version="5.gz". user = roberto" x = string. 1) --> x="hello hello world" x = string.gsub("hello world from Lua".3"} x = string.match (s. "%$(%w+)".gz" string. "%2 %1") --> x="world hello Lua from" x = string.x = string. "%1 %1") --> x="hello hello world world" x = string. "%w+". "%0 %0".gsub("$name-$version. v2.gsub("4+5 = $return 4+5$". t) --> x="lua-5.gsub("home = $HOME. init]) s pattern match pattern pattern init string.3.gsub("hello world". user = $USER".getenv) --> x="home = /home/roberto. function (s) return load(s)() end) --> x="4+5 = 9" local t = {name="lua".len (s) "" "a\000bc\000" string. "%$(.tar.lower (s) string.gsub("hello world".tar. "(%w+)%s*(%w+)". v1.

1.pack s z string. i [.match .upper (s) string.rep (s. sep]) n s sep sep n string.v1 v2 fmt string.find string.j) -i) i j s i j j string. i j j i string.reverse (s) s string. j]) s i j string.sub(s.unpack (fmt.gsub string.packsize (fmt) string. n [. s [.gmatch string.sub(s. pos]) fmt pos s s string.pack s string.sub (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-%%] .

)%w(%s*)" .) %w(%s*))" "a*(. %s* () "()aa()" "flaaap" .* + - * ? %n %bxy %b() %f[set] \0 ^ $ ^ $ "(a*(.

string.unpack sn xX string.unpack !n string.pack 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.unpack !1= .packsize n char char short short long long lua_Integer lua_Unsigned size_t n n float double lua_Number int int n op [n] <=>! string.pack in In n string.

i [.len (s [. j]]) j c .pack string.codes (s) for p.char (···) utf8.c z s string.codes(s) do body end s p utf8.unpack utf8 utf8.charpattern [\0-\x7F\xC2-\xF4][\x80-\xBF]* utf8. i [. c in utf8. j]]) s i i j i utf8.codepoint (s [.

a2]) a1 a2 a2[t]. list[#list] table.] value) list pos list[pos+1].list[i+1] ··· sep. ···. [pos..x) x value list[pos].insert (list.move (a1.offset (s. n [.concat (list [.a1[e] f a2 a1 .···.. t [.offset(s. j]]]) list[i]. i]) s n n i i #s + 1 n utf8.insert(t.list[j] j #list i sep j i table.. -n) i n n s i s table __len table. e.··· = a1[f]. i [. pos t #list+1 table. f.sep.s i i j j utf8. sep [.

abs (x) .ceil math.sort (list [. pos #list + 1 list[pos] table.table. list[j] i j #list math integer/float math.modf math.floor math.list[i]) comp < table.remove (list [. list[pos+2]. j]]) return list[i].remove(l) l table. list[#list] #list pos list[#list] #list pos list[pos+1].pack (···) n table. list[i+1].unpack (list [. ···. i [. comp]) list[1] comp list[#list] not comp(list[i+1]. pos]) list pos #list ···.

x math.asin (x) x math.floor (x) x math.atan (y [.cos (x) x math.ceil (x) x math. x]) y/x x x math.huge HUGE_VAL y . y) x y math.deg (x) x math.atan(y) math.fmod (x.acos (x) x math.exp (x) e math.

rad (x) x math.randomseed (x) math.random ([m [. n]]) m n math.max (x. ···) < math.n) .random(1.maxinteger math.mininteger math.math.pi math.modf (x) x math.min (x. ···) < math.random(n) math. base]) x base x math.random math.log (x [.

sqrt (x) x x^0.stdout io.sin (x) x math.open io io.x math.stderr .stdin io.ult (m.tan (x) x math. n) m n m n io io.tointeger (x) x math.type (x) x integer float x math.5 math.

lines() io.flush () io.close ([file]) file:close() file io.input():lines("*l") io.open (filename [.lines ([filename ···]) file:lines(···) io. mode]) mode mode r w a r+ w+ a+ .input ([file]) io.output():flush() io.errno io.

popen (prog [. mode]) mode "w" mode prog "r" io.input():read(···) io.popen os.write (···) io.mode b io.tmpfile () io.input io.read (···) io.type (obj) obj obj "file" "closed file" obj obj io.output ([file]) io.execute file:close .output():write(···) file:close () file io.

offset]]) 3.4e- .lines file:read (···) file n 0x i a l L number l L file:seek ([whence [.file:flush () file file:lines (···) l for c in file:lines(1) do body end io.

time]]) .flush size file:write (···) file file os os.date ([format [.offset whence whence set cur end seek seek whence "cur" offset file:seek() file:seek("set") file:seek("end") file:setvbuf (mode [. size]) no full flush line io.clock () os.

date("%c") gmtime localtime os.time ! format *t month sec min yday format strftime *t date year hour day wday isdst date date os. close]]) exit EXIT_SUCCESS code code .exit ([code [.time t2 t1 os.date() os.difftime (t2.execute os.format time date format os.execute ([command]) system command exit signal os. t1) t1 t2 os.

getenv (varname) varname os.EXIT_FAILURE code code close os.time ([table]) year month hour isdst min day sec os.date os.remove (filename) os.difftime . category]) locale category "ctype" "monetary" "all" locale locale "all" "numeric" "collate" "time" C setlocale os.setlocale (locale [. newname) oldname newname os.date time os.rename (oldname.

sethook debug.] f [.os.gethook ([thread]) debug.tmpfile debug debug.debug debug. what]) .getinfo ([thread.debug () cont debug.tmpname () io.

getlocal ([thread. up) f up .getinfo(print) print debug.] f.getregistry () debug.getupvalue (f.f f getinfo getinfo f getinfo what lua_getinfo what f func activelines L debug.getmetatable (value) value debug.getinfo(1. local) f local debug."n") debug.getinfo ( f getlocal debug.

getinfo debug.setupvalue (f.( debug. value) value f up "tail .] level.getlocal debug. value) value level local level debug.setmetatable (value. table) value table value debug. mask [.] hook. count]) mask count c r l count count debug.getuservalue (u) u u debug.sethook ([thread.setlocal ([thread.sethook "call" call" "return" "line" "count" getinfo getinfo debug. local. up.

debug. n) n debug. value) value udata udata udata debug.upvalueid (f.] [message [.upvaluejoin (f1.setuservalue (udata. n1. f2.traceback ([thread. n2) f1 n1 lua lua [options] [script [args]] -e stat -l mod -i -v -E f2 n2 . level]]) message message message level traceback debug.

lua t1 t2 arg = { [-2] = "lua".h -E $ lua -e'a=1' -e 'print(a)' script.lua".cpath -i lua -E LUA_CPATH LUA_INIT lua LUA_INIT package. [2] = "t2" } $ lua -e "print(arg[1])" -e arg[1] arg[#arg] .lua a a script.path luaconf.-- stdin lua stdin lua lua -v -i lua - -E LUA_INIT_5_3 @filename LUA_PATH package. [1] = "t1".lua $ lua arg $ lua -la b. [-1] = "-la". [0] = "b.

h .__tostring lua_close os.exit # chmod +x #! #!/usr/local/bin/lua lua PATH #!/usr/bin/env lua luaconf.

pow(x..2 已经是 这样 处理 了,但 是并没 有写 在文档 .0 .0 2 bit32 bit32 ipairs io.exp)。 若用到其它操作,你可以写一个扩展库,或 在 Lua 中实现它们。 require 在搜索 C 加载器时处理版本号的方式有所变化。 现在,版 本号应该跟在模块名后(其它大多数工具都是这样干的)。 出于兼 容性考虑,如果使用新格式找不到加载器的话,搜索器依然会尝试 旧格式 。 (Lua 5.0^exp 替换 math.ldexp(x.0 2.0 x = x + 0.read __ipairs * atan2 cosh sinh tanh pow frexp ldexp x^y math.atan 替换 math.atan2,前 者现 在 可 以 接 收 一 或 两 个 参 数; 你 可 以 用 x * 2.y); 你可以用 math.

4.8; 对 于 最 终 符 号,名 字,数 字,字 符 串 字 面 量 的 解 释,参见 §3.’ exp [‘.1。) chunk ::= block block ::= {stat} [retstat] stat ::= ‘.’ exp] do block end | for namelist in explist do block end | function funcname funcbody | .里。) 延 续 函 数 现 在 接 收 原 来 用 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)。 这是一份采用扩展 BNF 描述的 Lua 完整语法。 在扩展 BNF 中, {A} 表示 0 或多个 A , [A] 表示一个可选的 A 。 (操作符优先级,参见 §3.’ | varlist ‘=’ explist | functioncall | label | break | goto Name | do block end | while exp do block end | repeat block until exp | if exp then block {elseif exp then block} [else block] end for Name ‘=’ exp ‘.

’ | ‘..’ ‘..’ binop ::= ‘+’ | ‘-’ | ‘*’ | ‘/’ | ‘//’ | ‘^’ | ‘%’ | ‘&’ | ‘~’ | ‘|’ | ‘>>’ | ‘<<’ | ‘.’ Name} explist ::= exp {‘.’ | functiondef | prefixexp | tableconstructor | exp binop exp | unop exp prefixexp ::= var | functioncall | ‘(’ exp ‘)’ functioncall ::= prefixexp args | prefixexp ‘:’ Name args args ::= ‘(’ [explist] ‘)’ | tableconstructor | LiteralString functiondef ::= function funcbody funcbody ::= ‘(’ [parlist] ‘)’ block end parlist ::= namelist [‘..local function Name funcbody | local namelist [‘=’ explist] retstat ::= return [explist] [‘.’ var} var ::= Name | prefixexp ‘[’ exp ‘]’ | prefixexp ‘..’ Name namelist ::= Name {‘..’ | ‘<’ | ‘<=’ | ‘>’ | ‘>=’ | ‘==’ | ‘~=’ | and | or .’ tableconstructor ::= ‘{’ [fieldlist] ‘}’ fieldlist ::= field {fieldsep field} [fieldsep] field ::= ‘[’ exp ‘]’ ‘=’ exp | Name ‘=’ exp | exp fieldsep ::= ‘.’ Name} [‘:’ Name] varlist ::= var {‘...’] | ‘.’] label ::= ‘::’ Name ‘::’ funcname ::= Name {‘.’ exp} exp ::= nil | false | true | Numeral | LiteralString | ‘.

unop ::= ‘-’ | not | ‘#’ | ‘~’ 最后更新时间: 2015年1月18日19:54 .