예제 #1
0
 protected void OnApplicationPause(bool pauseStatus)
 {
     if (luaState != null)
     {
         luaState.Call("OnApplicationPause", pauseStatus);
     }
 }
 public void StartLua()
 {
     m_cLuaState.Start();
     m_cLuaState.DoFile("FirstRequire.lua");
     if (m_cLuaState != null)
     {
         m_cLuaState.Call("Main", false);
     }
 }
예제 #3
0
    void Start()
    {
#if UNITY_5_4_OR_NEWER
        Application.logMessageReceived += ShowTips;
#else
        Application.RegisterLogCallback(ShowTips);
#endif
        new LuaResLoader();
        lua = new LuaState();
        lua.Start();
        LuaBinder.Bind(lua);
        lua.DoString(script, "TestInherit.cs");

        float time = Time.realtimeSinceStartup;

        for (int i = 0; i < 200000; i++)
        {
            Vector3 v = transform.position;
            transform.position = v;
        }

        time = Time.realtimeSinceStartup - time;
        Debugger.Log("c# Transform get set cost time: " + time);
        lua.Call("Test", transform, true);
        lua.Dispose();
        lua = null;
    }
예제 #4
0
    public virtual void Destroy()
    {
        if (m_LuaState != null)
        {
#if UNITY_5_4_OR_NEWER
            SceneManager.sceneLoaded -= OnSceneLoaded;
#endif
            m_LuaState.Call("OnApplicationQuit", false);
            DetachProfiler();
            LuaState state = m_LuaState;
            m_LuaState = null;

            if (m_LevelLoaded != null)
            {
                m_LevelLoaded.Dispose();
                m_LevelLoaded = null;
            }

            if (m_Looper != null)
            {
                m_Looper.Destroy();
                m_Looper = null;
            }

            state.Dispose();
            instance = null;
        }
    }
예제 #5
0
    public virtual void Destroy()
    {
        if (luaState == null)
        {
            return;
        }
        SceneManager.sceneLoaded -= OnSceneLoaded;
        luaState.Call("OnApplicationQuit", false);
        DetachProfiler();
        LuaState state = luaState;

        luaState = null;

        if (onSocketfunc != null)
        {
            onSocketfunc.Dispose();
            onSocketfunc = null;
        }

        if (loop != null)
        {
            loop.Destroy();
            loop = null;
        }

        state.Dispose();
        luaInstance = null;
    }
예제 #6
0
    public virtual void Destroy()
    {
        if (luaState != null)
        {
#if UNITY_5_4_OR_NEWER
            SceneManager.sceneLoaded -= OnSceneLoaded;
#endif
            luaState.Call("OnApplicationQuit", false);
            DetachProfiler();
            LuaState state = luaState;
            luaState = null;

            if (levelLoaded != null)
            {
                levelLoaded.Dispose();
                levelLoaded = null;
            }

            if (loop != null)
            {
                loop.Destroy();
                loop = null;
            }

            state.Dispose();
            Instance = null;
        }
    }
예제 #7
0
    void TestToLua2()
    {
        string filename = "TestToLuaC2";

        m_state.DoFile(filename);

        //这里获取不到
        GameLogger.Log("Get Lua Local Value : " + m_state["local_num"]);

        //可以读取到全局的变量
        GameLogger.Log("Get Lua Value : " + m_state["global_num"]);
        m_state["global_num"] = 10;
        GameLogger.Log("Set Lua Value : " + m_state["global_num"]);

        //调用lua方法
        LuaFunction luaFunc = m_state.GetFunction("Count");

        luaFunc.Call();
        GameLogger.Log("Get Lua Value : " + m_state["global_num"]);
        //也可以直接
        m_state.Call("Count", false);
        GameLogger.Log("Get Lua Value : " + m_state["global_num"]);

        //方法传入参数
        LuaFunction valueFunc = m_state.GetFunction("InputValue");

        valueFunc.BeginPCall();
        valueFunc.Push("-- 这是CSharp中的参数----");
        valueFunc.PCall();
        valueFunc.EndPCall();

        valueFunc.Call("--这是CSharp中直接调用传入参数-----");

        // Get Table
        LuaTable table = m_state.GetTable("mytable");

        table.Call("tableFunc");

        LuaFunction tableFunc = table.GetLuaFunction("tableFunc");

        GameLogger.Log("Lua Table Function");
        tableFunc.Call();
        //这里访问的时table的变量,不是local或者全局变量
        GameLogger.Log("Get Table Value local_num : " + table["local_num"]);
        GameLogger.Log("Get Table Value global_num : " + table["global_num"]);
        GameLogger.Log("Get Table Value table_num : " + table["table_num"]);
        for (int i = 0; i < table.Length; ++i)
        {
            GameLogger.Log("table " + i.ToString() + " : " + table[i + 1]);
        }

        LuaDictTable dicTable = table.ToDictTable();

        foreach (var item in dicTable)
        {
            GameLogger.LogFormat("dicTable {0} -- {1}", item.Key, item.Value);
        }
    }
예제 #8
0
        public object Call(string func, params object[] args)
        {
            if (luaState != null)
            {
                return(luaState.Call(func, args));
            }

            return(null);
        }
예제 #9
0
파일: LuaMgr.cs 프로젝트: twwk120120/LuaBT
    private void Awake()
    {
        instance = this;
        luastate = new LuaState();
        luastate.AddSearchPath(LuaConst.btDir);
        luastate.Start();
        LuaBinder.Bind(luastate);

        luastate.Require("Test/Test");
        luastate.Call("Test.Run", false);
    }
예제 #10
0
        void Awake()
        {
            if (LuaClient.Instance == null)
            {
                gameObject.AddComponent <LuaClient> ();
            }
            _luaState = LuaClient.GetMainState();
            GameObject.DontDestroyOnLoad(gameObject);

            _luaState.Call("RunGame", false);
        }
예제 #11
0
        public bool CallVoidFunc(string name)
        {
            bool ret = false;

            try{
                _luaState.Call(name, true);
                ret = true;
            }catch (Exception e) {
                Debug.LogException(e);
            }
            return(ret);
        }
예제 #12
0
        public void TestAtPanic()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                Assert.Throws<ArgumentNullException>(() => L.AtPanic(null));

                // Default panic
                L.PushCClosure(l => {
                    L.PushString("Test panic");
                    L.Error();
                    return 0;
                }, 0);
                Exception ex = Assert.Throws<LuaAtPanicException>(() => L.Call(0, 0));
                Assert.Equal("Test panic", ex.Message);

                // user panic
                L.PushCClosure(l => {
                    L.PushString("Test panic");
                    L.Error();
                    return 0;
                }, 0);
                var old = L.AtPanic(l => {
                    throw new ApplicationException(String.Format("Panic !! => {0}", l.ToString(-1)));
                });
                ex = Assert.Throws<ApplicationException>(() => L.Call(0, 0));
                Assert.Equal("Panic !! => Test panic", ex.Message);

                // Restore
                L.AtPanic(old);

                // Restore the default
                Assert.True(L.RestoreOriginalAtPanic());
                Assert.False(L.RestoreOriginalAtPanic());
            }
        }
예제 #13
0
    public void CallFunc(string file, string func, MonoBehaviour obj)
    {
        luaState = LuaClient.GetMainState();
        luaState.DoFile(file);

        try
        {
            luaState.Call(func, obj);
        }
        catch (System.Exception e)
        {
            // Awake中必须这样特殊处理异常
            luaState.ThrowLuaException(e);
        }
    }
예제 #14
0
    public static object[] CallTableFunc(this LuaTable curTable, string strFuncName, params object[] pParams)
    {
        LuaState curLuaState = curTable.GetLuaState();
        int      dwTop       = curLuaState.LuaGetTop();

        object[] pRtnObjs = null;

        try
        {
            if (curTable.BeginCall(strFuncName, dwTop))
            {
                int dwParamNum = 0;

                //压入self
                {
                    curLuaState.PushGeneric(curTable);
                    ++dwParamNum;
                }
                //压入参数
                if (pParams != null)
                {
                    for (int i = 0; i < pParams.Length; ++i)
                    {
                        curLuaState.PushGeneric(pParams[i]);
                        ++dwParamNum;
                    }
                }

                curLuaState.Call(dwParamNum, dwTop + 2, dwTop);
                //由于beginCall压入了一个table和trace,所以起始偏移+2
                pRtnObjs = curLuaState.CheckObjects(dwTop + 2);
            }
            else
            {
                curLuaState.LuaSetTop(dwTop);
                throw new LuaException("call fail");
            }
            curLuaState.LuaSetTop(dwTop);
        }
        catch (Exception e)
        {
            curLuaState.LuaSetTop(dwTop);
            throw e;
        }

        return(pRtnObjs);
    }
예제 #15
0
/*        void OnSceneLoaded(Scene scene, LoadSceneMode mode) {
 *
 *          if (luaState != null)
 *          {
 *              luaState.RefreshDelegateMap();
 *          }
 *      }*/


        public virtual void Destroy()
        {
            if (luaState != null)
            {
                //SceneManager.sceneLoaded -= OnSceneLoaded;
                luaState.Call("OnDestroy", false);
                DetachProfiler();
                LuaState state = luaState;
                luaState = null;
                if (loop != null)
                {
                    loop.Destroy();
                    loop = null;
                }

                state.Dispose();
                Instance = null;
            }
        }
    private void Start()
    {
        luaState = new LuaState();
        luaState.Start();
        LuaBinder.Bind(luaState);
        luaState.DoString(script, "TestInherit.cs");

        float time = Time.realtimeSinceStartup;

        for (int i = 0; i < 200000; i++)
        {
            Vector3 v = transform.position;
            transform.position = v;
        }

        time = Time.realtimeSinceStartup - time;

        Debugger.Log("C# transform get set cost time:" + time);
        luaState.Call("Test", transform, true);
        luaState.Dispose();
        luaState = null;
    }
예제 #17
0
    void Start()
    {
#if UNITY_5 || UNITY_2017 || UNITY_2018
        Application.logMessageReceived += ShowTips;
#else
        Application.RegisterLogCallback(ShowTips);
#endif
        new LuaResLoader();
        lua = new LuaState();
        lua.Start();
        DelegateFactory.Init();
        lua.DoString(script);

        int num = lua.Invoke <int, int>("test.luaFunc", 123456, true);
        Debugger.Log("luastate call return: {0}", num);
        lua.Call("test.luaPrint", "hhhh", true);

        //Get the function object
        luaFunc = lua.GetFunction("test.luaFunc");

        if (luaFunc != null)
        {
            num = luaFunc.Invoke <int, int>(123456);
            Debugger.Log("generic call return: {0}", num);

            luaFunc = lua.GetFunction("test.luaFunc2");
            num     = CallFunc();
            Debugger.Log("expansion call return: {0}", num);

            luaFunc = lua.GetFunction("test.luaFunc");
            Func <int, int> Func = luaFunc.ToDelegate <Func <int, int> >();
            num = Func(123456);
            Debugger.Log("Delegate call return: {0}", num);
        }

        lua.CheckTop();
    }
예제 #18
0
        public void TestCall()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                L.PushFunction(l => {
                    var a = L.ToNumber(1);
                    var b = L.ToNumber(2);
                    L.PushNumber(a * b);
                    return 1;
                });
                L.PushNumber(12);
                L.PushNumber(4);
                L.Call(2, 1);
                Assert.Equal(1, L.GetTop());
                Assert.Equal(48, L.ToNumber(-1));

                L.DoString(@"
            function testA(a,b)
            return a-b
            end
            function testB(a,b)
            DoAnError(a,b)
            end
            ");
                Assert.Equal(1, L.GetTop());
                L.GetGlobal("testA");
                L.PushNumber(12);
                L.PushNumber(4);
                L.Call(2, 1);
                Assert.Equal(2, L.GetTop());
                Assert.Equal(8, L.ToNumber(-1));

                L.GetGlobal("testB");
                L.PushNumber(12);
                L.PushNumber(4);
                var ex = Assert.Throws<LuaAtPanicException>(() => L.Call(2, 1));
                Assert.Equal("[string \"\r...\"]:6: attempt to call a nil value (global 'DoAnError')", ex.Message);
            }
        }
예제 #19
0
파일: LuaMgr.cs 프로젝트: twwk120120/LuaBT
 public void Update()
 {
     luastate.Call("Test.Update", false);
 }
예제 #20
0
 public object Call(string func, params object[] args)
 {
     return(luaState.Call(func, args));
 }