From c6111ba0172da91dbcc8c70dc723378e31bf4593 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 20 Sep 2020 16:38:26 -0700 Subject: [PATCH 1/3] expose if buildingplan is enabled to lua --- docs/Lua API.rst | 5 +++-- plugins/buildingplan.cpp | 5 +++++ plugins/lua/buildingplan.lua | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/Lua API.rst b/docs/Lua API.rst index 633ae2278..31e48015a 100644 --- a/docs/Lua API.rst +++ b/docs/Lua API.rst @@ -3616,8 +3616,9 @@ buildingplan Native functions: -* ``bool isPlannableBuilding(df::building_type type)`` returns whether the building type is handled by buildingplan -* ``void addPlannedBuilding(df::building *bld)`` suspends the building jobs and adds the building to the monitor list +* ``bool isEnabled()`` returns whether the plugin is enabled. +* ``bool isPlannableBuilding(df::building_type type)`` returns whether the building type is handled by buildingplan. +* ``void addPlannedBuilding(df::building *bld)`` suspends the building jobs and adds the building to the monitor list. * ``void doCycle()`` runs a check for whether buildlings in the monitor list can be assigned items and unsuspended. This method runs automatically twice a game day, so you only need to call it directly if you want buildingplan to do a check right now. burrows diff --git a/plugins/buildingplan.cpp b/plugins/buildingplan.cpp index c42aeac53..4b91d0f84 100644 --- a/plugins/buildingplan.cpp +++ b/plugins/buildingplan.cpp @@ -418,6 +418,10 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan // Lua API section +static bool isEnabled() { + return is_enabled; +} + static bool isPlannableBuilding(df::building_type type) { return planner.isPlanableBuilding(type); } @@ -431,6 +435,7 @@ static void doCycle() { } DFHACK_PLUGIN_LUA_FUNCTIONS { + DFHACK_LUA_FUNCTION(isEnabled), DFHACK_LUA_FUNCTION(isPlannableBuilding), DFHACK_LUA_FUNCTION(addPlannedBuilding), DFHACK_LUA_FUNCTION(doCycle), diff --git a/plugins/lua/buildingplan.lua b/plugins/lua/buildingplan.lua index 071c07395..6bf60f4b8 100644 --- a/plugins/lua/buildingplan.lua +++ b/plugins/lua/buildingplan.lua @@ -4,6 +4,7 @@ local _ENV = mkmodule('plugins.buildingplan') Native functions: + * bool isEnabled() * bool isPlannableBuilding(df::building_type type) * void addPlannedBuilding(df::building *bld) * void doCycle() From 12769de232df8616bd2af9b4dbd9fe9efe972db1 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Tue, 22 Sep 2020 23:24:20 -0700 Subject: [PATCH 2/3] revert dup isEnabled and document real isEnabled --- docs/Lua API.rst | 12 +++++++++--- plugins/buildingplan.cpp | 5 ----- plugins/lua/buildingplan.lua | 1 - 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/Lua API.rst b/docs/Lua API.rst index 31e48015a..038ccb30f 100644 --- a/docs/Lua API.rst +++ b/docs/Lua API.rst @@ -3596,6 +3596,13 @@ to lua contexts. They are automatically imported by ``mkmodule('plugins.')``; this means that a lua module file is still necessary for ``require`` to read. +In addition to any native functions documented here, plugins that can be +disabled (that is, plugins that support the enable/disable API) will have the +following functions defined: + +* ``isEnabled()`` returns whether the plugin is enabled. +* ``setEnabled(boolean)`` sets whether the plugin is enabled. + The following plugins have lua support. blueprint @@ -3616,9 +3623,8 @@ buildingplan Native functions: -* ``bool isEnabled()`` returns whether the plugin is enabled. -* ``bool isPlannableBuilding(df::building_type type)`` returns whether the building type is handled by buildingplan. -* ``void addPlannedBuilding(df::building *bld)`` suspends the building jobs and adds the building to the monitor list. +* ``bool isPlannableBuilding(df::building_type type)`` returns whether the building type is handled by buildingplan +* ``void addPlannedBuilding(df::building *bld)`` suspends the building jobs and adds the building to the monitor list * ``void doCycle()`` runs a check for whether buildlings in the monitor list can be assigned items and unsuspended. This method runs automatically twice a game day, so you only need to call it directly if you want buildingplan to do a check right now. burrows diff --git a/plugins/buildingplan.cpp b/plugins/buildingplan.cpp index 4b91d0f84..c42aeac53 100644 --- a/plugins/buildingplan.cpp +++ b/plugins/buildingplan.cpp @@ -418,10 +418,6 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan // Lua API section -static bool isEnabled() { - return is_enabled; -} - static bool isPlannableBuilding(df::building_type type) { return planner.isPlanableBuilding(type); } @@ -435,7 +431,6 @@ static void doCycle() { } DFHACK_PLUGIN_LUA_FUNCTIONS { - DFHACK_LUA_FUNCTION(isEnabled), DFHACK_LUA_FUNCTION(isPlannableBuilding), DFHACK_LUA_FUNCTION(addPlannedBuilding), DFHACK_LUA_FUNCTION(doCycle), diff --git a/plugins/lua/buildingplan.lua b/plugins/lua/buildingplan.lua index 6bf60f4b8..071c07395 100644 --- a/plugins/lua/buildingplan.lua +++ b/plugins/lua/buildingplan.lua @@ -4,7 +4,6 @@ local _ENV = mkmodule('plugins.buildingplan') Native functions: - * bool isEnabled() * bool isPlannableBuilding(df::building_type type) * void addPlannedBuilding(df::building *bld) * void doCycle() From 3c037ef52a4c3b0d761fec38f1a7b7b55aee8e30 Mon Sep 17 00:00:00 2001 From: lethosor Date: Thu, 24 Sep 2020 00:16:32 -0400 Subject: [PATCH 3/3] Clean up plugin mkmodule/require explanation --- docs/Lua API.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/Lua API.rst b/docs/Lua API.rst index 1aaf73eda..8707a0d99 100644 --- a/docs/Lua API.rst +++ b/docs/Lua API.rst @@ -3656,19 +3656,22 @@ Plugins .. contents:: :local: -DFHack plugins may export native functions and events -to lua contexts. They are automatically imported by -``mkmodule('plugins.')``; this means that a lua -module file is still necessary for ``require`` to read. +DFHack plugins may export native functions and events to Lua contexts. These are +exposed as ``plugins.`` modules, which can be imported with +``require('plugins.')``. The plugins listed in this section expose +functions and/or data to Lua in this way. In addition to any native functions documented here, plugins that can be -disabled (that is, plugins that support the enable/disable API) will have the -following functions defined: +enabled (that is, plugins that support the `enable/disable API `) will +have the following functions defined: * ``isEnabled()`` returns whether the plugin is enabled. * ``setEnabled(boolean)`` sets whether the plugin is enabled. -The following plugins have lua support. +For plugin developers, note that a Lua file in ``plugins/lua`` is required for +``require()`` to work, even if it contains no pure-Lua functions. This file must +contain ``mkmodule('plugins.')`` to import any native functions defined in +the plugin. See existing files in ``plugins/lua`` for examples. blueprint =========