Added save specific scripts to lua interpreter script, also better error reporting.

develop
Warmist 2012-11-11 12:39:49 +02:00
parent 33f674eee2
commit 856c9ebd4b
1 changed files with 19 additions and 2 deletions

@ -1,9 +1,26 @@
local args={...} local args={...}
if args[1]=="--file" or args[1]=="-f" then if args[1]=="--file" or args[1]=="-f" then
local f=loadfile (args[2]) local f,err=loadfile (args[2])
if f==nil then
qerror(err)
end
dfhack.pcall(f,table.unpack(args,3))
elseif args[1]=="--save" or args[1]=="-s" then
if df.global.world.cur_savegame.save_dir=="" then
qerror("Savefile not loaded")
end
local fname=args[2] or "dfhack.lua"
fname=string.format("data/save/%s/%s",df.global.world.cur_savegame.save_dir,fname)
local f,err=loadfile (fname)
if f==nil then
qerror(err)
end
dfhack.pcall(f,table.unpack(args,3)) dfhack.pcall(f,table.unpack(args,3))
elseif args[1]~=nil then elseif args[1]~=nil then
local f=load(args[1],'=(lua command)', 't') local f,err=load(args[1],'=(lua command)', 't')
if f==nil then
qerror(err)
end
dfhack.pcall(f,table.unpack(args,2)) dfhack.pcall(f,table.unpack(args,2))
else else
dfhack.interpreter("lua","lua.history") dfhack.interpreter("lua","lua.history")