Esempio n. 1
0
        private void UF_LuaBaseStart(GLuaState luastate)
        {
            if (luastate != null)
            {
                string toluaroot = LuaRoot;

                string[] luafiles =
                {
                    "Main.lua",

                    "Mathf.lua",        //ToLua/UnityEngine/Mathf.lua
                    "Vector3.lua",      //ToLua/UnityEngine/Vector3.lua
                    "Quaternion.lua",   //ToLua/UnityEngine/Quaternion.lua
                    "Vector2.lua",      //ToLua/UnityEngine/Vector2.lua
                    "Vector4.lua",      //ToLua/UnityEngine/Vector4.lua
                    "Color.lua",        //ToLua/UnityEngine/Color.lua
                    "Ray.lua",          //ToLua/UnityEngine/Ray.lua
                    "Bounds.lua",       //ToLua/UnityEngine/Bounds.lua
                    "RaycastHit.lua",   //ToLua/UnityEngine/RaycastHit.lua
                    "Touch.lua",        //ToLua/UnityEngine/Touch.lua
                    "LayerMask.lua",    //ToLua/UnityEngine/LayerMask.lua
                    "Plane.lua",        //ToLua/UnityEngine/Plane.lua
                    "TypeOf.lua",       //ToLua/System/TypeOf.lua
                    "ValueType.lua",    //ToLua/System/ValueType.lua
                    "BindingFlags.lua", //ToLua/System/BindingFlags.lua
                };

                int top = m_Luastate.LuaGetTop();
                for (int k = 0; k < luafiles.Length; k++)
                {
                    var assetinfo = AssetDataBases.UF_GetAssetInfo(luafiles[k]);
                    if (assetinfo == default(AssetDataBases.AssetFileInfo))
                    {
                        throw new LuaException(string.Format("Can not get lua file[{0}] in AssetDataBase,Load file failed!", luafiles[k]), LuaException.GetLastError());
                    }
                    if (!UF_DoFile(m_Luastate.LuaGetL(), assetinfo.path, Path.GetFileNameWithoutExtension(assetinfo.name)))
                    {
                        string err = m_Luastate.LuaToString(-1);
                        m_Luastate.LuaSetTop(top);
                        throw new LuaException(err, LuaException.GetLastError());
                    }
                }
                m_Luastate.LuaSetTop(top);

                //打开基础库
                LuaUnityLibs.OpenLuaLibs(luastate.LuaGetL());

                luastate.Start();
            }
        }
Esempio n. 2
0
        //绑定全局方法
        static void UF_RegisterGFunction(GLuaState luastate)
        {
            if (luastate == null)
            {
                return;
            }

            IntPtr L = luastate.LuaGetL();

            LuaDLL.tolua_pushcsfunction(L, UF_PrintTag);
            LuaDLL.lua_setglobal(L, "printt");

            LuaDLL.tolua_pushcsfunction(L, UF_PrintWarn);
            LuaDLL.lua_setglobal(L, "warn");

            LuaDLL.tolua_pushcsfunction(L, UF_PrintError);
            LuaDLL.lua_setglobal(L, "error");

            LuaDLL.tolua_pushcsfunction(L, UF_Unit64ToString);
            LuaDLL.lua_setglobal(L, "unit64_tostring");

            LuaDLL.tolua_pushcsfunction(L, UF_MonoGC);
            LuaDLL.lua_setglobal(L, "GCMono");

            LuaDLL.tolua_pushcsfunction(L, UF_TrackMsg);
            LuaDLL.lua_setglobal(L, "TrackMsg");

            LuaDLL.lua_pushboolean(L, GlobalSettings.DebugMode);
            LuaDLL.lua_setglobal(L, "DEBUG_MODE");
        }
Esempio n. 3
0
        public static void UF_Register(GLuaState luastate)
        {
            IntPtr L = luastate.LuaGetL();

            int oldTop = LuaDLL.lua_gettop(L);

            oldTop = oldTop < 0? 0 : oldTop;

            LuaCSFunction rFunc    = null;
            string        nameFunc = string.Empty;

            LuaDLL.lua_newtable(L);

            for (int k = 0; k < sub.Length / 2; k++)
            {
                rFunc    = (LuaCSFunction)sub[k, 0];
                nameFunc = sub[k, 1].ToString();
                LuaDLL.tolua_pushcsfunction(L, rFunc);
                LuaDLL.lua_setfield(L, oldTop + 1, nameFunc);
            }

            LuaDLL.lua_setglobal(L, "CNetwork");
            LuaDLL.lua_settop(L, oldTop);
        }