Lesson5_Lua调用C#_CallRef、Out

--调用C#协变逆变相关知识
Lesson5 =CS.Lesson5
local obj = Lesson5()
//Lesson5声明如下

public class Lesson5
{
    public int RefFun(int a,ref int b,ref int c,int d)
    {
        b = a + d;
        c = a - d;
        return 100;
    }
    public int OutFun(int a, out int b, out int c, int d)
    {
        b = a + d;
        c = a - d;
        return 200;
    }
    public int RefOutFun(int a, out int b, ref int c)
    {
        b = a * 10;
        c = a * 20;
        return 300;
    }
}

--ref参数 以多返回值的形式返回给lua
local a,b,c =obj:RefFun(1,0,0,1) --第一个变量返回函数原本的返回值(如果有,这里的a根据上方的函数来看,a=100),剩下的变量接收Ref返回的值(b=2,c=0),ref参数的位置需要传数去占位置(比如0,就是占个位置就行)

--out参数 以多返回值的形式返回给lua
--如果函数有返回值,第一个返回值就是函数返回值
--out参数不需要传占位置的数
local a,b,c = obj:OutFun(20,30)

posted @ 2024-02-29 12:42  波奇型蠢驴  阅读(4)  评论(0)    收藏  举报