Implement a helper to create lua environments with shortcuts (e.g. scr, unit)

Used in gui/gm-editor and lua

Closes #977
develop
lethosor 2016-08-23 21:47:41 -04:00
parent ddc0c1b3cb
commit 7487f44fc8
2 changed files with 37 additions and 7 deletions

@ -622,4 +622,34 @@ function unfillTable(table1,table2)
end end
end end
function df_shortcut_var(k)
if k == 'scr' or k == 'screen' then
return dfhack.gui.getCurViewscreen()
elseif k == 'bld' or k == 'building' then
return dfhack.gui.getSelectedBuilding()
elseif k == 'item' then
return dfhack.gui.getSelectedItem()
elseif k == 'job' then
return dfhack.gui.getSelectedJob()
elseif k == 'wsjob' or k == 'workshop_job' then
return dfhack.gui.getSelectedWorkshopJob()
elseif k == 'unit' then
return dfhack.gui.getSelectedUnit()
else
for g in pairs(df.global) do
if g == k then
return df.global[k]
end
end
return _G[k]
end
end
function df_shortcut_env()
local env = {}
setmetatable(env, {__index = function(self, k) return df_shortcut_var(k) end})
return env
end
return _ENV return _ENV

@ -1 +1 @@
Subproject commit 042fcffd051c1f1ceab268e54bed1ed197b1f91e Subproject commit 3e3fb7bff6dce41e7ea85ee3addf44291b53f800