一、值与类型
Lua 是一门动态类型语言。 这意味着变量没有类型也就可以是任意类型;只有值才有类型。 语言中不设类型定义。 所有的值携带自己的类型。值类型分为八种:nil、boolean、number、string、function、userdata、thread、table。
Lua值类型和C#对比:
1、nil -->null
2、boolean -->System.Boolean
3、number -->int、float、double(整数、实数)
4、string -->System.String
5、function -->LuaInterface.LuaFunction
6、userdata -->用户自定义的数据类型
7、thread -->LuaInterface.LuaThread线程
8、table -->LuaInterface.LuaTable
二、表达式使用
1、and or not
a and b --> 如果a为false,则返回a,否则返回b
a
or b --> 如果a为true,则返回a,否则返回b
not -->如果a为false,则返回true,相当于C#中的!
print(4
and 5) --> 5
print(nil and 13) --> nil
print(4 or 5) --> 4
print(false or 5) --> 5
C# 中 a?b:c 相当于Lua中的 (a and b) or c
2、字符串连接
print("Hello
" .. "World") --> Hello World
三、基本语法
详细请看 Programming in lua这本书,以下是一些注意部分
1、Lua中所有变量、方法都相当于C#中的静态变量。
2、Lua中for循环从1开始,也可以从0开始但是很多Lua的库则不能使用。
3、Lua中函数的返回值可以是多个,变量数>值个数自动补nil,变量数<值个数多余值忽略。
4、Lua中函数可以接受可变数目的参数。