forked from DFHack/scripts
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua.lua
More file actions
Latest commit
53 lines (47 loc) · 1.49 KB
/
Copy pathlua.lua
File metadata and controls
53 lines (47 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- Execute lua commands interactively or from files.
localutils=require'utils'
localargs= {...}
localcmd=args[1]
env=envorutils.df_shortcut_env()
ifcmd=="--file" orcmd=="-f" then--luacheck: skip
localf,err=loadfile (args[2])
iff==nilthen
qerror(err)
end
dfhack.safecall(f,table.unpack(args,3))
elseifcmd=="--save" orcmd=="-s" then--luacheck: skip
ifdf.global.world.cur_savegame.save_dir=="" then
qerror("Savefile not loaded")
end
localfname=args[2] or"dfhack.lua"
fname=string.format("save/%s/%s",df.global.world.cur_savegame.save_dir,fname)
localf,err=loadfile (fname)
iff==nilthen
qerror(err)
end
dfhack.safecall(f,table.unpack(args,3))
elseifcmd~=nilthen--luacheck: skip
-- Support some of the prefixes allowed by dfhack.interpreter
localprefix
ifstring.match(cmd, "^[~@!^]") then
prefix=string.sub(cmd, 1, 1)
cmd='return '..string.sub(cmd, 2)
end
localf, err=load(cmd, '=(lua command)', 't', env)
iff==nilthen
qerror(err)
end
localrv=table.pack(dfhack.safecall(f,table.unpack(args,2)))
ifrv[1] andprefixthen
print(table.unpack(rv,2,rv.n))
ifprefix=='~' then
printall(rv[2])
elseifprefix=='@' then
printall_ipairs(rv[2])
elseifprefix=='^' then
printall_recurse(rv[2])
end
end
else
dfhack.interpreter("lua","dfhack-config/lua.history",env)
end