From b8bbca83cadb13060c7a351c24385f7adfae421d Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 25 Jul 2025 09:45:39 -0500 Subject: [PATCH 1/5] second half of fixing mod manager --- library/include/DataIdentity.h | 21 +++++++++++++++++++++ library/include/LuaWrapper.h | 5 +++-- plugins/CMakeLists.txt | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/library/include/DataIdentity.h b/library/include/DataIdentity.h index 5aa256809a..e9fb5a9aa3 100644 --- a/library/include/DataIdentity.h +++ b/library/include/DataIdentity.h @@ -37,6 +37,7 @@ distribution. #include #include "DataDefs.h" +#include "LuaWrapper.h" namespace std { class condition_variable; @@ -113,6 +114,7 @@ namespace DFHack }; class DFHACK_EXPORT container_identity : public constructed_identity { + protected: const type_identity *item; const enum_identity *ienum; @@ -418,6 +420,25 @@ namespace df ct.insert(ct.begin()+idx, *(typename T::value_type*)item); return true; } + virtual bool lua_insert2(lua_State* state, int fname_idx, void* ptr, int idx, int val_index) const + { + using VT = typename T::value_type; + VT tmp{}; + auto id = (type_identity*)lua_touserdata(state, DFHack::LuaWrapper::UPVAL_ITEM_ID); + auto pitem = DFHack::LuaWrapper::get_object_internal(state, id, val_index, false); + bool useTemporary = (!pitem && id->isPrimitive()); + + if (useTemporary) + { + pitem = &tmp; + id->lua_write(state, fname_idx, pitem, val_index); + } + + if (id != item || !pitem) + DFHack::LuaWrapper::field_error(state, fname_idx, "incompatible object type", "insert"); + + return insert(ptr, idx, pitem); + } protected: virtual int item_count(void *ptr, CountMode) const { return (int)((T*)ptr)->size(); } diff --git a/library/include/LuaWrapper.h b/library/include/LuaWrapper.h index 6d77af87db..67301b52cc 100644 --- a/library/include/LuaWrapper.h +++ b/library/include/LuaWrapper.h @@ -29,8 +29,6 @@ distribution. #include #include -#include "DataDefs.h" - #include #include @@ -41,6 +39,9 @@ distribution. namespace DFHack { struct FunctionReg; + + class function_identity_base; + namespace LuaWrapper { struct LuaToken; diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 3ef551a49e..405a11baa0 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -36,7 +36,7 @@ option(BUILD_SUPPORTED "Build the supported plugins (reveal, probe, etc.)." ON) if(BUILD_SUPPORTED) dfhack_plugin(3dveins 3dveins.cpp) dfhack_plugin(army-controller-sanity army-controller-sanity.cpp) - dfhack_plugin(add-spatter add-spatter.cpp) + dfhack_plugin(add-spatter add-spatter.cpp LINK_LIBRARIES lua) dfhack_plugin(aquifer aquifer.cpp LINK_LIBRARIES lua) dfhack_plugin(autobutcher autobutcher.cpp LINK_LIBRARIES lua) dfhack_plugin(autochop autochop.cpp LINK_LIBRARIES lua) From 36a0b1f8aa4d41526978bd21518de223250d8191 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 25 Jul 2025 09:56:38 -0500 Subject: [PATCH 2/5] add comment to plugin CMakeLists.txt --- plugins/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 405a11baa0..1f721ec713 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -32,6 +32,10 @@ set_source_files_properties( Brushes.h PROPERTIES HEADER_FILE_ONLY TRUE ) # proto file must be in the proto/ folder # dfhack_plugin(rename rename.cpp LINK_LIBRARIES lua PROTOBUFS rename) +# warning: for complicated reasons, if a plugin uses a vmethod interpose, it must +# link to lua even if it doesn't otherwise use lua. we'll fix this someday, we promise. +# we apologize for the inconvenience. + option(BUILD_SUPPORTED "Build the supported plugins (reveal, probe, etc.)." ON) if(BUILD_SUPPORTED) dfhack_plugin(3dveins 3dveins.cpp) From bcea2c9b6021c5a212316879f443bcdab9dc1d5d Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 25 Jul 2025 10:02:09 -0500 Subject: [PATCH 3/5] didn't know about this one --- plugins/devel/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/devel/CMakeLists.txt b/plugins/devel/CMakeLists.txt index 210669a75d..c044fa1044 100644 --- a/plugins/devel/CMakeLists.txt +++ b/plugins/devel/CMakeLists.txt @@ -23,7 +23,7 @@ dfhack_plugin(tilesieve tilesieve.cpp) # dfhack_plugin(zoom zoom.cpp) if(UNIX) - dfhack_plugin(ref-index ref-index.cpp) + dfhack_plugin(ref-index ref-index.cpp LINK_LIBRARIES lua) endif() add_subdirectory(check-structures-sanity) From 1c0663c4bc04b53c4632b4395a370ec145038c1c Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 25 Jul 2025 10:18:33 -0500 Subject: [PATCH 4/5] add changelog also included a bit i forgot from #5514 --- docs/changelog.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index 24cfa47f03..483e0b0570 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -64,8 +64,10 @@ Template for new versions: ## Documentation ## API +- ``Filesystem::getBaseDir`` and ``Filesystem::getInstallDir`` added (and made available in Lua) ## Lua +- ``insert``ing values into STL containers containing nonprimitive types is now supported ## Removed From 772b637ca7ce63e9c24c365145bdcc728163fde3 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 25 Jul 2025 10:33:51 -0500 Subject: [PATCH 5/5] Update changelog.txt --- docs/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 483e0b0570..bf01965a3c 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -67,7 +67,7 @@ Template for new versions: - ``Filesystem::getBaseDir`` and ``Filesystem::getInstallDir`` added (and made available in Lua) ## Lua -- ``insert``ing values into STL containers containing nonprimitive types is now supported +- inserting values into STL containers containing nonprimitive types is now supported ## Removed