Ejemplo n.º 1
0
        static int _m_Dispose(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                XLua.LuaEnv gen_to_be_invoked = (XLua.LuaEnv)translator.FastGetCSObj(L, 1);


                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 1)
                {
                    gen_to_be_invoked.Dispose(  );



                    return(0);
                }
                if (gen_param_count == 2 && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 2))
                {
                    bool _dispose = LuaAPI.lua_toboolean(L, 2);

                    gen_to_be_invoked.Dispose(_dispose);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to XLua.LuaEnv.Dispose!"));
        }
Ejemplo n.º 2
0
    static void CopyLuaBytesFiles(string sourceDir, string destDir, bool appendext = true, string searchPattern = "*.lua", SearchOption option = SearchOption.AllDirectories)
    {
        if (!Directory.Exists(sourceDir))
        {
            return;
        }

        string[] files = Directory.GetFiles(sourceDir, searchPattern, option);
        int      len   = sourceDir.Length;

        if (sourceDir[len - 1] == '/' || sourceDir[len - 1] == '\\')
        {
            --len;
        }
        XLua.LuaEnv L = new XLua.LuaEnv();
        for (int i = 0; i < files.Length; i++)
        {
            string str  = files[i].Remove(0, len);
            string dest = destDir + "/" + str;
            if (appendext && !dest.EndsWith(".bytes"))
            {
                dest += ".bytes";
            }
            string dir = Path.GetDirectoryName(dest);
            Directory.CreateDirectory(dir);
            CompileLuaFile(L, files[i], dest);
            //File.Copy(files[i], dest, true);
        }

        L.LuacClear();
        L.GC();
        L.Dispose();
    }
Ejemplo n.º 3
0
    private void DoDestroy(bool disposeGRoot = true)
    {
        // 销毁UI残余界面,否则可能UI组件引用着LUA中的回调函数
        // 就会导致销毁lua虚拟机时抛异常
        FairyGUI.Timers.inst.Clear();
        FairyGUI.GRoot.inst.CleanupChildren();

        if (disposeGRoot)
        {
            FairyGUI.GRoot.inst.Dispose();
        }

        // 最后销毁大厅模块
        if (lobby != null)
        {
            lobby.OnDestroy();
            lobby = null;
        }

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

        if (lobbyLuaEnv != null)
        {
            lobbyLuaEnv.Dispose();
        }
    }
Ejemplo n.º 4
0
    // Start is called before the first frame update
    void Start()
    {
        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();

        XLua.LuaEnv luaenv = new XLua.LuaEnv();
        var         main   = System.IO.File.ReadAllText(Application.dataPath + "\\main.lua");

        luaenv.DoString(main);
        stopwatch.Start();
        for (int i = 0; i < 1000; i++)
        {
            luaenv.DoString("StaticFunTest()");
        }
        Debug.LogWarning($"耗時 {stopwatch.Elapsed}");

        stopwatch.Restart();
        for (int i = 0; i < 1000; i++)
        {
            luaenv.DoString("StaticFunTest2('123')");
        }
        Debug.LogWarning($"耗時 {stopwatch.Elapsed}");

        stopwatch.Restart();
        for (int i = 0; i < 1000; i++)
        {
            luaenv.DoString("AddGenericList()");
        }
        Debug.LogWarning($"耗時 {stopwatch.Elapsed}");

        stopwatch.Restart();
        luaenv.Dispose();
    }
Ejemplo n.º 5
0
    /// <summary>
    /// 销毁控制器
    /// </summary>
    /// <returns>是否销毁成功</returns>
    public bool Destory()
    {
        if (mStatus == EnumConfig.SystemControllerStatusEnum.OVER)
        {
            Debug.LogError("system controller status is overed. destory faild.");
            return(false);
        }
        mStatus = EnumConfig.SystemControllerStatusEnum.OVER;

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

        if (mLuaenv != null)
        {
            mLuaenv.Dispose();
        }
        mLuaStart     = null;
        mLuaUpdate    = null;
        mLuaOnDestroy = null;
        mLuaenv       = null;
        mScriptEnv.Dispose();
        injections = null;
        return(true);
    }
