C++ | C# | Lua | |
---|---|---|---|
变量范围 | 同C# | 函数里变量是局部 | 只要没加local都是全局变量 |
引用变量 | 同C# | 变量要开地址 | 完全就是一个 |
局部变量范围 | 同C# | 块当中 | 块当中而且还保持条件上 |
类型 | type | typeof | |
空块 | 同C# | {} | do end |
不用转义 | @字符串 | [[]] | |
字符串拼接 | + | . . | |
长度 | Length | # | |
模拟返回 | return后面是注释 | do return end后面是注释 | |
可选参数 | : | 通过{}来模拟 | |
捕获 | 同C# | try catch | if pcall |
串联 | string.join | table.concat | |
省类型写法 | auto | var | local |
foreach | for : | for in | for k,v |
字典 | unordered_map | dic | table |
hashSet | unordered_set | hashSet | table |
Contains | Count()>0 | Contains | |
false的情况 | 零和null和false | false | false和nil |
枚举 | 赋值不需要带枚举类型 | 需要带枚举类型 | |
数学 | 直接用全局函数 | 带Math.xx() | math.xx() |
引用类型(别名) | int &a | ref int a | table |
转换字符串 | to_string(k) | ||
转int | stoi(s); | int.parese | tonumber |