Exemple #1
0
    public static XLua.LuaTable getSimpleEnvTable()
    {
        XLua.LuaTable scriptEnv = LuaManager.LuaEnv.NewTable();
        // 为每个脚本设置一个独立的环境,可一定程度上防止脚本间全局变量、函数冲突
        XLua.LuaTable meta = LuaManager.LuaEnv.NewTable();
        meta.Set("__index", LuaManager.LuaEnv.Global);
        scriptEnv.SetMetaTable(meta);
        meta.Dispose();

        return(scriptEnv);
    }
    public static void BindMetaTable(XLua.LuaEnv env, XLua.LuaTable table)
    {
        if (env == null)
        {
            return;
        }
        if (table == null)
        {
            return;
        }
        LuaTable t = env.NewTable();

        t.Set("__index", env.Global);
        table.SetMetaTable(t);
        t.Dispose();
    }
Exemple #3
0
        /// <summary>
        /// 创建拓展的LuaTable
        /// </summary>
        /// <param name="tableName">做key</param>
        /// <returns></returns>
        public LuaTable CreateExpandTable(string tableName)
        {
            if (_luaTableMap.ContainsKey(tableName))
            {
                Error("CreateExpandTable():the table has existed :{0}", tableName);
                return(null);
            }
            LuaTable luaTable  = _luaEnv.NewTable();
            LuaTable metaTable = _luaEnv.NewTable();

            metaTable.Set("__index", _luaEnv.Global);
            luaTable.SetMetaTable(metaTable);
            metaTable.Dispose();
            AddTable(tableName, luaTable);
            return(luaTable);
        }
Exemple #4
0
    public static XLua.LuaTable getInterpreterEnvTable(GameInterpreter interpreter)
    {
        XLua.LuaTable scriptEnv = LuaManager.LuaEnv.NewTable();
        // 为每个脚本设置一个独立的环境,可一定程度上防止脚本间全局变量、函数冲突
        XLua.LuaTable meta = LuaManager.LuaEnv.NewTable();
        meta.Set("__index", LuaManager.LuaEnv.Global);
        scriptEnv.SetMetaTable(meta);
        meta.Dispose();

        scriptEnv.Set("self", interpreter);
        scriptEnv.Set("gameVariables", GameTemp.gameVariables);
        scriptEnv.Set("gameSwitches", GameTemp.gameSwitches);
        scriptEnv.Set("gameSelfSwitches", GameTemp.gameSelfSwitches);
        scriptEnv.Set("gamePlayer", GameTemp.gamePlayer);
        scriptEnv.Set("gameMap", GameTemp.gameMap);

        return(scriptEnv);
    }
        static int _m_SetMetaTable(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


            XLua.LuaTable __cl_gen_to_be_invoked = (XLua.LuaTable)translator.FastGetCSObj(L, 1);


            try {
                {
                    XLua.LuaTable metaTable = (XLua.LuaTable)translator.GetObject(L, 2, typeof(XLua.LuaTable));

                    __cl_gen_to_be_invoked.SetMetaTable(metaTable);



                    return(0);
                }
            } catch (System.Exception __gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e));
            }
        }
    //----------------------------------------------------------------------------
    // PlayState.Playingに変更されたときに呼び出される
    public override void OnBehaviourPlay(
        UnityEngine.Playables.Playable playable,
        UnityEngine.Playables.FrameData info
        )
    {
        if (textAsset != null)
        {
            scriptEnv = LuaEngine.LuaEnv.NewTable();
            // スクリプトごとに別々の環境を設定すると、スクリプト間でのグローバル変数と関数の競合をある程度防ぐことができます。
            XLua.LuaTable meta = LuaEngine.LuaEnv.NewTable();
            meta.Set("__index", LuaEngine.LuaEnv.Global);
            scriptEnv.SetMetaTable(meta);
            meta.Dispose();

            scriptEnv.Set("self", owner);
            LuaEngine.LuaEnv.DoString(textAsset.text, textAsset.GetHashCode().ToString(), scriptEnv);

            Action luaAwake = scriptEnv.Get <Action>("awake");
            scriptEnv.Get("update", out luaUpdate);
            scriptEnv.Get("ondestroy", out luaOnDestroy);

            luaAwake?.Invoke();
        }
    }