Lua binding update
- Added files & Register_X methods for modules Graphics, Renderer and Utility - Added Nz::AbstractImage binding (WIP) Former-commit-id: 91fd641c7676c12034e5f702bd3ba45e2a826263
This commit is contained in:
parent
95f6977c1f
commit
04aac4363f
|
|
@ -25,6 +25,9 @@ namespace Ndk
|
|||
static void Register_Audio(Nz::LuaInstance& instance);
|
||||
static void Register_Core(Nz::LuaInstance& instance);
|
||||
static void Register_Math(Nz::LuaInstance& instance);
|
||||
static void Register_Utility(Nz::LuaInstance& instance);
|
||||
static void Register_Graphics(Nz::LuaInstance& instance);
|
||||
static void Register_Renderer(Nz::LuaInstance& instance);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Lua/LuaClass.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaAPI::Register_Graphics(Nz::LuaInstance& instance)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,147 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <Nazara/Lua/LuaClass.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaAPI::Register_Renderer(Nz::LuaInstance& instance)
|
||||
{
|
||||
/*********************************** Nz::AbstractImage **********************************/
|
||||
Nz::LuaClass<Nz::AbstractImage*> abstractImage("AbstractImage");
|
||||
|
||||
abstractImage.SetMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel);
|
||||
abstractImage.SetMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.SetMethod("GetFormat", &Nz::AbstractImage::GetFormat);
|
||||
abstractImage.SetMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.SetMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
||||
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("GetType", &Nz::AbstractImage::GetType);
|
||||
abstractImage.SetMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.SetMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
||||
abstractImage.SetMethod("IsCubemap", &Nz::AbstractImage::IsCubemap);
|
||||
|
||||
abstractImage.SetMethod("GetMemoryUsage",
|
||||
[](Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
unsigned int memory = 0;
|
||||
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
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?
|
||||
else
|
||||
memory = abstractImage->GetMemoryUsage();
|
||||
|
||||
lua.PushInteger(memory);
|
||||
return 1;
|
||||
});
|
||||
|
||||
abstractImage.SetMethod("__tostring",
|
||||
[](Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
lua.PushString(Nz::StringStream("AbstractImage()"));
|
||||
return 1;
|
||||
});
|
||||
|
||||
abstractImage.SetMethod("Update",
|
||||
[](Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
if (argCount < 1)
|
||||
{
|
||||
lua.Error("No matching overload for method AbstractImage::Update");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool rValue;
|
||||
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(lua.CheckString(1));
|
||||
|
||||
if (argCount == 1)
|
||||
rValue = abstractImage->Update(pixels);
|
||||
else
|
||||
{
|
||||
// Three possible overloads, based on second argument type
|
||||
if (lua.IsOfType(2, Nz::LuaType_Number)) // Overload #1
|
||||
{
|
||||
/* Prototype is:
|
||||
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 srcHeight = 0;
|
||||
Nz::UInt8 level = 0;
|
||||
|
||||
if (argCount >= 3)
|
||||
{
|
||||
srcHeight = static_cast<unsigned int>(lua.CheckInteger(3)); // Range check?
|
||||
if (argCount >= 4)
|
||||
level = static_cast<Nz::UInt8>(lua.CheckInteger(3)); // Range check?
|
||||
}
|
||||
|
||||
rValue = abstractImage->Update(pixels, srcWidth, srcHeight, level);
|
||||
}
|
||||
else if (lua.IsOfType(2, "Box")) // Overload #2
|
||||
{
|
||||
/* Prototype is:
|
||||
virtual bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
*/
|
||||
|
||||
Nz::Boxui box (*(static_cast<Nz::Boxui*>(lua.ToUserdata(2)))); // Placeholder. Ask Lynix about templates & bindings. Nz::Box<T> has to be bound, too.
|
||||
unsigned int srcWidth = 0;
|
||||
unsigned int srcHeight = 0;
|
||||
Nz::UInt8 level = 0;
|
||||
|
||||
if (argCount >= 3)
|
||||
{
|
||||
srcWidth = static_cast<unsigned int>(lua.CheckInteger(3)); // Range check?
|
||||
if (argCount >= 4)
|
||||
{
|
||||
srcHeight = static_cast<unsigned int>(lua.CheckInteger(4)); // Range check?
|
||||
if (argCount >= 5)
|
||||
level = static_cast<Nz::UInt8>(lua.CheckInteger(5)); // Range check?
|
||||
}
|
||||
}
|
||||
rValue = abstractImage->Update(pixels, box, srcWidth, srcHeight, level);
|
||||
}
|
||||
else if (lua.IsOfType(2, "Rect")) // Overload #3
|
||||
{
|
||||
/* Prototype is:
|
||||
virtual bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
*/
|
||||
|
||||
Nz::Rectui rect(*(static_cast<Nz::Rectui*>(lua.ToUserdata(2)))); // Placeholder. See comment at box declaration in overload #2
|
||||
unsigned int z = 0;
|
||||
unsigned int srcWidth = 0;
|
||||
unsigned int srcHeight = 0;
|
||||
Nz::UInt8 level = 0;
|
||||
|
||||
if (argCount >= 3)
|
||||
{
|
||||
z = static_cast<unsigned int>(lua.CheckInteger(3)); // Range check?
|
||||
if (argCount >= 4)
|
||||
{
|
||||
srcWidth = static_cast<unsigned int>(lua.CheckInteger(4)); // Range check?
|
||||
if (argCount >= 5)
|
||||
{
|
||||
srcHeight = static_cast<unsigned int>(lua.CheckInteger(5)); // Range check?
|
||||
if (argCount >= 6)
|
||||
level = static_cast<Nz::UInt8>(lua.CheckInteger(6)); // Range check?
|
||||
}
|
||||
}
|
||||
}
|
||||
rValue = abstractImage->Update(pixels, rect, z, srcWidth, srcHeight, level);
|
||||
}
|
||||
}
|
||||
|
||||
lua.PushBoolean(rValue);
|
||||
return 1;
|
||||
});
|
||||
|
||||
abstractImage.Register(instance);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <Nazara/Lua/LuaClass.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaAPI::Register_Utility(Nz::LuaInstance& instance)
|
||||
{
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue