From ce449c37b159bb0928264e419c772f1538fd3b65 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Thu, 30 Nov 2017 10:30:42 +0100 Subject: [PATCH] Reworked the sanitization of debug Fixed an issue in Designate for the messages. --- Moose Development/Moose/Core/Base.lua | 61 ++++++++++--------- Moose Development/Moose/Core/Fsm.lua | 12 ++-- Moose Development/Moose/Core/Menu.lua | 37 +++++++---- .../Moose/Core/ScheduleDispatcher.lua | 4 +- .../Moose/Functional/Designate.lua | 8 ++- Moose Mission Setup/Moose.lua | 2 +- Moose Mission Setup/Moose_.lua | 2 +- 7 files changed, 73 insertions(+), 53 deletions(-) diff --git a/Moose Development/Moose/Core/Base.lua b/Moose Development/Moose/Core/Base.lua index 4519a61f3..0f09aa8e6 100644 --- a/Moose Development/Moose/Core/Base.lua +++ b/Moose Development/Moose/Core/Base.lua @@ -198,6 +198,7 @@ BASE = { ClassID = 0, Events = {}, States = {}, + Debug = debug, } @@ -820,7 +821,7 @@ end -- TODO: Make trace function using variable parameters. --- Set trace on or off --- Note that when trace is off, no debug statement is performed, increasing performance! +-- Note that when trace is off, no BASE.Debug statement is performed, increasing performance! -- When Moose is loaded statically, (as one file), tracing is switched off by default. -- So tracing must be switched on manually in your mission if you are using Moose statically. -- When moose is loading dynamically (for moose class development), tracing is switched on by default. @@ -842,7 +843,7 @@ end -- @return #boolean function BASE:IsTrace() - if debug and ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) then + if BASE.Debug and ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) then return true else return false @@ -898,10 +899,10 @@ end -- @param Arguments A #table or any field. function BASE:_F( Arguments, DebugInfoCurrentParam, DebugInfoFromParam ) - if debug and ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) then + if BASE.Debug and ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) then - local DebugInfoCurrent = DebugInfoCurrentParam and DebugInfoCurrentParam or debug.getinfo( 2, "nl" ) - local DebugInfoFrom = DebugInfoFromParam and DebugInfoFromParam or debug.getinfo( 3, "l" ) + local DebugInfoCurrent = DebugInfoCurrentParam and DebugInfoCurrentParam or BASE.Debug.getinfo( 2, "nl" ) + local DebugInfoFrom = DebugInfoFromParam and DebugInfoFromParam or BASE.Debug.getinfo( 3, "l" ) local Function = "function" if DebugInfoCurrent.name then @@ -927,9 +928,9 @@ end -- @param Arguments A #table or any field. function BASE:F( Arguments ) - if debug and _TraceOnOff then - local DebugInfoCurrent = debug.getinfo( 2, "nl" ) - local DebugInfoFrom = debug.getinfo( 3, "l" ) + if BASE.Debug and _TraceOnOff then + local DebugInfoCurrent = BASE.Debug.getinfo( 2, "nl" ) + local DebugInfoFrom = BASE.Debug.getinfo( 3, "l" ) if _TraceLevel >= 1 then self:_F( Arguments, DebugInfoCurrent, DebugInfoFrom ) @@ -943,9 +944,9 @@ end -- @param Arguments A #table or any field. function BASE:F2( Arguments ) - if debug and _TraceOnOff then - local DebugInfoCurrent = debug.getinfo( 2, "nl" ) - local DebugInfoFrom = debug.getinfo( 3, "l" ) + if BASE.Debug and _TraceOnOff then + local DebugInfoCurrent = BASE.Debug.getinfo( 2, "nl" ) + local DebugInfoFrom = BASE.Debug.getinfo( 3, "l" ) if _TraceLevel >= 2 then self:_F( Arguments, DebugInfoCurrent, DebugInfoFrom ) @@ -958,9 +959,9 @@ end -- @param Arguments A #table or any field. function BASE:F3( Arguments ) - if debug and _TraceOnOff then - local DebugInfoCurrent = debug.getinfo( 2, "nl" ) - local DebugInfoFrom = debug.getinfo( 3, "l" ) + if BASE.Debug and _TraceOnOff then + local DebugInfoCurrent = BASE.Debug.getinfo( 2, "nl" ) + local DebugInfoFrom = BASE.Debug.getinfo( 3, "l" ) if _TraceLevel >= 3 then self:_F( Arguments, DebugInfoCurrent, DebugInfoFrom ) @@ -973,10 +974,10 @@ end -- @param Arguments A #table or any field. function BASE:_T( Arguments, DebugInfoCurrentParam, DebugInfoFromParam ) - if debug and ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) then + if BASE.Debug and ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) then - local DebugInfoCurrent = DebugInfoCurrentParam and DebugInfoCurrentParam or debug.getinfo( 2, "nl" ) - local DebugInfoFrom = DebugInfoFromParam and DebugInfoFromParam or debug.getinfo( 3, "l" ) + local DebugInfoCurrent = DebugInfoCurrentParam and DebugInfoCurrentParam or BASE.Debug.getinfo( 2, "nl" ) + local DebugInfoFrom = DebugInfoFromParam and DebugInfoFromParam or BASE.Debug.getinfo( 3, "l" ) local Function = "function" if DebugInfoCurrent.name then @@ -1002,9 +1003,9 @@ end -- @param Arguments A #table or any field. function BASE:T( Arguments ) - if debug and _TraceOnOff then - local DebugInfoCurrent = debug.getinfo( 2, "nl" ) - local DebugInfoFrom = debug.getinfo( 3, "l" ) + if BASE.Debug and _TraceOnOff then + local DebugInfoCurrent = BASE.Debug.getinfo( 2, "nl" ) + local DebugInfoFrom = BASE.Debug.getinfo( 3, "l" ) if _TraceLevel >= 1 then self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom ) @@ -1018,9 +1019,9 @@ end -- @param Arguments A #table or any field. function BASE:T2( Arguments ) - if debug and _TraceOnOff then - local DebugInfoCurrent = debug.getinfo( 2, "nl" ) - local DebugInfoFrom = debug.getinfo( 3, "l" ) + if BASE.Debug and _TraceOnOff then + local DebugInfoCurrent = BASE.Debug.getinfo( 2, "nl" ) + local DebugInfoFrom = BASE.Debug.getinfo( 3, "l" ) if _TraceLevel >= 2 then self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom ) @@ -1033,9 +1034,9 @@ end -- @param Arguments A #table or any field. function BASE:T3( Arguments ) - if debug and _TraceOnOff then - local DebugInfoCurrent = debug.getinfo( 2, "nl" ) - local DebugInfoFrom = debug.getinfo( 3, "l" ) + if BASE.Debug and _TraceOnOff then + local DebugInfoCurrent = BASE.Debug.getinfo( 2, "nl" ) + local DebugInfoFrom = BASE.Debug.getinfo( 3, "l" ) if _TraceLevel >= 3 then self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom ) @@ -1048,9 +1049,9 @@ end -- @param Arguments A #table or any field. function BASE:E( Arguments ) - if debug then - local DebugInfoCurrent = debug.getinfo( 2, "nl" ) - local DebugInfoFrom = debug.getinfo( 3, "l" ) + if BASE.Debug then + local DebugInfoCurrent = BASE.Debug.getinfo( 2, "nl" ) + local DebugInfoFrom = BASE.Debug.getinfo( 3, "l" ) local Function = "function" if DebugInfoCurrent.name then @@ -1064,6 +1065,8 @@ function BASE:E( Arguments ) end env.info( string.format( "%6d(%6d)/%1s:%20s%05d.%s(%s)" , LineCurrent, LineFrom, "E", self.ClassName, self.ClassID, Function, routines.utils.oneLineSerialize( Arguments ) ) ) + else + env.info( string.format( "%1s:%20s%05d(%s)" , "E", self.ClassName, self.ClassID, routines.utils.oneLineSerialize( Arguments ) ) ) end end diff --git a/Moose Development/Moose/Core/Fsm.lua b/Moose Development/Moose/Core/Fsm.lua index d934f68ad..d107fc903 100644 --- a/Moose Development/Moose/Core/Fsm.lua +++ b/Moose Development/Moose/Core/Fsm.lua @@ -562,8 +562,8 @@ do -- FSM local ErrorHandler = function( errmsg ) env.info( "Error in SCHEDULER function:" .. errmsg ) - if debug ~= nil then - env.info( debug.traceback() ) + if BASE.Debug ~= nil then + env.info( BASE.Debug.traceback() ) end return errmsg @@ -860,8 +860,8 @@ do -- FSM_CONTROLLABLE local ErrorHandler = function( errmsg ) env.info( "Error in SCHEDULER function:" .. errmsg ) - if debug ~= nil then - env.info( debug.traceback() ) + if BASE.Debug ~= nil then + env.info( BASE.Debug.traceback() ) end return errmsg @@ -920,8 +920,8 @@ do -- FSM_PROCESS local ErrorHandler = function( errmsg ) env.info( "Error in FSM_PROCESS call handler:" .. errmsg ) - if debug ~= nil then - env.info( debug.traceback() ) + if BASE.Debug ~= nil then + env.info( BASE.Debug.traceback() ) end return errmsg diff --git a/Moose Development/Moose/Core/Menu.lua b/Moose Development/Moose/Core/Menu.lua index 3adf00c6f..e3b9e08c9 100644 --- a/Moose Development/Moose/Core/Menu.lua +++ b/Moose Development/Moose/Core/Menu.lua @@ -293,8 +293,8 @@ do -- MENU_COMMAND_BASE -- This error handler catches the menu error and displays the full call stack. local ErrorHandler = function( errmsg ) env.info( "MOOSE error in MENU COMMAND function: " .. errmsg ) - if debug ~= nil then - env.info( debug.traceback() ) + if BASE.Debug ~= nil then + env.info( BASE.Debug.traceback() ) end return errmsg end @@ -413,7 +413,10 @@ do -- MENU_MISSION self:RemoveSubMenus() if not MenuTime or self.MenuTime ~= MenuTime then if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then - missionCommands.removeItem( self.MenuPath ) + self:E( { Text = self.MenuText, Path = self.MenuPath } ) + if self.MenuPath ~= nil then + missionCommands.removeItem( self.MenuPath ) + end MENU_INDEX:ClearMissionMenu( self.Path ) self:ClearParentMenu( self.MenuText ) return nil @@ -495,7 +498,10 @@ do -- MENU_MISSION_COMMAND if MissionMenu == self then if not MenuTime or self.MenuTime ~= MenuTime then if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then - missionCommands.removeItem( self.MenuPath ) + self:E( { Text = self.MenuText, Path = self.MenuPath } ) + if self.MenuPath ~= nil then + missionCommands.removeItem( self.MenuPath ) + end MENU_INDEX:ClearMissionMenu( self.Path ) self:ClearParentMenu( self.MenuText ) return nil @@ -628,7 +634,10 @@ do -- MENU_COALITION self:RemoveSubMenus() if not MenuTime or self.MenuTime ~= MenuTime then if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then - missionCommands.removeItemForCoalition( self.Coalition, self.MenuPath ) + self:E( { Coalition = self.Coalition, Text = self.MenuText, Path = self.MenuPath } ) + if self.MenuPath ~= nil then + missionCommands.removeItemForCoalition( self.Coalition, self.MenuPath ) + end MENU_INDEX:ClearCoalitionMenu( self.Coalition, Path ) self:ClearParentMenu( self.MenuText ) return nil @@ -713,10 +722,12 @@ do -- MENU_COALITION_COMMAND local CoalitionMenu = MENU_INDEX:HasCoalitionMenu( self.Coalition, Path ) if CoalitionMenu == self then - self:RemoveSubMenus() if not MenuTime or self.MenuTime ~= MenuTime then if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then - missionCommands.removeItemForCoalition( self.Coalition, self.MenuPath ) + self:E( { Coalition = self.Coalition, Text = self.MenuText, Path = self.MenuPath } ) + if self.MenuPath ~= nil then + missionCommands.removeItemForCoalition( self.Coalition, self.MenuPath ) + end MENU_INDEX:ClearCoalitionMenu( self.Coalition, Path ) self:ClearParentMenu( self.MenuText ) return nil @@ -880,7 +891,10 @@ do self:RemoveSubMenus( MenuTime, MenuTag ) if not MenuTime or self.MenuTime ~= MenuTime then if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then - missionCommands.removeItemForGroup( self.GroupID, self.MenuPath ) + self:E( { Group = self.GroupID, Text = self.MenuText, Path = self.MenuPath } ) + if self.MenuPath ~= nil then + missionCommands.removeItemForGroup( self.GroupID, self.MenuPath ) + end MENU_INDEX:ClearGroupMenu( self.Group, Path ) self:ClearParentMenu( self.MenuText ) return nil @@ -969,7 +983,10 @@ do if GroupMenu == self then if not MenuTime or self.MenuTime ~= MenuTime then if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then - missionCommands.removeItemForGroup( self.GroupID, self.MenuPath ) + self:E( { Group = self.GroupID, Text = self.MenuText, Path = self.MenuPath } ) + if self.MenuPath ~= nil then + missionCommands.removeItemForGroup( self.GroupID, self.MenuPath ) + end MENU_INDEX:ClearGroupMenu( self.Group, Path ) self:ClearParentMenu( self.MenuText ) return nil @@ -979,8 +996,6 @@ do return self end - - end diff --git a/Moose Development/Moose/Core/ScheduleDispatcher.lua b/Moose Development/Moose/Core/ScheduleDispatcher.lua index adba0c601..a98b040fb 100644 --- a/Moose Development/Moose/Core/ScheduleDispatcher.lua +++ b/Moose Development/Moose/Core/ScheduleDispatcher.lua @@ -91,8 +91,8 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr local ErrorHandler = function( errmsg ) env.info( "Error in timer function: " .. errmsg ) - if debug ~= nil then - env.info( debug.traceback() ) + if BASE.Debug ~= nil then + env.info( BASE.Debug.traceback() ) end return errmsg end diff --git a/Moose Development/Moose/Functional/Designate.lua b/Moose Development/Moose/Functional/Designate.lua index 7775f78eb..a190f23c7 100644 --- a/Moose Development/Moose/Functional/Designate.lua +++ b/Moose Development/Moose/Functional/Designate.lua @@ -1085,14 +1085,16 @@ do -- DESIGNATE self.LaserCodesUsed[LaserCode] = LaserCodeIndex local Spot = RecceUnit:LaseUnit( TargetUnit, LaserCode, Duration ) local AttackSet = self.AttackSet + local DesignateName = self.DesignateName function Spot:OnAfterDestroyed( From, Event, To ) - self:E( "Destroyed Message" ) - self.Recce:ToSetGroup( "Target " .. TargetUnit:GetTypeName() .. " destroyed. " .. TargetSetUnit:Count() .. " targets left.", 5, AttackSet, self.DesignateName ) + self.Recce:MessageToSetGroup( "Target " .. TargetUnit:GetTypeName() .. " destroyed. " .. TargetSetUnit:Count() .. " targets left.", + 5, AttackSet, self.DesignateName ) end self.Recces[TargetUnit] = RecceUnit - RecceUnit:MessageToSetGroup( "Marking " .. TargetUnit:GetTypeName() .. " with laser " .. RecceUnit:GetSpot().LaserCode .. " for " .. Duration .. "s.", 5, self.AttackSet, self.DesignateName ) + RecceUnit:MessageToSetGroup( "Marking " .. TargetUnit:GetTypeName() .. " with laser " .. RecceUnit:GetSpot().LaserCode .. " for " .. Duration .. "s.", + 5, self.AttackSet, DesignateName ) -- OK. We have assigned for the Recce a TargetUnit. We can exit the function. MarkingCount = MarkingCount + 1 local TargetUnitType = TargetUnit:GetTypeName() diff --git a/Moose Mission Setup/Moose.lua b/Moose Mission Setup/Moose.lua index 73093f60f..3113b56df 100644 --- a/Moose Mission Setup/Moose.lua +++ b/Moose Mission Setup/Moose.lua @@ -1,5 +1,5 @@ env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' ) -env.info( 'Moose Generation Timestamp: 20171122_0612' ) +env.info( 'Moose Generation Timestamp: 20171130_1029' ) local base = _G diff --git a/Moose Mission Setup/Moose_.lua b/Moose Mission Setup/Moose_.lua index bafc5cf9f..04c2cd949 100644 --- a/Moose Mission Setup/Moose_.lua +++ b/Moose Mission Setup/Moose_.lua @@ -1,5 +1,5 @@ env.info('*** MOOSE DYNAMIC INCLUDE START *** ') -env.info('Moose Generation Timestamp: 20171122_0612') +env.info('Moose Generation Timestamp: 20171130_1029') local base=_G MOOSE={} MOOSE.Include=function(LuaPath,IncludeFile)