From 4b84d227f0d51b856172707c404d50dec91cfbfe Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Mon, 12 Feb 2024 18:34:12 +0100 Subject: [PATCH 1/2] Spawn - reference original template when using SpawnWithAlias in Group.TemplateDonor --- Moose Development/Moose/Core/Spawn.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/Moose Development/Moose/Core/Spawn.lua b/Moose Development/Moose/Core/Spawn.lua index c7095dc8f..a6651a7c1 100644 --- a/Moose Development/Moose/Core/Spawn.lua +++ b/Moose Development/Moose/Core/Spawn.lua @@ -1699,6 +1699,7 @@ function SPAWN:SpawnWithIndex( SpawnIndex, NoBirth ) end self.SpawnGroups[self.SpawnIndex].Spawned = true + self.SpawnGroups[self.SpawnIndex].Group.TemplateDonor = self.SpawnTemplatePrefix return self.SpawnGroups[self.SpawnIndex].Group else -- self:E( { self.SpawnTemplatePrefix, "No more Groups to Spawn:", SpawnIndex, self.SpawnMaxGroups } ) From 67e52120d4c0d7d68d604733add59cb2e0f7ee2e Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Mon, 12 Feb 2024 18:35:22 +0100 Subject: [PATCH 2/2] Nicer BASE:I() etc output --- Moose Development/Moose/Core/Base.lua | 51 +++++++-------------- Moose Development/Moose/Utilities/Utils.lua | 18 ++++++-- 2 files changed, 29 insertions(+), 40 deletions(-) diff --git a/Moose Development/Moose/Core/Base.lua b/Moose Development/Moose/Core/Base.lua index ce3675189..dede44ad3 100644 --- a/Moose Development/Moose/Core/Base.lua +++ b/Moose Development/Moose/Core/Base.lua @@ -1144,6 +1144,18 @@ function BASE:TraceClassMethod( Class, Method ) self:I( "Tracing method " .. Method .. " of class " .. Class ) end +--- (Internal) Serialize arguments +-- @param #BASE self +-- @param #table Arguments +-- @return #string Text +function BASE:_Serialize(Arguments) + local text = UTILS.PrintTableToLog({Arguments}, 0, true) + text = string.gsub(text,"\n","") + text = string.gsub(text,"%(%(","%(") + text = string.gsub(text,"%)%)","%)") + return text +end + --- Trace a function call. This function is private. -- @param #BASE self -- @param Arguments A #table or any field. @@ -1168,7 +1180,7 @@ function BASE:_F( Arguments, DebugInfoCurrentParam, DebugInfoFromParam ) if DebugInfoFrom then LineFrom = DebugInfoFrom.currentline end - env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s(%s)", LineCurrent, LineFrom, "F", self.ClassName, self.ClassID, Function, UTILS.BasicSerialize( Arguments ) ) ) + env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s(%s)", LineCurrent, LineFrom, "F", self.ClassName, self.ClassID, Function, BASE:_Serialize(Arguments) ) ) end end end @@ -1242,7 +1254,7 @@ function BASE:_T( Arguments, DebugInfoCurrentParam, DebugInfoFromParam ) if DebugInfoFrom then LineFrom = DebugInfoFrom.currentline end - env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s", LineCurrent, LineFrom, "T", self.ClassName, self.ClassID, UTILS.BasicSerialize( Arguments ) ) ) + env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s", LineCurrent, LineFrom, "T", self.ClassName, self.ClassID, BASE:_Serialize(Arguments) ) ) end end end @@ -1314,7 +1326,7 @@ function BASE:E( Arguments ) env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s(%s)", LineCurrent, LineFrom, "E", self.ClassName, self.ClassID, Function, UTILS.BasicSerialize( Arguments ) ) ) else - env.info( string.format( "%1s:%30s%05d(%s)", "E", self.ClassName, self.ClassID, UTILS.BasicSerialize( Arguments ) ) ) + env.info( string.format( "%1s:%30s%05d(%s)", "E", self.ClassName, self.ClassID, BASE:_Serialize(Arguments) ) ) end end @@ -1341,39 +1353,8 @@ function BASE:I( Arguments ) env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s(%s)", LineCurrent, LineFrom, "I", self.ClassName, self.ClassID, Function, UTILS.BasicSerialize( Arguments ) ) ) else - env.info( string.format( "%1s:%30s%05d(%s)", "I", self.ClassName, self.ClassID, UTILS.BasicSerialize( Arguments ) ) ) + env.info( string.format( "%1s:%30s%05d(%s)", "I", self.ClassName, self.ClassID, BASE:_Serialize(Arguments)) ) end end ---- old stuff - --- function BASE:_Destructor() --- --self:E("_Destructor") --- --- --self:EventRemoveAll() --- end - --- THIS IS WHY WE NEED LUA 5.2 ... --- function BASE:_SetDestructor() --- --- -- TODO: Okay, this is really technical... --- -- When you set a proxy to a table to catch __gc, weak tables don't behave like weak... --- -- Therefore, I am parking this logic until I've properly discussed all this with the community. --- --- local proxy = newproxy(true) --- local proxyMeta = getmetatable(proxy) --- --- proxyMeta.__gc = function () --- env.info("In __gc for " .. self:GetClassNameAndID() ) --- if self._Destructor then --- self:_Destructor() --- end --- end --- --- -- keep the userdata from newproxy reachable until the object --- -- table is about to be garbage-collected - then the __gc hook --- -- will be invoked and the destructor called --- rawset( self, '__proxy', proxy ) --- --- end diff --git a/Moose Development/Moose/Utilities/Utils.lua b/Moose Development/Moose/Utilities/Utils.lua index 259f6d223..6005dcbce 100644 --- a/Moose Development/Moose/Utilities/Utils.lua +++ b/Moose Development/Moose/Utilities/Utils.lua @@ -444,10 +444,11 @@ end --- Print a table to log in a nice format -- @param #table table The table to print -- @param #number indent Number of indents +-- @param #boolean noprint Don't log but return text -- @return #string text Text created on the fly of the log output -function UTILS.PrintTableToLog(table, indent) +function UTILS.PrintTableToLog(table, indent, noprint) local text = "\n" - if not table then + if not table or type(table) ~= "table" then env.warning("No table passed!") return nil end @@ -455,11 +456,16 @@ function UTILS.PrintTableToLog(table, indent) for k, v in pairs(table) do if string.find(k," ") then k='"'..k..'"'end if type(v) == "table" then - env.info(string.rep(" ", indent) .. tostring(k) .. " = {") + if not noprint then + env.info(string.rep(" ", indent) .. tostring(k) .. " = {") + end text = text ..string.rep(" ", indent) .. tostring(k) .. " = {\n" text = text .. tostring(UTILS.PrintTableToLog(v, indent + 1)).."\n" - env.info(string.rep(" ", indent) .. "},") + if not noprint then + env.info(string.rep(" ", indent) .. "},") + end text = text .. string.rep(" ", indent) .. "},\n" + elseif type(v) == "function" then else local value if tostring(v) == "true" or tostring(v) == "false" or tonumber(v) ~= nil then @@ -467,7 +473,9 @@ function UTILS.PrintTableToLog(table, indent) else value = '"'..tostring(v)..'"' end - env.info(string.rep(" ", indent) .. tostring(k) .. " = " .. tostring(value)..",\n") + if not noprint then + env.info(string.rep(" ", indent) .. tostring(k) .. " = " .. tostring(value)..",\n") + end text = text .. string.rep(" ", indent) .. tostring(k) .. " = " .. tostring(value)..",\n" end end