1、多返回值
Lua的function可以有多个返回值,c#中的return显示不合适。
这个时候可以使用ref和out(推荐使用out 不需要在外部赋值)
c#调用Lua 时 lua函数的return 其返回值会赋值给out中的变量
Lua调用c#时 out变量不需要赋值 会自动变成返回值
public class Test
{
public void TestFunction(out int a,out int b)
{
a = 10;
b = 20;
}
}
Test = CS.Test
test = Test()
print(test:TestFunction())
2、调用成员方法
在Lua中调用C#类的成员方法时 需要使用:(冒号) 类的静态方法则使用.(点)调用
3、生成Array数组
local arr = Array.CreateInstance(typeof(CS.System.Int32),10)
4、生成List链表
local List_String = CS.System.Collections.Generic.List(CS.System.String)
local list = List_String()
5、生成Dictionary字典
Dictionary比较特殊 通过[Key]的方式只能获得nil 可以通过:get_Item 或者TryGetValue获取值
使用TryGetValue的时候可以验证1中的多返回值
这个函数的返回值是Bool 参数是String 和 out value
当print的时候 会同时打印True 和 123
Dictionary_String_Int = CS.System.Collections.Generic.Dictionary(CS.System.String,CS.System.Int32)
local dictionary = Dictionary_String_Int()
dictionary:Add("字典",123)
print(dictionary:get_Item("字典"))
print(dictionary:TryGetValue("字典"))
print(dictionary["字典"])