using System.Collections; using System.Collections.Generic; using UnityEngine; public class TestXLua : MonoBehaviour { public TextAsset luaText; [XLua.CSharpCallLua] public delegate int LuaFuncBDelegate(int a, int b); [XLua.CSharpCallLua] public delegate int LuaFuncCDelegate(int a, int b, int c, out int ret); // Use this for initialization void Start () { XLua.LuaEnv luaState = new XLua.LuaEnv(); luaState.DoString("CS.UnityEngine.Debug.Log('Hello XLua.')"); luaState.DoString(luaText.text); int nLuaNum1 = luaState.Global.Get("nNum1"); Debug.Log("nLuaNum1 -> " + nLuaNum1); string strLuaString = luaState.Global.GetInPath("tValueTable.strString"); Debug.Log("strLuaString -> " + strLuaString); //luaState.Global.SetInPath("tValueTable.nInt", 999); Debug.Log("---------------------------------------------------------"); System.Action luaFuncA = luaState.Global.Get("FuncA"); luaFuncA(); luaFuncA = null; Debug.Log("---------------------------------------------------------"); LuaFuncBDelegate luaFuncB = luaState.Global.Get("FuncB"); Debug.Log("luaFuncB Result -> " + luaFuncB(11, 22)); luaFuncB = null; Debug.Log("---------------------------------------------------------"); LuaFuncCDelegate luaFuncC = luaState.Global.Get("FuncC"); int ret = 0; int result = 0; result = luaFuncC(11, 22, 33, out ret); Debug.Log("luaFuncC result -> " + result + " ret -> " + ret); luaFuncC = null; Debug.Log("---------------------------------------------------------"); luaState.Dispose(); } // Update is called once per frame void Update () { } }