1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-29 18:32:36 +00:00

Lua: String overload for effects store index.

This commit is contained in:
Mads Buvik Sandvei 2023-07-30 23:55:19 +00:00 committed by Petr Mikheev
parent e76ce6b696
commit edb7081ea6
2 changed files with 9 additions and 2 deletions

View File

@ -240,8 +240,12 @@ namespace MWLua
magicEffectStoreT[sol::meta_function::to_string] = [](const MagicEffectStore& store) {
return "ESM3_MagicEffectStore{" + std::to_string(store.getSize()) + " effects}";
};
magicEffectStoreT[sol::meta_function::index]
= [](const MagicEffectStore& store, int id) -> const ESM::MagicEffect* { return store.find(id); };
magicEffectStoreT[sol::meta_function::index] = sol::overload(
[](const MagicEffectStore& store, int id) -> const ESM::MagicEffect* { return store.find(id); },
[](const MagicEffectStore& store, std::string_view id) -> const ESM::MagicEffect* {
int index = ESM::MagicEffect::indexNameToIndex(id);
return store.find(index);
});
auto magicEffectsIter = [magicEffectStore](sol::this_state lua, const sol::object& /*store*/,
sol::optional<int> id) -> std::tuple<sol::object, sol::object> {
MagicEffectStore::iterator iter;

View File

@ -663,6 +663,9 @@
-- print(effect.name)
-- end
-- end
-- @usage -- Look up the record of a specific effect and print its icon
-- local mgef = core.magic.effects[core.magic.EFFECT_TYPE.Reflect]
-- print('Reflect Icon: '..tostring(mgef.icon))
--- List of all @{#Enchantment}s.
-- @field [parent=#Magic] #list<#Enchantment> enchantments