Fix and improve last PR

Former-commit-id: 16afead68e42411402dfb5a7bd957a4940b6f83a
This commit is contained in:
Lynix
2016-01-24 15:20:14 +01:00
parent a32a1d428f
commit d7ab29e5ef
14 changed files with 325 additions and 1279 deletions

View File

@@ -15,7 +15,6 @@
#include <Nazara/Lua/Enums.hpp>
#include <cstddef>
#include <functional>
#include <limits>
struct lua_Debug;
struct lua_State;
@@ -48,6 +47,8 @@ namespace Nz
void CheckAny(int index) const;
bool CheckBoolean(int index) const;
bool CheckBoolean(int index, bool defValue) const;
template<typename T> T CheckBoundInteger(int index) const;
template<typename T> T CheckBoundInteger(int index, T defValue) const;
template<typename T> T CheckField(const char* fieldName, int tableIndex = -1) const;
template<typename T> T CheckField(const String& fieldName, int tableIndex = -1) const;
template<typename T> T CheckField(const char* fieldName, T defValue, int tableIndex = -1) const;
@@ -176,6 +177,7 @@ namespace Nz
static LuaInstance* GetInstance(lua_State* state);
private:
template<typename T> T CheckBounds(int index, long long value) const;
bool Run(int argCount, int resultCount);
static void* MemoryAllocator(void *ud, void *ptr, std::size_t osize, std::size_t nsize);
@@ -190,14 +192,6 @@ namespace Nz
lua_State* m_state;
unsigned int m_level;
};
// Performs a 'ranged cast' to type T, i.e. a cast guaranteed to end up within the numerical limits of the type (or the limits provided in argument),
// without over- or under-flowing.
// Values beyond that range will be truncated to the type minimum (resp. maximum) if they are greater (resp. lesser) than the initial value.
template <class T> T ranged_cast(long long a, T high = std::numeric_limits<T>::max(), T low = std::numeric_limits<T>::min())
{
return static_cast<T>(std::min(static_cast<long long>(high), std::max(a, static_cast<long long>(low))));
}
}
#include <Nazara/Lua/LuaInstance.inl>