Ejemplo n.º 6
0
    public static void SaveString2()
    {
        TextAsset test = Resources.Load <TextAsset>("code/Skill001.lua");

        XLua.LuaEnv luaenv = new XLua.LuaEnv();
        //luaenv.DoString("CS.UnityEngine.Debug.Log('hello world')");
        luaenv.DoString(test.text);
        luaenv.Dispose();
        Debug.Log(test);
        return;

        CustomSkill skill = SkillUtils.MakeCustomSkill("001");

        skill.id = 001;
        skill.Trigger(CustomSkill.TriggerType.fight);
        return;

        FormulaUtils.GetTowerExtraAttributes(false);
        return;

        for (int i = 0; i < 10; i++)
        {
            Debug.Log(UnityEngine.Random.Range(0, 0.5f));
        }
        return;

        //PlayerSQLPrefs.yzTowerLevel = 10;
        //PlayerSQLPrefs.yzTowerABSLevel = 10;
        PlayerOtherItem.ReduceItem(GameInstance.GameDatabase.otherItem[0].Id, 10);
    }
Ejemplo n.º 7
0
 // Start is called before the first frame update
 void Start()
 {
     //Debug.Log("Hello world!");
     XLua.LuaEnv luaenv = new XLua.LuaEnv();
     luaenv.DoString("CS.UnityEngine.Debug.Log('hello world')");
     luaenv.Dispose();
 }
Ejemplo n.º 8
0
 private void OnDestroy()
 {
     if (luaEnv != null)
     {
         luaEnv.Dispose();
     }
     luaEnv = null;
 }
Ejemplo n.º 9
0
    private void Start()
    {
        var env = new XLua.LuaEnv();

        env.AddLoader(CustomLoad);

        env.DoString("print('this is CustomLoader'");

        env.Dispose();
        env = null;
    }
Ejemplo n.º 10
0
    // Use this for initialization
    void Start()
    {
        XLua.LuaEnv luaenv = new XLua.LuaEnv();
        luaenv.DoString(@"
            CS.UnityEngine.Debug.Log('hello world')
            require 'socket'
            require 'pack'
            CS.UnityEngine.Debug.Log('哈哈')
            print(tonumber('40050.0'));
        ");

        var max = luaenv.Global.GetInPath <LuaMax>("math.max");

        Debug.Log("max:" + max(32, 12).ToString());
        max = null;

        luaenv.Dispose();
    }
Ejemplo n.º 11
0
 void _ReloadLua()
 {
     if (_env != null)
     {
         if (LuaEntry.Dispose != null)
         {
             LuaEntry.Dispose();
             //_env.DoString(@"print('随便再执行一行lua代码,重新创建env就不会报错')");
         }
         _env.Dispose();
         _env = null;
     }
     _env = new XLua.LuaEnv();
     _env.DoString(@"require 'main'");
     if (LuaEntry.Init != null)
     {
         LuaEntry.Init();
     }
 }
Ejemplo n.º 12
0
    // Start is called before the first frame update
    private void Start()
    {
        var first  = new XLua.LuaEnv();
        var second = new XLua.LuaEnv();

        first.DoString("require LuaScript.somefolder.somescript");

        first.Global.Set <string, int>("A", 10);
        second.Global.Set <string, int>("B", 20);

        Debug.Log(first.Global.Get <int>("A"));      // 10
        //Debug.Log(first.Global.Get<int>("B"));      // Error


        first.DoString("print(A)");

        //Debug.Log(second.Global.Get<int>("A"));     // Error
        Debug.Log(second.Global.Get <int>("B"));     // 20


        first.Dispose();
        second.Dispose();
    }
Ejemplo n.º 13
0
 private void OnDestroy()
 {
     luaEnv.Dispose();
 }
Ejemplo n.º 14
0
 // Use this for initialization
 void Start()
 {
     XLua.LuaEnv luaenv = new XLua.LuaEnv();
     luaenv.DoString("CS.UnityEngine.Debug.Log('hello Unity')");
     luaenv.Dispose();
 }
Ejemplo n.º 15
0
 void OnDestroy()
 {
     L.Dispose();
 }
Ejemplo n.º 16
0
 public static void disposeLuaEnv()
 {
     LuaEnv.Dispose();
 }