Skip to content

Commit 5424546

Browse files
authored
Merge pull request #5516 from ab9rf/fix-mod-manager
second half of fixing mod manager
2 parents 1e527de + 772b637 commit 5424546

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

docs/changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ Template for new versions:
6464
## Documentation
6565

6666
## API
67+
- ``Filesystem::getBaseDir`` and ``Filesystem::getInstallDir`` added (and made available in Lua)
6768

6869
## Lua
70+
- inserting values into STL containers containing nonprimitive types is now supported
6971

7072
## Removed
7173

library/include/DataIdentity.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ distribution.
3737
#include <filesystem>
3838

3939
#include "DataDefs.h"
40+
#include "LuaWrapper.h"
4041

4142
namespace std {
4243
class condition_variable;
@@ -113,6 +114,7 @@ namespace DFHack
113114
};
114115

115116
class DFHACK_EXPORT container_identity : public constructed_identity {
117+
protected:
116118
const type_identity *item;
117119
const enum_identity *ienum;
118120

@@ -418,6 +420,25 @@ namespace df
418420
ct.insert(ct.begin()+idx, *(typename T::value_type*)item);
419421
return true;
420422
}
423+
virtual bool lua_insert2(lua_State* state, int fname_idx, void* ptr, int idx, int val_index) const
424+
{
425+
using VT = typename T::value_type;
426+
VT tmp{};
427+
auto id = (type_identity*)lua_touserdata(state, DFHack::LuaWrapper::UPVAL_ITEM_ID);
428+
auto pitem = DFHack::LuaWrapper::get_object_internal(state, id, val_index, false);
429+
bool useTemporary = (!pitem && id->isPrimitive());
430+
431+
if (useTemporary)
432+
{
433+
pitem = &tmp;
434+
id->lua_write(state, fname_idx, pitem, val_index);
435+
}
436+
437+
if (id != item || !pitem)
438+
DFHack::LuaWrapper::field_error(state, fname_idx, "incompatible object type", "insert");
439+
440+
return insert(ptr, idx, pitem);
441+
}
421442

422443
protected:
423444
virtual int item_count(void *ptr, CountMode) const { return (int)((T*)ptr)->size(); }

library/include/LuaWrapper.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ distribution.
2929
#include <vector>
3030
#include <map>
3131

32-
#include "DataDefs.h"
33-
3432
#include <lua.h>
3533
#include <lauxlib.h>
3634

@@ -41,6 +39,9 @@ distribution.
4139

4240
namespace DFHack {
4341
struct FunctionReg;
42+
43+
class function_identity_base;
44+
4445
namespace LuaWrapper {
4546
struct LuaToken;
4647

plugins/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ set_source_files_properties( Brushes.h PROPERTIES HEADER_FILE_ONLY TRUE )
3232
# proto file must be in the proto/ folder
3333
# dfhack_plugin(rename rename.cpp LINK_LIBRARIES lua PROTOBUFS rename)
3434

35+
# warning: for complicated reasons, if a plugin uses a vmethod interpose, it must
36+
# link to lua even if it doesn't otherwise use lua. we'll fix this someday, we promise.
37+
# we apologize for the inconvenience.
38+
3539
option(BUILD_SUPPORTED "Build the supported plugins (reveal, probe, etc.)." ON)
3640
if(BUILD_SUPPORTED)
3741
dfhack_plugin(3dveins 3dveins.cpp)
3842
dfhack_plugin(army-controller-sanity army-controller-sanity.cpp)
39-
dfhack_plugin(add-spatter add-spatter.cpp)
43+
dfhack_plugin(add-spatter add-spatter.cpp LINK_LIBRARIES lua)
4044
dfhack_plugin(aquifer aquifer.cpp LINK_LIBRARIES lua)
4145
dfhack_plugin(autobutcher autobutcher.cpp LINK_LIBRARIES lua)
4246
dfhack_plugin(autochop autochop.cpp LINK_LIBRARIES lua)

plugins/devel/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dfhack_plugin(tilesieve tilesieve.cpp)
2323
# dfhack_plugin(zoom zoom.cpp)
2424

2525
if(UNIX)
26-
dfhack_plugin(ref-index ref-index.cpp)
26+
dfhack_plugin(ref-index ref-index.cpp LINK_LIBRARIES lua)
2727
endif()
2828

2929
add_subdirectory(check-structures-sanity)

0 commit comments

Comments
 (0)