diff --git a/LUA_API.rst b/LUA_API.rst index 8698e1b23..fc86070c3 100644 --- a/LUA_API.rst +++ b/LUA_API.rst @@ -696,6 +696,19 @@ Units module Adds or removes the unit from the burrow. +Items module +------------ + +* ``dfhack.items.getOwner(item)`` + + Returns the owner unit or *nil*. + +* ``dfhack.items.setOwner(item,unit)`` + + Replaces the owner of the item. If unit is *nil*, removes ownership. + Returns *false* in case of error. + + Maps module ----------- diff --git a/Lua API.html b/Lua API.html index 0ca88966c..7c3eeddb9 100644 --- a/Lua API.html +++ b/Lua API.html @@ -340,7 +340,8 @@ ul.auto-toc {
dfhack.items.getOwner(item)
+Returns the owner unit or nil.
+dfhack.items.setOwner(item,unit)
+Replaces the owner of the item. If unit is nil, removes ownership. +Returns false in case of error.
+dfhack.maps.getSize()
Returns map size in blocks: x, y, z
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index fb818c206..febc59026 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -42,6 +42,7 @@ distribution. #include "modules/Job.h" #include "modules/Translation.h" #include "modules/Units.h" +#include "modules/Items.h" #include "modules/Materials.h" #include "modules/Maps.h" @@ -609,6 +610,12 @@ static const LuaWrapper::FunctionReg dfhack_units_module[] = { { NULL, NULL } }; +static const LuaWrapper::FunctionReg dfhack_items_module[] = { + WRAPM(Items, getOwner), + WRAPM(Items, setOwner), + { NULL, NULL } +}; + static bool maps_isBlockBurrowTile(df::burrow *burrow, df::map_block *block, int x, int y) { return Maps::isBlockBurrowTile(burrow, block, df::coord2d(x,y)); @@ -666,5 +673,6 @@ void OpenDFHackApi(lua_State *state) OpenModule(state, "gui", dfhack_gui_module); OpenModule(state, "job", dfhack_job_module, dfhack_job_funcs); OpenModule(state, "units", dfhack_units_module); + OpenModule(state, "items", dfhack_items_module); OpenModule(state, "maps", dfhack_maps_module, dfhack_maps_funcs); } diff --git a/library/include/DataDefs.h b/library/include/DataDefs.h index b9b4707d9..d4d757d94 100644 --- a/library/include/DataDefs.h +++ b/library/include/DataDefs.h @@ -425,6 +425,9 @@ namespace df static compound_identity *get() { return &T::_identity; } }; + template