#ifndef OPENMW_COMPONENTS_MISC_FINITEVALUES_HPP #define OPENMW_COMPONENTS_MISC_FINITEVALUES_HPP #include #include #include #include #include #include #include #include namespace Misc { template struct FiniteValue { T mValue; FiniteValue(T v) { constexpr bool isVecType = std::is_same_v || std::is_same_v || std::is_same_v; if constexpr (isVecType) { for (int i = 0; i < T::num_components; ++i) if (!std::isfinite(v[i])) throw std::invalid_argument("Vector must contain finite numbers"); } else { if (!std::isfinite(v)) throw std::invalid_argument("Value must be a finite number"); } mValue = v; } operator T() const { return mValue; } }; using FiniteDouble = FiniteValue; using FiniteFloat = FiniteValue; using FiniteVec2f = FiniteValue; using FiniteVec3f = FiniteValue; using FiniteVec4f = FiniteValue; } namespace sol { template bool sol_lua_check( types>, lua_State* state, int index, Handler&& handler, stack::record& tracking) { bool success = stack::check(state, lua_absindex(state, index), std::forward(handler)); tracking.use(1); return success; } template static Misc::FiniteValue sol_lua_get( types>, lua_State* state, int index, stack::record& tracking) { T value = stack::get(state, lua_absindex(state, index)); tracking.use(1); return value; } } #endif