C#访问lua获取全局函数——此函数带多个返回值

在这里插入图片描述

function f(a, b)
	print('a', a, 'b', b)
	return 1, {f1 = 1024}, 999, "hello,world"
end

有返回值4个
1——为函数的返回值
{f1=1024}——带出返回值table
999——带出返回值int
hello,world——带出返回值string

C#端代码:
在这里插入图片描述

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using XLua;
using System;

namespace Tutorial
{
    public class CSCallLua : MonoBehaviour
    {
        LuaEnv luaenv = null;
        public class DClass
        {
            public int f1;
            public int f2;
        }

        [CSharpCallLua]
        public delegate int FDelegate(int a, string b, out DClass c, ref int x, ref string y);


        void Start()
        {
            luaenv = new LuaEnv();
            TextAsset luaScript = Resources.Load<TextAsset>("hello");
            luaenv.DoString(luaScript.text);
            FDelegate f = luaenv.Global.Get<FDelegate>("f");
            DClass d_ret;
            int x = 0;
            string y = string.Empty;
            int f_ret = f(100, "John", out d_ret, ref x, ref y);
        }


        void OnDestroy()
        {
            luaenv.Dispose();
        }
    }
}


版权声明:本文为wodownload2原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。