diff --git a/apps/openmw/mwlua/objectbindings.cpp b/apps/openmw/mwlua/objectbindings.cpp index cbd8347d0d..f803f4b1c8 100644 --- a/apps/openmw/mwlua/objectbindings.cpp +++ b/apps/openmw/mwlua/objectbindings.cpp @@ -409,11 +409,18 @@ namespace MWLua return GObject(splitted); }; - objectT["moveInto"] = [removeFn, context](const GObject& object, const Inventory& inventory) { + objectT["moveInto"] = [removeFn, context](const GObject& object, const sol::object& dest) { const MWWorld::Ptr& ptr = object.ptr(); int count = ptr.getRefData().getCount(); + MWWorld::Ptr destPtr; + if (dest.is()) + destPtr = dest.as().ptr(); + else + destPtr = LuaUtil::cast>(dest).mObj.ptr(); + destPtr.getContainerStore(); // raises an error if there is no container store + std::optional delayedRemovalFn = removeFn(ptr, count); - context.mLuaManager->addAction([item = object, count, cont = inventory.mObj, delayedRemovalFn] { + context.mLuaManager->addAction([item = object, count, cont = GObject(destPtr), delayedRemovalFn] { const MWWorld::Ptr& oldPtr = item.ptr(); auto& refData = oldPtr.getRefData(); refData.setCount(count); // temporarily undo removal to run ContainerStore::add diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index 6901940edd..aaeec102f5 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -241,8 +241,10 @@ -- Can be called only from a global script. -- @function [parent=#GameObject] moveInto -- @param self --- @param #Inventory dest +-- @param #any dest @{#Inventory} or @{#GameObject} -- @usage item:moveInto(types.Actor.inventory(actor)) +-- @usage item:moveInto(types.Container.content(container)) +-- @usage item:moveInto(container) --- -- Removes an object or reduces a stack of objects.