Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
beats-dh committed Dec 3, 2023
1 parent 481198d commit dba8195
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/lua/functions/lua_functions_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,13 @@ class LuaFunctionsLoader {
template <typename T>
static typename std::enable_if<std::is_enum<T>::value, T>::type
getNumber(lua_State* L, int32_t arg) {
return static_cast<T>(static_cast<int64_t>(lua_tonumber(L, arg)));
return safe_convert<T>(safe_convert<int64_t>(lua_tonumber(L, arg), __FUNCTION__), __FUNCTION__);
}
template <typename T>
static typename std::enable_if<std::is_integral<T>::value || std::is_floating_point<T>::value, T>::type getNumber(lua_State* L, int32_t arg) {
auto number = lua_tonumber(L, arg);
// If there is overflow, we return the value 0
if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T>) {
if (number < 0) {
g_logger().debug("[{}] overflow, setting to default signed value (0)", __FUNCTION__);
number = T(0);
}
}

return static_cast<T>(number);
return safe_convert<T>(number, __FUNCTION__, 0);
}
template <typename T>
static T getNumber(lua_State* L, int32_t arg, T defaultValue) {
Expand Down

0 comments on commit dba8195

Please sign in to comment.