diff --git a/include/Nazara/Lua/LuaState.hpp b/include/Nazara/Lua/LuaState.hpp index f3bfdc34a..fe34d794a 100644 --- a/include/Nazara/Lua/LuaState.hpp +++ b/include/Nazara/Lua/LuaState.hpp @@ -15,6 +15,7 @@ #include #include #include +#include struct lua_Debug; struct lua_State; @@ -182,7 +183,8 @@ namespace Nz protected: LuaState(lua_State* internalState); - template T CheckBounds(int index, long long value) const; + template std::enable_if_t::value, T> CheckBounds(int index, long long value) const; + template std::enable_if_t::value, T> CheckBounds(int index, long long value) const; virtual bool Run(int argCount, int resultCount); static int ProxyFunc(lua_State* internalState); diff --git a/include/Nazara/Lua/LuaState.inl b/include/Nazara/Lua/LuaState.inl index fa4ecaaf0..da191d8a2 100644 --- a/include/Nazara/Lua/LuaState.inl +++ b/include/Nazara/Lua/LuaState.inl @@ -771,7 +771,7 @@ namespace Nz } template - T LuaState::CheckBounds(int index, long long value) const + std::enable_if_t::value, T> LuaState::CheckBounds(int index, long long value) const { constexpr long long minBounds = std::numeric_limits::min(); constexpr long long maxBounds = std::numeric_limits::max(); @@ -785,6 +785,21 @@ namespace Nz return static_cast(value); } + template + std::enable_if_t::value, T> LuaState::CheckBounds(int index, long long value) const + { + constexpr unsigned long long minBounds = 0; + constexpr unsigned long long maxBounds = std::numeric_limits::max(); + if (value < minBounds || value > maxBounds) + { + Nz::StringStream stream; + stream << "Argument #" << index << " is outside value range [" << minBounds << ", " << maxBounds << "] (" << value << ')'; + Error(stream); + } + + return static_cast(value); + } + inline LuaState LuaState::GetState(lua_State* internalState) { return LuaState(internalState);