diff --git a/Source/lua/metadoc.hpp b/Source/lua/metadoc.hpp index c7461245d..7be85291f 100644 --- a/Source/lua/metadoc.hpp +++ b/Source/lua/metadoc.hpp @@ -35,12 +35,18 @@ inline std::string LuaUserdataMemberTypeKey(std::string_view key) namespace lua_metadoc_internal { template -inline void SetUsertypeSignatureAndDocstring(sol::usertype &table, std::string_view key, const char *signature, const char *doc, LuaUserdataMemberType memberType) +void SetUsertypeSignatureAndDocstring(sol::usertype &table, std::string_view key, const char *signature, const char *doc, LuaUserdataMemberType memberType) { table.set(LuaSignatureKey(key), sol::var(signature)); table.set(LuaDocstringKey(key), sol::var(doc)); table.set(LuaUserdataMemberTypeKey(key), sol::var(static_cast(memberType))); } + +inline void SetSignatureAndDocstring(sol::table &table, std::string_view key, const char *signature, const char *doc) +{ + table.set(LuaSignatureKey(key), signature); + table.set(LuaDocstringKey(key), doc); +} } // namespace lua_metadoc_internal template @@ -75,20 +81,18 @@ template void LuaSetDoc(sol::table &table, std::string_view key, const char *signature, const char *doc, T &&value) { table.set(key, std::forward(value)); - table.set(LuaSignatureKey(key), signature); - table.set(LuaDocstringKey(key), doc); + lua_metadoc_internal::SetSignatureAndDocstring(table, key, signature, doc); } template void LuaSetDocFn(sol::table &table, std::string_view key, const char *signature, const char *doc, T &&value) { table.set_function(key, std::forward(value)); - table.set(LuaSignatureKey(key), signature); - table.set(LuaDocstringKey(key), doc); + lua_metadoc_internal::SetSignatureAndDocstring(table, key, signature, doc); } template -void LuaSetDocFn(sol::table &table, std::string_view key, std::string_view signature, T &&value) +void LuaSetDocFn(sol::table &table, std::string_view key, const char *signature, T &&value) { table.set_function(key, std::forward(value)); table.set(LuaSignatureKey(key), signature); diff --git a/Source/lua/modules/dev/items.cpp b/Source/lua/modules/dev/items.cpp index b5bc0e03d..6a8dd46bc 100644 --- a/Source/lua/modules/dev/items.cpp +++ b/Source/lua/modules/dev/items.cpp @@ -20,21 +20,24 @@ namespace devilution { namespace { -std::string DebugCmdItemInfo() +const Item *DebugCmdGetItem() { - Player &myPlayer = *MyPlayer; - Item *pItem = nullptr; - if (!myPlayer.HoldItem.isEmpty()) { - pItem = &myPlayer.HoldItem; - } else if (pcursinvitem != -1) { - if (pcursinvitem <= INVITEM_INV_LAST) - pItem = &myPlayer.InvList[pcursinvitem - INVITEM_INV_FIRST]; - else - pItem = &myPlayer.SpdList[pcursinvitem - INVITEM_BELT_FIRST]; - } else if (pcursitem != -1) { - pItem = &Items[pcursitem]; + const Player &myPlayer = *MyPlayer; + if (!myPlayer.HoldItem.isEmpty()) return &myPlayer.HoldItem; + if (pcursinvitem != -1) { + if (pcursinvitem < INVITEM_INV_FIRST) return &myPlayer.InvBody[pcursinvitem]; + if (pcursinvitem <= INVITEM_INV_LAST) return &myPlayer.InvList[pcursinvitem - INVITEM_INV_FIRST]; + return &myPlayer.SpdList[pcursinvitem - INVITEM_BELT_FIRST]; } + if (pcursitem != -1) return &Items[pcursitem]; + return nullptr; +} + +std::string DebugCmdItemInfo() +{ + const Item *pItem = DebugCmdGetItem(); if (pItem != nullptr) { + const Player &myPlayer = *MyPlayer; std::string_view netPackValidation { "N/A" }; if (gbIsMultiplayer) { ItemNetPack itemPack; @@ -194,6 +197,7 @@ std::string DebugSpawnUniqueItem(std::string itemName) sol::table LuaDevItemsModule(sol::state_view &lua) { sol::table table = lua.create_table(); + LuaSetDocFn(table, "get", "() -> Item", "Get the currently selected item.", &DebugCmdGetItem); LuaSetDocFn(table, "info", "()", "Show info of currently selected item.", &DebugCmdItemInfo); LuaSetDocFn(table, "spawn", "(name: string)", "Attempt to generate an item.", &DebugSpawnItem); LuaSetDocFn(table, "spawnUnique", "(name: string)", "Attempt to generate a unique item.", &DebugSpawnUniqueItem);