Sdk: Remake LuaAPI internal
Former-commit-id: 297c30dbeca443d934edfd8d889cd7a6c725d0e1
This commit is contained in:
parent
1ecc52c718
commit
6808d60cc1
|
|
@ -16,20 +16,22 @@ namespace Nz
|
|||
|
||||
namespace Ndk
|
||||
{
|
||||
class LuaBinding;
|
||||
|
||||
class NDK_API LuaAPI
|
||||
{
|
||||
public:
|
||||
LuaAPI() = delete;
|
||||
~LuaAPI() = delete;
|
||||
|
||||
static void Register_Audio(Nz::LuaInstance& instance);
|
||||
static void Register_Core(Nz::LuaInstance& instance);
|
||||
static void Register_Graphics(Nz::LuaInstance& instance);
|
||||
static void Register_Math(Nz::LuaInstance& instance);
|
||||
static void Register_Network(Nz::LuaInstance& instance);
|
||||
static void Register_Renderer(Nz::LuaInstance& instance);
|
||||
static void Register_SDK(Nz::LuaInstance& instance);
|
||||
static void Register_Utility(Nz::LuaInstance& instance);
|
||||
static bool Initialize();
|
||||
|
||||
static void RegisterClasses(Nz::LuaInstance& instance);
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static LuaBinding* s_binding;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
bool LuaAPI::Initialize()
|
||||
{
|
||||
s_binding = new LuaBinding;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LuaAPI::RegisterClasses(Nz::LuaInstance& instance)
|
||||
{
|
||||
if (!s_binding && !Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize binding");
|
||||
return;
|
||||
}
|
||||
|
||||
s_binding->RegisterClasses(instance);
|
||||
}
|
||||
|
||||
void LuaAPI::Uninitialize()
|
||||
{
|
||||
delete s_binding;
|
||||
}
|
||||
|
||||
LuaBinding* LuaAPI::s_binding = nullptr;
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
// 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)
|
||||
{
|
||||
/*********************************** 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));
|
||||
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 argCount = std::min(lua.GetStackTop(), 1U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return lua.Push(abstractImage->GetMemoryUsage());
|
||||
|
||||
case 1:
|
||||
{
|
||||
int index = 1;
|
||||
Nz::UInt8 level(lua.Check<Nz::UInt8>(&index));
|
||||
|
||||
return lua.Push(abstractImage->GetMemoryUsage(level));
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method GetMemoryUsage");
|
||||
return 0;
|
||||
});
|
||||
|
||||
abstractImage.SetMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 6U);
|
||||
int argIndex = 1;
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(lua.CheckString(argIndex++, &bufferSize));
|
||||
|
||||
if (argCount < 2 || lua.IsOfType(2, Nz::LuaType_Number))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
/* Disabled until Box and Rect have been ported
|
||||
else if (lua.IsOfType(2, "Box"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Boxui box = lua.Check<Nz::Boxui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
else if (lua.IsOfType(2, "Rect"))
|
||||
{
|
||||
// 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 box = lua.Check<Nz::Rectui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}*/
|
||||
|
||||
lua.Error("No matching overload for method Update");
|
||||
return 0;
|
||||
});
|
||||
|
||||
abstractImage.Register(instance);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
LuaBinding::LuaBinding() :
|
||||
// Core
|
||||
clockClass("Clock"),
|
||||
directoryClass("Directory"),
|
||||
fileClass("File"),
|
||||
streamClass("Stream"),
|
||||
|
||||
// Math
|
||||
eulerAnglesClass("EulerAngles"),
|
||||
quaternionClass("Quaternion"),
|
||||
vector2dClass("Vector2"),
|
||||
vector3dClass("Vector3"),
|
||||
|
||||
// Network
|
||||
abstractSocketClass("AbstractSocket"),
|
||||
ipAddressClass("IpAddress"),
|
||||
|
||||
// Utility
|
||||
abstractImage("AbstractImage"),
|
||||
nodeClass("Node"),
|
||||
|
||||
// SDK
|
||||
nodeComponent("NodeComponent"),
|
||||
entityClass("Entity"),
|
||||
worldClass("World")
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
,
|
||||
|
||||
// Audio
|
||||
soundBuffer("SoundBuffer"),
|
||||
soundEmitter("SoundEmitter"),
|
||||
soundClass("Sound"),
|
||||
|
||||
// Graphics
|
||||
instancedRenderable("InstancedRenderable"),
|
||||
modelClass("Model"),
|
||||
|
||||
// SDK
|
||||
graphicsComponent("GraphicsComponent")
|
||||
#endif
|
||||
{
|
||||
BindCore();
|
||||
BindMath();
|
||||
BindNetwork();
|
||||
BindSDK();
|
||||
BindUtility();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
BindAudio();
|
||||
BindGraphics();
|
||||
BindRenderer();
|
||||
#endif
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterClasses(Nz::LuaInstance& instance)
|
||||
{
|
||||
RegisterCore(instance);
|
||||
RegisterMath(instance);
|
||||
RegisterNetwork(instance);
|
||||
RegisterSDK(instance);
|
||||
RegisterUtility(instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
RegisterAudio(instance);
|
||||
RegisterGraphics(instance);
|
||||
RegisterRenderer(instance);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_LUABINDING_HPP
|
||||
#define NDK_LUABINDING_HPP
|
||||
|
||||
#include <Nazara/Core.hpp>
|
||||
#include <Nazara/Lua.hpp>
|
||||
#include <Nazara/Math.hpp>
|
||||
#include <Nazara/Network.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <NDK/Components.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/Systems.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <Nazara/Audio.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class LuaBinding
|
||||
{
|
||||
public:
|
||||
LuaBinding();
|
||||
~LuaBinding() = default;
|
||||
|
||||
void RegisterClasses(Nz::LuaInstance& instance);
|
||||
|
||||
private:
|
||||
void BindCore();
|
||||
void BindMath();
|
||||
void BindNetwork();
|
||||
void BindSDK();
|
||||
void BindUtility();
|
||||
|
||||
template<typename T> void EnableComponentBinding();
|
||||
|
||||
void RegisterCore(Nz::LuaInstance& instance);
|
||||
void RegisterMath(Nz::LuaInstance& instance);
|
||||
void RegisterNetwork(Nz::LuaInstance& instance);
|
||||
void RegisterSDK(Nz::LuaInstance& instance);
|
||||
void RegisterUtility(Nz::LuaInstance& instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
void BindAudio();
|
||||
void BindGraphics();
|
||||
void BindRenderer();
|
||||
|
||||
void RegisterAudio(Nz::LuaInstance& instance);
|
||||
void RegisterGraphics(Nz::LuaInstance& instance);
|
||||
void RegisterRenderer(Nz::LuaInstance& instance);
|
||||
#endif
|
||||
|
||||
// Core
|
||||
Nz::LuaClass<Nz::Clock> clockClass;
|
||||
Nz::LuaClass<Nz::Directory> directoryClass;
|
||||
Nz::LuaClass<Nz::File> fileClass;
|
||||
Nz::LuaClass<Nz::Stream> streamClass;
|
||||
|
||||
// Math
|
||||
Nz::LuaClass<Nz::EulerAnglesd> eulerAnglesClass;
|
||||
Nz::LuaClass<Nz::Quaterniond> quaternionClass;
|
||||
Nz::LuaClass<Nz::Vector2d> vector2dClass;
|
||||
Nz::LuaClass<Nz::Vector3d> vector3dClass;
|
||||
|
||||
// Network
|
||||
Nz::LuaClass<Nz::AbstractSocket> abstractSocketClass;
|
||||
Nz::LuaClass<Nz::IpAddress> ipAddressClass;
|
||||
|
||||
// Utility
|
||||
Nz::LuaClass<Nz::AbstractImage*> abstractImage;
|
||||
Nz::LuaClass<Nz::Node> nodeClass;
|
||||
|
||||
// SDK
|
||||
Nz::LuaClass<EntityHandle> entityClass;
|
||||
Nz::LuaClass<NodeComponentHandle> nodeComponent;
|
||||
Nz::LuaClass<WorldHandle> worldClass;
|
||||
|
||||
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);
|
||||
using GetComponentFunc = int(*)(Nz::LuaInstance&, BaseComponent&);
|
||||
|
||||
struct ComponentBinding
|
||||
{
|
||||
AddComponentFunc adder;
|
||||
GetComponentFunc getter;
|
||||
bool valid = false;
|
||||
};
|
||||
|
||||
std::vector<ComponentBinding> m_componentBinding;
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
// Audio
|
||||
Nz::LuaClass<Nz::Sound> soundClass;
|
||||
Nz::LuaClass<Nz::SoundBufferRef> soundBuffer;
|
||||
Nz::LuaClass<Nz::SoundEmitter> soundEmitter;
|
||||
|
||||
// Graphics
|
||||
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable;
|
||||
Nz::LuaClass<Nz::ModelRef> modelClass;
|
||||
|
||||
// SDK
|
||||
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_HPP
|
||||
|
|
@ -1,16 +1,13 @@
|
|||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <Nazara/Audio.hpp>
|
||||
#include <Nazara/Lua/LuaClass.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaAPI::Register_Audio(Nz::LuaInstance& instance)
|
||||
void LuaBinding::BindAudio()
|
||||
{
|
||||
/*********************************** Nz::SoundBuffer **********************************/
|
||||
Nz::LuaClass<Nz::SoundBufferRef> soundBuffer("SoundBuffer");
|
||||
|
||||
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::SoundBufferRef*
|
||||
{
|
||||
return new Nz::SoundBufferRef(new Nz::SoundBuffer);
|
||||
|
|
@ -65,8 +62,6 @@ namespace Ndk
|
|||
return 1;
|
||||
});
|
||||
|
||||
soundBuffer.Register(instance);
|
||||
|
||||
/*********************************** Nz::SoundEmitter **********************************/
|
||||
Nz::LuaClass<Nz::SoundEmitter> soundEmitter("SoundEmitter");
|
||||
|
||||
|
|
@ -93,8 +88,6 @@ namespace Ndk
|
|||
soundEmitter.SetMethod("SetVolume", &Nz::SoundEmitter::SetVolume);
|
||||
soundEmitter.SetMethod("Stop", &Nz::SoundEmitter::Stop);
|
||||
|
||||
soundEmitter.Register(instance);
|
||||
|
||||
/*********************************** Nz::Sound **********************************/
|
||||
Nz::LuaClass<Nz::Sound> soundClass("Sound");
|
||||
soundClass.Inherit(soundEmitter);
|
||||
|
|
@ -122,7 +115,12 @@ namespace Ndk
|
|||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterAudio(Nz::LuaInstance& instance)
|
||||
{
|
||||
soundClass.Register(instance);
|
||||
soundBuffer.Register(instance);
|
||||
soundEmitter.Register(instance);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,13 @@
|
|||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <Nazara/Core.hpp>
|
||||
#include <Nazara/Lua/LuaClass.hpp>
|
||||
|
||||
#include <Nazara/Core/Hash/MD5.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaAPI::Register_Core(Nz::LuaInstance& instance)
|
||||
void LuaBinding::BindCore()
|
||||
{
|
||||
/*********************************** Nz::Clock **********************************/
|
||||
Nz::LuaClass<Nz::Clock> clockClass("Clock");
|
||||
|
||||
clockClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Clock*
|
||||
{
|
||||
int argIndex = 1;
|
||||
|
|
@ -39,12 +34,7 @@ namespace Ndk
|
|||
return 1;
|
||||
});
|
||||
|
||||
|
||||
clockClass.Register(instance);
|
||||
|
||||
/********************************* Nz::Directory ********************************/
|
||||
Nz::LuaClass<Nz::Directory> directoryClass("Directory");
|
||||
|
||||
directoryClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Directory*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
|
||||
|
|
@ -93,12 +83,7 @@ namespace Ndk
|
|||
return 1;
|
||||
});
|
||||
|
||||
|
||||
directoryClass.Register(instance);
|
||||
|
||||
/*********************************** Nz::Stream ***********************************/
|
||||
Nz::LuaClass<Nz::Stream> streamClass("Stream");
|
||||
|
||||
streamClass.SetMethod("EnableTextMode", &Nz::Stream::EnableTextMode);
|
||||
streamClass.SetMethod("Flush", &Nz::Stream::Flush);
|
||||
streamClass.SetMethod("GetCursorPos", &Nz::Stream::GetCursorPos);
|
||||
|
|
@ -139,10 +124,7 @@ namespace Ndk
|
|||
return 1;
|
||||
});
|
||||
|
||||
streamClass.Register(instance);
|
||||
|
||||
/*********************************** Nz::File ***********************************/
|
||||
Nz::LuaClass<Nz::File> fileClass("File");
|
||||
fileClass.Inherit(streamClass);
|
||||
|
||||
fileClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::File*
|
||||
|
|
@ -242,8 +224,15 @@ namespace Ndk
|
|||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterCore(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
clockClass.Register(instance);
|
||||
directoryClass.Register(instance);
|
||||
fileClass.Register(instance);
|
||||
streamClass.Register(instance);
|
||||
|
||||
// Enums
|
||||
|
||||
|
|
@ -251,9 +240,9 @@ namespace Ndk
|
|||
static_assert(Nz::CursorPosition_Max + 1 == 3, "Nz::CursorPosition has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 3);
|
||||
{
|
||||
instance.SetField("AtBegin", Nz::CursorPosition_AtBegin);
|
||||
instance.SetField("AtBegin", Nz::CursorPosition_AtBegin);
|
||||
instance.SetField("AtCurrent", Nz::CursorPosition_AtCurrent);
|
||||
instance.SetField("AtEnd", Nz::CursorPosition_AtEnd);
|
||||
instance.SetField("AtEnd", Nz::CursorPosition_AtEnd);
|
||||
}
|
||||
instance.SetGlobal("CursorPosition");
|
||||
|
||||
|
|
@ -277,13 +266,13 @@ namespace Ndk
|
|||
static_assert(Nz::OpenMode_Max + 1 == 2 * (64), "Nz::OpenModeFlags has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 8);
|
||||
{
|
||||
instance.SetField("Append", Nz::OpenMode_Append);
|
||||
instance.SetField("NotOpen", Nz::OpenMode_NotOpen);
|
||||
instance.SetField("Lock", Nz::OpenMode_Lock);
|
||||
instance.SetField("ReadOnly", Nz::OpenMode_ReadOnly);
|
||||
instance.SetField("Append", Nz::OpenMode_Append);
|
||||
instance.SetField("NotOpen", Nz::OpenMode_NotOpen);
|
||||
instance.SetField("Lock", Nz::OpenMode_Lock);
|
||||
instance.SetField("ReadOnly", Nz::OpenMode_ReadOnly);
|
||||
instance.SetField("ReadWrite", Nz::OpenMode_ReadWrite);
|
||||
instance.SetField("Text", Nz::OpenMode_Text);
|
||||
instance.SetField("Truncate", Nz::OpenMode_Truncate);
|
||||
instance.SetField("Text", Nz::OpenMode_Text);
|
||||
instance.SetField("Truncate", Nz::OpenMode_Truncate);
|
||||
instance.SetField("WriteOnly", Nz::OpenMode_WriteOnly);
|
||||
}
|
||||
instance.SetGlobal("OpenMode");
|
||||
|
|
@ -1,18 +1,16 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Lua/LuaClass.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaAPI::Register_Graphics(Nz::LuaInstance& instance)
|
||||
void LuaBinding::BindGraphics()
|
||||
{
|
||||
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable("InstancedRenderable");
|
||||
/*********************************** Nz::InstancedRenderable ***********************************/
|
||||
|
||||
Nz::LuaClass<Nz::ModelRef> modelClass("Model");
|
||||
/*********************************** Nz::Model ***********************************/
|
||||
modelClass.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::ModelRef* model) -> Nz::InstancedRenderableRef*
|
||||
{
|
||||
return reinterpret_cast<Nz::InstancedRenderableRef*>(model); //TODO: Make a ObjectRefCast
|
||||
|
|
@ -39,7 +37,10 @@ namespace Ndk
|
|||
//modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence);
|
||||
modelClass.SetMethod("SetSkin", &Nz::Model::SetSkin);
|
||||
modelClass.SetMethod("SetSkinCount", &Nz::Model::SetSkinCount);
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterGraphics(Nz::LuaInstance& instance)
|
||||
{
|
||||
instancedRenderable.Register(instance);
|
||||
modelClass.Register(instance);
|
||||
}
|
||||
|
|
@ -1,16 +1,14 @@
|
|||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <Nazara/Math.hpp>
|
||||
#include <Nazara/Lua/LuaClass.hpp>
|
||||
#include <cstring>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaAPI::Register_Math(Nz::LuaInstance& instance)
|
||||
void LuaBinding::BindMath()
|
||||
{
|
||||
/*********************************** Nz::EulerAngles **********************************/
|
||||
Nz::LuaClass<Nz::EulerAnglesd> eulerAnglesClass("EulerAngles");
|
||||
|
||||
eulerAnglesClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::EulerAnglesd*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 3U);
|
||||
|
|
@ -147,11 +145,7 @@ namespace Ndk
|
|||
return false;
|
||||
});
|
||||
|
||||
eulerAnglesClass.Register(instance);
|
||||
|
||||
/*********************************** Nz::Quaternion **********************************/
|
||||
Nz::LuaClass<Nz::Quaterniond> quaternionClass("Quaternion");
|
||||
|
||||
quaternionClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Quaterniond*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
|
|
@ -243,11 +237,7 @@ namespace Ndk
|
|||
return false;
|
||||
});
|
||||
|
||||
quaternionClass.Register(instance);
|
||||
|
||||
/*********************************** Nz::Vector2 **********************************/
|
||||
Nz::LuaClass<Nz::Vector2d> vector2dClass("Vector2");
|
||||
|
||||
vector2dClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Vector2d*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
|
@ -354,11 +344,7 @@ namespace Ndk
|
|||
return false;
|
||||
});
|
||||
|
||||
vector2dClass.Register(instance);
|
||||
|
||||
/*********************************** Nz::Vector3 **********************************/
|
||||
Nz::LuaClass<Nz::Vector3d> vector3dClass("Vector3");
|
||||
|
||||
vector3dClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Vector3d*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 3U);
|
||||
|
|
@ -484,7 +470,13 @@ namespace Ndk
|
|||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterMath(Nz::LuaInstance& instance)
|
||||
{
|
||||
eulerAnglesClass.Register(instance);
|
||||
quaternionClass.Register(instance);
|
||||
vector2dClass.Register(instance);
|
||||
vector3dClass.Register(instance);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +1,22 @@
|
|||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <Nazara/Network.hpp>
|
||||
#include <Nazara/Lua/LuaClass.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaAPI::Register_Network(Nz::LuaInstance& instance)
|
||||
void LuaBinding::BindNetwork()
|
||||
{
|
||||
/*********************************** Nz::AbstractSocket **********************************/
|
||||
Nz::LuaClass<Nz::AbstractSocket> abstractSocketClass("AbstractSocket");
|
||||
|
||||
abstractSocketClass.SetMethod("Close", &Nz::AbstractSocket::Close);
|
||||
abstractSocketClass.SetMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking);
|
||||
abstractSocketClass.SetMethod("GetLastError", &Nz::AbstractSocket::GetLastError);
|
||||
abstractSocketClass.SetMethod("GetState", &Nz::AbstractSocket::GetState);
|
||||
abstractSocketClass.SetMethod("GetType", &Nz::AbstractSocket::GetType);
|
||||
abstractSocketClass.SetMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled);
|
||||
abstractSocketClass.SetMethod("Close", &Nz::AbstractSocket::Close);
|
||||
abstractSocketClass.SetMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking);
|
||||
abstractSocketClass.SetMethod("GetLastError", &Nz::AbstractSocket::GetLastError);
|
||||
abstractSocketClass.SetMethod("GetState", &Nz::AbstractSocket::GetState);
|
||||
abstractSocketClass.SetMethod("GetType", &Nz::AbstractSocket::GetType);
|
||||
abstractSocketClass.SetMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled);
|
||||
abstractSocketClass.SetMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes);
|
||||
|
||||
abstractSocketClass.Register(instance);
|
||||
|
||||
Nz::LuaClass<Nz::IpAddress> ipAddressClass("IpAddress");
|
||||
|
||||
/*********************************** Nz::IpAddress **********************************/
|
||||
ipAddressClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::IpAddress*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 9U);
|
||||
|
|
@ -43,18 +37,18 @@ namespace Ndk
|
|||
case 8:
|
||||
case 9:
|
||||
return new Nz::IpAddress(lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex),
|
||||
lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex, 0));
|
||||
lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex, 0));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
ipAddressClass.SetMethod("GetPort", &Nz::IpAddress::GetPort);
|
||||
ipAddressClass.SetMethod("GetPort", &Nz::IpAddress::GetPort);
|
||||
ipAddressClass.SetMethod("GetProtocol", &Nz::IpAddress::GetProtocol);
|
||||
ipAddressClass.SetMethod("IsLoopback", &Nz::IpAddress::IsLoopback);
|
||||
ipAddressClass.SetMethod("IsValid", &Nz::IpAddress::IsValid);
|
||||
ipAddressClass.SetMethod("ToUInt32", &Nz::IpAddress::ToUInt32);
|
||||
ipAddressClass.SetMethod("__tostring", &Nz::IpAddress::ToString);
|
||||
ipAddressClass.SetMethod("IsLoopback", &Nz::IpAddress::IsLoopback);
|
||||
ipAddressClass.SetMethod("IsValid", &Nz::IpAddress::IsValid);
|
||||
ipAddressClass.SetMethod("ToUInt32", &Nz::IpAddress::ToUInt32);
|
||||
ipAddressClass.SetMethod("__tostring", &Nz::IpAddress::ToString);
|
||||
|
||||
ipAddressClass.SetStaticMethod("ResolveAddress", [] (Nz::LuaInstance& instance) -> int
|
||||
{
|
||||
|
|
@ -96,10 +90,10 @@ namespace Ndk
|
|||
{
|
||||
instance.PushInteger(index++);
|
||||
instance.PushTable(0, 4);
|
||||
instance.SetField("Address", std::move(info.address));
|
||||
instance.SetField("Address", std::move(info.address));
|
||||
instance.SetField("CanonicalName", std::move(info.canonicalName));
|
||||
instance.SetField("Protocol", std::move(info.protocol));
|
||||
instance.SetField("SocketType", std::move(info.socketType));
|
||||
instance.SetField("Protocol", std::move(info.protocol));
|
||||
instance.SetField("SocketType", std::move(info.socketType));
|
||||
instance.SetTable();
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +106,12 @@ namespace Ndk
|
|||
return 2;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterNetwork(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
abstractSocketClass.Register(instance);
|
||||
ipAddressClass.Register(instance);
|
||||
|
||||
// Enums
|
||||
|
|
@ -2,14 +2,16 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <Nazara/Lua/LuaClass.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaAPI::Register_Renderer(Nz::LuaInstance& instance)
|
||||
void LuaBinding::BindRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterRenderer(Nz::LuaInstance& instance)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,173 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
namespace
|
||||
{
|
||||
int AddNilComponent(Nz::LuaInstance& lua, EntityHandle&)
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
|
||||
T& component = handle->AddComponent<T>();
|
||||
lua.Push(component.CreateHandle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int PushNilComponent(Nz::LuaInstance& lua, BaseComponent&)
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
|
||||
T& rightComponent = static_cast<T&>(component);
|
||||
lua.Push(rightComponent.CreateHandle());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void LuaBinding::BindSDK()
|
||||
{
|
||||
/*********************************** Ndk::NodeComponent **********************************/
|
||||
nodeComponent.Inherit<Nz::Node>(nodeClass, [] (NodeComponentHandle* handle) -> Nz::Node*
|
||||
{
|
||||
return handle->GetObject();
|
||||
});
|
||||
|
||||
/*********************************** Ndk::Entity **********************************/
|
||||
entityClass.SetMethod("Enable", &Entity::Enable);
|
||||
entityClass.SetMethod("GetId", &Entity::GetId);
|
||||
entityClass.SetMethod("GetWorld", &Entity::GetWorld);
|
||||
entityClass.SetMethod("Kill", &Entity::Kill);
|
||||
entityClass.SetMethod("IsEnabled", &Entity::IsEnabled);
|
||||
entityClass.SetMethod("IsValid", &Entity::IsValid);
|
||||
entityClass.SetMethod("RemoveComponent", (void(Entity::*)(ComponentIndex)) &Entity::RemoveComponent);
|
||||
entityClass.SetMethod("RemoveAllComponents", &Entity::RemoveAllComponents);
|
||||
entityClass.SetMethod("__tostring", &EntityHandle::ToString);
|
||||
|
||||
entityClass.SetMethod("AddComponent", [this] (Nz::LuaInstance& lua, EntityHandle& handle) -> int
|
||||
{
|
||||
int index = 1;
|
||||
ComponentIndex componentIndex = lua.Check<ComponentIndex>(&index);
|
||||
|
||||
if (componentIndex > m_componentBinding.size())
|
||||
{
|
||||
lua.Error("Invalid component index");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ComponentBinding& binding = m_componentBinding[componentIndex];
|
||||
if (!binding.valid)
|
||||
{
|
||||
lua.Error("This component is not available to the LuaAPI");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return binding.adder(lua, handle);
|
||||
});
|
||||
|
||||
entityClass.SetMethod("GetComponent", [this] (Nz::LuaInstance& lua, EntityHandle& handle) -> int
|
||||
{
|
||||
int index = 1;
|
||||
ComponentIndex componentIndex = lua.Check<ComponentIndex>(&index);
|
||||
|
||||
if (!handle->HasComponent(componentIndex))
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (componentIndex > m_componentBinding.size())
|
||||
{
|
||||
lua.Error("Invalid component index");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ComponentBinding& binding = m_componentBinding[componentIndex];
|
||||
if (!binding.valid)
|
||||
{
|
||||
lua.Error("This component is not available to the LuaAPI");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return binding.getter(lua, handle->GetComponent(componentIndex));
|
||||
});
|
||||
|
||||
/*********************************** Ndk::World **********************************/
|
||||
worldClass.SetMethod("CreateEntity", &World::CreateEntity);
|
||||
worldClass.SetMethod("CreateEntities", &World::CreateEntities);
|
||||
worldClass.SetMethod("Clear", &World::Clear);
|
||||
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
/*********************************** Ndk::GraphicsComponent **********************************/
|
||||
graphicsComponent.SetMethod("Attach", &GraphicsComponent::Attach, 0);
|
||||
#endif
|
||||
|
||||
|
||||
// Components functions
|
||||
m_componentBinding.resize(BaseComponent::GetMaxComponentIndex() + 1);
|
||||
|
||||
EnableComponentBinding<NodeComponent>();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
EnableComponentBinding<GraphicsComponent>();
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void LuaBinding::EnableComponentBinding()
|
||||
{
|
||||
ComponentBinding binding;
|
||||
binding.adder = &AddComponentOfType<T>;
|
||||
binding.getter = &PushComponentOfType<T>;
|
||||
binding.valid = true;
|
||||
|
||||
NazaraAssert(T::componentIndex < m_componentBinding.size(), "Component index is over component binding size");
|
||||
|
||||
m_componentBinding[T::componentIndex] = std::move(binding);
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterSDK(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
entityClass.Register(instance);
|
||||
nodeComponent.Register(instance);
|
||||
worldClass.Register(instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
graphicsComponent.Register(instance);
|
||||
#endif
|
||||
|
||||
// Enums
|
||||
|
||||
// ComponentType (fake enumeration to expose component indexes)
|
||||
instance.PushTable();
|
||||
{
|
||||
#ifndef NDK_SERVER
|
||||
instance.PushInteger(GraphicsComponent::componentIndex);
|
||||
instance.SetField("Graphics");
|
||||
#endif
|
||||
|
||||
instance.PushInteger(NodeComponent::componentIndex);
|
||||
instance.SetField("Node");
|
||||
}
|
||||
instance.SetGlobal("ComponentType");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,94 +1,94 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <Nazara/Lua/LuaClass.hpp>
|
||||
#include <NDK/Components.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
namespace
|
||||
void LuaBinding::BindUtility()
|
||||
{
|
||||
int AddNilComponent(Nz::LuaInstance& lua, EntityHandle&)
|
||||
/*********************************** Nz::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));
|
||||
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
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
|
||||
T& component = handle->AddComponent<T>();
|
||||
lua.Push(component.CreateHandle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int AddComponent(Nz::LuaInstance& lua, EntityHandle& handle, ComponentIndex index)
|
||||
{
|
||||
std::vector<int(*)(Nz::LuaInstance&, EntityHandle&)> componentAdder(BaseComponent::GetMaxComponentIndex(), AddNilComponent);
|
||||
componentAdder[GraphicsComponent::componentIndex] = &AddComponentOfType<GraphicsComponent>;
|
||||
componentAdder[NodeComponent::componentIndex] = &AddComponentOfType<NodeComponent>;
|
||||
|
||||
if (index > componentAdder.size())
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
|
||||
switch (argCount)
|
||||
{
|
||||
lua.Error("Invalid component index");
|
||||
return 0;
|
||||
case 0:
|
||||
return lua.Push(abstractImage->GetMemoryUsage());
|
||||
|
||||
case 1:
|
||||
{
|
||||
int index = 1;
|
||||
Nz::UInt8 level(lua.Check<Nz::UInt8>(&index));
|
||||
|
||||
return lua.Push(abstractImage->GetMemoryUsage(level));
|
||||
}
|
||||
}
|
||||
|
||||
return componentAdder[index](lua, handle);
|
||||
}
|
||||
lua.Error("No matching overload for method GetMemoryUsage");
|
||||
return 0;
|
||||
});
|
||||
|
||||
int PushNilComponent(Nz::LuaInstance& lua, BaseComponent&)
|
||||
abstractImage.SetMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 6U);
|
||||
int argIndex = 1;
|
||||
|
||||
template<typename T>
|
||||
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
std::size_t bufferSize = 0;
|
||||
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(lua.CheckString(argIndex++, &bufferSize));
|
||||
|
||||
T& rightComponent = static_cast<T&>(component);
|
||||
lua.Push(rightComponent.CreateHandle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int PushComponent(Nz::LuaInstance& lua, BaseComponent& component)
|
||||
{
|
||||
std::vector<int(*)(Nz::LuaInstance&, BaseComponent&)> componentConverter(BaseComponent::GetMaxComponentIndex(), PushNilComponent);
|
||||
componentConverter[GraphicsComponent::componentIndex] = &PushComponentOfType<GraphicsComponent>;
|
||||
componentConverter[NodeComponent::componentIndex] = &PushComponentOfType<NodeComponent>;
|
||||
|
||||
ComponentIndex index = component.GetIndex();
|
||||
|
||||
if (index > componentConverter.size())
|
||||
if (argCount < 2 || lua.IsOfType(2, Nz::LuaType_Number))
|
||||
{
|
||||
lua.Error("Invalid component index");
|
||||
return 0;
|
||||
// bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
/* Disabled until Box and Rect have been ported
|
||||
else if (lua.IsOfType(2, "Box"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Boxui box = lua.Check<Nz::Boxui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
return componentConverter[index](lua, component);
|
||||
}
|
||||
}
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
else if (lua.IsOfType(2, "Rect"))
|
||||
{
|
||||
// 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 box = lua.Check<Nz::Rectui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
void LuaAPI::Register_SDK(Nz::LuaInstance& instance)
|
||||
{
|
||||
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent("GraphicsComponent");
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}*/
|
||||
|
||||
graphicsComponent.SetMethod("Attach", &GraphicsComponent::Attach, 0);
|
||||
|
||||
graphicsComponent.Register(instance);
|
||||
|
||||
Nz::LuaClass<Nz::Node> nodeClass("Node"); //< TODO: Move to Utility
|
||||
lua.Error("No matching overload for method Update");
|
||||
return 0;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Node **********************************/
|
||||
nodeClass.SetMethod("GetBackward", &Nz::Node::GetBackward);
|
||||
//nodeClass.SetMethod("GetChilds", &Nz::Node::GetChilds);
|
||||
nodeClass.SetMethod("GetDown", &Nz::Node::GetDown);
|
||||
|
|
@ -245,69 +245,11 @@ namespace Ndk
|
|||
lua.Error("No matching overload for method SetInitialScale");
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterUtility(Nz::LuaInstance& instance)
|
||||
{
|
||||
abstractImage.Register(instance);
|
||||
nodeClass.Register(instance);
|
||||
|
||||
Nz::LuaClass<NodeComponentHandle> nodeComponent("NodeComponent");
|
||||
nodeComponent.Inherit<Nz::Node>(nodeClass, [] (NodeComponentHandle* handle) -> Nz::Node*
|
||||
{
|
||||
return handle->GetObject();
|
||||
});
|
||||
|
||||
nodeComponent.Register(instance);
|
||||
|
||||
Nz::LuaClass<EntityHandle> entityClass("Entity");
|
||||
|
||||
entityClass.SetMethod("Enable", &Entity::Enable);
|
||||
entityClass.SetMethod("GetId", &Entity::GetId);
|
||||
entityClass.SetMethod("GetWorld", &Entity::GetWorld);
|
||||
entityClass.SetMethod("Kill", &Entity::Kill);
|
||||
entityClass.SetMethod("IsEnabled", &Entity::IsEnabled);
|
||||
entityClass.SetMethod("IsValid", &Entity::IsValid);
|
||||
entityClass.SetMethod("RemoveComponent", (void(Entity::*)(ComponentIndex)) &Entity::RemoveComponent);
|
||||
entityClass.SetMethod("RemoveAllComponents", &Entity::RemoveAllComponents);
|
||||
entityClass.SetMethod("__tostring", &EntityHandle::ToString);
|
||||
|
||||
entityClass.SetMethod("AddComponent", [] (Nz::LuaInstance& lua, EntityHandle& handle) -> int
|
||||
{
|
||||
int index = 1;
|
||||
ComponentIndex componentIndex = lua.Check<ComponentIndex>(&index);
|
||||
|
||||
return AddComponent(lua, handle, componentIndex);
|
||||
});
|
||||
|
||||
entityClass.SetMethod("GetComponent", [] (Nz::LuaInstance& lua, EntityHandle& handle) -> int
|
||||
{
|
||||
int index = 1;
|
||||
ComponentIndex componentIndex = lua.Check<ComponentIndex>(&index);
|
||||
|
||||
if (!handle->HasComponent(componentIndex))
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
return PushComponent(lua, handle->GetComponent(componentIndex));
|
||||
});
|
||||
|
||||
entityClass.Register(instance);
|
||||
|
||||
Nz::LuaClass<WorldHandle> worldClass("World");
|
||||
|
||||
worldClass.SetMethod("CreateEntity", &World::CreateEntity);
|
||||
worldClass.SetMethod("CreateEntities", &World::CreateEntities);
|
||||
worldClass.SetMethod("Clear", &World::Clear);
|
||||
|
||||
worldClass.Register(instance);
|
||||
|
||||
instance.PushTable(0, 2);
|
||||
{
|
||||
instance.PushInteger(GraphicsComponent::componentIndex);
|
||||
instance.SetField("Graphics");
|
||||
|
||||
instance.PushInteger(NodeComponent::componentIndex);
|
||||
instance.SetField("Node");
|
||||
}
|
||||
instance.SetGlobal("ComponentType");
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,8 @@ TOOL.Defines = {
|
|||
}
|
||||
|
||||
TOOL.Includes = {
|
||||
"../SDK/include"
|
||||
"../SDK/include",
|
||||
"../SDK/src"
|
||||
}
|
||||
|
||||
TOOL.Files = {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ TOOL.Defines = {
|
|||
}
|
||||
|
||||
TOOL.Includes = {
|
||||
"../SDK/include"
|
||||
"../SDK/include",
|
||||
"../SDK/src"
|
||||
}
|
||||
|
||||
TOOL.Files = {
|
||||
|
|
@ -29,9 +30,9 @@ TOOL.FilesExclusion = {
|
|||
"../SDK/**/ListenerComponent.*",
|
||||
"../SDK/**/ListenerSystem.*",
|
||||
"../SDK/**/RenderSystem.*",
|
||||
"../SDK/**/LuaAPI_Audio.*",
|
||||
"../SDK/**/LuaAPI_Graphics.*",
|
||||
"../SDK/**/LuaAPI_Renderer.*",
|
||||
"../SDK/**/LuaBinding_Audio.*",
|
||||
"../SDK/**/LuaBinding_Graphics.*",
|
||||
"../SDK/**/LuaBinding_Renderer.*"
|
||||
}
|
||||
|
||||
TOOL.Libraries = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue