diff --git a/apps/openmw/mwlua/types/armor.cpp b/apps/openmw/mwlua/types/armor.cpp index 91a4c05d8b..8c741a4684 100644 --- a/apps/openmw/mwlua/types/armor.cpp +++ b/apps/openmw/mwlua/types/armor.cpp @@ -98,8 +98,11 @@ namespace MWLua record["icon"] = sol::readonly_property([vfs](const ESM::Armor& rec) -> std::string { return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs); }); - record["enchant"] - = sol::readonly_property([](const ESM::Armor& rec) -> std::string { return rec.mEnchant.serializeText(); }); + record["enchant"] = sol::readonly_property([](const ESM::Armor& rec) -> sol::optional { + if (rec.mEnchant.empty()) + return sol::nullopt; + return rec.mEnchant.serializeText(); + }); record["mwscript"] = sol::readonly_property([](const ESM::Armor& rec) -> std::string { return rec.mScript.serializeText(); }); record["weight"] = sol::readonly_property([](const ESM::Armor& rec) -> float { return rec.mData.mWeight; }); diff --git a/apps/openmw/mwlua/types/book.cpp b/apps/openmw/mwlua/types/book.cpp index ce2138127d..92bea13748 100644 --- a/apps/openmw/mwlua/types/book.cpp +++ b/apps/openmw/mwlua/types/book.cpp @@ -110,8 +110,11 @@ namespace MWLua return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs); }); record["text"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mText; }); - record["enchant"] - = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mEnchant.serializeText(); }); + record["enchant"] = sol::readonly_property([](const ESM::Book& rec) -> sol::optional { + if (rec.mEnchant.empty()) + return sol::nullopt; + return rec.mEnchant.serializeText(); + }); record["isScroll"] = sol::readonly_property([](const ESM::Book& rec) -> bool { return rec.mData.mIsScroll; }); record["value"] = sol::readonly_property([](const ESM::Book& rec) -> int { return rec.mData.mValue; }); record["weight"] = sol::readonly_property([](const ESM::Book& rec) -> float { return rec.mData.mWeight; }); diff --git a/apps/openmw/mwlua/types/clothing.cpp b/apps/openmw/mwlua/types/clothing.cpp index 894748946d..8679ce0b67 100644 --- a/apps/openmw/mwlua/types/clothing.cpp +++ b/apps/openmw/mwlua/types/clothing.cpp @@ -93,8 +93,11 @@ namespace MWLua record["icon"] = sol::readonly_property([vfs](const ESM::Clothing& rec) -> std::string { return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs); }); - record["enchant"] = sol::readonly_property( - [](const ESM::Clothing& rec) -> std::string { return rec.mEnchant.serializeText(); }); + record["enchant"] = sol::readonly_property([](const ESM::Clothing& rec) -> sol::optional { + if (rec.mEnchant.empty()) + return sol::nullopt; + return rec.mEnchant.serializeText(); + }); record["mwscript"] = sol::readonly_property( [](const ESM::Clothing& rec) -> std::string { return rec.mScript.serializeText(); }); record["weight"] = sol::readonly_property([](const ESM::Clothing& rec) -> float { return rec.mData.mWeight; }); diff --git a/apps/openmw/mwlua/types/weapon.cpp b/apps/openmw/mwlua/types/weapon.cpp index f09cd96dad..71fab2e0f5 100644 --- a/apps/openmw/mwlua/types/weapon.cpp +++ b/apps/openmw/mwlua/types/weapon.cpp @@ -131,8 +131,11 @@ namespace MWLua record["icon"] = sol::readonly_property([vfs](const ESM::Weapon& rec) -> std::string { return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs); }); - record["enchant"] = sol::readonly_property( - [](const ESM::Weapon& rec) -> std::string { return rec.mEnchant.serializeText(); }); + record["enchant"] = sol::readonly_property([](const ESM::Weapon& rec) -> sol::optional { + if (rec.mEnchant.empty()) + return sol::nullopt; + return rec.mEnchant.serializeText(); + }); record["mwscript"] = sol::readonly_property([](const ESM::Weapon& rec) -> std::string { return rec.mScript.serializeText(); }); record["isMagical"] = sol::readonly_property( diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index f9aeaf97af..d686df144a 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -1329,7 +1329,7 @@ -- @field #string model VFS path to the model -- @field #string mwscript MWScript on this armor (can be empty) -- @field #string icon VFS path to the icon --- @field #string enchant The enchantment ID of this armor (can be empty) +-- @field #string enchant The enchantment ID of this armor (can be nil) -- @field #number weight -- @field #number value -- @field #number type See @{#Armor.TYPE} @@ -1418,7 +1418,7 @@ -- @field #string model VFS path to the model -- @field #string mwscript MWScript on this book (can be empty) -- @field #string icon VFS path to the icon --- @field #string enchant The enchantment ID of this book (can be empty) +-- @field #string enchant The enchantment ID of this book (can be nil) -- @field #string text The text content of the book -- @field #number weight -- @field #number value @@ -1496,7 +1496,7 @@ -- @field #string model VFS path to the model -- @field #string mwscript MWScript on this clothing (can be empty) -- @field #string icon VFS path to the icon --- @field #string enchant The enchantment ID of this clothing (can be empty) +-- @field #string enchant The enchantment ID of this clothing (can be nil) -- @field #number weight -- @field #number value -- @field #number type See @{#Clothing.TYPE} @@ -1821,7 +1821,7 @@ -- @field #string model VFS path to the model -- @field #string mwscript MWScript on this weapon (can be empty) -- @field #string icon VFS path to the icon --- @field #string enchant +-- @field #string enchant The enchantment ID of this weapon (can be nil) -- @field #boolean isMagical -- @field #boolean isSilver -- @field #number weight