From b9358521cc7deed114402e1b1d46f373c263a680 Mon Sep 17 00:00:00 2001 From: trav5 Date: Sat, 27 Apr 2024 15:02:45 +0200 Subject: [PATCH] Better return values --- apps/openmw/mwlua/dialoguebindings.cpp | 26 ++++++++++++-------------- files/lua_api/openmw/core.lua | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwlua/dialoguebindings.cpp b/apps/openmw/mwlua/dialoguebindings.cpp index 9ba6f18fcb..22681908f0 100644 --- a/apps/openmw/mwlua/dialoguebindings.cpp +++ b/apps/openmw/mwlua/dialoguebindings.cpp @@ -145,7 +145,7 @@ namespace storeBindingsClass[sol::meta_function::length] = [](const StoreT& store) { return store.getSize(); }; storeBindingsClass[sol::meta_function::index] = sol::overload( [](const StoreT& store, size_t index) -> const ESM::Dialogue* { - if (index == 0 || index > store.getSize()) + if (index == 0) { return nullptr; } @@ -174,13 +174,12 @@ namespace void prepareBindingsForDialogueRecord(sol::state_view& lua) { auto recordBindingsClass = lua.new_usertype("ESM3_Dialogue"); - recordBindingsClass[sol::meta_function::to_string] = [lua](const ESM::Dialogue& rec) -> sol::object { - return sol::make_object(lua, "ESM3_Dialogue[" + rec.mId.toDebugString() + "]"); - }; - recordBindingsClass["id"] = sol::readonly_property( - [lua](const ESM::Dialogue& rec) { return sol::make_object(lua, rec.mId.serializeText()); }); + recordBindingsClass[sol::meta_function::to_string] + = [](const ESM::Dialogue& rec) { return "ESM3_Dialogue[" + rec.mId.toDebugString() + "]"; }; + recordBindingsClass["id"] + = sol::readonly_property([](const ESM::Dialogue& rec) { return rec.mId.serializeText(); }); recordBindingsClass["name"] - = sol::readonly_property([lua](const ESM::Dialogue& rec) { return sol::make_object(lua, rec.mStringId); }); + = sol::readonly_property([](const ESM::Dialogue& rec) -> std::string_view { return rec.mStringId; }); recordBindingsClass["questName"] = sol::readonly_property([lua](const ESM::Dialogue& rec) -> sol::object { if (rec.mType != ESM::Dialogue::Type::Journal) { @@ -196,7 +195,7 @@ namespace return sol::nil; }); recordBindingsClass["infos"] - = sol::readonly_property([lua](const ESM::Dialogue& rec) { return DialogueInfos{ rec.mId }; }); + = sol::readonly_property([](const ESM::Dialogue& rec) { return DialogueInfos{ rec.mId }; }); } void prepareBindingsForDialogueRecordInfoList(sol::state_view& lua) @@ -234,13 +233,12 @@ namespace { auto recordInfoBindingsClass = lua.new_usertype("ESM3_Dialogue_Info"); - recordInfoBindingsClass[sol::meta_function::to_string] = [lua](const ESM::DialInfo& rec) { - return sol::make_object(lua, "ESM3_Dialogue_Info[" + rec.mId.toDebugString() + "]"); - }; - recordInfoBindingsClass["id"] = sol::readonly_property( - [lua](const ESM::DialInfo& rec) { return sol::make_object(lua, rec.mId.serializeText()); }); + recordInfoBindingsClass[sol::meta_function::to_string] + = [](const ESM::DialInfo& rec) { return "ESM3_Dialogue_Info[" + rec.mId.toDebugString() + "]"; }; + recordInfoBindingsClass["id"] + = sol::readonly_property([](const ESM::DialInfo& rec) { return rec.mId.serializeText(); }); recordInfoBindingsClass["text"] - = sol::readonly_property([lua](const ESM::DialInfo& rec) { return sol::make_object(lua, rec.mResponse); }); + = sol::readonly_property([](const ESM::DialInfo& rec) -> std::string_view { return rec.mResponse; }); recordInfoBindingsClass["questStage"] = sol::readonly_property([lua](const ESM::DialInfo& rec) -> sol::object { if (rec.mData.mType != ESM::Dialogue::Type::Journal) { diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index ff8c37363e..4686419164 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -992,7 +992,7 @@ --- -- A read-only list of all @{#DialogueRecord}s in the world database, may be indexed by recordId, which doesn't have to be lowercase. --- Implements [iterables#List](iterables.html#List) of #DialogueRecord. +-- Implements [iterables#List](iterables.html#list-iterable) of #DialogueRecord. -- @field [parent=#DialogueRecords] #list<#DialogueRecord> records -- @usage local record = core.dialogue.journal.records['ms_fargothring'] -- @usage local record = core.dialogue.journal.records['MS_FargothRing']