Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 21 additions & 0 deletions library/include/DataIdentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ distribution.
#include <filesystem>

#include "DataDefs.h"
#include "LuaWrapper.h"

namespace std {
class condition_variable;
Expand Down Expand Up @@ -113,6 +114,7 @@ namespace DFHack
};

class DFHACK_EXPORT container_identity : public constructed_identity {
protected:
const type_identity *item;
const enum_identity *ienum;

Expand Down Expand Up @@ -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(); }
Expand Down
5 changes: 3 additions & 2 deletions library/include/LuaWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ distribution.
#include <vector>
#include <map>

#include "DataDefs.h"

#include <lua.h>
#include <lauxlib.h>

Expand All @@ -41,6 +39,9 @@ distribution.

namespace DFHack {
struct FunctionReg;

class function_identity_base;

namespace LuaWrapper {
struct LuaToken;

Expand Down
6 changes: 5 additions & 1 deletion plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion plugins/devel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)