把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
}