Skip to content

Commit c40efa2

Browse files
committed
Add some useful built-in variables to the lua interpreter environment
1 parent 8b05d47 commit c40efa2

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lua.lua

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ There are the following ways to invoke this command:
2727
local args={...}
2828
local cmd = args[1]
2929

30+
env = env or {}
31+
setmetatable(env, {__index = function(self, k)
32+
if k == 'scr' or k == 'screen' then
33+
return dfhack.gui.getCurViewscreen()
34+
elseif k == 'bld' or k == 'building' then
35+
return dfhack.gui.getSelectedBuilding()
36+
elseif k == 'item' then
37+
return dfhack.gui.getSelectedItem()
38+
elseif k == 'job' then
39+
return dfhack.gui.getSelectedJob()
40+
elseif k == 'wsjob' or k == 'workshop_job' then
41+
return dfhack.gui.getSelectedWorkshopJob()
42+
elseif k == 'unit' then
43+
return dfhack.gui.getSelectedUnit()
44+
else
45+
return _G[k]
46+
end
47+
end})
48+
3049
if cmd=="--file" or cmd=="-f" then
3150
local f,err=loadfile (args[2])
3251
if f==nil then
@@ -68,5 +87,5 @@ elseif cmd~=nil then
6887
end
6988
end
7089
else
71-
dfhack.interpreter("lua","lua.history")
90+
dfhack.interpreter("lua","lua.history",env)
7291
end

0 commit comments

Comments
 (0)