Learning Lua has to understand its methods or grammatical characteristics, such as:
Multi-value return
function Maximum (a) 1 -- maximum index = A[mi]-- maximum value for if val > m then = I = val end End Return m, miend
Print (Maximum ({8,10,23,12,5}))--23 3
Variable parameters
function g (A, B, ...) End or function g (...) Endcall PARAMETERSG (3) a=3, B=nil, arg={n=0}g (34) a= 3, b=4, arg={n=0}g (3458) a=3, b=4, arg={58; n=2}
Tail call
It feels like recursion, recursion is calling itself, the function of tail call tune is not necessarily self
feel like recursion, recursion is called itself, the function of tail call tune is not necessarily self function foo (n) if 0 return 1 ) endendfunction f (x) // do something at x return g (x) End
Advantages:
The tail call does not need to use the stack space (itself stack control), then the tail call recursive hierarchy can be unrestricted, without worrying about stack overflow. These are not tail calls:
function f (x) // not a tail call return return function return1do The addition return 1 result return 1 Resultend
Some features of the LUA approach--lua and Android