Lua/Binding: Fix unsigned integer binding

This commit is contained in:
Lynix 2017-06-12 14:42:36 +02:00
parent 713f7dfd5b
commit 7875854e7d
2 changed files with 19 additions and 2 deletions

View File

@ -15,6 +15,7 @@
#include <Nazara/Lua/Enums.hpp>
#include <cstddef>
#include <functional>
#include <type_traits>
struct lua_Debug;
struct lua_State;
@ -182,7 +183,8 @@ namespace Nz
protected:
LuaState(lua_State* internalState);
template<typename T> T CheckBounds(int index, long long value) const;
template<typename T> std::enable_if_t<std::is_signed<T>::value, T> CheckBounds(int index, long long value) const;
template<typename T> std::enable_if_t<std::is_unsigned<T>::value, T> CheckBounds(int index, long long value) const;
virtual bool Run(int argCount, int resultCount);
static int ProxyFunc(lua_State* internalState);

View File

@ -771,7 +771,7 @@ namespace Nz
}
template<typename T>
T LuaState::CheckBounds(int index, long long value) const
std::enable_if_t<std::is_signed<T>::value, T> LuaState::CheckBounds(int index, long long value) const
{
constexpr long long minBounds = std::numeric_limits<T>::min();
constexpr long long maxBounds = std::numeric_limits<T>::max();
@ -785,6 +785,21 @@ namespace Nz
return static_cast<T>(value);
}
template<typename T>
std::enable_if_t<std::is_unsigned<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<T>::max();
if (value < minBounds || value > maxBounds)
{
Nz::StringStream stream;
stream << "Argument #" << index << " is outside value range [" << minBounds << ", " << maxBounds << "] (" << value << ')';
Error(stream);
}
return static_cast<T>(value);
}
inline LuaState LuaState::GetState(lua_State* internalState)
{
return LuaState(internalState);