日拱一卒,功不唐捐!Cnblog Labs. 🔬|

畅知

园龄:1年4个月粉丝:68关注:22

Lua中调用ref和out修饰参数的函数/重载函数

[12] lua中调用ref 和 out 修饰参数的函数数值

public int RefCompute(int a, ref int b, ref int c, int d)
{
b += a;
c += d;
return b + c;
}
public int OutCompute(int a, out int b, out int c,int d)
{
b = a + 1;
c = d + 2;
return b + c;
}
public int RefOutCompute(int a, ref int b, out int c,int d)
{
a += b;
c = d + 3;
return a + c;
}

lua脚本中进行调用

------------------lua中调用C#的ref 和 out方法
---- lua调用ref参数的函数 ref修饰的参数会返回值形式返回
---第一个返回值为函数返回会值
---之后返回值为ref修饰的参数结果
local a,b,c = student:RefCompute(1,2,3,4)
print("a=" .. a) -- 10
print("b=" .. b) -- 1+2
print("c=" .. c) -- 3+4
--与ref修饰参数一样
---out修饰的参数也会随结果返回
local d,e,f = student:OutCompute(10,9,8,7)
print("d=" .. d) -- 20
print("e=" .. e) -- 10 + 1
print("f=" .. f) --7 + 2
--调用参数类型含有ref和out修饰的函数
--会依次随着函数结果返回
local d,e,f = student:RefOutCompute(10,9,8,7)
print("d=" .. d) -- 19
print("e=" .. e) -- 9 ref修饰参数返回值 参数数值未变
print("f=" .. f) --10+ 9+ 3 + 7 out修饰参数返回值

image-20240523221229817

[13]Lua中调用C#的重载函数

几个简单的方法,注意有out修饰参数类型的重载函数.

img

lua脚本中调用:

img

运行结果:

image-20240523232123784

本文作者:畅知

本文链接:https://www.cnblogs.com/TonyCode/p/18209616

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   畅知  阅读(55)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起