当C#的函数中有out和ref参数时,out参数、ref参数会和函数的返回值一起返回,且Lua中调用的时候out参数不需要传入
C#中:
namespace testLuaInterface{
class Person
{
// public string name = "little ai";
//测试out参数
public void TestOut(string name, int count){
Console.WriteLine(name);
count = name.Length;
}
//测试ref参数
public void TestRef(string name, ref count){
Console.WriteLine(name);
count = name.Length; //修改传进来的 ref参数count
}
}
}
Lua中:
require "luanet"
luanet.load_assembly("testLuaInterface")
Person = luanet.import_type("testLuaInterface.Person")
Person1 = Person( )
//测试out
void,nameLength = Person1:TestOut("hello" ) --out参数不需要传入
print(void,nameLength) --输出 nil 5 因为TestOut返回值void是返回null,在Lua中也需要去接收
//测试ref
void, strLength = person1:TestRef("little",10) --ref参数需要传入
print(void,strLength) --输出:nil 5 因为ref参数 10在C#中被修改了