一、深入lua函数
一些必要的概念:
参考自: https://www.douban.com/note/183992679/?type=rec#sep http://en.wikipedia.org/wiki/First-class_object http://en.wikipedia.org/wiki/Scope
- 第一类值:
In programming language design, a first-class citizen (also type,object, entity, or value) in a given programming language is an entity which supports all the operations generally available to other entities. These operations typically include being passed as an argument, returned from a function, and assigned to a variable.
第一类值具备的特征: 可以存放在变量和数据结构中 可以当做参数传递给函数 可以作为函数的返回值 可以在运行期间被创建 独立于给定的名字
- 词法界定(静态域):
With lexical scope, a name always refers to its (more or less) local lexical environment. This is a property of the program text and is madeindependent of the runtime call stack by the language implementation. Because this matching only requires analysis of the static program text, this type of scoping is also called static scoping.
- 静态域和动态域的比较:
The use of local variables — of variable names with limited scope,that only exist within a specific function — helps avoid the risk of a name collision between two identically named variables. However,there are two very different approaches to answering this question:What does it mean to be “within” a function?
In lexical scoping (or lexical scope; also called static scoping or static scope), if a variable name’s scope is a certain function, then its scope is the program text of the function definition: within that text, the variable name exists, and is bound to the variable’s value,but outside that text, the variable name does not ex