| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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<int>("nNum1");
- Debug.Log("nLuaNum1 -> " + nLuaNum1);
- string strLuaString = luaState.Global.GetInPath<string>("tValueTable.strString");
- Debug.Log("strLuaString -> " + strLuaString);
- //luaState.Global.SetInPath<int>("tValueTable.nInt", 999);
- Debug.Log("---------------------------------------------------------");
- System.Action luaFuncA = luaState.Global.Get<System.Action>("FuncA");
- luaFuncA();
- luaFuncA = null;
- Debug.Log("---------------------------------------------------------");
- LuaFuncBDelegate luaFuncB = luaState.Global.Get<LuaFuncBDelegate>("FuncB");
- Debug.Log("luaFuncB Result -> " + luaFuncB(11, 22));
- luaFuncB = null;
- Debug.Log("---------------------------------------------------------");
- LuaFuncCDelegate luaFuncC = luaState.Global.Get<LuaFuncCDelegate>("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 () {
- }
- }
|