diff --git a/plugins/lua/stockpiles.lua b/plugins/lua/stockpiles.lua index 0e190a90b..88b7b2c3f 100644 --- a/plugins/lua/stockpiles.lua +++ b/plugins/lua/stockpiles.lua @@ -7,6 +7,7 @@ local _ENV = mkmodule('plugins.stockpiles') * stockpiles_list_settings(dir_path), list files in directory * stockpiles_load(file), with full path * stockpiles_save(file), with full path + * isEnabled() --]] -- diff --git a/plugins/stockpiles/stockpiles.cpp b/plugins/stockpiles/stockpiles.cpp index 0b48116d7..724783511 100644 --- a/plugins/stockpiles/stockpiles.cpp +++ b/plugins/stockpiles/stockpiles.cpp @@ -494,6 +494,12 @@ static std::vector clean_dfstock_list ( const std::string &path ) return files; } +static bool isEnabled( lua_State *L ) +{ + Lua::Push(L, is_enabled); + return 1; +} + static int stockpiles_list_settings ( lua_State *L ) { auto path = luaL_checkstring ( L, 1 ); diff --git a/scripts/gui/stockpiles.lua b/scripts/gui/stockpiles.lua index b4478ee3a..c5e1a9547 100644 --- a/scripts/gui/stockpiles.lua +++ b/scripts/gui/stockpiles.lua @@ -2,6 +2,10 @@ local stock = require 'plugins.stockpiles' +function check_enabled() + return stock.isEnabled() +end + function world_guard() if not dfhack.isMapLoaded() then qerror("World is not loaded") @@ -9,6 +13,7 @@ function world_guard() end return true end + function guard() if not string.match(dfhack.gui.getCurFocus(), '^dwarfmode/QueryBuilding/Some/Stockpile') then qerror("This script requires a stockpile selected in the 'q' mode") @@ -39,7 +44,10 @@ function usage() print("") end -if args.load then +if not check_enabled() then + qerror("Stockpiles plugin not enabled. Enable it with: enable stockpiles") + return +elseif args.load then if not guard() then return end stock.load_settings() elseif args.save then @@ -52,4 +60,3 @@ elseif args.dir then else usage() end -