public static void DoString(IntPtr L, string script) { LuaHook.isHook = false; byte[] chunk = Encoding.UTF8.GetBytes(script); int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "miku_handle_error"); if (LuaDLL.luaL_loadbuffer(L, chunk, (IntPtr)chunk.Length, "chunk") == 0) { if (LuaDLL.lua_pcall(L, 0, -1, oldTop + 1) == 0) { LuaDLL.lua_remove(L, oldTop + 1); } } else { Debug.Log(script); } LuaHook.isHook = true; LuaDLL.lua_settop(L, oldTop); }
public static void DoString(IntPtr L, string script) { byte[] chunk = Encoding.UTF8.GetBytes(script); int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "miku_handle_error"); MessageBox.Show("dostring"); if (LuaDLL.luaL_loadbufferUnHook(L, chunk, (IntPtr)chunk.Length, "chunk") == 0) { if (LuaDLL.lua_pcall(L, 0, -1, oldTop + 1) == 0) { LuaDLL.lua_remove(L, oldTop + 1); } } else { MessageBox.Show("error:" + script); } MessageBox.Show("dostring end"); LuaDLL.lua_settop(L, oldTop); }
public static void DoRefLuaFun(IntPtr L, string funName, int reference) { LuaDLL.lua_getref(L, reference); int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "miku_handle_error"); do { LuaDLL.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); LuaDLL.lua_pop(L, 1); }
public static void Record() { IntPtr L = LuaProfiler.mainL; if (L == IntPtr.Zero) { return; } isHook = false; ClearRecord(); Resources.UnloadUnusedAssets(); // 调用C# LuaTable LuaFunction WeakTable的析构 来清理掉lua的 ref GC.Collect(); // 清理掉C#强ref后,顺便清理掉很多弱引用 LuaDLL.lua_gc(L, LuaGCOptions.LUA_GCCOLLECT, 0); int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "miku_handle_error"); LuaDLL.lua_getglobal(L, "miku_do_record"); LuaDLL.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); LuaDLL.lua_getglobal(L, "miku_handle_error"); LuaDLL.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; }
public static LuaDiffInfo Diff() { IntPtr L = LuaProfiler.mainL; if (L == IntPtr.Zero) { return(null); } isHook = false; Resources.UnloadUnusedAssets(); // 调用C# LuaTable LuaFunction WeakTable的析构 来清理掉lua的 ref GC.Collect(); // 清理掉C#强ref后,顺便清理掉很多弱引用 LuaDLL.lua_gc(L, LuaGCOptions.LUA_GCCOLLECT, 0); if (staticHistoryRef == -100) { Debug.LogError("has no history"); return(null); } if (historyRef == -100) { Debug.LogError("has no history"); return(null); } int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "miku_handle_error"); LuaDLL.lua_getglobal(L, "miku_diff"); LuaDLL.lua_getref(L, historyRef); LuaDLL.lua_getref(L, staticHistoryRef); if (LuaDLL.lua_type(L, -1) != LuaTypes.LUA_TTABLE && LuaDLL.lua_type(L, -2) != LuaTypes.LUA_TTABLE) { Debug.LogError(LuaDLL.lua_type(L, -1)); LuaDLL.lua_settop(L, oldTop); historyRef = -100; staticHistoryRef = -100; return(null); } if (LuaDLL.lua_pcall(L, 2, 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(); SetTable(nullObjectRef, ld.nullRef, ld.nullDetail); SetTable(rmRef, ld.rmRef, ld.rmDetail); SetTable(addRef, ld.addRef, ld.addDetail); LuaDLL.lua_unref(L, nullObjectRef); LuaDLL.lua_unref(L, rmRef); LuaDLL.lua_unref(L, addRef); LuaDLL.lua_settop(L, oldTop); isHook = true; return(ld); }
public static LuaDiffInfo RecordStatic() { IntPtr L = LuaProfiler.mainL; if (L == IntPtr.Zero) { return(null); } LuaDLL.isHook = false; ClearStaticRecord(); Resources.UnloadUnusedAssets(); // 调用C# LuaTable LuaFunction WeakTable的析构 来清理掉lua的 ref GC.Collect(); // 清理掉C#强ref后,顺便清理掉很多弱引用 LuaDLL.lua_gc_unhook(L, LuaGCOptions.LUA_GCCOLLECT, 0); int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "miku_handle_error"); LuaDLL.lua_getglobal(L, "miku_do_record"); LuaDLL.lua_getglobal(L, "_G"); LuaDLL.lua_pushstring(L, ""); LuaDLL.lua_pushstring(L, "_G"); //recrod LuaDLL.lua_newtable(L); staticHistoryRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_getref(L, staticHistoryRef); //history LuaDLL.lua_pushnil(L); //null_list LuaDLL.lua_newtable(L); LuaDLL.lua_pushvalue(L, -1); int nullObjectRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); 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); LuaDLL.lua_getglobal(L, "miku_handle_error"); LuaDLL.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, staticHistoryRef); //history LuaDLL.lua_pushnil(L); //null_list LuaDLL.lua_getref(L, nullObjectRef); if (LuaDLL.lua_pcall(L, 6, 0, oldTop + 1) == 0) { LuaDLL.lua_remove(L, oldTop + 1); } LuaDLL.lua_settop(L, oldTop); LuaDiffInfo ld = LuaDiffInfo.Create(); SetTable(nullObjectRef, ld.nullRef, ld.nullDetail); LuaDLL.lua_unref(L, nullObjectRef); LuaDLL.isHook = true; return(ld); }