From 06788c04d75a21e85f64f22cf7993cb19d558d64 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 20 May 2018 18:34:50 +0100 Subject: [PATCH 1/2] Added verbose --- ExpCore/gui.lua | 1 + ExpCore/load.lua | 12 +++++++----- ExpCore/ranking.lua | 4 ++++ ExpCore/sync.lua | 7 +++++++ StdLib/load.lua | 13 ++++++------ control.lua | 48 +++++++++++++++++++++++++++------------------ 6 files changed, 55 insertions(+), 30 deletions(-) diff --git a/ExpCore/gui.lua b/ExpCore/gui.lua index a9f14934..a16ca0f6 100644 --- a/ExpCore/gui.lua +++ b/ExpCore/gui.lua @@ -28,6 +28,7 @@ function Gui._get_data(key) return Gui_data[key] end function Gui:_load_parts(parts) for _,part in pairs(parts) do + verbose('Gui Extraction: '..part) self[part] = require('/GuiParts/'..part) end end diff --git a/ExpCore/load.lua b/ExpCore/load.lua index 0a95d3a1..ac2b5610 100644 --- a/ExpCore/load.lua +++ b/ExpCore/load.lua @@ -17,11 +17,12 @@ Pass a table with the names of the objects you want and it will be return in tha local StdExpCoreLib = {} -require '/commands' -StdExpCoreLib.Ranking = require '/ranking' -StdExpCoreLib.Server = require '/server' -StdExpCoreLib.Sync = require '/sync' -StdExpCoreLib.Gui = require '/gui' +require('/commands') +StdExpCoreLib.Ranking = require('/ranking') +StdExpCoreLib.Server = require('/server') +StdExpCoreLib.Sync = require('/sync') +StdExpCoreLib.Gui = require('/gui') +verbose('Begain Gui Part Loading') StdExpCoreLib.Gui:_load_parts{ 'inputs', 'toolbar', @@ -34,6 +35,7 @@ return function(rtn) local _return = {} for _,name in pairs(rtn) do if StdExpCoreLib[name] then + verbose('Core File Extraction: '..name) table.insert(_return,StdExpCoreLib[name]) end end diff --git a/ExpCore/ranking.lua b/ExpCore/ranking.lua index e0a3cf87..bad35ad0 100644 --- a/ExpCore/ranking.lua +++ b/ExpCore/ranking.lua @@ -284,6 +284,7 @@ end -- see Addons/playerRanks for examples function Ranking._rank:edit(key,set_value,value) if game then return end + verbose('Edited Rank: '..self.name..'/'..key) if set_value then self[key] = value return end if key == 'disallow' then self.disallow = table.merge(self.disallow,value,true) @@ -300,6 +301,7 @@ end function Ranking._group:create(obj) if game then return end if not is_type(obj.name,'string') then return end + verbose('Created Group: '..obj.name) setmetatable(obj,{__index=Ranking._group}) self.index = #Ranking._groups(names)+1 obj.ranks = {} @@ -318,6 +320,7 @@ function Ranking._group:add_rank(obj) not is_type(obj.short_hand,'string') or not is_type(obj.tag,'string') or not is_type(obj.colour,'table') then return end + verbose('Created Rank: '..obj.name) setmetatable(obj,{__index=Ranking._rank}) obj.group = self obj.allow = obj.allow or {} @@ -336,6 +339,7 @@ end -- see Addons/playerRanks for examples function Ranking._group:edit(key,set_value,value) if game then return end + verbose('Edited Group: '..self.name..'/'..key) if set_value then self[key] = value return end if key == 'disallow' then self.disallow = table.merge(self.disallow,value,true) diff --git a/ExpCore/sync.lua b/ExpCore/sync.lua index 3e148464..dec82cf8 100644 --- a/ExpCore/sync.lua +++ b/ExpCore/sync.lua @@ -90,6 +90,13 @@ function Sync.emit_embeded(args) game.write_file('embeded.json',table.json(log_data)..'\n',true,0) end +-- set up error handle +verbose('Set New Error Handle') +_G.error_handle = function(err) + local color = _G.Color and Color.to_hex(defines.text_color.bg) or '0x0' + Sync.emit_embeded{title='SCRIPT ERROR',color=color,description='There was an error in the script @Developers ',Error=err} +end + --- used to get the number of admins currently online -- @usage Sync.count_admins() -- @treturn int the number of admins online diff --git a/StdLib/load.lua b/StdLib/load.lua index 22fe25e3..85cab6be 100644 --- a/StdLib/load.lua +++ b/StdLib/load.lua @@ -17,17 +17,18 @@ Pass a table with the names of the objects you want and it will be return in tha local StdLib = {} -require '/table' -require '/string' -require '/time' -StdLib.Color = require '/color' -StdLib.Game = require '/game' -StdLib.Event = require '/event' +require('/table') +require('/string') +require('/time') +StdLib.Color = require('/color') +StdLib.Game = require('/game') +StdLib.Event = require('/event') return function(rtn) local _return = {} for _,name in pairs(rtn) do if StdLib[name] then + verbose('StdLib Extraction: '..name) table.insert(_return,StdLib[name]) end end diff --git a/control.lua b/control.lua index 7be7606a..ab37fe20 100644 --- a/control.lua +++ b/control.lua @@ -8,59 +8,69 @@ Discord: https://discord.gg/r6dC2uK ]] --Please Only Edit Below This Line----------------------------------------------------------- --- A base for functions to keep things clean -_G._ = {} - -- Replaces the base error function _error = error error = function(err) - if _G.Sync and _G.Sync.emit_embeded and game then - local color = _G.Color and Color.to_hex(defines.text_color.bg) or '0x0' - Sync.emit_embeded{title='SCRIPT ERROR',color=color,description='There was an error in the script @Developers ',Error=err} - elseif _G.error_handle and type(error_handle) == 'function' then + verbose('Error Called: '..err) + if _G.error_handle and type(error_handle) == 'function' then + verbose('Exception Caught By Error Handle') local success, _err = error_handle(err) if not success then _error({handle=_err,err=err}) end elseif _G.Game and game then + verbose('Exception Caught By Game Print') if Game.print_all(err) == 0 then _error(err) end else + verbose('Failed to catch error') _error(err) end end --- Replaces the base require function +-- Replaces the base require function and verbose function +_verbose = true -- Set to true for more on the loading of the files +function verbose(str) if _verbose then log(str) print(str) end end +verbose('============================= START =============================') require_return_err = false -- Set to false when removing files; set to true for debuging _require = require require = function(path) local _return = {pcall(_require,path)} - if not table.remove(_return, 1) and require_return_err then error(unpack(_return)) end + if not table.remove(_return, 1) then verbose('Failed to load: '..path..' ('.._return[1]..')') if require_return_err then error(unpack(_return)) end + else verbose('Loaded: '..path) end return unpack(_return) end -require("mod-gui") +verbose('Begain Base Lib Loading') +require('mod-gui') -- Loads the stdlib and allows Core Game and Event -Color, Game, Event = require('/StdLib/load'){'Color','Game','Event'} +Color, Game, Event = require('StdLib/load'){'Color','Game','Event'} -- loads the ExpLib, functions are placed into the lua global local ExpLib = require 'ExpLib' +verbose('ExpLib Initiation') ExpLib._unpack_to_G(ExpLib) ---_G.Sync.emit_embeded = nil -- Un-comment this line if you are not using the json.data +verbose('Begain Core File Loading') -- Loads the ExpCore files. These are need in order to run the other addons -Ranking, Sync, Server, Gui = require('/ExpCore/load'){'Ranking','Sync','Server','Gui'} -local success,err = pcall(require,'/ExpCore/GuiParts/test') -if success then Gui.test = err end -if Gui.popup then Gui.popup._load() end -if Sync._load then Sync._load() end +Ranking, Sync, Server, Gui = require('ExpCore/load'){'Ranking','Sync','Server','Gui'} +local success,err = require('ExpCore/GuiParts/test') +if success then verbose('Gui Test Initiation') Gui.test = err end +if Gui.popup then verbose('Gui Popup Initiation') Gui.popup._load() end +if Sync._load then verbose('Sync Initiation') Sync._load() end -- Loads the ranks that Ranking uses -require('/ExpCore/ranks') +verbose('Base Ranks Initiation') +require('ExpCore/ranks') -- Loads any edits that are not need in core pcall as file may not be present -pcall(require,'/Addons/playerRanks') +verbose('Extented Ranks Initiation') +require('Addons/playerRanks') -- Makes sure that all the little details are cleaned up +verbose('Ranking Initiation') Ranking._auto_edit_ranks() -- Loads all the addons +verbose('Begain Addons Loading') local success,err = pcall(require,'Addons/load') if not success then error(err) end -- Loads anything that does not use ExpCore (source given in the file) +verbose('Begain Stand Alone Loading') local success,err = pcall(require,'StandAlone/load') if not success then error(err) end +verbose('============================== END ==============================') \ No newline at end of file From a2f64f2aef30895ba91e6c1241f7db2ff6877757 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 20 May 2018 18:35:10 +0100 Subject: [PATCH 2/2] Set Default Verbose To False --- control.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control.lua b/control.lua index ab37fe20..95a73cbc 100644 --- a/control.lua +++ b/control.lua @@ -27,7 +27,7 @@ error = function(err) end end -- Replaces the base require function and verbose function -_verbose = true -- Set to true for more on the loading of the files +_verbose = false -- Set to true for more on the loading of the files function verbose(str) if _verbose then log(str) print(str) end end verbose('============================= START =============================') require_return_err = false -- Set to false when removing files; set to true for debuging