Prepend script name to qerror messages, if applicable

Resolves #1282
develop
lethosor 2018-05-20 09:30:46 -04:00
parent 8cb5e7fa88
commit eb199d97b5
1 changed files with 6 additions and 2 deletions

@ -61,6 +61,10 @@ function dfhack.pcall(f, ...)
end end
function qerror(msg, level) function qerror(msg, level)
local name = dfhack.current_script_name()
if name and not tostring(msg):match(name) then
msg = name .. ': ' .. tostring(msg)
end
dfhack.error(msg, (level or 1) + 1, false) dfhack.error(msg, (level or 1) + 1, false)
end end
@ -562,7 +566,7 @@ function dfhack.run_script_with_env(envVars, name, flags, ...)
return script_code(...), env return script_code(...), env
end end
local function current_script_name() function dfhack.current_script_name()
local frame = 1 local frame = 1
while true do while true do
local info = debug.getinfo(frame, 'f') local info = debug.getinfo(frame, 'f')
@ -584,7 +588,7 @@ local function current_script_name()
end end
function dfhack.script_help(script_name, extension) function dfhack.script_help(script_name, extension)
script_name = script_name or current_script_name() script_name = script_name or dfhack.current_script_name()
extension = extension or 'lua' extension = extension or 'lua'
local full_name = script_name .. '.' .. extension local full_name = script_name .. '.' .. extension
local path = dfhack.internal.findScript(script_name .. '.' .. extension) local path = dfhack.internal.findScript(script_name .. '.' .. extension)