diff --git a/docs/changelog.txt b/docs/changelog.txt index 24cfa47f03..bf01965a3c 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 +- inserting values into STL containers containing nonprimitive types is now supported ## Removed 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..1f721ec713 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -32,11 +32,15 @@ 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) 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) 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)