# 【Lua】Lua学习五：函数([Lua] Lua learning 5: function)-lua

## 【Lua】Lua学习五：函数([Lua] Lua learning 5: function)

table的构造式

return语句

return

end

Lua中的函数都是匿名函数

function foo(x) return 2*x end 等价于 foo = function (x) return 2*x end

table.sort(network, function (a,b) return (a.name > b.name) end)

Lua中只有closure，没有函数。因为函数本身就是一种特殊的closure。

沙盒？

————————

I:

2： Multiple return values

Multiple assignment: if a function call is not the last element of a series of expressions, only one value will be generated

List of arguments passed in during function call

Construction of table

return statement

3： Variable length parameter

return

end

4： Named argument

5： Function

All functions in Lua are anonymous

function foo(x) return 2*x end 等价于 foo = function (x) return 2*x end

table.sort(network, function (a,b) return (a.name > b.name) end)

Functions that can accept functions as parameters are called higher-order functions

6： Closure

Lua has only closures and no functions. Because the function itself is a special closure.

Sandbox?

7： Non global function

8： Correct tail call

Application: write state machine?