1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-29 08:15:35 +00:00

Better return values

This commit is contained in:
trav5 2024-04-27 15:02:45 +02:00
parent 4449b66846
commit b9358521cc
2 changed files with 13 additions and 15 deletions

View file

@ -145,7 +145,7 @@ namespace
storeBindingsClass[sol::meta_function::length] = [](const StoreT& store) { return store.getSize(); }; storeBindingsClass[sol::meta_function::length] = [](const StoreT& store) { return store.getSize(); };
storeBindingsClass[sol::meta_function::index] = sol::overload( storeBindingsClass[sol::meta_function::index] = sol::overload(
[](const StoreT& store, size_t index) -> const ESM::Dialogue* { [](const StoreT& store, size_t index) -> const ESM::Dialogue* {
if (index == 0 || index > store.getSize()) if (index == 0)
{ {
return nullptr; return nullptr;
} }
@ -174,13 +174,12 @@ namespace
void prepareBindingsForDialogueRecord(sol::state_view& lua) void prepareBindingsForDialogueRecord(sol::state_view& lua)
{ {
auto recordBindingsClass = lua.new_usertype<ESM::Dialogue>("ESM3_Dialogue"); auto recordBindingsClass = lua.new_usertype<ESM::Dialogue>("ESM3_Dialogue");
recordBindingsClass[sol::meta_function::to_string] = [lua](const ESM::Dialogue& rec) -> sol::object { recordBindingsClass[sol::meta_function::to_string]
return sol::make_object(lua, "ESM3_Dialogue[" + rec.mId.toDebugString() + "]"); = [](const ESM::Dialogue& rec) { return "ESM3_Dialogue[" + rec.mId.toDebugString() + "]"; };
}; recordBindingsClass["id"]
recordBindingsClass["id"] = sol::readonly_property( = sol::readonly_property([](const ESM::Dialogue& rec) { return rec.mId.serializeText(); });
[lua](const ESM::Dialogue& rec) { return sol::make_object(lua, rec.mId.serializeText()); });
recordBindingsClass["name"] 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 { recordBindingsClass["questName"] = sol::readonly_property([lua](const ESM::Dialogue& rec) -> sol::object {
if (rec.mType != ESM::Dialogue::Type::Journal) if (rec.mType != ESM::Dialogue::Type::Journal)
{ {
@ -196,7 +195,7 @@ namespace
return sol::nil; return sol::nil;
}); });
recordBindingsClass["infos"] 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) void prepareBindingsForDialogueRecordInfoList(sol::state_view& lua)
@ -234,13 +233,12 @@ namespace
{ {
auto recordInfoBindingsClass = lua.new_usertype<ESM::DialInfo>("ESM3_Dialogue_Info"); auto recordInfoBindingsClass = lua.new_usertype<ESM::DialInfo>("ESM3_Dialogue_Info");
recordInfoBindingsClass[sol::meta_function::to_string] = [lua](const ESM::DialInfo& rec) { recordInfoBindingsClass[sol::meta_function::to_string]
return sol::make_object(lua, "ESM3_Dialogue_Info[" + rec.mId.toDebugString() + "]"); = [](const ESM::DialInfo& rec) { return "ESM3_Dialogue_Info[" + rec.mId.toDebugString() + "]"; };
}; recordInfoBindingsClass["id"]
recordInfoBindingsClass["id"] = sol::readonly_property( = sol::readonly_property([](const ESM::DialInfo& rec) { return rec.mId.serializeText(); });
[lua](const ESM::DialInfo& rec) { return sol::make_object(lua, rec.mId.serializeText()); });
recordInfoBindingsClass["text"] 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 { recordInfoBindingsClass["questStage"] = sol::readonly_property([lua](const ESM::DialInfo& rec) -> sol::object {
if (rec.mData.mType != ESM::Dialogue::Type::Journal) if (rec.mData.mType != ESM::Dialogue::Type::Journal)
{ {

View file

@ -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. -- 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 -- @field [parent=#DialogueRecords] #list<#DialogueRecord> records
-- @usage local record = core.dialogue.journal.records['ms_fargothring'] -- @usage local record = core.dialogue.journal.records['ms_fargothring']
-- @usage local record = core.dialogue.journal.records['MS_FargothRing'] -- @usage local record = core.dialogue.journal.records['MS_FargothRing']