doc: update lua.md #133
This commit is contained in:
parent
376b40eb7a
commit
78929052b2
46
docs/lua.md
46
docs/lua.md
@ -1,7 +1,7 @@
|
|||||||
Lua 备忘清单
|
Lua 备忘清单
|
||||||
===
|
===
|
||||||
|
|
||||||
包含最重要概念、函数、方法等的 Lua 备忘单。 初学者的完整快速参考。
|
包含最重要概念、函数、方法等的 [Lua](http://www.lua.org) 备忘单。 初学者的完整快速参考。
|
||||||
|
|
||||||
入门
|
入门
|
||||||
---
|
---
|
||||||
@ -16,7 +16,7 @@ $ brew install lua
|
|||||||
|
|
||||||
#### 其它下载方式
|
#### 其它下载方式
|
||||||
|
|
||||||
* [下载地址](https://luabinaries.sourceforge.net/download.html)
|
* [下载地址](https://luabinaries.sourceforge.net/download.html) _(sourceforge.net)_
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 查看 lua 是否安装成功
|
# 查看 lua 是否安装成功
|
||||||
@ -299,12 +299,12 @@ print(a ^ b) -- 64.0
|
|||||||
|
|
||||||
符号 | 含义
|
符号 | 含义
|
||||||
:- | :-
|
:- | :-
|
||||||
== | 等于
|
`==` | 等于
|
||||||
~= | 不等于
|
`~=` | 不等于
|
||||||
\> | 大于
|
`>` | 大于
|
||||||
\< | 小于
|
`<` | 小于
|
||||||
\>= | 大于等于
|
`>=` | 大于等于
|
||||||
\<= | 小于等于
|
`<=` | 小于等于
|
||||||
<!--rehype:className=show-header-->
|
<!--rehype:className=show-header-->
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
@ -347,8 +347,6 @@ end
|
|||||||
### if 语句
|
### if 语句
|
||||||
<!--rehype:wrap-class=row-span-2-->
|
<!--rehype:wrap-class=row-span-2-->
|
||||||
|
|
||||||
<span style="color:red">注意: Lua 中 0 为 true,但是 Lua 中的 `nil` 可以当作 `false`</span>
|
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
if(0)
|
if(0)
|
||||||
then
|
then
|
||||||
@ -377,6 +375,8 @@ end
|
|||||||
print("age 的值为 :", age)
|
print("age 的值为 :", age)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<red>注意: </red>`Lua` 中 `0` 为 `true`,但是 `Lua` 中的 `nil` 可以当作 `false`
|
||||||
|
|
||||||
### for 循环
|
### for 循环
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
@ -389,24 +389,20 @@ end
|
|||||||
* 参数三,是可选的,如果不指定,默认是 1
|
* 参数三,是可选的,如果不指定,默认是 1
|
||||||
* 参数二只会在一开始求值,其后不会再进行运算
|
* 参数二只会在一开始求值,其后不会再进行运算
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local f = function(x)
|
local f = function(x)
|
||||||
print("in f(x) ")
|
print("in f(x) ")
|
||||||
return x * 2
|
return x * 2
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, f(5) do
|
for i = 1, f(5) do
|
||||||
print(i)
|
print(i)
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
<!--rehype:className=style-round wrap-text-->
|
||||||
<!--rehype:className=style-round-->
|
|
||||||
<!--rehype:className=wrap-text -->
|
|
||||||
|
|
||||||
### repeat...until 循环
|
### repeat...until 循环
|
||||||
|
|
||||||
repeat...until 循环的条件语句在当前循环结束后判断
|
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local num = 11
|
local num = 11
|
||||||
repeat
|
repeat
|
||||||
@ -416,6 +412,8 @@ until (num > 10)
|
|||||||
-- num 的值为:11
|
-- num 的值为:11
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`repeat...until` 循环的条件语句在当前循环结束后判断
|
||||||
|
|
||||||
### break
|
### break
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
@ -432,6 +430,6 @@ until (num > 20)
|
|||||||
另见
|
另见
|
||||||
----
|
----
|
||||||
|
|
||||||
* [Lua](http://www.lua.org)
|
* [Lua 官网](http://www.lua.org) _(lua.org)_
|
||||||
* [luatos](https://wiki.luatos.com/luaGuide/introduction.html)
|
* [luatos](https://wiki.luatos.com/luaGuide/introduction.html) _(wiki.luatos.com)_
|
||||||
* [Lua 教程](https://www.twle.cn/l/yufei/lua53/lua-basic-index.html)
|
* [Lua 教程](https://www.twle.cn/l/yufei/lua53/lua-basic-index.html) _(twle.cn)_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user