Ref、Out参数

RefOutParam.lua.txt

  1. local RefOutParam = CS.UnityEngine.Object.FindObjectOfType(typeof(CS.shenjun.RefOutParam))
  2. -- 1out参数不需要传入实参
  3. -- 2、返回值顺序:如果函数有返回值那么第一个是函数返回值
  4. -- 其他的都是refout参数的传出的,按顺序传出
  5. -- 3、如果函数没有返回值,那么按顺序返回refout参数
  6. local a, b, c = RefOutParam:RefOutParamFunc("shenjun", 10, 30)
  7. print("Lua Return :" ,a, b, c)

RefOutParam.cs

  1. /*
  2. * created by shenjun
  3. */
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using XLua;
  8. namespace shenjun
  9. {
  10. public class RefOutParam : MonoBehaviour {
  11. void Start () {
  12. LuaEnv luaEnv = new LuaEnv();
  13. luaEnv.DoString("require 'RefOutParam'");
  14. luaEnv.Dispose();
  15. }
  16. void Update () {
  17. }
  18. public void RefOutParamFunc(string s, ref int a, out int b, ref int c)
  19. {
  20. b = 1;
  21. Debug.Log("s :" + s + ", a : " + a + ", b : " + b + ", c : " + c);
  22. }
  23. }
  24. }

?