C#调用TableByInterface

把Lua里的Table转换为Interface,通过接口获取到Lua的对象。是值引用

C#

using UnityEngine;
using XLua;
public class CsCallLua : MonoBehaviour {

	void Start () {
        var luaenv = new XLua.LuaEnv();
        luaenv.DoString("require 'CsCallLua'");       

        //table to interface
        ITeather t = luaenv.Global.Get<ITeather>("teather");
        print(t.name+"-Interface");

        luaenv.Dispose();
    }    

    //table to interface
    [CSharpCallLua]//告诉编辑器这个接口是Lua的一个接口
    interface ITeather
    {
        string name { get; set; }
        int age { get; set; }
    }
}

CsCallLua.lua

teather = {
	name = "NewDaliy",
	age = 18,
	isHandsome = true
}

 

 

发布了205 篇原创文章 · 获赞 8 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/cuijiahao/article/details/103905136
今日推荐