synchronized with EN version.

This commit is contained in:
qinhanlei 2016-01-21 16:55:20 +08:00
parent 9a5bb28668
commit f39e2fcab7

View File

@ -92,7 +92,7 @@ until num == 0
----------------------------------------------------
function fib(n)
if n < 2 then return 1 end
if n < 2 then return n end
return fib(n - 2) + fib(n - 1)
end
@ -130,8 +130,10 @@ f = function (x) return x * x end
-- 这些也是等价的:
local function g(x) return math.sin(x) end
local g; g = function (x) return math.sin(x) end
-- 'local g'使得g可以自引用。
local g; g = function (x) return math.sin(x) end
-- 以上均因'local g'使得g可以自引用。
local g = function(x) return math.sin(x) end
-- 等价于 local function g(x)..., 但函数体中g不可自引用
-- 顺便提下,三角函数以弧度为单位。
@ -328,7 +330,7 @@ seymour:makeSound() -- 'woof woof woof' -- 4.
-- 如果有必要子类也可以有new(),与基类相似:
function LoudDog:new()
newObj = {}
local newObj = {}
-- 初始化newObj
self.__index = self
return setmetatable(newObj, self)
@ -340,7 +342,9 @@ end
--[[ 我把这部分给注释了,这样脚本剩下的部分可以运行
```
```lua
-- 假设文件mod.lua的内容类似这样
local M = {}
@ -411,4 +415,9 @@ lua-users.org上的[Lua简明参考](http://lua-users.org/files/wiki_insecure/us
* <a href="http://lua-users.org/wiki/IoLibraryTutorial">io library</a>
* <a href="http://lua-users.org/wiki/OsLibraryTutorial">os library</a>
顺便说一下整个文件是可运行的Lua;
保存为 learn-cn.lua 用命令 `lua learn.lua` 启动吧!
本文首次撰写于 [tylerneylon.com](http://tylerneylon.com) 同时也有 <a href="https://gist.github.com/tylerneylon/5853042">github gist</a> 版.
使用Lua欢乐常在