コード例 #1
0
 private void register_common_libs()
 {
     LuaThread.LoadLibs(_luaState);
     LuaSystemLib.Load(_luaState); // <-- @todo この書式に統一したい
     LuaGameObject.RegisterClass(_luaState);
     LuaComponentBehaviour.RegisterClass(_luaState);
     LuaComponentTransform.RegisterClass(_luaState);
     LuaComponentRectTransform.RegisterClass(_luaState);
     LuaComponentUI.RegisterClass(_luaState);
     LuaMathf.LoadLibs(_luaState);
     LuaUtilLib.Load(_luaState);
 }
コード例 #2
0
ファイル: LuaGameObject.cs プロジェクト: oinkgms/catan-lwf
        // -- describing object oriented class in Lua
        // Test = {}
        // function Test:new()
        //   o = {}
        //   setmetatable(o, self)
        //   self.__index = self
        //   return o
        // end
        // function Test:hoge()
        //   return 3
        // end
        // NewTest = Test:new()
        // function NewTest:hoge()
        //   return 4
        // end
        public static int PushNew(ILuaState lua, GameObject obj)
        {
            LuaVM.Assert(lua, obj != null);
            LuaGameObjectCache cache = obj.GetComponent <LuaGameObjectCache>();

            if (cache != null && cache.index == LuaConstants.LUA_NOREF)
            {
                Object.Destroy(cache);
                cache = null;
            }
            if (cache == null)
            {
                cache = obj.AddComponent <LuaGameObjectCache>();
                // o = {}
                lua.NewTable();
                // setmetatable(o, self)
                //lua.PushValue(-2); // self
                lua.GetGlobal(klassName);
                lua.SetMetaTable(-2); // -> o
                // self.__index = self
                lua.GetMetaTable(-1);
                lua.SetField(-1, "__index");
                // return o
                set_internal <GameObject>(lua, -1, obj);
                set_boolean(lua, -1, "is_prefab", false);
                //
                LuaScriptBehaviour lsb = obj.GetComponent <LuaScriptBehaviour>();
                if (lsb != null)
                {
                    LuaComponentBehaviour.PushNew(lua, lsb);
                    lua.SetField(-2, "behaviour");
                }
                LuaComponentTransform.PushNew(lua, obj.transform);
                lua.SetField(-2, "transform");
                RectTransform rt = obj.GetComponent <RectTransform>();
                if (rt != null)
                {
                    LuaComponentRectTransform.PushNew(lua, rt);
                    lua.SetField(-2, "rect_transform");
                }
                LuaComponentUIText.PushNew(lua, obj);
                lua.SetField(-2, "ui_text");
                LuaComponentUIImage.PushNew(lua, obj);
                lua.SetField(-2, "ui_image");
                if (constructorHook != null)
                {
                    constructorHook(lua, obj);
                }
                lua.PushValue(-1);
                int refidx = lua.L_Ref(LuaDef.LUA_REGISTRYINDEX);
                cache.index    = refidx;
                cache.luaState = lua;
            }
            lua.RawGetI(LuaDef.LUA_REGISTRYINDEX, cache.index);
            //Debug.Log(string.Format("Find {0} {1}", objid, obj.name));
            if (get_internal <GameObject>(lua, -1) == null)
            {
                set_internal <GameObject>(lua, -1, obj);
            }
            return(1);
        }