Permalink
Browse files

replace Spring.Echo with Spring.Log in most places in cont/

  • Loading branch information...
1 parent b279c1f commit 1b517997169e4889834f956598cdefce232c55e3 @abma abma committed Jun 30, 2012
View
@@ -40,6 +40,7 @@ local SAFEWRAP = 1
local SAFEDRAW = false -- requires SAFEWRAP to work
local glPopAttrib = gl.PopAttrib
local glPushAttrib = gl.PushAttrib
+local section = 'widgets.lua'
--------------------------------------------------------------------------------
@@ -305,17 +306,17 @@ local function GetWidgetInfo(name, mode)
local info = {}
local chunk, err = loadstring(table.concat(infoLines, '\n'))
if (not chunk) then
- Spring.Echo('not loading ' .. name .. ': ' .. err)
+ Spring.Log(section, LOG.INFO, 'not loading ' .. name .. ': ' .. err)
else
setfenv(chunk, info)
local success, err = pcall(chunk)
if (not success) then
- Spring.Echo('not loading ' .. name .. ': ' .. err)
+ Spring.Log(section, LOG.INFO, 'not loading ' .. name .. ': ' .. err)
end
end
for k,v in pairs(info) do
- Spring.Echo(name, k, 'type: ' .. type(v), '<'..tostring(v)..'>')
+ Spring.Log(section, LOG.INFO, name, k, 'type: ' .. type(v), '<'..tostring(v)..'>')
end
end
@@ -374,7 +375,7 @@ function widgetHandler:Initialize()
local name = w.whInfo.name
local basename = w.whInfo.basename
local source = self.knownWidgets[name].fromZip and "mod: " or "user:"
- Spring.Echo(string.format("Loading widget from %s %-18s <%s> ...", source, name, basename))
+ Spring.Log(section, LOG.INFO, string.format("Loading widget from %s %-18s <%s> ...", source, name, basename))
widgetHandler:InsertWidget(w)
end
@@ -388,20 +389,20 @@ function widgetHandler:LoadWidget(filename, fromZip)
local basename = Basename(filename)
local text = VFS.LoadFile(filename)
if (text == nil) then
- Spring.Echo('Failed to load: ' .. basename .. ' (missing file: ' .. filename ..')')
+ Spring.Log(section, LOG.ERROR, 'Failed to load: ' .. basename .. ' (missing file: ' .. filename ..')')
return nil
end
local chunk, err = loadstring(text, filename)
if (chunk == nil) then
- Spring.Echo('Failed to load: ' .. basename .. ' (' .. err .. ')')
+ Spring.Log(section, LOG.ERROR, 'Failed to load: ' .. basename .. ' (' .. err .. ')')
return nil
end
local widget = widgetHandler:NewWidget()
setfenv(chunk, widget)
local success, err = pcall(chunk)
if (not success) then
- Spring.Echo('Failed to load: ' .. basename .. ' (' .. err .. ')')
+ Spring.Log(section, LOG.ERROR, 'Failed to load: ' .. basename .. ' (' .. err .. ')')
return nil
end
if (err == false) then
@@ -421,14 +422,14 @@ function widgetHandler:LoadWidget(filename, fromZip)
err = self:ValidateWidget(widget)
if (err) then
- Spring.Echo('Failed to load: ' .. basename .. ' (' .. err .. ')')
+ Spring.Log(section, LOG.ERROR, 'Failed to load: ' .. basename .. ' (' .. err .. ')')
return nil
end
local knownInfo = self.knownWidgets[name]
if (knownInfo) then
if (knownInfo.active) then
- Spring.Echo('Failed to load: ' .. basename .. ' (duplicate name)')
+ Spring.Log(section, LOG.ERROR, 'Failed to load: ' .. basename .. ' (duplicate name)')
return nil
end
else
@@ -446,7 +447,7 @@ function widgetHandler:LoadWidget(filename, fromZip)
knownInfo.active = true
if (widget.GetInfo == nil) then
- Spring.Echo('Failed to load: ' .. basename .. ' (no GetInfo() call)')
+ Spring.Log(section, LOG.ERROR, 'Failed to load: ' .. basename .. ' (no GetInfo() call)')
return nil
end
@@ -540,7 +541,7 @@ function widgetHandler:NewWidget()
if (self.inCommandsChanged) then
table.insert(self.customCommands, cmd)
else
- Spring.Echo("AddLayoutCommand() can only be used in CommandsChanged()")
+ Spring.Log(section, LOG.ERROR, "AddLayoutCommand() can only be used in CommandsChanged()")
end
end
@@ -625,12 +626,12 @@ local function SafeWrapFuncNoGL(func, funcName)
if (funcName ~= 'Shutdown') then
widgetHandler:RemoveWidget(w)
else
- Spring.Echo('Error in Shutdown()')
+ Spring.Log(section, LOG.ERROR, 'Error in Shutdown()')
end
local name = w.whInfo.name
- Spring.Echo(r[1])
- Spring.Echo('Error in ' .. funcName ..'(): ' .. tostring(r[2]))
- Spring.Echo('Removed widget: ' .. name)
+ Spring.Log(section, LOG.ERROR, r[1])
+ Spring.Log(section, LOG.ERROR, 'Error in ' .. funcName ..'(): ' .. tostring(r[2]))
+ Spring.Log(section, LOG.ERROR, 'Removed widget: ' .. name)
return nil
end
end
@@ -653,11 +654,11 @@ local function SafeWrapFuncGL(func, funcName)
if (funcName ~= 'Shutdown') then
widgetHandler:RemoveWidget(w)
else
- Spring.Echo('Error in Shutdown()')
+ Spring.Log(section, LOG.ERROR, 'Error in Shutdown()')
end
local name = w.whInfo.name
- Spring.Echo('Error in ' .. funcName ..'(): ' .. tostring(r[2]))
- Spring.Echo('Removed widget: ' .. name)
+ Spring.Log(section, LOG.ERROR, 'Error in ' .. funcName ..'(): ' .. tostring(r[2]))
+ Spring.Log(section, LOG.ERROR, 'Removed widget: ' .. name)
return nil
end
end
@@ -682,7 +683,7 @@ local function SafeWrapWidget(widget)
return
elseif (SAFEWRAP == 1) then
if (widget.GetInfo and widget.GetInfo().unsafe) then
- Spring.Echo('LuaUI: loaded unsafe widget: ' .. widget.whInfo.name)
+ Spring.LOG(section, LOG.INFO, 'LuaUI: loaded unsafe widget: ' .. widget.whInfo.name)
return
end
end
@@ -813,7 +814,7 @@ function widgetHandler:UpdateWidgetCallIn(name, w)
end
self:UpdateCallIn(name)
else
- Spring.Echo('UpdateWidgetCallIn: bad name: ' .. name)
+ Spring.Log(section, LOG.ERROR, 'UpdateWidgetCallIn: bad name: ' .. name)
end
end
@@ -825,7 +826,7 @@ function widgetHandler:RemoveWidgetCallIn(name, w)
ArrayRemove(ciList, w)
self:UpdateCallIn(name)
else
- Spring.Echo('RemoveWidgetCallIn: bad name: ' .. name)
+ Spring.Log(section, LOG.ERROR, 'RemoveWidgetCallIn: bad name: ' .. name)
end
end
@@ -850,11 +851,11 @@ end
function widgetHandler:EnableWidget(name)
local ki = self.knownWidgets[name]
if (not ki) then
- Spring.Echo("EnableWidget(), could not find widget: " .. tostring(name))
+ Spring.Log(section, LOG.ERROR, "EnableWidget(), could not find widget: " .. tostring(name))
return false
end
if (not ki.active) then
- Spring.Echo('Loading: '..ki.filename)
+ Spring.Log(section, LOG.INFO, 'Loading: '..ki.filename)
local order = widgetHandler.orderList[name]
if (not order or (order <= 0)) then
self.orderList[name] = 1
@@ -876,13 +877,13 @@ end
function widgetHandler:DisableWidget(name)
local ki = self.knownWidgets[name]
if (not ki) then
- Spring.Echo("DisableWidget(), could not find widget: " .. tostring(name))
+ Spring.Log(section, LOG.ERROR, "DisableWidget(), could not find widget: " .. tostring(name))
return false
end
if (ki.active) then
local w = self:FindWidget(name)
if (not w) then return false end
- Spring.Echo('Removed: '..ki.filename)
+ Spring.Log(section, LOG.INFO, 'Removed: '..ki.filename)
self:RemoveWidget(w) -- deactivate
self.orderList[name] = 0 -- disable
self:SaveConfigData()
@@ -899,7 +900,7 @@ end
function widgetHandler:ToggleWidget(name)
local ki = self.knownWidgets[name]
if (not ki) then
- Spring.Echo("ToggleWidget(), could not find widget: " .. tostring(name))
+ Spring.Log(section, LOG.ERROR, "ToggleWidget(), could not find widget: " .. tostring(name))
return
end
if (ki.active) then
@@ -1112,7 +1113,7 @@ function widgetHandler:ConfigureLayout(command)
if (command == 'tweakgui') then
self.tweakKeys = {}
self.tweakMode = true
- Spring.Echo("LuaUI TweakMode: ON")
+ Spring.Log(section, LOG.INFO, "LuaUI TweakMode: ON")
return true
elseif (command == 'reconf') then
self:SendConfigData()
@@ -1336,7 +1337,7 @@ function widgetHandler:KeyRelease(key, mods, label, unicode)
if (mo and mo.TweakKeyRelease) then
mo:TweakKeyRelease(key, mods, label, unicode)
elseif (key == KEYSYMS.ESCAPE) then
- Spring.Echo("LuaUI TweakMode: OFF")
+ Spring.Log(section, LOG.INFO, "LuaUI TweakMode: OFF")
self.tweakMode = false
end
return true
@@ -32,6 +32,7 @@
-- scope: 'all', 'player', 'team', 'allyteam' <<< not supported yet >>>
--
+local section = 'setupopts.lua'
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
@@ -252,19 +253,19 @@ local function SetupOpts(mapInfo)
local wantedOpts = CreateWantedOpts(mapInfo.defaultoptions)
if (not wantedOpts) then
- Spring.Echo('could not parse default map options')
+ Spring.Log(section, LOG.ERROR, 'could not parse default map options')
return {}
end
local defaultVals = VFS.Include('maphelper/mapdefaults.lua')
if (not defaultVals) then
- Spring.Echo('could not load default map values')
+ Spring.Log(section, LOG.ERROR, 'could not load default map values')
return {}
end
local optionDefs = CreateOptionDefs(mapInfo, defaultVals)
if (not optionDefs) then
- Spring.Echo('could not create map options')
+ Spring.Log(section, LOG.ERROR, 'could not create map options')
return {}
end
@@ -274,7 +275,7 @@ local function SetupOpts(mapInfo)
local optDef = optionDefs[opt]
if (optDef) then
if (type(optDef[4]) ~= 'function') then
- Spring.Echo('bad option definition in MapOptions.lua: ' .. opt)
+ Spring.Log(section, LOG.ERROR, 'bad option definition in MapOptions.lua: ' .. opt)
else
table.insert(options, optDef[4](optDef))
end
@@ -201,6 +201,7 @@ Format: {
(inner tables are in order the calls to Sleep were made)
--]]
local sleepers = {}
+local section = 'unit_script.lua'
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
@@ -240,7 +241,7 @@ local function RunOnError(thread)
if fun then
local good, err = pcall(fun, err)
if (not good) then
- Spring.Echo("error in error handler: " .. err)
+ Spring.Log(section, LOG.ERROR, "error in error handler: " .. err)
end
end
end
@@ -252,8 +253,8 @@ local function WakeUp(thread, ...)
local co = thread.thread
local good, err = co_resume(co, ...)
if (not good) then
- Spring.Echo(err)
- Spring.Echo(debug.traceback(co))
+ Spring.Log(section, LOG.ERROR, err)
+ Spring.Log(section, LOG.ERROR, debug.traceback(co))
RunOnError(thread)
end
end
@@ -491,12 +492,12 @@ end
local function LoadChunk(filename)
local text = VFS.LoadFile(filename, VFSMODE)
if (text == nil) then
- Spring.Echo("Failed to load: " .. filename)
+ Spring.Log(section, LOG.ERROR, "Failed to load: " .. filename)
return nil
end
local chunk, err = loadstring(scriptHeader .. text, filename)
if (chunk == nil) then
- Spring.Echo("Failed to load: " .. Basename(filename) .. " (" .. err .. ")")
+ Spring.Log(section, LOG.ERROR, "Failed to load: " .. Basename(filename) .. " (" .. err .. ")")
return nil
end
return chunk
@@ -511,7 +512,7 @@ end
function gadget:Initialize()
- Spring.Echo(string.format("Loading gadget: %-18s <%s>", ghInfo.name, ghInfo.basename))
+ Spring.Log(section, LOG.ERROR, string.format("Loading gadget: %-18s <%s>", ghInfo.name, ghInfo.basename))
-- This initialization code has following properties:
-- * all used scripts are loaded => early syntax error detection
@@ -545,7 +546,7 @@ function gadget:Initialize()
local filename = scriptFiles[fn] or scriptFiles[bn] or
scriptFiles[cfn] or scriptFiles[cbn]
if filename then
- Spring.Echo(" Loading unit script: " .. filename)
+ Spring.Log(section, LOG.INFO, " Loading unit script: " .. filename)
LoadScript(unitDef.scriptName, filename)
end
end
Oops, something went wrong.

0 comments on commit 1b51799

Please sign in to comment.