Lua Binding update
- Added range check on various casts (ranged_cast routine needs to be moved somewhere else) - Added Nz::Vector3ui type to auto-bind system Former-commit-id: 3ec773b26d9cc85e40879c011cad0fb2a3d05571
This commit is contained in:
parent
6b0c750e54
commit
69a1be70ba
|
|
@ -48,6 +48,16 @@ namespace Nz
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& lua, int index, Vector3ui* vec, TypeTag<Vector3ui>)
|
||||||
|
{
|
||||||
|
Vector3d vecDouble;
|
||||||
|
unsigned int ret = LuaImplQueryArg(lua, index, &vecDouble, TypeTag<Vector3d>());
|
||||||
|
|
||||||
|
vec->Set(vecDouble);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag<const SoundBuffer*>)
|
inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag<const SoundBuffer*>)
|
||||||
{
|
{
|
||||||
instance.PushInstance<SoundBufferConstRef>("SoundBuffer", val);
|
instance.PushInstance<SoundBufferConstRef>("SoundBuffer", val);
|
||||||
|
|
@ -65,4 +75,10 @@ namespace Nz
|
||||||
instance.PushInstance<Vector3d>("Vector3", val);
|
instance.PushInstance<Vector3d>("Vector3", val);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3ui val, TypeTag<Vector3ui>)
|
||||||
|
{
|
||||||
|
instance.PushInstance<Vector3d>("Vector3", val);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||||
// This file is part of the "Nazara Development Kit"
|
// This file is part of the "Nazara Development Kit"
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
|
@ -6,6 +7,14 @@
|
||||||
#include <Nazara/Renderer.hpp>
|
#include <Nazara/Renderer.hpp>
|
||||||
#include <Nazara/Lua/LuaClass.hpp>
|
#include <Nazara/Lua/LuaClass.hpp>
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
// WIP: I don't know where to put it...
|
||||||
|
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))));
|
||||||
|
}
|
||||||
|
|
||||||
namespace Ndk
|
namespace Ndk
|
||||||
{
|
{
|
||||||
void LuaAPI::Register_Renderer(Nz::LuaInstance& instance)
|
void LuaAPI::Register_Renderer(Nz::LuaInstance& instance)
|
||||||
|
|
@ -19,7 +28,7 @@ namespace Ndk
|
||||||
abstractImage.SetMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
abstractImage.SetMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
||||||
abstractImage.SetMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
abstractImage.SetMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
||||||
abstractImage.SetMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
|
abstractImage.SetMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
|
||||||
/*abstractImage.SetMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));*/ // Need to add Nz::Vector3ui to auto binding mecanism, or do it by hand
|
abstractImage.SetMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
|
||||||
abstractImage.SetMethod("GetType", &Nz::AbstractImage::GetType);
|
abstractImage.SetMethod("GetType", &Nz::AbstractImage::GetType);
|
||||||
abstractImage.SetMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
abstractImage.SetMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
||||||
abstractImage.SetMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
abstractImage.SetMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
||||||
|
|
@ -32,7 +41,7 @@ namespace Ndk
|
||||||
|
|
||||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||||
if (argCount == 1 && lua.IsOfType(1, Nz::LuaType_Number))
|
if (argCount == 1 && lua.IsOfType(1, Nz::LuaType_Number))
|
||||||
memory = abstractImage->GetMemoryUsage(static_cast<Nz::UInt8>(lua.CheckInteger(1))); // Maybe do a range check instead of casting like a savage?
|
memory = abstractImage->GetMemoryUsage(ranged_cast<Nz::UInt8>(lua.CheckInteger(1)));
|
||||||
else
|
else
|
||||||
memory = abstractImage->GetMemoryUsage();
|
memory = abstractImage->GetMemoryUsage();
|
||||||
|
|
||||||
|
|
@ -72,15 +81,15 @@ namespace Ndk
|
||||||
virtual bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
virtual bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned int srcWidth = static_cast<unsigned int>(lua.CheckInteger(2)); // Range check?
|
unsigned int srcWidth = ranged_cast<unsigned int>(lua.CheckInteger(2));
|
||||||
unsigned int srcHeight = 0;
|
unsigned int srcHeight = 0;
|
||||||
Nz::UInt8 level = 0;
|
Nz::UInt8 level = 0;
|
||||||
|
|
||||||
if (argCount >= 3)
|
if (argCount >= 3)
|
||||||
{
|
{
|
||||||
srcHeight = static_cast<unsigned int>(lua.CheckInteger(3)); // Range check?
|
srcHeight = ranged_cast<unsigned int>(lua.CheckInteger(3));
|
||||||
if (argCount >= 4)
|
if (argCount >= 4)
|
||||||
level = static_cast<Nz::UInt8>(lua.CheckInteger(3)); // Range check?
|
level = ranged_cast<Nz::UInt8>(lua.CheckInteger(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
rValue = abstractImage->Update(pixels, srcWidth, srcHeight, level);
|
rValue = abstractImage->Update(pixels, srcWidth, srcHeight, level);
|
||||||
|
|
@ -98,12 +107,12 @@ namespace Ndk
|
||||||
|
|
||||||
if (argCount >= 3)
|
if (argCount >= 3)
|
||||||
{
|
{
|
||||||
srcWidth = static_cast<unsigned int>(lua.CheckInteger(3)); // Range check?
|
srcWidth = ranged_cast<unsigned int>(lua.CheckInteger(3));
|
||||||
if (argCount >= 4)
|
if (argCount >= 4)
|
||||||
{
|
{
|
||||||
srcHeight = static_cast<unsigned int>(lua.CheckInteger(4)); // Range check?
|
srcHeight = ranged_cast<unsigned int>(lua.CheckInteger(4));
|
||||||
if (argCount >= 5)
|
if (argCount >= 5)
|
||||||
level = static_cast<Nz::UInt8>(lua.CheckInteger(5)); // Range check?
|
level = ranged_cast<Nz::UInt8>(lua.CheckInteger(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rValue = abstractImage->Update(pixels, box, srcWidth, srcHeight, level);
|
rValue = abstractImage->Update(pixels, box, srcWidth, srcHeight, level);
|
||||||
|
|
@ -122,15 +131,15 @@ namespace Ndk
|
||||||
|
|
||||||
if (argCount >= 3)
|
if (argCount >= 3)
|
||||||
{
|
{
|
||||||
z = static_cast<unsigned int>(lua.CheckInteger(3)); // Range check?
|
z = ranged_cast<unsigned int>(lua.CheckInteger(3));
|
||||||
if (argCount >= 4)
|
if (argCount >= 4)
|
||||||
{
|
{
|
||||||
srcWidth = static_cast<unsigned int>(lua.CheckInteger(4)); // Range check?
|
srcWidth = ranged_cast<unsigned int>(lua.CheckInteger(4));
|
||||||
if (argCount >= 5)
|
if (argCount >= 5)
|
||||||
{
|
{
|
||||||
srcHeight = static_cast<unsigned int>(lua.CheckInteger(5)); // Range check?
|
srcHeight = ranged_cast<unsigned int>(lua.CheckInteger(5));
|
||||||
if (argCount >= 6)
|
if (argCount >= 6)
|
||||||
level = static_cast<Nz::UInt8>(lua.CheckInteger(6)); // Range check?
|
level = ranged_cast<Nz::UInt8>(lua.CheckInteger(6));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue