Exemple #1
0
    public void InitStart(string enterPath)
    {
        scriptEnv = luaenv.NewTable();

        LuaTable meta = luaenv.NewTable();

        meta.Set("__index", luaenv.Global);
        scriptEnv.SetMetaTable(meta);
        meta.Dispose();
        scriptEnv.Set("self", this);
        try
        {
            luaenv.DoString("require '" + enterPath + "'", "LuaBehaviour", scriptEnv);
        }
        catch (LuaException exp)
        {
            Debug.LogError(exp.Message);
        }
        //table.Get 获取lua中的delegate以供调用
        scriptEnv.Get("Update", out luaUpdate);
        scriptEnv.Get("Stop", out luaStop);
        scriptEnv.Get("Focus", out luaFocus);
        scriptEnv.Get("Pause", out luaPause);
        scriptEnv.Get("ExecuteGm", out executeGm);
        scriptEnv.Get("Collectgarbage", out collectgarbage);
    }
Exemple #2
0
 public void Dispose()
 {
     LuaEnvironment?.Dispose();
     RealPackageTable?.Dispose();
     Triggers?.Dispose();
     Hooks?.Dispose();
 }
Exemple #3
0
    void Awake()
    {
        scriptEnv = luaEnv.NewTable();

        LuaTable meta = luaEnv.NewTable();

        //设置__index,如果scriptEnv元表里没找到想要的值,就在__index里找
        meta.Set("__index", luaEnv.Global);
        scriptEnv.SetMetaTable(meta);
        meta.Dispose();

        scriptEnv.Set("this", this);
        foreach (var injection in injections)
        {
            scriptEnv.Set(injection.name, injection.value);
        }

        luaEnv.DoString(luaScript.text, "LuaBehaviour", scriptEnv);

        Action luaAwake = scriptEnv.Get <Action>("awake");

        scriptEnv.Get("start", out luaStart);
        scriptEnv.Get("update", out luaUpdate);
        scriptEnv.Get("ondestroy", out luaOnDestroy);

        if (luaAwake != null)
        {
            luaAwake();
        }

        int    a   = 1;
        object o_a = a;
    }
        void Awake()
        {
            scriptEnv = LuaEnv.NewTable();

            LuaTable meta = LuaEnv.NewTable();

            meta.Set("__index", LuaEnv.Global);
            scriptEnv.SetMetaTable(meta);
            meta.Dispose();

            scriptEnv.Set("self", this);
            foreach (var injection in injections)
            {
                scriptEnv.Set(injection.name, injection.value);
            }

            TextAsset text = Application.Make <IResources>().Load <TextAsset>(luaPath).Get <TextAsset>(scriptEnv);

            LuaEnv.DoString(text.text, "LuaBehaviour", scriptEnv);

            Action luaAwake = scriptEnv.Get <Action>("awake");

            scriptEnv.Get("start", out luaStart);
            scriptEnv.Get("update", out luaUpdate);
            scriptEnv.Get("ondestroy", out luaOnDestroy);

            if (luaAwake != null)
            {
                luaAwake();
            }
        }
Exemple #5
0
        void Awake()
        {
            scriptEnv = luaEnv.NewTable();

            // 为每个脚本设置一个独立的环境,可一定程度上防止脚本间全局变量、函数冲突
            LuaTable meta = luaEnv.NewTable();

            meta.Set("__index", luaEnv.Global);
            scriptEnv.SetMetaTable(meta);
            meta.Dispose();

            scriptEnv.Set("self", this);
            luaEnv.DoString(luaScript.text, "MemoryUI", scriptEnv);

            //Register Actions
            Action luaAwake = scriptEnv.Get <Action>("awake");

            scriptEnv.Get("start", out luaStart);
            scriptEnv.Get("update", out luaUpdate);
            scriptEnv.Get("ondestroy", out luaOnDestroy);
            scriptEnv.Get("filterstr", out luaFilter);
            scriptEnv.Get("takesnap", out luaTakeSnap);
            scriptEnv.Get("calculation", out luaCalculSnap);
            scriptEnv.Get("total", out luaMemoryTotal);

            if (luaAwake != null)
            {
                luaAwake();
            }
        }
Exemple #6
0
    // Start is called before the first frame update
    void Start()
    {
        LuaMgr.GetInstance().Init();
        LuaMgr.GetInstance().DoLuaFile("Main");

        //不建议使用LuaTable和LuaFunction 效率低
        //引用对象
        LuaTable table = LuaMgr.GetInstance().Global.Get <LuaTable>("testClas");

        Debug.Log(table.Get <int>("testInt"));
        Debug.Log(table.Get <bool>("testBool"));
        Debug.Log(table.Get <float>("testFloat"));
        Debug.Log(table.Get <string>("testString"));

        table.Get <LuaFunction>("testFun").Call();
        //改  引用
        table.Set("testInt", 55);
        Debug.Log(table.Get <int>("testInt"));
        LuaTable table2 = LuaMgr.GetInstance().Global.Get <LuaTable>("testClas");

        Debug.Log(table2.Get <int>("testInt"));

        table.Dispose();
        table2.Dispose();
    }
Exemple #7
0
        void Awake()
        {
            Debug.LogMsg("LuaClient Awake");

            LuaEnv.CustomLoader custom = Require;
            luaEnv.AddLoader(custom);

            scriptTable = luaEnv.NewTable();

            LuaTable meta = luaEnv.NewTable();

            meta.Set("__index", luaEnv.Global);
            scriptTable.SetMetaTable(meta);
            meta.Dispose();

            scriptTable.Set("self", this);
            //foreach (var injection in injections)
            //{
            //    scriptTable.Set(injection.name, injection.value);
            //}

            luaScript = ResourcesManager.Load <TextAsset>(mainPath);
            luaEnv.DoString(luaScript.text, "Client", scriptTable);

            Action luaAwake = scriptTable.Get <Action>("Awake");

            scriptTable.Get("Start", out luaStart);
            scriptTable.Get("Update", out luaUpdate);
            scriptTable.Get("OnDestroy", out luaOnDestroy);

            if (luaAwake != null)
            {
                luaAwake();
            }
        }
Exemple #8
0
 public void DetachProfiler()
 {
     if (profiler != null)
     {
         profiler.Call("stop", profiler);
         profiler.Dispose();
     }
 }
Exemple #9
0
 public void ShutDown()
 {
     if (null != ondestroy)
     {
         ondestroy();
     }
     scriptEnv.Dispose();
 }
Exemple #10
0
 void OnDestroy()
 {
     luaOnDestroy?.Invoke();
     luaOnDestroy = null;
     luaUpdate    = null;
     luaStart     = null;
     scriptEnv?.Dispose();
 }
Exemple #11
0
 /// <summary>
 /// 清理Lua脚本缓存,下次执行时将重新加载Lua
 /// </summary>
 public void ReloadLua()
 {
     if (_luaTable != null)
     {
         _luaTable.Dispose();
         _luaTable = null;
     }
 }
Exemple #12
0
 public void Dispose()
 {
     if (itemLuaClass != null)
     {
         itemLuaClass.Dispose();
         itemLuaClass = null;
     }
 }
Exemple #13
0
 protected void SafeRelease(ref LuaTable table)
 {
     if (table != null)
     {
         table.Dispose();
         table = null;
     }
 }
Exemple #14
0
 public void SetMsgHandle(LuaTable _luaNet)
 {
     if (luaNetwork != null)
     {
         luaNetwork.Dispose();
     }
     luaNetwork = _luaNet;
 }
Exemple #15
0
 public void Dispose()
 {
     if (m_LuaClass != null)
     {
         m_LuaClass.Dispose();
         m_LuaClass = null;
     }
 }
 private void ClearLoadedTable()
 {
     if (tableCreated != null)
     {
         tableCreated.Dispose();
         tableCreated = null;
     }
 }
Exemple #17
0
 private void ResetScriptEnv()
 {
     luaAwake     = null;
     luaStart     = null;
     luaUpdate    = null;
     luaOnDestroy = null;
     scriptEnv.Dispose();
 }
Exemple #18
0
 /// <summary>
 /// This function is called when the behaviour becomes disabled or inactive.
 /// </summary>
 void OnDisable()
 {
     if (luaTable != null)
     {
         luaTable.Dispose();
         luaEnv.Dispose();
     }
 }
Exemple #19
0
 private void SafeRelease(ref LuaTable table)
 {
     if (table != null)
     {
         table.Dispose();
         table = null;
     }
 }
Exemple #20
0
        public void Dispose()
        {
            luaFunction.Dispose();
            table.Dispose();

            luaFunction = null;
            table       = null;
        }
Exemple #21
0
        //void Awake()
        //{
        //	if (Initilize(LuaPath))
        //		CallLuaFunction(LuaMain.FuncName.Awake);
        //}

        //void OnEnable()
        //{
        //	CallLuaFunction(LuaMain.FuncName.OnEnable);
        //}

        //void Start()
        //{
        //	CallLuaFunction(LuaMain.FuncName.Start);
        //}

        //void Update()
        //{
        //	CallLuaFunction(LuaMain.FuncName.Update);
        //}

        //void OnDisable()
        //{
        //	CallLuaFunction(LuaMain.FuncName.OnDisable);
        //}

        //void OnDestroy()
        //{
        //	CallLuaFunction(LuaMain.FuncName.OnDestroy);

        //	if (null != mSelfLuaTable)
        //	{
        //		mSelfLuaTable.Dispose();
        //		mSelfLuaTable = null;
        //	}
        //}

        public void DisposeLuaTable()
        {
            if (null != mSelfLuaTable)
            {
                mSelfLuaTable.Dispose();
                mSelfLuaTable = null;
            }
        }
 private void OnDestroy()
 {
     if (_onDestroyFunc != null)
     {
         _onDestroyFunc.Invoke();
     }
     ScriptEnv.Dispose();
 }
 protected virtual void OnDestory()
 {
     if (m_LuaTable != null)
     {
         m_LuaTable.Dispose();
     }
     m_LuaTable = null;
 }
Exemple #24
0
        public static void Main(string[] args)
        {
            try
            {
                TestRemoting( );

                using (Lua state = new Lua(  ))
                {
                    LuaFunction print = state["print"] as LuaFunction;

                    LuaTable table = state.CreateTable();
                    table.SetValue("test", "value");
                    state["incomingTable"] = table;

                    state.DoFile("test.lua");
                    var f = new Function();
                    state["TestClr"] = f;

                    LuaFunction f1 = state["AFunction"] as LuaFunction;

                    state.DoString("AFunction = nil");

                    print.Call("AFunction returned: " + f1.Call(  )[0]);
                    f1.Dispose(  );

                    LuaFunction f2 = state["BFunction"] as LuaFunction;
                    f2.Call(  );
                    f2.Dispose(  );

                    LuaTable sillytable = state["SillyTable"] as LuaTable;

                    string str = sillytable["aaa"] as string;

                    print.Call(str);

                    sillytable["aaa"] = 9001;

                    foreach (var val in sillytable)
                    {
                        Console.WriteLine("{0} = {1}", val.Key, val.Value);
                    }

                    print.Call(state["SillyTable", "aaa"]);

                    sillytable.Dispose(  );

                    state.CreateTable("table");
                    print.Call(state["table"] as LuaTable);

                    print.Dispose(  );
                    GC.KeepAlive(f);
                }
            }
            catch (LuaException e)
            {
                Console.WriteLine("Fail: " + e.Message);
            }
        }
Exemple #25
0
    protected void OnDestroy()
    {
        CallMethod("OnDestroy");

        if (table != null)
        {
            table.Dispose();
        }
    }
 public void ShutDown()
 {
     Debug.Log("lua PureMVC framework start up...");
     if (null != ondestroy)
     {
         ondestroy();
     }
     scriptEnv.Dispose();
 }
Exemple #27
0
        public override void Dispose()
        {
            base.Dispose();

            if (Lua != null)
            {
                Lua.Dispose();
            }
        }
Exemple #28
0
        public override void Dispose()
        {
            base.Dispose();

            if (_peerTable != null)
            {
                _peerTable.Dispose();
            }
        }
 private void OnDestroy()
 {
     if (luaTable != null)
     {
         luaTable.Call("OnDestroy", luaTable);
     }
     luaTable.Dispose();
     luaTable = null;
 }
Exemple #30
0
 void OnDestroy()
 {
     luaOnDestroy?.Invoke();
     luaOnDestroy = null;
     luaUpdate    = null;
     luaStart     = null;
     luaTSrc.Dispose();
     injections = null;
 }