#ifndef OPENMW_LUAUI_PROPERTIES #define OPENMW_LUAUI_PROPERTIES #include #include #include #include namespace LuaUi { template sol::optional getProperty(sol::object from, std::string_view field) { sol::object value = LuaUtil::getFieldOrNil(from, field); if (value == sol::nil) return sol::nullopt; if (value.is()) return value.as(); std::string error("Property \""); error += field; error += "\" has an invalid value \""; error += LuaUtil::toString(value); error += "\""; throw std::logic_error(error); } template T parseProperty(sol::object from, std::string_view field, const T& defaultValue) { sol::optional opt = getProperty(from, field); if (opt.has_value()) return opt.value(); else return defaultValue; } template MyGUI::types::TPoint parseProperty( sol::object from, std::string_view field, const MyGUI::types::TPoint& defaultValue) { auto v = getProperty(from, field); if (v.has_value()) return MyGUI::types::TPoint(v.value().x(), v.value().y()); else return defaultValue; } template MyGUI::types::TSize parseProperty( sol::object from, std::string_view field, const MyGUI::types::TSize& defaultValue) { auto v = getProperty(from, field); if (v.has_value()) return MyGUI::types::TSize(v.value().x(), v.value().y()); else return defaultValue; } } #endif // !OPENMW_LUAUI_PROPERTIES