From 34d2265e7809f6ff78037a9c80bed55b880d6fd2 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 31 Dec 2024 17:42:35 -0600 Subject: [PATCH 1/7] split plugin lua macros to separate header this will reduce the number of translation units that require the includes from the lua dependency --- library/CMakeLists.txt | 1 + library/VTableInterpose.cpp | 3 ++- library/include/PluginLua.h | 19 +++++++++++++++++++ library/include/PluginManager.h | 14 -------------- plugins/aquifer.cpp | 1 + plugins/autobutcher.cpp | 1 + plugins/autochop.cpp | 1 + plugins/autoclothing.cpp | 1 + plugins/autonestbox.cpp | 1 + plugins/blueprint.cpp | 1 + plugins/buildingplan/buildingplan.cpp | 1 + plugins/burrow.cpp | 1 + plugins/cxxrandom.cpp | 7 ++++--- plugins/design.cpp | 2 ++ plugins/dig-now.cpp | 1 + plugins/dig.cpp | 1 + plugins/dwarfvet.cpp | 1 + plugins/eventful.cpp | 1 + plugins/fix-occupancy.cpp | 1 + plugins/hotkeys.cpp | 1 + plugins/infinite-sky.cpp | 1 + plugins/liquids.cpp | 1 + plugins/logistics.cpp | 1 + plugins/luasocket.cpp | 1 + plugins/misery.cpp | 1 + plugins/overlay.cpp | 1 + plugins/pathable.cpp | 1 + plugins/plant.cpp | 1 + plugins/preserve-rooms.cpp | 1 + plugins/prospector.cpp | 1 + plugins/regrass.cpp | 1 + plugins/reveal.cpp | 1 + plugins/seedwatch.cpp | 1 + plugins/sort.cpp | 1 + plugins/stockpiles/stockpiles.cpp | 1 + plugins/suspendmanager.cpp | 1 + plugins/tailor.cpp | 1 + plugins/tiletypes.cpp | 1 + plugins/timestream.cpp | 1 + plugins/tweak/tweak.cpp | 1 + plugins/xlsxreader.cpp | 1 + 41 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 library/include/PluginLua.h diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 7c9a52e816..452682fab3 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -68,6 +68,7 @@ set(MAIN_HEADERS include/Module.h include/MemAccess.h include/ModuleFactory.h + include/PluginLua.h include/PluginManager.h include/PluginStatics.h include/RemoteClient.h diff --git a/library/VTableInterpose.cpp b/library/VTableInterpose.cpp index 2bcfac7ff9..797161240e 100644 --- a/library/VTableInterpose.cpp +++ b/library/VTableInterpose.cpp @@ -29,8 +29,9 @@ distribution. #include #include -#include "MemAccess.h" #include "Core.h" +#include "DataFuncs.h" +#include "MemAccess.h" #include "VersionInfo.h" #include "VTableInterpose.h" diff --git a/library/include/PluginLua.h b/library/include/PluginLua.h new file mode 100644 index 0000000000..16d447b7bf --- /dev/null +++ b/library/include/PluginLua.h @@ -0,0 +1,19 @@ +/* + * Additional macros for calling Lua from a plugin + */ + +#pragma once + +#include "DataFuncs.h" + +#define DFHACK_PLUGIN_LUA_COMMANDS \ + DFhackCExport const DFHack::CommandReg plugin_lua_commands[] = +#define DFHACK_PLUGIN_LUA_FUNCTIONS \ + DFhackCExport const DFHack::FunctionReg plugin_lua_functions[] = +#define DFHACK_PLUGIN_LUA_EVENTS \ + DFhackCExport const DFHack::EventReg plugin_lua_events[] = + +#define DFHACK_LUA_COMMAND(name) { #name, name } +#define DFHACK_LUA_FUNCTION(name) { #name, df::wrap_function(name,true) } +#define DFHACK_LUA_EVENT(name) { #name, &name##_event } +#define DFHACK_LUA_END { NULL, NULL } diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h index 9138ea2288..3749ff9548 100644 --- a/library/include/PluginManager.h +++ b/library/include/PluginManager.h @@ -34,7 +34,6 @@ distribution. #include #include "Core.h" -#include "DataFuncs.h" typedef struct lua_State lua_State; @@ -324,19 +323,6 @@ extern "C" { \ DFhackDataExport bool plugin_is_enabled = false; \ bool &varname = plugin_is_enabled; -#define DFHACK_PLUGIN_LUA_COMMANDS \ - DFhackCExport const DFHack::CommandReg plugin_lua_commands[] = -#define DFHACK_PLUGIN_LUA_FUNCTIONS \ - DFhackCExport const DFHack::FunctionReg plugin_lua_functions[] = -#define DFHACK_PLUGIN_LUA_EVENTS \ - DFhackCExport const DFHack::EventReg plugin_lua_events[] = - -#define DFHACK_LUA_COMMAND(name) { #name, name } -#define DFHACK_LUA_FUNCTION(name) { #name, df::wrap_function(name,true) } -#define DFHACK_LUA_EVENT(name) { #name, &name##_event } -#define DFHACK_LUA_END { NULL, NULL } - - #define REQUIRE_GLOBAL_NO_USE(global_name) \ static int VARIABLE_IS_NOT_USED CONCAT_TOKENS(required_globals_, __LINE__) = \ (plugin_globals->push_back(#global_name), 0); diff --git a/plugins/aquifer.cpp b/plugins/aquifer.cpp index eaefbb5422..124fa29838 100644 --- a/plugins/aquifer.cpp +++ b/plugins/aquifer.cpp @@ -1,6 +1,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "TileTypes.h" #include "modules/Maps.h" diff --git a/plugins/autobutcher.cpp b/plugins/autobutcher.cpp index b50d6cbab0..9e93018cc9 100644 --- a/plugins/autobutcher.cpp +++ b/plugins/autobutcher.cpp @@ -7,6 +7,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/Persistence.h" #include "modules/Units.h" diff --git a/plugins/autochop.cpp b/plugins/autochop.cpp index 8378086b44..7c2cfc9a5e 100644 --- a/plugins/autochop.cpp +++ b/plugins/autochop.cpp @@ -3,6 +3,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "TileTypes.h" #include "modules/Burrows.h" diff --git a/plugins/autoclothing.cpp b/plugins/autoclothing.cpp index 621ac4b1de..cdd9fd981d 100644 --- a/plugins/autoclothing.cpp +++ b/plugins/autoclothing.cpp @@ -2,6 +2,7 @@ #include "Debug.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/Items.h" #include "modules/Materials.h" diff --git a/plugins/autonestbox.cpp b/plugins/autonestbox.cpp index ee62f9406d..f7f1bdd84b 100644 --- a/plugins/autonestbox.cpp +++ b/plugins/autonestbox.cpp @@ -7,6 +7,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/Buildings.h" #include "modules/Gui.h" diff --git a/plugins/blueprint.cpp b/plugins/blueprint.cpp index 9d0e36a97d..c7ce4114e7 100644 --- a/plugins/blueprint.cpp +++ b/plugins/blueprint.cpp @@ -15,6 +15,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "TileTypes.h" #include "modules/Buildings.h" diff --git a/plugins/buildingplan/buildingplan.cpp b/plugins/buildingplan/buildingplan.cpp index 8df2257380..fe317e4705 100644 --- a/plugins/buildingplan/buildingplan.cpp +++ b/plugins/buildingplan/buildingplan.cpp @@ -6,6 +6,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/Burrows.h" #include "modules/World.h" diff --git a/plugins/burrow.cpp b/plugins/burrow.cpp index e415b31e2c..d06e95efb6 100644 --- a/plugins/burrow.cpp +++ b/plugins/burrow.cpp @@ -1,6 +1,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "TileTypes.h" #include "modules/Burrows.h" diff --git a/plugins/cxxrandom.cpp b/plugins/cxxrandom.cpp index 9d69f681e2..498847316e 100644 --- a/plugins/cxxrandom.cpp +++ b/plugins/cxxrandom.cpp @@ -25,11 +25,12 @@ Updated: Dec. 21 2017 #include #include +#include "Console.h" #include "Error.h" +#include "Export.h" #include "DataFuncs.h" -#include -#include -#include +#include "PluginManager.h" +#include "PluginLua.h" using namespace DFHack; DFHACK_PLUGIN("cxxrandom"); diff --git a/plugins/design.cpp b/plugins/design.cpp index 2a0a9ca23e..23818667b5 100644 --- a/plugins/design.cpp +++ b/plugins/design.cpp @@ -9,6 +9,8 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" + #include "df/graphic_viewportst.h" #include "df/world.h" #include "modules/Gui.h" diff --git a/plugins/dig-now.cpp b/plugins/dig-now.cpp index 7e46b3e7cc..c248b241de 100644 --- a/plugins/dig-now.cpp +++ b/plugins/dig-now.cpp @@ -6,6 +6,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "TileTypes.h" #include "modules/Buildings.h" diff --git a/plugins/dig.cpp b/plugins/dig.cpp index ab96a5989e..bc9089a654 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -2,6 +2,7 @@ #include "LuaTools.h" #include "MemAccess.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/EventManager.h" #include "modules/Gui.h" diff --git a/plugins/dwarfvet.cpp b/plugins/dwarfvet.cpp index 7e4e7a5840..6f3e32d00f 100644 --- a/plugins/dwarfvet.cpp +++ b/plugins/dwarfvet.cpp @@ -23,6 +23,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/Persistence.h" #include "modules/Units.h" diff --git a/plugins/eventful.cpp b/plugins/eventful.cpp index 924b6720e9..0ed06d9284 100644 --- a/plugins/eventful.cpp +++ b/plugins/eventful.cpp @@ -1,5 +1,6 @@ #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "VTableInterpose.h" #include "modules/EventManager.h" diff --git a/plugins/fix-occupancy.cpp b/plugins/fix-occupancy.cpp index eb153a3e5d..7b5a416dbb 100644 --- a/plugins/fix-occupancy.cpp +++ b/plugins/fix-occupancy.cpp @@ -1,6 +1,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/Buildings.h" #include "modules/Maps.h" diff --git a/plugins/hotkeys.cpp b/plugins/hotkeys.cpp index 9eb5714605..15d28a4c09 100644 --- a/plugins/hotkeys.cpp +++ b/plugins/hotkeys.cpp @@ -8,6 +8,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" DFHACK_PLUGIN("hotkeys"); diff --git a/plugins/infinite-sky.cpp b/plugins/infinite-sky.cpp index f0af8ed046..3a2aefacb5 100644 --- a/plugins/infinite-sky.cpp +++ b/plugins/infinite-sky.cpp @@ -2,6 +2,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/EventManager.h" #include "modules/Maps.h" diff --git a/plugins/liquids.cpp b/plugins/liquids.cpp index 0c6a3c0b91..a814bbd5b0 100644 --- a/plugins/liquids.cpp +++ b/plugins/liquids.cpp @@ -24,6 +24,7 @@ #include "Export.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "TileTypes.h" #include "modules/Gui.h" diff --git a/plugins/logistics.cpp b/plugins/logistics.cpp index 1856d40cfe..52b9bf43a4 100644 --- a/plugins/logistics.cpp +++ b/plugins/logistics.cpp @@ -1,6 +1,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/Buildings.h" #include "modules/Job.h" diff --git a/plugins/luasocket.cpp b/plugins/luasocket.cpp index a034829598..89bd82850a 100644 --- a/plugins/luasocket.cpp +++ b/plugins/luasocket.cpp @@ -1,6 +1,7 @@ #include "Console.h" #include "Export.h" #include "PluginManager.h" +#include "PluginLua.h" #include "DataDefs.h" #include diff --git a/plugins/misery.cpp b/plugins/misery.cpp index f73c22071e..b81a4f1daa 100644 --- a/plugins/misery.cpp +++ b/plugins/misery.cpp @@ -1,6 +1,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/Persistence.h" #include "modules/Units.h" diff --git a/plugins/overlay.cpp b/plugins/overlay.cpp index 6fe0547f80..6e81bf198c 100644 --- a/plugins/overlay.cpp +++ b/plugins/overlay.cpp @@ -22,6 +22,7 @@ #include "LuaTools.h" #include "MemAccess.h" #include "PluginManager.h" +#include "PluginLua.h" #include "VTableInterpose.h" #include "modules/Gui.h" diff --git a/plugins/pathable.cpp b/plugins/pathable.cpp index 4587dafd44..3bf9e2c010 100644 --- a/plugins/pathable.cpp +++ b/plugins/pathable.cpp @@ -1,6 +1,7 @@ #include "Debug.h" #include "Error.h" #include "PluginManager.h" +#include "PluginLua.h" #include "TileTypes.h" #include "df/building_type.h" diff --git a/plugins/plant.cpp b/plugins/plant.cpp index d413d5de62..10046ccb2d 100644 --- a/plugins/plant.cpp +++ b/plugins/plant.cpp @@ -4,6 +4,7 @@ #include "Error.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "TileTypes.h" #include "modules/Gui.h" diff --git a/plugins/preserve-rooms.cpp b/plugins/preserve-rooms.cpp index ba0de1c973..52f6151637 100644 --- a/plugins/preserve-rooms.cpp +++ b/plugins/preserve-rooms.cpp @@ -1,6 +1,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/Buildings.h" #include "modules/EventManager.h" diff --git a/plugins/prospector.cpp b/plugins/prospector.cpp index 67d16162ea..159b557e4f 100644 --- a/plugins/prospector.cpp +++ b/plugins/prospector.cpp @@ -4,6 +4,7 @@ #include "Export.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "MiscUtils.h" #include "DataDefs.h" diff --git a/plugins/regrass.cpp b/plugins/regrass.cpp index f69472d3e6..d40e1bc6dc 100644 --- a/plugins/regrass.cpp +++ b/plugins/regrass.cpp @@ -5,6 +5,7 @@ #include "Error.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "TileTypes.h" #include "modules/Gui.h" diff --git a/plugins/reveal.cpp b/plugins/reveal.cpp index e4bcbaf025..1feb72bbc6 100644 --- a/plugins/reveal.cpp +++ b/plugins/reveal.cpp @@ -1,4 +1,5 @@ #include "PluginManager.h" +#include "PluginLua.h" #include "TileTypes.h" #include "modules/EventManager.h" diff --git a/plugins/seedwatch.cpp b/plugins/seedwatch.cpp index 4f10e57f6c..994ac067ac 100644 --- a/plugins/seedwatch.cpp +++ b/plugins/seedwatch.cpp @@ -7,6 +7,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "TileTypes.h" #include "modules/Items.h" diff --git a/plugins/sort.cpp b/plugins/sort.cpp index babb7a60f0..add54688c4 100644 --- a/plugins/sort.cpp +++ b/plugins/sort.cpp @@ -1,6 +1,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/Gui.h" #include "modules/Units.h" diff --git a/plugins/stockpiles/stockpiles.cpp b/plugins/stockpiles/stockpiles.cpp index 44cbd105ae..33ce855b42 100644 --- a/plugins/stockpiles/stockpiles.cpp +++ b/plugins/stockpiles/stockpiles.cpp @@ -1,6 +1,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "StockpileUtils.h" #include "StockpileSerializer.h" diff --git a/plugins/suspendmanager.cpp b/plugins/suspendmanager.cpp index a5ea04f7b5..e67e679c42 100644 --- a/plugins/suspendmanager.cpp +++ b/plugins/suspendmanager.cpp @@ -1,6 +1,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "TileTypes.h" #include "modules/Buildings.h" diff --git a/plugins/tailor.cpp b/plugins/tailor.cpp index 4ac2e1f4c0..51ad0e7bf8 100644 --- a/plugins/tailor.cpp +++ b/plugins/tailor.cpp @@ -5,6 +5,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/Materials.h" #include "modules/Persistence.h" diff --git a/plugins/tiletypes.cpp b/plugins/tiletypes.cpp index a4c5ffef46..95c5bd4424 100644 --- a/plugins/tiletypes.cpp +++ b/plugins/tiletypes.cpp @@ -38,6 +38,7 @@ using std::set; #include "Export.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "TileTypes.h" #include "modules/Gui.h" diff --git a/plugins/timestream.cpp b/plugins/timestream.cpp index a157679236..3cb8f7a462 100644 --- a/plugins/timestream.cpp +++ b/plugins/timestream.cpp @@ -1,6 +1,7 @@ #include "Debug.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "modules/EventManager.h" #include "modules/Items.h" diff --git a/plugins/tweak/tweak.cpp b/plugins/tweak/tweak.cpp index e5c6869bd5..74276bba1c 100644 --- a/plugins/tweak/tweak.cpp +++ b/plugins/tweak/tweak.cpp @@ -3,6 +3,7 @@ #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "VTableInterpose.h" DFHACK_PLUGIN("tweak"); diff --git a/plugins/xlsxreader.cpp b/plugins/xlsxreader.cpp index 8e8c11229b..db98ca18c0 100644 --- a/plugins/xlsxreader.cpp +++ b/plugins/xlsxreader.cpp @@ -9,6 +9,7 @@ #include "Error.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginLua.h" #include "PluginStatics.h" using namespace DFHack; From 072cb3ce1a1a91b4b3d9490055806b7e218159c1 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 31 Dec 2024 21:08:32 -0600 Subject: [PATCH 2/7] remove unneeded includes from `cxxrandom.cpp` --- plugins/cxxrandom.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/cxxrandom.cpp b/plugins/cxxrandom.cpp index 498847316e..3f6a405598 100644 --- a/plugins/cxxrandom.cpp +++ b/plugins/cxxrandom.cpp @@ -25,9 +25,6 @@ Updated: Dec. 21 2017 #include #include -#include "Console.h" -#include "Error.h" -#include "Export.h" #include "DataFuncs.h" #include "PluginManager.h" #include "PluginLua.h" From f2b481814e6e8b2ef7a962ed973deaa324042ca3 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 31 Dec 2024 21:49:29 -0600 Subject: [PATCH 3/7] remove unneeded includes from `eventExample.cpp` --- plugins/devel/eventExample.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/devel/eventExample.cpp b/plugins/devel/eventExample.cpp index e0a1252c73..ceaec29921 100644 --- a/plugins/devel/eventExample.cpp +++ b/plugins/devel/eventExample.cpp @@ -1,9 +1,6 @@ -#include "Console.h" -#include "Export.h" #include "PluginManager.h" #include "DataDefs.h" -#include "VTableInterpose.h" #include "modules/EventManager.h" From 88b84a71b2cd9c6cedc64400d56477331569bf44 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 31 Dec 2024 21:55:03 -0600 Subject: [PATCH 4/7] add mention of `PluginLua.h` in `skeleton.cpp` --- plugins/examples/skeleton.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/examples/skeleton.cpp b/plugins/examples/skeleton.cpp index 9d44f539cb..5b22d77cb8 100644 --- a/plugins/examples/skeleton.cpp +++ b/plugins/examples/skeleton.cpp @@ -11,6 +11,9 @@ #include "Debug.h" #include "MemAccess.h" #include "PluginManager.h" +// this include is only required if the plugin is going to bind to Lua +// events, functions, or commands +#include "PluginLua.h" #include "modules/Gui.h" #include "modules/Persistence.h" From 1afbb4ed4e198ed2b4d1a5d62bdf118d35748df1 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Wed, 1 Jan 2025 09:46:21 -0600 Subject: [PATCH 5/7] reduce lua dependency in plugins now only add-spatter and spectate, due to `VTableInterpose.h` VTableInterpose.h needs `return_type::is_method` whch is defined in `DataFuncs.h` which requires lua headers due to using `Lua::Push` in an inlined method --- plugins/CMakeLists.txt | 8 ++++++++ plugins/Plugins.cmake | 4 ---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index bb1b140aea..10b6d8b4a1 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -157,6 +157,14 @@ if(BUILD_SUPPORTED) dfhack_plugin(work-now work-now.cpp) dfhack_plugin(xlsxreader xlsxreader.cpp LINK_LIBRARIES lua xlsxio_read_STATIC zip expat) dfhack_plugin(zone zone.cpp LINK_LIBRARIES lua) + + # remove when VTableInterpose.h no longer has a dependency on DataFuncs.h + if(BUILD_PLUGINS) + get_target_property(lua_INCLUDES lua INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories(add-spatter PRIVATE ${lua_INCLUDES}) + target_include_directories(spectate PRIVATE ${lua_INCLUDES}) + endif() + endif(BUILD_SUPPORTED) # If you are adding a plugin that you do not intend to commit to the DFHack repo, diff --git a/plugins/Plugins.cmake b/plugins/Plugins.cmake index 0b66e8c4c1..3726b86c7c 100644 --- a/plugins/Plugins.cmake +++ b/plugins/Plugins.cmake @@ -126,10 +126,6 @@ macro(dfhack_plugin) endif() target_link_libraries(${PLUGIN_NAME} dfhack dfhack-version ${PLUGIN_LINK_LIBRARIES}) - # since PluginManager currently uses Lua headers, even when Lua is not used - get_target_property(lua_INCLUDES lua INTERFACE_INCLUDE_DIRECTORIES) - target_include_directories(${PLUGIN_NAME} PRIVATE ${lua_INCLUDES}) - if(UNIX) set(PLUGIN_COMPILE_FLAGS "${PLUGIN_COMPILE_FLAGS} ${PLUGIN_COMPILE_FLAGS_GCC}") else() From 7cb1bff04e3784091db101e2f0c15c554a479cca Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Wed, 1 Jan 2025 10:16:42 -0600 Subject: [PATCH 6/7] remove `VTableInterpose.h` dependency on lua headers accomplished by moving the `return_type` trait definition from `DataFuncs.h` to `DataDefs.h` also fixed a few minor style issues --- library/include/DataDefs.h | 30 +++++++++++++++++++++ library/include/DataFuncs.h | 44 +++++-------------------------- library/include/VTableInterpose.h | 3 ++- plugins/CMakeLists.txt | 8 ------ 4 files changed, 39 insertions(+), 46 deletions(-) diff --git a/library/include/DataDefs.h b/library/include/DataDefs.h index 4fb0563414..c6a7eb8272 100644 --- a/library/include/DataDefs.h +++ b/library/include/DataDefs.h @@ -586,6 +586,36 @@ namespace df } namespace enums {} + + /** + * A trait to obtain return type and class identity from an invokable + * used for invoking C++ methods from Lua and for vtable interposes + * moved here from DataFuncs.h to minimize header dependencies + */ + + template struct return_type {}; + + template + struct return_type { + using type = RT; + static const bool is_method = false; + }; + + template + struct return_type { + using type = RT; + using class_type = CT; + static const bool is_method = true; + }; + + template + struct return_type { + using type = RT; + using class_type = CT; + static const bool is_method = true; + }; + + } /* diff --git a/library/include/DataFuncs.h b/library/include/DataFuncs.h index 36d756471f..5f5a4bd72e 100644 --- a/library/include/DataFuncs.h +++ b/library/include/DataFuncs.h @@ -42,28 +42,6 @@ namespace df { operator DFHack::color_ostream& () { return *out; } }; - template struct return_type {}; - - template - struct return_type{ - using type = RT; - static const bool is_method = false; - }; - - template - struct return_type{ - using type = RT; - using class_type = CT; - static const bool is_method = true; - }; - - template - struct return_type{ - using type = RT; - using class_type = CT; - static const bool is_method = true; - }; - // the std::is_enum_v alternative is because pushing is_primitive // into all the enum identities would require changing codegen @@ -77,11 +55,9 @@ namespace df { return val; } - - template + template requires std::is_invocable_r_v - && isPrimitive - void call_and_push_impl(lua_State* L, int base, std::index_sequence, FT fun, ET... extra) + void call_and_push_impl(lua_State* L, int base, std::index_sequence, FT fun, ET... extra) { if constexpr (std::is_same_v) { std::invoke(fun, extra..., (get_from_lua_state(L, base+I))...); @@ -94,10 +70,8 @@ namespace df { } } - template > + template > requires std::is_invocable_r_v - && isPrimitive - void call_and_push(lua_State* L, int base, FT fun, ET... extra) { call_and_push_impl(L, base, indices{}, fun, extra...); @@ -105,8 +79,7 @@ namespace df { template struct function_wrapper {}; - template - requires isPrimitive + template struct function_wrapper { static const int num_args = sizeof...(AT); static void execute(lua_State *L, int base, RT (fun)(DFHack::color_ostream& out, AT...)) { @@ -115,8 +88,7 @@ namespace df { } }; - template - requires isPrimitive + template struct function_wrapper { static const int num_args = sizeof...(AT); static void execute(lua_State *L, int base, RT (fun)(AT...)) { @@ -124,8 +96,7 @@ namespace df { } }; - template - requires isPrimitive + template struct function_wrapper { static const int num_args = sizeof...(AT)+1; static void execute(lua_State *L, int base, RT(CT::*mem_fun)(AT...)) { @@ -134,8 +105,7 @@ namespace df { }; }; - template - requires isPrimitive + template struct function_wrapper { static const int num_args = sizeof...(AT)+1; static void execute(lua_State *L, int base, RT(CT::*mem_fun)(AT...) const) { diff --git a/library/include/VTableInterpose.h b/library/include/VTableInterpose.h index 7886762396..7575ee18c2 100644 --- a/library/include/VTableInterpose.h +++ b/library/include/VTableInterpose.h @@ -24,7 +24,8 @@ distribution. #pragma once -#include "DataFuncs.h" +#include "DataDefs.h" +#include "DataIdentity.h" namespace DFHack { diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 10b6d8b4a1..bb1b140aea 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -157,14 +157,6 @@ if(BUILD_SUPPORTED) dfhack_plugin(work-now work-now.cpp) dfhack_plugin(xlsxreader xlsxreader.cpp LINK_LIBRARIES lua xlsxio_read_STATIC zip expat) dfhack_plugin(zone zone.cpp LINK_LIBRARIES lua) - - # remove when VTableInterpose.h no longer has a dependency on DataFuncs.h - if(BUILD_PLUGINS) - get_target_property(lua_INCLUDES lua INTERFACE_INCLUDE_DIRECTORIES) - target_include_directories(add-spatter PRIVATE ${lua_INCLUDES}) - target_include_directories(spectate PRIVATE ${lua_INCLUDES}) - endif() - endif(BUILD_SUPPORTED) # If you are adding a plugin that you do not intend to commit to the DFHack repo, From 1075c942377a8f3f707d490378c33380c342f412 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Wed, 1 Jan 2025 10:59:17 -0600 Subject: [PATCH 7/7] comment out `PluginLua.h` in `skeleton.cpp` solely so the skeleton compiles without requiring lua libraries also expanded the comment --- plugins/examples/skeleton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/examples/skeleton.cpp b/plugins/examples/skeleton.cpp index 5b22d77cb8..fd77ab691a 100644 --- a/plugins/examples/skeleton.cpp +++ b/plugins/examples/skeleton.cpp @@ -13,7 +13,7 @@ #include "PluginManager.h" // this include is only required if the plugin is going to bind to Lua // events, functions, or commands -#include "PluginLua.h" +// #include "PluginLua.h" #include "modules/Gui.h" #include "modules/Persistence.h"