Ejemplo n.º 1
0
        public static void Record()
        {
#if XLUA || TOLUA || SLUA
            IntPtr L = LuaProfiler.mainL;
            if (L == IntPtr.Zero)
            {
                return;
            }
            isHook = false;
            ClearRecord();
            int oldTop = LuaDLL.lua_gettop(L);
            LuaLib.lua_getglobal(L, "miku_handle_error");

            LuaLib.lua_getglobal(L, "miku_do_record");
            LuaLib.lua_getglobal(L, "_G");
            LuaDLL.lua_pushstring(L, "");
            LuaDLL.lua_pushstring(L, "_G");
            //recrod
            LuaDLL.lua_newtable(L);
            historyRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
            LuaDLL.lua_getref(L, historyRef);
            //history
            LuaDLL.lua_pushnil(L);
            //null_list
            LuaDLL.lua_newtable(L);

            if (LuaDLL.lua_pcall(L, 6, 0, oldTop + 1) == 0)
            {
                LuaDLL.lua_remove(L, oldTop + 1);
            }
            LuaDLL.lua_settop(L, oldTop);

            oldTop = LuaDLL.lua_gettop(L);
            LuaLib.lua_getglobal(L, "miku_handle_error");

            LuaLib.lua_getglobal(L, "miku_do_record");
            LuaDLL.lua_pushvalue(L, LuaIndexes.LUA_REGISTRYINDEX);
            LuaDLL.lua_pushstring(L, "");
            LuaDLL.lua_pushstring(L, "_R");
            LuaDLL.lua_getref(L, historyRef);
            //history
            LuaDLL.lua_pushnil(L);
            //null_list
            LuaDLL.lua_newtable(L);

            if (LuaDLL.lua_pcall(L, 6, 0, oldTop + 1) == 0)
            {
                LuaDLL.lua_remove(L, oldTop + 1);
            }
            LuaDLL.lua_settop(L, oldTop);

            isHook = true;
#endif
        }
Ejemplo n.º 2
0
        public static void RefString(IntPtr strPoint, int index, string s, IntPtr L)
        {
#if XLUA || TOLUA || SLUA
            int oldTop = LuaDLL.lua_gettop(L);
            //把字符串ref了之后就不GC了
            LuaLib.lua_getglobal(L, "MikuLuaProfilerStrTb");
            LuaDLL.lua_pushvalue(L, index);
            LuaDLL.lua_insert(L, -2);

            LuaDLL.lua_settop(L, oldTop);
            stringDict[(long)strPoint] = s;
#endif
        }
Ejemplo n.º 3
0
        public static void Diff()
        {
#if XLUA || TOLUA || SLUA
            IntPtr L = LuaProfiler.mainL;
            if (L == IntPtr.Zero)
            {
                return;
            }
            isHook = false;

            if (historyRef == -100)
            {
                Debug.LogError("has no history");
                return;
            }

            int oldTop = LuaDLL.lua_gettop(L);
            LuaLib.lua_getglobal(L, "miku_handle_error");

            LuaLib.lua_getglobal(L, "miku_diff");
            LuaDLL.lua_getref(L, historyRef);
            if (LuaDLL.lua_type(L, -1) != LuaTypes.LUA_TTABLE)
            {
                Debug.LogError(LuaDLL.lua_type(L, -1));
                LuaDLL.lua_settop(L, oldTop);
                historyRef = -100;
                return;
            }

            if (LuaDLL.lua_pcall(L, 1, 3, oldTop + 1) == 0)
            {
                LuaDLL.lua_remove(L, oldTop + 1);
            }
            int         nullObjectRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
            int         rmRef         = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
            int         addRef        = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
            LuaDiffInfo ld            = LuaDiffInfo.Create();
            SetNullObject(nullObjectRef, ld.nullRef);
            SetAddOrRm(rmRef, ld.rmRef, ld.rmDetail);
            SetAddOrRm(addRef, ld.addRef, ld.addDetail);

            NetWorkClient.SendMessage(ld);

            LuaDLL.lua_unref(L, nullObjectRef);
            LuaDLL.lua_unref(L, rmRef);
            LuaDLL.lua_unref(L, addRef);
            LuaDLL.lua_settop(L, oldTop);

            isHook = true;
#endif
        }
Ejemplo n.º 4
0
        public static void Diff()
        {
#if XLUA || TOLUA || SLUA
            IntPtr L = LuaProfiler.mainL;
            if (L == IntPtr.Zero)
            {
                return;
            }
            isHook = false;

            if (historyRef == -100)
            {
                Debug.LogError("has no history");
                return;
            }

            int oldTop = LuaDLL.lua_gettop(L);
            LuaLib.lua_getglobal(L, "miku_handle_error");

            LuaLib.lua_getglobal(L, "miku_diff");
            LuaDLL.lua_getref(L, historyRef);
            if (LuaDLL.lua_type(L, -1) != LuaTypes.LUA_TTABLE)
            {
                Debug.LogError(LuaDLL.lua_type(L, -1));
                LuaDLL.lua_settop(L, oldTop);
                historyRef = -100;
                return;
            }

            if (LuaDLL.lua_pcall(L, 1, 3, oldTop + 1) == 0)
            {
                LuaDLL.lua_remove(L, oldTop + 1);
            }
            int nullObjectRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
            int rmRef         = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
            int addRef        = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
            LogTable(addRef, "add: ");
            LogTable(rmRef, "rm: ");
            LogNullObject(nullObjectRef);

            LuaDLL.lua_unref(L, nullObjectRef);
            LuaDLL.lua_unref(L, rmRef);
            LuaDLL.lua_unref(L, addRef);
            LuaDLL.lua_settop(L, oldTop);

            isHook = true;
#endif
        }
Ejemplo n.º 5
0
        public static void DoRefLuaFun(IntPtr L, string funName)
        {
            int oldTop = LuaDLL.lua_gettop(L);

            lua_getglobal(L, "miku_handle_error");
            do
            {
                LuaLib.lua_getglobal(L, funName);
                if (!LuaDLL.lua_isfunction(L, -1))
                {
                    break;
                }
                LuaDLL.lua_pushvalue(L, oldTop);
                if (LuaDLL.lua_pcall(L, 1, 0, oldTop + 1) == 0)
                {
                    LuaDLL.lua_remove(L, oldTop + 1);
                }
            } while (false);

            LuaDLL.lua_settop(L, oldTop);
        }
        public static void DoRefLuaFun(IntPtr L, string funName)
        {
            int oldTop = LuaDLL.lua_gettop(L);

            do
            {
#if XLUA
                int errFunc = LuaDLL.load_error_func(L, -1);
                LuaLib.lua_getglobal(L, funName);
                if (!LuaDLL.lua_isfunction(L, -1))
                {
                    break;
                }
                LuaDLL.lua_pushvalue(L, -3);
                if (LuaDLL.lua_pcall(L, 1, 0, errFunc) == 0)
                {
                    LuaDLL.lua_remove(L, errFunc);
                }
#elif TOLUA
                LuaLib.lua_getglobal(L, funName);
                if (!LuaDLL.lua_isfunction(L, -1))
                {
                    break;
                }
                LuaDLL.lua_pushvalue(L, -2);
                LuaDLL.lua_call(L, 1, 0);
#elif SLUA
                LuaLib.lua_getglobal(L, funName);
                if (!LuaDLL.lua_isfunction(L, -1))
                {
                    break;
                }
                LuaDLL.lua_pushvalue(L, -2);
                LuaDLL.lua_call(L, 1, 0);
#endif
            } while (false);

            LuaDLL.lua_settop(L, oldTop);
        }