From 7f143e41f891fe6689af5ce3e65f1c705debcffb Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 24 Nov 2016 22:54:48 +0100 Subject: [PATCH] SDK/Lua: Rework LuaBinding classes to try to improve compile time and binary size --- SDK/include/NDK/Console.hpp | 2 + SDK/include/NDK/LuaBinding.hpp | 113 +- SDK/include/NDK/LuaBinding.inl | 24 +- SDK/include/NDK/LuaBinding_Audio.hpp | 33 + SDK/include/NDK/LuaBinding_Base.hpp | 53 + SDK/include/NDK/LuaBinding_Core.hpp | 33 + SDK/include/NDK/LuaBinding_Graphics.hpp | 36 + SDK/include/NDK/LuaBinding_Math.hpp | 37 + SDK/include/NDK/LuaBinding_Network.hpp | 29 + SDK/include/NDK/LuaBinding_Renderer.hpp | 29 + SDK/include/NDK/LuaBinding_SDK.hpp | 42 + SDK/include/NDK/LuaBinding_Utility.hpp | 34 + SDK/src/NDK/LuaBinding.cpp | 105 +- SDK/src/NDK/LuaBinding_Audio.cpp | 295 ++-- SDK/src/NDK/LuaBinding_Base.cpp | 13 + SDK/src/NDK/LuaBinding_Core.cpp | 467 +++---- SDK/src/NDK/LuaBinding_Graphics.cpp | 589 ++++---- SDK/src/NDK/LuaBinding_Math.cpp | 1628 ++++++++++++----------- SDK/src/NDK/LuaBinding_Network.cpp | 235 ++-- SDK/src/NDK/LuaBinding_Renderer.cpp | 138 +- SDK/src/NDK/LuaBinding_SDK.cpp | 368 ++--- SDK/src/NDK/LuaBinding_Utility.cpp | 15 +- 22 files changed, 2309 insertions(+), 2009 deletions(-) create mode 100644 SDK/include/NDK/LuaBinding_Audio.hpp create mode 100644 SDK/include/NDK/LuaBinding_Base.hpp create mode 100644 SDK/include/NDK/LuaBinding_Core.hpp create mode 100644 SDK/include/NDK/LuaBinding_Graphics.hpp create mode 100644 SDK/include/NDK/LuaBinding_Math.hpp create mode 100644 SDK/include/NDK/LuaBinding_Network.hpp create mode 100644 SDK/include/NDK/LuaBinding_Renderer.hpp create mode 100644 SDK/include/NDK/LuaBinding_SDK.hpp create mode 100644 SDK/include/NDK/LuaBinding_Utility.hpp create mode 100644 SDK/src/NDK/LuaBinding_Base.cpp diff --git a/SDK/include/NDK/Console.hpp b/SDK/include/NDK/Console.hpp index 1c007065f..59a98df0d 100644 --- a/SDK/include/NDK/Console.hpp +++ b/SDK/include/NDK/Console.hpp @@ -4,6 +4,7 @@ #pragma once +#ifndef NDK_SERVER #ifndef NDK_CONSOLE_HPP #define NDK_CONSOLE_HPP @@ -99,3 +100,4 @@ namespace Ndk #include #endif // NDK_CONSOLE_HPP +#endif // NDK_SERVER diff --git a/SDK/include/NDK/LuaBinding.hpp b/SDK/include/NDK/LuaBinding.hpp index 559d6ac1f..038717e5e 100644 --- a/SDK/include/NDK/LuaBinding.hpp +++ b/SDK/include/NDK/LuaBinding.hpp @@ -7,28 +7,17 @@ #ifndef NDK_LUABINDING_HPP #define NDK_LUABINDING_HPP -#include -#include -#include -#include -#include -#include -#include +#include #include -#include -#include - -#ifndef NDK_SERVER -#include -#include -#include -#include -#endif +#include +#include namespace Ndk { class NDK_API LuaBinding { + friend class LuaBinding_SDK; + public: LuaBinding(); ~LuaBinding() = default; @@ -37,86 +26,24 @@ namespace Ndk void RegisterClasses(Nz::LuaInstance& instance); - // Core - Nz::LuaClass clock; - Nz::LuaClass directory; - Nz::LuaClass file; - Nz::LuaClass stream; - - // Math - Nz::LuaClass eulerAngles; - Nz::LuaClass matrix4d; - Nz::LuaClass quaternion; - Nz::LuaClass rect; - Nz::LuaClass vector2d; - Nz::LuaClass vector3d; - - // Network - Nz::LuaClass abstractSocket; - Nz::LuaClass ipAddress; - - // Utility - Nz::LuaClass abstractImage; - Nz::LuaClass font; - Nz::LuaClass keyboard; - Nz::LuaClass node; - - // SDK - Nz::LuaClass application; - Nz::LuaClass entity; - Nz::LuaClass nodeComponent; - Nz::LuaClass velocityComponent; - Nz::LuaClass world; + std::unique_ptr core; + std::unique_ptr math; + std::unique_ptr network; + std::unique_ptr sdk; + std::unique_ptr utility; #ifndef NDK_SERVER - // Audio - Nz::LuaClass music; - Nz::LuaClass sound; - Nz::LuaClass soundBuffer; - Nz::LuaClass soundEmitter; - - // Graphics - Nz::LuaClass abstractViewer; - Nz::LuaClass instancedRenderable; - Nz::LuaClass material; - Nz::LuaClass model; - Nz::LuaClass sprite; - Nz::LuaClass spriteLibrary; - Nz::LuaClass textureLibrary; - Nz::LuaClass textureManager; - - // Renderer - Nz::LuaClass texture; - - // SDK - Nz::LuaClass cameraComponent; - Nz::LuaClass console; - Nz::LuaClass graphicsComponent; + std::unique_ptr audio; + std::unique_ptr graphics; + std::unique_ptr renderer; #endif private: - void BindCore(); - void BindMath(); - void BindNetwork(); - void BindSDK(); - void BindUtility(); - - 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 + template + static int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle); + template + static int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component); using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&); using GetComponentFunc = int(*)(Nz::LuaInstance&, BaseComponent&); @@ -134,12 +61,6 @@ namespace Ndk std::vector m_componentBinding; std::unordered_map m_componentBindingByName; }; - - template - int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle); - - template - int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component); } #include diff --git a/SDK/include/NDK/LuaBinding.inl b/SDK/include/NDK/LuaBinding.inl index e4ae72254..15b65311d 100644 --- a/SDK/include/NDK/LuaBinding.inl +++ b/SDK/include/NDK/LuaBinding.inl @@ -32,18 +32,8 @@ namespace Ndk m_componentBindingByName[name] = T::componentIndex; } - /*! - * \brief Adds a component to an entity - * \return 1 in case of success - * - * \param instance Lua instance that will interact with the component - * \param handle Entity which component will be added to - * - * \remark T must be a subtype of BaseComponent - */ - template - int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle) + int LuaBinding::AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle) { static_assert(std::is_base_of::value, "ComponentType must inherit BaseComponent"); @@ -52,18 +42,8 @@ namespace Ndk return 1; } - /*! - * \brief Pushes a component - * \return 1 in case of success - * - * \param instance Lua instance that will interact with the component - * \param component Component that will be pushed - * - * \remark T must be a subtype of BaseComponent - */ - template - int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component) + int LuaBinding::PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component) { static_assert(std::is_base_of::value, "ComponentType must inherit BaseComponent"); diff --git a/SDK/include/NDK/LuaBinding_Audio.hpp b/SDK/include/NDK/LuaBinding_Audio.hpp new file mode 100644 index 000000000..4f6df9d10 --- /dev/null +++ b/SDK/include/NDK/LuaBinding_Audio.hpp @@ -0,0 +1,33 @@ +// 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_AUDIO_HPP +#define NDK_LUABINDING_AUDIO_HPP + +#include +#include +#include +#include +#include + +namespace Ndk +{ + class NDK_API LuaBinding_Audio : public LuaBinding_Base + { + public: + LuaBinding_Audio(LuaBinding& binding); + ~LuaBinding_Audio() = default; + + void Register(Nz::LuaInstance& instance) override; + + Nz::LuaClass music; + Nz::LuaClass sound; + Nz::LuaClass soundBuffer; + Nz::LuaClass soundEmitter; + }; +} + +#endif // NDK_LUABINDING_CORE_HPP diff --git a/SDK/include/NDK/LuaBinding_Base.hpp b/SDK/include/NDK/LuaBinding_Base.hpp new file mode 100644 index 000000000..29c486835 --- /dev/null +++ b/SDK/include/NDK/LuaBinding_Base.hpp @@ -0,0 +1,53 @@ +// 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_BASE_HPP +#define NDK_LUABINDING_BASE_HPP + +#include +#include +#include + +namespace Ndk +{ + class LuaBinding; + + class LuaBinding_Audio; + class LuaBinding_Core; + class LuaBinding_Graphics; + class LuaBinding_Math; + class LuaBinding_Network; + class LuaBinding_Renderer; + class LuaBinding_SDK; + class LuaBinding_Utility; + + class NDK_API LuaBinding_Base + { + public: + LuaBinding_Base(LuaBinding& binding); + virtual ~LuaBinding_Base(); + + virtual void Register(Nz::LuaInstance& instance) = 0; + + // Implementation lies in the respective .cpp files (still searching for a cleaner way..) + static std::unique_ptr BindCore(LuaBinding& binding); + static std::unique_ptr BindMath(LuaBinding& binding); + static std::unique_ptr BindNetwork(LuaBinding& binding); + static std::unique_ptr BindSDK(LuaBinding& binding); + static std::unique_ptr BindUtility(LuaBinding& binding); + + #ifndef NDK_SERVER + static std::unique_ptr BindAudio(LuaBinding& binding); + static std::unique_ptr BindGraphics(LuaBinding& binding); + static std::unique_ptr BindRenderer(LuaBinding& binding); + #endif + + protected: + LuaBinding& m_binding; + }; +} + +#endif // NDK_LUABINDING_BASE_HPP diff --git a/SDK/include/NDK/LuaBinding_Core.hpp b/SDK/include/NDK/LuaBinding_Core.hpp new file mode 100644 index 000000000..93ad22eac --- /dev/null +++ b/SDK/include/NDK/LuaBinding_Core.hpp @@ -0,0 +1,33 @@ +// 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_CORE_HPP +#define NDK_LUABINDING_CORE_HPP + +#include +#include +#include +#include +#include + +namespace Ndk +{ + class NDK_API LuaBinding_Core : public LuaBinding_Base + { + public: + LuaBinding_Core(LuaBinding& binding); + ~LuaBinding_Core() = default; + + void Register(Nz::LuaInstance& instance) override; + + Nz::LuaClass clock; + Nz::LuaClass directory; + Nz::LuaClass file; + Nz::LuaClass stream; + }; +} + +#endif // NDK_LUABINDING_CORE_HPP diff --git a/SDK/include/NDK/LuaBinding_Graphics.hpp b/SDK/include/NDK/LuaBinding_Graphics.hpp new file mode 100644 index 000000000..328e2a9b0 --- /dev/null +++ b/SDK/include/NDK/LuaBinding_Graphics.hpp @@ -0,0 +1,36 @@ +// 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_GRAPHICS_HPP +#define NDK_LUABINDING_GRAPHICS_HPP + +#include +#include +#include +#include +#include +#include + +namespace Ndk +{ + class NDK_API LuaBinding_Graphics : public LuaBinding_Base + { + public: + LuaBinding_Graphics(LuaBinding& binding); + ~LuaBinding_Graphics() = default; + + void Register(Nz::LuaInstance& instance) override; + + Nz::LuaClass abstractViewer; + Nz::LuaClass instancedRenderable; + Nz::LuaClass material; + Nz::LuaClass model; + Nz::LuaClass sprite; + Nz::LuaClass spriteLibrary; + }; +} + +#endif // NDK_LUABINDING_GRAPHICS_HPP diff --git a/SDK/include/NDK/LuaBinding_Math.hpp b/SDK/include/NDK/LuaBinding_Math.hpp new file mode 100644 index 000000000..ac8ca46c0 --- /dev/null +++ b/SDK/include/NDK/LuaBinding_Math.hpp @@ -0,0 +1,37 @@ +// 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_MATH_HPP +#define NDK_LUABINDING_MATH_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace Ndk +{ + class NDK_API LuaBinding_Math : public LuaBinding_Base + { + public: + LuaBinding_Math(LuaBinding& binding); + ~LuaBinding_Math() = default; + + void Register(Nz::LuaInstance& instance) override; + + Nz::LuaClass eulerAngles; + Nz::LuaClass matrix4d; + Nz::LuaClass quaternion; + Nz::LuaClass rect; + Nz::LuaClass vector2d; + Nz::LuaClass vector3d; + }; +} + +#endif // NDK_LUABINDING_MATH_HPP diff --git a/SDK/include/NDK/LuaBinding_Network.hpp b/SDK/include/NDK/LuaBinding_Network.hpp new file mode 100644 index 000000000..4d2ea53f1 --- /dev/null +++ b/SDK/include/NDK/LuaBinding_Network.hpp @@ -0,0 +1,29 @@ +// 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_NETWORK_HPP +#define NDK_LUABINDING_NETWORK_HPP + +#include +#include +#include + +namespace Ndk +{ + class NDK_API LuaBinding_Network : public LuaBinding_Base + { + public: + LuaBinding_Network(LuaBinding& binding); + ~LuaBinding_Network() = default; + + void Register(Nz::LuaInstance& instance) override; + + Nz::LuaClass abstractSocket; + Nz::LuaClass ipAddress; + }; +} + +#endif // NDK_LUABINDING_NETWORK_HPP diff --git a/SDK/include/NDK/LuaBinding_Renderer.hpp b/SDK/include/NDK/LuaBinding_Renderer.hpp new file mode 100644 index 000000000..ee8a88836 --- /dev/null +++ b/SDK/include/NDK/LuaBinding_Renderer.hpp @@ -0,0 +1,29 @@ +// 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_RENDERER_HPP +#define NDK_LUABINDING_RENDERER_HPP + +#include +#include + +namespace Ndk +{ + class NDK_API LuaBinding_Renderer : public LuaBinding_Base + { + public: + LuaBinding_Renderer(LuaBinding& binding); + ~LuaBinding_Renderer() = default; + + void Register(Nz::LuaInstance& instance) override; + + Nz::LuaClass texture; + Nz::LuaClass textureLibrary; + Nz::LuaClass textureManager; + }; +} + +#endif // NDK_LUABINDING_RENDERER_HPP diff --git a/SDK/include/NDK/LuaBinding_SDK.hpp b/SDK/include/NDK/LuaBinding_SDK.hpp new file mode 100644 index 000000000..a0c64290e --- /dev/null +++ b/SDK/include/NDK/LuaBinding_SDK.hpp @@ -0,0 +1,42 @@ +// 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_SDK_HPP +#define NDK_LUABINDING_SDK_HPP + +#include +#include +#include +#include + +namespace Ndk +{ + class Application; + + class NDK_API LuaBinding_SDK : public LuaBinding_Base + { + public: + LuaBinding_SDK(LuaBinding& binding); + ~LuaBinding_SDK() = default; + + void Register(Nz::LuaInstance& instance) override; + + Nz::LuaClass application; + Nz::LuaClass entity; + Nz::LuaClass nodeComponent; + Nz::LuaClass velocityComponent; + Nz::LuaClass world; + + #ifndef NDK_SERVER + Nz::LuaClass cameraComponent; + Nz::LuaClass console; + Nz::LuaClass graphicsComponent; + #endif + + }; +} + +#endif // NDK_LUABINDING_SDK_HPP diff --git a/SDK/include/NDK/LuaBinding_Utility.hpp b/SDK/include/NDK/LuaBinding_Utility.hpp new file mode 100644 index 000000000..196763d87 --- /dev/null +++ b/SDK/include/NDK/LuaBinding_Utility.hpp @@ -0,0 +1,34 @@ +// 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_UTILITY_HPP +#define NDK_LUABINDING_UTILITY_HPP + +#include +#include +#include +#include +#include + +namespace Ndk +{ + class NDK_API LuaBinding_Utility : public LuaBinding_Base + { + public: + LuaBinding_Utility(LuaBinding& binding); + ~LuaBinding_Utility() = default; + + void Register(Nz::LuaInstance& instance) override; + + // Utility + Nz::LuaClass abstractImage; + Nz::LuaClass font; + Nz::LuaClass keyboard; + Nz::LuaClass node; + }; +} + +#endif // NDK_LUABINDING_UTILITY_HPP diff --git a/SDK/src/NDK/LuaBinding.cpp b/SDK/src/NDK/LuaBinding.cpp index 9b990bdfd..1dc1699b4 100644 --- a/SDK/src/NDK/LuaBinding.cpp +++ b/SDK/src/NDK/LuaBinding.cpp @@ -14,76 +14,18 @@ namespace Ndk * \brief Binds modules to Lua */ - LuaBinding::LuaBinding() : - // Core - clock("Clock"), - directory("Directory"), - file("File"), - stream("Stream"), - - // Math - eulerAngles("EulerAngles"), - matrix4d("Matrix4"), - quaternion("Quaternion"), - rect("Rect"), - vector2d("Vector2"), - vector3d("Vector3"), - - // Network - abstractSocket("AbstractSocket"), - ipAddress("IpAddress"), - - // Utility - abstractImage("AbstractImage"), - font("Font"), - keyboard("Keyboard"), - node("Node"), - - // SDK - application("Application"), - entity("Entity"), - nodeComponent("NodeComponent"), - velocityComponent("VelocityComponent"), - world("World") - - #ifndef NDK_SERVER - , - - // Audio - music("Music"), - sound("Sound"), - soundBuffer("SoundBuffer"), - soundEmitter("SoundEmitter"), - - // Graphics - abstractViewer("AbstractViewer"), - instancedRenderable("InstancedRenderable"), - material("Material"), - model("Model"), - sprite("Sprite"), - spriteLibrary("SpriteLibrary"), - textureLibrary("TextureLibrary"), - textureManager("TextureManager"), - - // Renderer - texture("Texture"), - - // SDK - cameraComponent("CameraComponent"), - console("Console"), - graphicsComponent("GraphicsComponent") - #endif + LuaBinding::LuaBinding() { - BindCore(); - BindMath(); - BindNetwork(); - BindSDK(); - BindUtility(); + core = LuaBinding_Base::BindCore(*this); + math = LuaBinding_Base::BindMath(*this); + network = LuaBinding_Base::BindNetwork(*this); + sdk = LuaBinding_Base::BindSDK(*this); + utility = LuaBinding_Base::BindUtility(*this); #ifndef NDK_SERVER - BindAudio(); - BindGraphics(); - BindRenderer(); + audio = LuaBinding_Base::BindAudio(*this); + graphics = LuaBinding_Base::BindGraphics(*this); + renderer = LuaBinding_Base::BindRenderer(*this); #endif } @@ -95,16 +37,29 @@ namespace Ndk void LuaBinding::RegisterClasses(Nz::LuaInstance& instance) { - RegisterCore(instance); - RegisterMath(instance); - RegisterNetwork(instance); - RegisterSDK(instance); - RegisterUtility(instance); + core->Register(instance); + math->Register(instance); + network->Register(instance); + sdk->Register(instance); + utility->Register(instance); #ifndef NDK_SERVER - RegisterAudio(instance); - RegisterGraphics(instance); - RegisterRenderer(instance); + audio->Register(instance); + graphics->Register(instance); + renderer->Register(instance); #endif + + // ComponentType (fake enumeration to expose component indexes) + instance.PushTable(0, m_componentBinding.size()); + { + for (const ComponentBinding& entry : m_componentBinding) + { + if (entry.name.IsEmpty()) + continue; + + instance.PushField(entry.name, entry.index); + } + } + instance.SetGlobal("ComponentType"); } } diff --git a/SDK/src/NDK/LuaBinding_Audio.cpp b/SDK/src/NDK/LuaBinding_Audio.cpp index 60f504939..06ec7e207 100644 --- a/SDK/src/NDK/LuaBinding_Audio.cpp +++ b/SDK/src/NDK/LuaBinding_Audio.cpp @@ -1,172 +1,186 @@ // This file was automatically generated on 26 May 2014 at 01:05:31 -#include +#include #include #include namespace Ndk { - /*! - * \brief Binds Audio module to Lua - */ + std::unique_ptr LuaBinding_Base::BindAudio(LuaBinding& binding) + { + return std::make_unique(binding); + } - void LuaBinding::BindAudio() + LuaBinding_Audio::LuaBinding_Audio(LuaBinding& binding) : + LuaBinding_Base(binding) { /*********************************** Nz::Music **********************************/ - music.Inherit(soundEmitter); - - music.BindDefaultConstructor(); - - //musicClass.SetMethod("Create", &Nz::Music::Create); - //musicClass.SetMethod("Destroy", &Nz::Music::Destroy); - - music.BindMethod("EnableLooping", &Nz::Music::EnableLooping); - - music.BindMethod("GetDuration", &Nz::Music::GetDuration); - music.BindMethod("GetFormat", &Nz::Music::GetFormat); - music.BindMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset); - music.BindMethod("GetSampleCount", &Nz::Music::GetSampleCount); - music.BindMethod("GetSampleRate", &Nz::Music::GetSampleRate); - music.BindMethod("GetStatus", &Nz::Music::GetStatus); - - music.BindMethod("IsLooping", &Nz::Music::IsLooping); - - music.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams()); - - music.BindMethod("Pause", &Nz::Music::Pause); - music.BindMethod("Play", &Nz::Music::Play); - - music.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset); - - music.BindMethod("Stop", &Nz::Music::Stop); - - // Manual - music.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& instance, std::size_t /*argumentCount*/) -> int + music.Reset("Music"); { - Nz::StringStream ss("Music("); - ss << instance.GetFilePath() << ')'; + music.Inherit(soundEmitter); - lua.PushString(ss); - return 1; - }); + music.BindDefaultConstructor(); + + //musicClass.SetMethod("Create", &Nz::Music::Create); + //musicClass.SetMethod("Destroy", &Nz::Music::Destroy); + + music.BindMethod("EnableLooping", &Nz::Music::EnableLooping); + + music.BindMethod("GetDuration", &Nz::Music::GetDuration); + music.BindMethod("GetFormat", &Nz::Music::GetFormat); + music.BindMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset); + music.BindMethod("GetSampleCount", &Nz::Music::GetSampleCount); + music.BindMethod("GetSampleRate", &Nz::Music::GetSampleRate); + music.BindMethod("GetStatus", &Nz::Music::GetStatus); + + music.BindMethod("IsLooping", &Nz::Music::IsLooping); + + music.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams()); + + music.BindMethod("Pause", &Nz::Music::Pause); + music.BindMethod("Play", &Nz::Music::Play); + + music.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset); + + music.BindMethod("Stop", &Nz::Music::Stop); + + // Manual + music.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& instance, std::size_t /*argumentCount*/) -> int + { + Nz::StringStream ss("Music("); + ss << instance.GetFilePath() << ')'; + + lua.PushString(ss); + return 1; + }); + } /*********************************** Nz::Sound **********************************/ - sound.Inherit(soundEmitter); - - sound.BindDefaultConstructor(); - - sound.BindMethod("GetBuffer", &Nz::Sound::GetBuffer); - - sound.BindMethod("IsPlayable", &Nz::Sound::IsPlayable); - sound.BindMethod("IsPlaying", &Nz::Sound::IsPlaying); - - sound.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams()); - - sound.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset); - - // Manual - sound.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& instance, std::size_t /*argumentCount*/) -> int + sound.Reset("Sound"); { - Nz::StringStream ss("Sound("); - if (const Nz::SoundBuffer* buffer = instance.GetBuffer()) - ss << buffer; + sound.Inherit(soundEmitter); - ss << ')'; + sound.BindDefaultConstructor(); - lua.PushString(ss); - return 1; - }); + sound.BindMethod("GetBuffer", &Nz::Sound::GetBuffer); + + sound.BindMethod("IsPlayable", &Nz::Sound::IsPlayable); + sound.BindMethod("IsPlaying", &Nz::Sound::IsPlaying); + + sound.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams()); + + sound.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset); + + // Manual + sound.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& instance, std::size_t /*argumentCount*/) -> int + { + Nz::StringStream ss("Sound("); + if (const Nz::SoundBuffer* buffer = instance.GetBuffer()) + ss << buffer; + + ss << ')'; + + lua.PushString(ss); + return 1; + }); + } /*********************************** Nz::SoundBuffer **********************************/ - soundBuffer.SetConstructor([] (Nz::LuaInstance& lua, Nz::SoundBufferRef* instance, std::size_t argumentCount) + soundBuffer.Reset("SoundBuffer"); { - NazaraUnused(lua); - NazaraUnused(argumentCount); - - Nz::PlacementNew(instance, Nz::SoundBuffer::New()); - return true; - }); - - soundBuffer.BindMethod("Destroy", &Nz::SoundBuffer::Destroy); - - soundBuffer.BindMethod("GetDuration", &Nz::SoundBuffer::GetDuration); - soundBuffer.BindMethod("GetFormat", &Nz::SoundBuffer::GetFormat); - soundBuffer.BindMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount); - soundBuffer.BindMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate); - - soundBuffer.BindMethod("IsValid", &Nz::SoundBuffer::IsValid); - - soundBuffer.BindMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams()); - - soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported); - - // Manual - soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int - { - int index = 2; - Nz::AudioFormat format = lua.Check(&index); - unsigned int sampleCount = lua.Check(&index); - unsigned int sampleRate = lua.Check(&index); - - std::size_t bufferSize = 0; - const char* buffer = lua.CheckString(index, &bufferSize); - lua.ArgCheck(buffer && bufferSize >= sampleCount * sizeof(Nz::Int16), index, "Invalid buffer"); - - lua.PushBoolean(instance->Create(format, sampleCount, sampleRate, reinterpret_cast(buffer))); - return 1; - }); - - soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int - { - lua.PushString(reinterpret_cast(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16)); - return 1; - }); - - soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int - { - Nz::StringStream ss("SoundBuffer("); - if (instance->IsValid()) + soundBuffer.SetConstructor([] (Nz::LuaInstance& lua, Nz::SoundBufferRef* instance, std::size_t argumentCount) { - Nz::String filePath = instance->GetFilePath(); - if (!filePath.IsEmpty()) - ss << "File: " << filePath << ", "; + NazaraUnused(lua); + NazaraUnused(argumentCount); - ss << "Duration: " << instance->GetDuration() / 1000.f << "s"; - } - ss << ')'; + Nz::PlacementNew(instance, Nz::SoundBuffer::New()); + return true; + }); - lua.PushString(ss); - return 1; - }); + soundBuffer.BindMethod("Destroy", &Nz::SoundBuffer::Destroy); + + soundBuffer.BindMethod("GetDuration", &Nz::SoundBuffer::GetDuration); + soundBuffer.BindMethod("GetFormat", &Nz::SoundBuffer::GetFormat); + soundBuffer.BindMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount); + soundBuffer.BindMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate); + + soundBuffer.BindMethod("IsValid", &Nz::SoundBuffer::IsValid); + + soundBuffer.BindMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams()); + + soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported); + + // Manual + soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int + { + int index = 2; + Nz::AudioFormat format = lua.Check(&index); + unsigned int sampleCount = lua.Check(&index); + unsigned int sampleRate = lua.Check(&index); + + std::size_t bufferSize = 0; + const char* buffer = lua.CheckString(index, &bufferSize); + lua.ArgCheck(buffer && bufferSize >= sampleCount * sizeof(Nz::Int16), index, "Invalid buffer"); + + lua.PushBoolean(instance->Create(format, sampleCount, sampleRate, reinterpret_cast(buffer))); + return 1; + }); + + soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int + { + lua.PushString(reinterpret_cast(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16)); + return 1; + }); + + soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int + { + Nz::StringStream ss("SoundBuffer("); + if (instance->IsValid()) + { + Nz::String filePath = instance->GetFilePath(); + if (!filePath.IsEmpty()) + ss << "File: " << filePath << ", "; + + ss << "Duration: " << instance->GetDuration() / 1000.f << "s"; + } + ss << ')'; + + lua.PushString(ss); + return 1; + }); + } /*********************************** Nz::SoundEmitter **********************************/ - soundEmitter.BindMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping); - soundEmitter.BindMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization); + soundEmitter.Reset("SoundEmitter"); + { + soundEmitter.BindMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping); + soundEmitter.BindMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization); - soundEmitter.BindMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation); - soundEmitter.BindMethod("GetDuration", &Nz::SoundEmitter::GetDuration); - soundEmitter.BindMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance); - soundEmitter.BindMethod("GetPitch", &Nz::SoundEmitter::GetPitch); - soundEmitter.BindMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset); - soundEmitter.BindMethod("GetPosition", &Nz::Sound::GetPosition); - soundEmitter.BindMethod("GetStatus", &Nz::SoundEmitter::GetStatus); - soundEmitter.BindMethod("GetVelocity", &Nz::Sound::GetVelocity); - soundEmitter.BindMethod("GetVolume", &Nz::SoundEmitter::GetVolume); + soundEmitter.BindMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation); + soundEmitter.BindMethod("GetDuration", &Nz::SoundEmitter::GetDuration); + soundEmitter.BindMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance); + soundEmitter.BindMethod("GetPitch", &Nz::SoundEmitter::GetPitch); + soundEmitter.BindMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset); + soundEmitter.BindMethod("GetPosition", &Nz::Sound::GetPosition); + soundEmitter.BindMethod("GetStatus", &Nz::SoundEmitter::GetStatus); + soundEmitter.BindMethod("GetVelocity", &Nz::Sound::GetVelocity); + soundEmitter.BindMethod("GetVolume", &Nz::SoundEmitter::GetVolume); - soundEmitter.BindMethod("IsLooping", &Nz::SoundEmitter::IsLooping); - soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized); + soundEmitter.BindMethod("IsLooping", &Nz::SoundEmitter::IsLooping); + soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized); - soundEmitter.BindMethod("Pause", &Nz::SoundEmitter::Pause); - soundEmitter.BindMethod("Play", &Nz::SoundEmitter::Play); + soundEmitter.BindMethod("Pause", &Nz::SoundEmitter::Pause); + soundEmitter.BindMethod("Play", &Nz::SoundEmitter::Play); - soundEmitter.BindMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation); - soundEmitter.BindMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance); - soundEmitter.BindMethod("SetPitch", &Nz::SoundEmitter::SetPitch); - soundEmitter.BindMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition); - soundEmitter.BindMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity); - soundEmitter.BindMethod("SetVolume", &Nz::SoundEmitter::SetVolume); + soundEmitter.BindMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation); + soundEmitter.BindMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance); + soundEmitter.BindMethod("SetPitch", &Nz::SoundEmitter::SetPitch); + soundEmitter.BindMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition); + soundEmitter.BindMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity); + soundEmitter.BindMethod("SetVolume", &Nz::SoundEmitter::SetVolume); - soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop); + soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop); + } } /*! @@ -174,8 +188,7 @@ namespace Ndk * * \param instance Lua instance that will interact with the Audio classes */ - - void LuaBinding::RegisterAudio(Nz::LuaInstance& instance) + void LuaBinding_Audio::Register(Nz::LuaInstance& instance) { music.Register(instance); sound.Register(instance); diff --git a/SDK/src/NDK/LuaBinding_Base.cpp b/SDK/src/NDK/LuaBinding_Base.cpp new file mode 100644 index 000000000..daa8b99bd --- /dev/null +++ b/SDK/src/NDK/LuaBinding_Base.cpp @@ -0,0 +1,13 @@ +// This file was automatically generated on 26 May 2014 at 01:05:31 + +#include + +namespace Ndk +{ + LuaBinding_Base::LuaBinding_Base(LuaBinding& binding) : + m_binding(binding) + { + } + + LuaBinding_Base::~LuaBinding_Base() = default; +} diff --git a/SDK/src/NDK/LuaBinding_Core.cpp b/SDK/src/NDK/LuaBinding_Core.cpp index 3108e1a52..b49e7e87c 100644 --- a/SDK/src/NDK/LuaBinding_Core.cpp +++ b/SDK/src/NDK/LuaBinding_Core.cpp @@ -1,284 +1,298 @@ // This file was automatically generated on 26 May 2014 at 01:05:31 -#include +#include #include #include namespace Ndk { - /*! - * \brief Binds Core module to Lua - */ + std::unique_ptr LuaBinding_Base::BindCore(LuaBinding& binding) + { + return std::make_unique(binding); + } - void LuaBinding::BindCore() + LuaBinding_Core::LuaBinding_Core(LuaBinding& binding) : + LuaBinding_Base(binding) { /*********************************** Nz::Clock **********************************/ - clock.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* instance, std::size_t argumentCount) + clock.Reset("Clock"); { - std::size_t argCount = std::min(argumentCount, 2U); - - int argIndex = 2; - switch (argCount) + clock.SetConstructor([] (Nz::LuaInstance& lua, Nz::Clock* instance, std::size_t argumentCount) { - case 0: - Nz::PlacementNew(instance); - return true; + std::size_t argCount = std::min(argumentCount, 2U); - case 1: + int argIndex = 2; + switch (argCount) { - Nz::Int64 startingValue = lua.Check(&argIndex, 0); + case 0: + Nz::PlacementNew(instance); + return true; - Nz::PlacementNew(instance, startingValue); - return true; + case 1: + { + Nz::Int64 startingValue = lua.Check(&argIndex, 0); + + Nz::PlacementNew(instance, startingValue); + return true; + } + + case 2: + { + Nz::Int64 startingValue = lua.Check(&argIndex, 0); + bool paused = lua.Check(&argIndex, false); + + Nz::PlacementNew(instance, startingValue, paused); + return true; + } } - case 2: - { - Nz::Int64 startingValue = lua.Check(&argIndex, 0); - bool paused = lua.Check(&argIndex, false); + lua.Error("No matching overload for Clock constructor"); + return false; + }); - Nz::PlacementNew(instance, startingValue, paused); - return true; - } - } + clock.BindMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds); + clock.BindMethod("GetMilliseconds", &Nz::Clock::GetMilliseconds); + clock.BindMethod("GetSeconds", &Nz::Clock::GetSeconds); + clock.BindMethod("IsPaused", &Nz::Clock::IsPaused); + clock.BindMethod("Pause", &Nz::Clock::Pause); + clock.BindMethod("Restart", &Nz::Clock::Restart); + clock.BindMethod("Unpause", &Nz::Clock::Unpause); - lua.Error("No matching overload for Clock constructor"); - return false; - }); + // Manual + clock.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& instance, std::size_t /*argumentCount*/) -> int { + Nz::StringStream ss("Clock(Elapsed: "); + ss << instance.GetSeconds(); + ss << "s, Paused: "; + ss << instance.IsPaused(); + ss << ')'; - clock.BindMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds); - clock.BindMethod("GetMilliseconds", &Nz::Clock::GetMilliseconds); - clock.BindMethod("GetSeconds", &Nz::Clock::GetSeconds); - clock.BindMethod("IsPaused", &Nz::Clock::IsPaused); - clock.BindMethod("Pause", &Nz::Clock::Pause); - clock.BindMethod("Restart", &Nz::Clock::Restart); - clock.BindMethod("Unpause", &Nz::Clock::Unpause); - - // Manual - clock.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& instance, std::size_t /*argumentCount*/) -> int { - Nz::StringStream ss("Clock(Elapsed: "); - ss << instance.GetSeconds(); - ss << "s, Paused: "; - ss << instance.IsPaused(); - ss << ')'; - - lua.PushString(ss); - return 1; - }); + lua.PushString(ss); + return 1; + }); + } /********************************* Nz::Directory ********************************/ - directory.SetConstructor([](Nz::LuaInstance& lua, Nz::Directory* instance, std::size_t argumentCount) + directory.Reset("Directory"); { - std::size_t argCount = std::min(argumentCount, 1U); - - int argIndex = 2; - switch (argCount) + directory.SetConstructor([] (Nz::LuaInstance& lua, Nz::Directory* instance, std::size_t argumentCount) { - case 0: - Nz::PlacementNew(instance); - return true; + std::size_t argCount = std::min(argumentCount, 1U); - case 1: - Nz::PlacementNew(instance, lua.Check(&argIndex)); - return true; - } + int argIndex = 2; + switch (argCount) + { + case 0: + Nz::PlacementNew(instance); + return true; - return false; - }); + case 1: + Nz::PlacementNew(instance, lua.Check(&argIndex)); + return true; + } - directory.BindMethod("Close", &Nz::Directory::Close); - directory.BindMethod("Exists", &Nz::Directory::Exists); - directory.BindMethod("GetPath", &Nz::Directory::GetPath); - directory.BindMethod("GetPattern", &Nz::Directory::GetPattern); - directory.BindMethod("GetResultName", &Nz::Directory::GetResultName); - directory.BindMethod("GetResultPath", &Nz::Directory::GetResultPath); - directory.BindMethod("GetResultSize", &Nz::Directory::GetResultSize); - directory.BindMethod("IsOpen", &Nz::Directory::IsOpen); - directory.BindMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory); - directory.BindMethod("NextResult", &Nz::Directory::NextResult, true); - directory.BindMethod("Open", &Nz::Directory::Open); - directory.BindMethod("SetPath", &Nz::Directory::SetPath); - directory.BindMethod("SetPattern", &Nz::Directory::SetPattern); + return false; + }); - directory.BindStaticMethod("Copy", Nz::Directory::Copy); - directory.BindStaticMethod("Create", Nz::Directory::Create); - directory.BindStaticMethod("Exists", Nz::Directory::Exists); - directory.BindStaticMethod("GetCurrent", Nz::Directory::GetCurrent); - directory.BindStaticMethod("Remove", Nz::Directory::Remove); - directory.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent); + directory.BindMethod("Close", &Nz::Directory::Close); + directory.BindMethod("Exists", &Nz::Directory::Exists); + directory.BindMethod("GetPath", &Nz::Directory::GetPath); + directory.BindMethod("GetPattern", &Nz::Directory::GetPattern); + directory.BindMethod("GetResultName", &Nz::Directory::GetResultName); + directory.BindMethod("GetResultPath", &Nz::Directory::GetResultPath); + directory.BindMethod("GetResultSize", &Nz::Directory::GetResultSize); + directory.BindMethod("IsOpen", &Nz::Directory::IsOpen); + directory.BindMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory); + directory.BindMethod("NextResult", &Nz::Directory::NextResult, true); + directory.BindMethod("Open", &Nz::Directory::Open); + directory.BindMethod("SetPath", &Nz::Directory::SetPath); + directory.BindMethod("SetPattern", &Nz::Directory::SetPattern); - // Manual - directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& instance, std::size_t /*argumentCount*/) -> int { - Nz::StringStream ss("Directory("); - ss << instance.GetPath(); - ss << ')'; + directory.BindStaticMethod("Copy", Nz::Directory::Copy); + directory.BindStaticMethod("Create", Nz::Directory::Create); + directory.BindStaticMethod("Exists", Nz::Directory::Exists); + directory.BindStaticMethod("GetCurrent", Nz::Directory::GetCurrent); + directory.BindStaticMethod("Remove", Nz::Directory::Remove); + directory.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent); - lua.PushString(ss); - return 1; - }); + // Manual + directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& instance, std::size_t /*argumentCount*/) -> int { + Nz::StringStream ss("Directory("); + ss << instance.GetPath(); + ss << ')'; - /*********************************** Nz::Stream ***********************************/ - stream.BindMethod("EnableTextMode", &Nz::Stream::EnableTextMode); - stream.BindMethod("Flush", &Nz::Stream::Flush); - stream.BindMethod("GetCursorPos", &Nz::Stream::GetCursorPos); - stream.BindMethod("GetDirectory", &Nz::Stream::GetDirectory); - stream.BindMethod("GetPath", &Nz::Stream::GetPath); - stream.BindMethod("GetOpenMode", &Nz::Stream::GetOpenMode); - stream.BindMethod("GetStreamOptions", &Nz::Stream::GetStreamOptions); - stream.BindMethod("GetSize", &Nz::Stream::GetSize); - stream.BindMethod("ReadLine", &Nz::Stream::ReadLine, 0U); - stream.BindMethod("IsReadable", &Nz::Stream::IsReadable); - stream.BindMethod("IsSequential", &Nz::Stream::IsSequential); - stream.BindMethod("IsTextModeEnabled", &Nz::Stream::IsTextModeEnabled); - stream.BindMethod("IsWritable", &Nz::Stream::IsWritable); - stream.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos); - - stream.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int { - int argIndex = 2; - - std::size_t length = lua.Check(&argIndex); - - std::unique_ptr buffer(new char[length]); - std::size_t readLength = instance.Read(buffer.get(), length); - - lua.PushString(Nz::String(buffer.get(), readLength)); - return 1; - }); - - stream.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int { - int argIndex = 2; - - std::size_t bufferSize = 0; - const char* buffer = lua.CheckString(argIndex, &bufferSize); - - if (instance.IsTextModeEnabled()) - lua.Push(instance.Write(Nz::String(buffer, bufferSize))); - else - lua.Push(instance.Write(buffer, bufferSize)); - return 1; - }); + lua.PushString(ss); + return 1; + }); + } /*********************************** Nz::File ***********************************/ - file.Inherit(stream); - - file.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* instance, std::size_t argumentCount) + file.Reset("Stream"); { - std::size_t argCount = std::min(argumentCount, 1U); + file.Inherit(stream); - int argIndex = 2; - switch (argCount) + file.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* instance, std::size_t argumentCount) { - case 0: - Nz::PlacementNew(instance); - return true; + std::size_t argCount = std::min(argumentCount, 1U); - case 1: + int argIndex = 2; + switch (argCount) { - Nz::String filePath = lua.Check(&argIndex); + case 0: + Nz::PlacementNew(instance); + return true; - Nz::PlacementNew(instance, filePath); - return true; + case 1: + { + Nz::String filePath = lua.Check(&argIndex); + + Nz::PlacementNew(instance, filePath); + return true; + } + + case 2: + { + Nz::String filePath = lua.Check(&argIndex); + Nz::UInt32 openMode = lua.Check(&argIndex); + + Nz::PlacementNew(instance, filePath, openMode); + return true; + } } - case 2: + lua.Error("No matching overload for File constructor"); + return false; + }); + + file.BindMethod("Close", &Nz::File::Close); + file.BindMethod("Copy", &Nz::File::Copy); + file.BindMethod("Delete", &Nz::File::Delete); + file.BindMethod("EndOfFile", &Nz::File::EndOfFile); + file.BindMethod("Exists", &Nz::File::Exists); + file.BindMethod("GetCreationTime", &Nz::File::GetCreationTime); + file.BindMethod("GetFileName", &Nz::File::GetFileName); + file.BindMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime); + file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); + file.BindMethod("IsOpen", &Nz::File::IsOpen); + file.BindMethod("Rename", &Nz::File::GetLastWriteTime); + file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); + file.BindMethod("SetFile", &Nz::File::GetLastWriteTime); + + file.BindStaticMethod("AbsolutePath", &Nz::File::AbsolutePath); + file.BindStaticMethod("ComputeHash", (Nz::ByteArray(*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash); + file.BindStaticMethod("Copy", &Nz::File::Copy); + file.BindStaticMethod("Delete", &Nz::File::Delete); + file.BindStaticMethod("Exists", &Nz::File::Exists); + //fileClass.SetStaticMethod("GetCreationTime", &Nz::File::GetCreationTime); + file.BindStaticMethod("GetDirectory", &Nz::File::GetDirectory); + //fileClass.SetStaticMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime); + //fileClass.SetStaticMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); + file.BindStaticMethod("GetSize", &Nz::File::GetSize); + file.BindStaticMethod("IsAbsolute", &Nz::File::IsAbsolute); + file.BindStaticMethod("NormalizePath", &Nz::File::NormalizePath); + file.BindStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators); + file.BindStaticMethod("Rename", &Nz::File::Rename); + + // Manual + file.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int + { + std::size_t argCount = std::min(argumentCount, 2U); + + int argIndex = 2; + switch (argCount) { - Nz::String filePath = lua.Check(&argIndex); - Nz::UInt32 openMode = lua.Check(&argIndex); + case 0: + case 1: + return lua.Push(instance.Open(lua.Check(&argIndex, Nz::OpenMode_NotOpen))); - Nz::PlacementNew(instance, filePath, openMode); - return true; + case 2: + { + Nz::String filePath = lua.Check(&argIndex); + Nz::UInt32 openMode = lua.Check(&argIndex, Nz::OpenMode_NotOpen); + return lua.Push(instance.Open(filePath, openMode)); + } } - } - lua.Error("No matching overload for File constructor"); - return false; - }); + lua.Error("No matching overload for method Open"); + return 0; + }); - file.BindMethod("Close", &Nz::File::Close); - file.BindMethod("Copy", &Nz::File::Copy); - file.BindMethod("Delete", &Nz::File::Delete); - file.BindMethod("EndOfFile", &Nz::File::EndOfFile); - file.BindMethod("Exists", &Nz::File::Exists); - file.BindMethod("GetCreationTime", &Nz::File::GetCreationTime); - file.BindMethod("GetFileName", &Nz::File::GetFileName); - file.BindMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime); - file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); - file.BindMethod("IsOpen", &Nz::File::IsOpen); - file.BindMethod("Rename", &Nz::File::GetLastWriteTime); - file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); - file.BindMethod("SetFile", &Nz::File::GetLastWriteTime); + file.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int + { + std::size_t argCount = std::min(argumentCount, 2U); - file.BindStaticMethod("AbsolutePath", &Nz::File::AbsolutePath); - file.BindStaticMethod("ComputeHash", (Nz::ByteArray (*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash); - file.BindStaticMethod("Copy", &Nz::File::Copy); - file.BindStaticMethod("Delete", &Nz::File::Delete); - file.BindStaticMethod("Exists", &Nz::File::Exists); - //fileClass.SetStaticMethod("GetCreationTime", &Nz::File::GetCreationTime); - file.BindStaticMethod("GetDirectory", &Nz::File::GetDirectory); - //fileClass.SetStaticMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime); - //fileClass.SetStaticMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); - file.BindStaticMethod("GetSize", &Nz::File::GetSize); - file.BindStaticMethod("IsAbsolute", &Nz::File::IsAbsolute); - file.BindStaticMethod("NormalizePath", &Nz::File::NormalizePath); - file.BindStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators); - file.BindStaticMethod("Rename", &Nz::File::Rename); + int argIndex = 2; + switch (argCount) + { + case 1: + return lua.Push(instance.SetCursorPos(lua.Check(&argIndex))); - // Manual - file.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int + case 2: + { + Nz::CursorPosition curPos = lua.Check(&argIndex); + Nz::Int64 offset = lua.Check(&argIndex); + return lua.Push(instance.SetCursorPos(curPos, offset)); + } + } + + lua.Error("No matching overload for method SetCursorPos"); + return 0; + }); + + file.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t /*argumentCount*/) -> int { + Nz::StringStream ss("File("); + if (instance.IsOpen()) + ss << "Path: " << instance.GetPath(); + + ss << ')'; + + lua.PushString(ss); + return 1; + }); + } + + /*********************************** Nz::Stream ***********************************/ + stream.Reset("Stream"); { - std::size_t argCount = std::min(argumentCount, 2U); + stream.BindMethod("EnableTextMode", &Nz::Stream::EnableTextMode); + stream.BindMethod("Flush", &Nz::Stream::Flush); + stream.BindMethod("GetCursorPos", &Nz::Stream::GetCursorPos); + stream.BindMethod("GetDirectory", &Nz::Stream::GetDirectory); + stream.BindMethod("GetPath", &Nz::Stream::GetPath); + stream.BindMethod("GetOpenMode", &Nz::Stream::GetOpenMode); + stream.BindMethod("GetStreamOptions", &Nz::Stream::GetStreamOptions); + stream.BindMethod("GetSize", &Nz::Stream::GetSize); + stream.BindMethod("ReadLine", &Nz::Stream::ReadLine, 0U); + stream.BindMethod("IsReadable", &Nz::Stream::IsReadable); + stream.BindMethod("IsSequential", &Nz::Stream::IsSequential); + stream.BindMethod("IsTextModeEnabled", &Nz::Stream::IsTextModeEnabled); + stream.BindMethod("IsWritable", &Nz::Stream::IsWritable); + stream.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos); - int argIndex = 2; - switch (argCount) - { - case 0: - case 1: - return lua.Push(instance.Open(lua.Check(&argIndex, Nz::OpenMode_NotOpen))); + stream.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int { + int argIndex = 2; - case 2: - { - Nz::String filePath = lua.Check(&argIndex); - Nz::UInt32 openMode = lua.Check(&argIndex, Nz::OpenMode_NotOpen); - return lua.Push(instance.Open(filePath, openMode)); - } - } + std::size_t length = lua.Check(&argIndex); - lua.Error("No matching overload for method Open"); - return 0; - }); + std::unique_ptr buffer(new char[length]); + std::size_t readLength = instance.Read(buffer.get(), length); - file.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int - { - std::size_t argCount = std::min(argumentCount, 2U); + lua.PushString(Nz::String(buffer.get(), readLength)); + return 1; + }); - int argIndex = 2; - switch (argCount) - { - case 1: - return lua.Push(instance.SetCursorPos(lua.Check(&argIndex))); + stream.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int { + int argIndex = 2; - case 2: - { - Nz::CursorPosition curPos = lua.Check(&argIndex); - Nz::Int64 offset = lua.Check(&argIndex); - return lua.Push(instance.SetCursorPos(curPos, offset)); - } - } + std::size_t bufferSize = 0; + const char* buffer = lua.CheckString(argIndex, &bufferSize); - lua.Error("No matching overload for method SetCursorPos"); - return 0; - }); - - file.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t /*argumentCount*/) -> int { - Nz::StringStream ss("File("); - if (instance.IsOpen()) - ss << "Path: " << instance.GetPath(); - - ss << ')'; - - lua.PushString(ss); - return 1; - }); + if (instance.IsTextModeEnabled()) + lua.Push(instance.Write(Nz::String(buffer, bufferSize))); + else + lua.Push(instance.Write(buffer, bufferSize)); + return 1; + }); + } } /*! @@ -286,8 +300,7 @@ namespace Ndk * * \param instance Lua instance that will interact with the Core classes */ - - void LuaBinding::RegisterCore(Nz::LuaInstance& instance) + void LuaBinding_Core::Register(Nz::LuaInstance& instance) { // Classes clock.Register(instance); diff --git a/SDK/src/NDK/LuaBinding_Graphics.cpp b/SDK/src/NDK/LuaBinding_Graphics.cpp index cdee66636..4fafb96b9 100644 --- a/SDK/src/NDK/LuaBinding_Graphics.cpp +++ b/SDK/src/NDK/LuaBinding_Graphics.cpp @@ -1,354 +1,355 @@ // This file is part of the "Nazara Development Kit" // For conditions of distribution and use, see copyright notice in Prerequesites.hpp -#include +#include #include namespace Ndk { - /*! - * \brief Binds Graphics module to Lua - */ + std::unique_ptr LuaBinding_Base::BindGraphics(LuaBinding& binding) + { + return std::make_unique(binding); + } - void LuaBinding::BindGraphics() + LuaBinding_Graphics::LuaBinding_Graphics(LuaBinding& binding) : + LuaBinding_Base(binding) { /*********************************** Nz::AbstractViewer ***********************************/ - abstractViewer.BindMethod("GetAspectRatio", &Nz::AbstractViewer::GetAspectRatio); - abstractViewer.BindMethod("GetEyePosition", &Nz::AbstractViewer::GetEyePosition); - abstractViewer.BindMethod("GetForward", &Nz::AbstractViewer::GetForward); - //abstractViewer.BindMethod("GetFrustum", &Nz::AbstractViewer::GetFrustum); - abstractViewer.BindMethod("GetProjectionMatrix", &Nz::AbstractViewer::GetProjectionMatrix); - //abstractViewer.BindMethod("GetTarget", &Nz::AbstractViewer::GetTarget); - abstractViewer.BindMethod("GetViewMatrix", &Nz::AbstractViewer::GetViewMatrix); - abstractViewer.BindMethod("GetViewport", &Nz::AbstractViewer::GetViewport); - abstractViewer.BindMethod("GetZFar", &Nz::AbstractViewer::GetZFar); - abstractViewer.BindMethod("GetZNear", &Nz::AbstractViewer::GetZNear); + abstractViewer.Reset("AbstractViewer"); + { + abstractViewer.BindMethod("GetAspectRatio", &Nz::AbstractViewer::GetAspectRatio); + abstractViewer.BindMethod("GetEyePosition", &Nz::AbstractViewer::GetEyePosition); + abstractViewer.BindMethod("GetForward", &Nz::AbstractViewer::GetForward); + //abstractViewer.BindMethod("GetFrustum", &Nz::AbstractViewer::GetFrustum); + abstractViewer.BindMethod("GetProjectionMatrix", &Nz::AbstractViewer::GetProjectionMatrix); + //abstractViewer.BindMethod("GetTarget", &Nz::AbstractViewer::GetTarget); + abstractViewer.BindMethod("GetViewMatrix", &Nz::AbstractViewer::GetViewMatrix); + abstractViewer.BindMethod("GetViewport", &Nz::AbstractViewer::GetViewport); + abstractViewer.BindMethod("GetZFar", &Nz::AbstractViewer::GetZFar); + abstractViewer.BindMethod("GetZNear", &Nz::AbstractViewer::GetZNear); + } /*********************************** Nz::InstancedRenderable ***********************************/ + instancedRenderable.Reset("InstancedRenderable"); + { + } /*********************************** Nz::Material ***********************************/ - material.SetConstructor([] (Nz::LuaInstance& lua, Nz::MaterialRef* instance, std::size_t argumentCount) + material.Reset("Material"); { - switch (argumentCount) + material.SetConstructor([] (Nz::LuaInstance& lua, Nz::MaterialRef* instance, std::size_t argumentCount) { - case 0: - Nz::PlacementNew(instance, Nz::Material::New()); - return true; - - case 1: + switch (argumentCount) { - int argIndex = 1; - if (lua.IsOfType(argIndex, "MaterialPipeline")) - { - Nz::PlacementNew(instance, Nz::Material::New(*static_cast(lua.ToUserdata(argIndex)))); + case 0: + Nz::PlacementNew(instance, Nz::Material::New()); return true; - } - else if (lua.IsOfType(argIndex, "Material")) + + case 1: { - Nz::PlacementNew(instance, Nz::Material::New(**static_cast(lua.ToUserdata(argIndex)))); - return true; - } - else - { - Nz::PlacementNew(instance, Nz::Material::New(lua.Check(&argIndex))); - return true; + int argIndex = 1; + if (lua.IsOfType(argIndex, "MaterialPipeline")) + { + Nz::PlacementNew(instance, Nz::Material::New(*static_cast(lua.ToUserdata(argIndex)))); + return true; + } + else if (lua.IsOfType(argIndex, "Material")) + { + Nz::PlacementNew(instance, Nz::Material::New(**static_cast(lua.ToUserdata(argIndex)))); + return true; + } + else + { + Nz::PlacementNew(instance, Nz::Material::New(lua.Check(&argIndex))); + return true; + } } } - } - lua.Error("No matching overload for constructor"); - return false; - }); + lua.Error("No matching overload for constructor"); + return false; + }); - material.BindMethod("Configure", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "MaterialPipeline")) + material.BindMethod("Configure", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - instance->Configure(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else + int argIndex = 2; + if (lua.IsOfType(argIndex, "MaterialPipeline")) + { + instance->Configure(*static_cast(lua.ToUserdata(argIndex))); + return 0; + } + else + { + lua.Push(instance->Configure(lua.Check(&argIndex))); + return 1; + } + }); + + material.BindMethod("EnableAlphaTest", &Nz::Material::EnableAlphaTest); + material.BindMethod("EnableBlending", &Nz::Material::EnableBlending); + material.BindMethod("EnableColorWrite", &Nz::Material::EnableColorWrite); + material.BindMethod("EnableDepthBuffer", &Nz::Material::EnableDepthBuffer); + material.BindMethod("EnableDepthSorting", &Nz::Material::EnableDepthSorting); + material.BindMethod("EnableDepthWrite", &Nz::Material::EnableDepthWrite); + material.BindMethod("EnableFaceCulling", &Nz::Material::EnableFaceCulling); + material.BindMethod("EnableScissorTest", &Nz::Material::EnableScissorTest); + material.BindMethod("EnableShadowCasting", &Nz::Material::EnableShadowCasting); + material.BindMethod("EnableShadowReceive", &Nz::Material::EnableShadowReceive); + material.BindMethod("EnableStencilTest", &Nz::Material::EnableStencilTest); + + material.BindMethod("EnsurePipelineUpdate", &Nz::Material::EnsurePipelineUpdate); + + material.BindMethod("GetAlphaMap", &Nz::Material::GetAlphaMap); + material.BindMethod("GetAlphaThreshold", &Nz::Material::GetAlphaThreshold); + material.BindMethod("GetAmbientColor", &Nz::Material::GetAmbientColor); + material.BindMethod("GetDepthFunc", &Nz::Material::GetDepthFunc); + material.BindMethod("GetDepthMaterial", &Nz::Material::GetDepthMaterial); + material.BindMethod("GetDiffuseColor", &Nz::Material::GetDiffuseColor); + material.BindMethod("GetDiffuseMap", &Nz::Material::GetDiffuseMap); + //material.BindMethod("GetDiffuseSampler", &Nz::Material::GetDiffuseSampler); + material.BindMethod("GetDstBlend", &Nz::Material::GetDstBlend); + material.BindMethod("GetEmissiveMap", &Nz::Material::GetEmissiveMap); + material.BindMethod("GetFaceCulling", &Nz::Material::GetFaceCulling); + material.BindMethod("GetFaceFilling", &Nz::Material::GetFaceFilling); + material.BindMethod("GetHeightMap", &Nz::Material::GetHeightMap); + material.BindMethod("GetLineWidth", &Nz::Material::GetLineWidth); + material.BindMethod("GetNormalMap", &Nz::Material::GetNormalMap); + //material.BindMethod("GetPipeline", &Nz::Material::GetPipeline); + //material.BindMethod("GetPipelineInfo", &Nz::Material::GetPipelineInfo); + material.BindMethod("GetPointSize", &Nz::Material::GetPointSize); + //material.BindMethod("GetShader", &Nz::Material::GetShader); + material.BindMethod("GetShininess", &Nz::Material::GetShininess); + material.BindMethod("GetSpecularColor", &Nz::Material::GetSpecularColor); + material.BindMethod("GetSpecularMap", &Nz::Material::GetSpecularMap); + //material.BindMethod("GetSpecularSampler", &Nz::Material::GetSpecularSampler); + material.BindMethod("GetSrcBlend", &Nz::Material::GetSrcBlend); + + material.BindMethod("HasAlphaMap", &Nz::Material::HasAlphaMap); + material.BindMethod("HasDepthMaterial", &Nz::Material::HasDepthMaterial); + material.BindMethod("HasDiffuseMap", &Nz::Material::HasDiffuseMap); + material.BindMethod("HasEmissiveMap", &Nz::Material::HasEmissiveMap); + material.BindMethod("HasHeightMap", &Nz::Material::HasHeightMap); + material.BindMethod("HasNormalMap", &Nz::Material::HasNormalMap); + material.BindMethod("HasSpecularMap", &Nz::Material::HasSpecularMap); + + material.BindMethod("IsAlphaTestEnabled", &Nz::Material::IsAlphaTestEnabled); + material.BindMethod("IsBlendingEnabled", &Nz::Material::IsBlendingEnabled); + material.BindMethod("IsColorWriteEnabled", &Nz::Material::IsColorWriteEnabled); + material.BindMethod("IsDepthBufferEnabled", &Nz::Material::IsDepthBufferEnabled); + material.BindMethod("IsDepthSortingEnabled", &Nz::Material::IsDepthSortingEnabled); + material.BindMethod("IsDepthWriteEnabled", &Nz::Material::IsDepthWriteEnabled); + material.BindMethod("IsFaceCullingEnabled", &Nz::Material::IsFaceCullingEnabled); + material.BindMethod("IsScissorTestEnabled", &Nz::Material::IsScissorTestEnabled); + material.BindMethod("IsStencilTestEnabled", &Nz::Material::IsStencilTestEnabled); + material.BindMethod("IsShadowCastingEnabled", &Nz::Material::IsShadowCastingEnabled); + material.BindMethod("IsShadowReceiveEnabled", &Nz::Material::IsShadowReceiveEnabled); + + material.BindMethod("LoadFromFile", &Nz::Material::LoadFromFile, Nz::MaterialParams()); + + material.BindMethod("Reset", &Nz::Material::Reset); + + material.BindMethod("SetAlphaThreshold", &Nz::Material::SetAlphaThreshold); + material.BindMethod("SetAmbientColor", &Nz::Material::SetAmbientColor); + material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc); + material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc); + material.BindMethod("SetDepthMaterial", &Nz::Material::SetDepthMaterial); + material.BindMethod("SetDiffuseColor", &Nz::Material::SetDiffuseColor); + //material.BindMethod("SetDiffuseSampler", &Nz::Material::SetDiffuseSampler); + material.BindMethod("SetDstBlend", &Nz::Material::SetDstBlend); + material.BindMethod("SetFaceCulling", &Nz::Material::SetFaceCulling); + material.BindMethod("SetFaceFilling", &Nz::Material::SetFaceFilling); + material.BindMethod("SetLineWidth", &Nz::Material::SetLineWidth); + material.BindMethod("SetPointSize", &Nz::Material::SetPointSize); + material.BindMethod("SetShininess", &Nz::Material::SetShininess); + material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor); + material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor); + //material.BindMethod("SetSpecularSampler", &Nz::Material::SetSpecularSampler); + material.BindMethod("SetSrcBlend", &Nz::Material::SetSrcBlend); + + material.BindStaticMethod("GetDefault", &Nz::Material::GetDefault); + + material.BindMethod("SetAlphaMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - lua.Push(instance->Configure(lua.Check(&argIndex))); - return 1; - } - }); + int argIndex = 2; + if (lua.IsOfType(argIndex, "Texture")) + { + instance->SetAlphaMap(*static_cast(lua.ToUserdata(argIndex))); + return 0; + } + else + return lua.Push(instance->SetAlphaMap(lua.Check(&argIndex))); + }); - material.BindMethod("EnableAlphaTest", &Nz::Material::EnableAlphaTest); - material.BindMethod("EnableBlending", &Nz::Material::EnableBlending); - material.BindMethod("EnableColorWrite", &Nz::Material::EnableColorWrite); - material.BindMethod("EnableDepthBuffer", &Nz::Material::EnableDepthBuffer); - material.BindMethod("EnableDepthSorting", &Nz::Material::EnableDepthSorting); - material.BindMethod("EnableDepthWrite", &Nz::Material::EnableDepthWrite); - material.BindMethod("EnableFaceCulling", &Nz::Material::EnableFaceCulling); - material.BindMethod("EnableScissorTest", &Nz::Material::EnableScissorTest); - material.BindMethod("EnableShadowCasting", &Nz::Material::EnableShadowCasting); - material.BindMethod("EnableShadowReceive", &Nz::Material::EnableShadowReceive); - material.BindMethod("EnableStencilTest", &Nz::Material::EnableStencilTest); - - material.BindMethod("EnsurePipelineUpdate", &Nz::Material::EnsurePipelineUpdate); - - material.BindMethod("GetAlphaMap", &Nz::Material::GetAlphaMap); - material.BindMethod("GetAlphaThreshold", &Nz::Material::GetAlphaThreshold); - material.BindMethod("GetAmbientColor", &Nz::Material::GetAmbientColor); - material.BindMethod("GetDepthFunc", &Nz::Material::GetDepthFunc); - material.BindMethod("GetDepthMaterial", &Nz::Material::GetDepthMaterial); - material.BindMethod("GetDiffuseColor", &Nz::Material::GetDiffuseColor); - material.BindMethod("GetDiffuseMap", &Nz::Material::GetDiffuseMap); - //material.BindMethod("GetDiffuseSampler", &Nz::Material::GetDiffuseSampler); - material.BindMethod("GetDstBlend", &Nz::Material::GetDstBlend); - material.BindMethod("GetEmissiveMap", &Nz::Material::GetEmissiveMap); - material.BindMethod("GetFaceCulling", &Nz::Material::GetFaceCulling); - material.BindMethod("GetFaceFilling", &Nz::Material::GetFaceFilling); - material.BindMethod("GetHeightMap", &Nz::Material::GetHeightMap); - material.BindMethod("GetLineWidth", &Nz::Material::GetLineWidth); - material.BindMethod("GetNormalMap", &Nz::Material::GetNormalMap); - //material.BindMethod("GetPipeline", &Nz::Material::GetPipeline); - //material.BindMethod("GetPipelineInfo", &Nz::Material::GetPipelineInfo); - material.BindMethod("GetPointSize", &Nz::Material::GetPointSize); - //material.BindMethod("GetShader", &Nz::Material::GetShader); - material.BindMethod("GetShininess", &Nz::Material::GetShininess); - material.BindMethod("GetSpecularColor", &Nz::Material::GetSpecularColor); - material.BindMethod("GetSpecularMap", &Nz::Material::GetSpecularMap); - //material.BindMethod("GetSpecularSampler", &Nz::Material::GetSpecularSampler); - material.BindMethod("GetSrcBlend", &Nz::Material::GetSrcBlend); - - material.BindMethod("HasAlphaMap", &Nz::Material::HasAlphaMap); - material.BindMethod("HasDepthMaterial", &Nz::Material::HasDepthMaterial); - material.BindMethod("HasDiffuseMap", &Nz::Material::HasDiffuseMap); - material.BindMethod("HasEmissiveMap", &Nz::Material::HasEmissiveMap); - material.BindMethod("HasHeightMap", &Nz::Material::HasHeightMap); - material.BindMethod("HasNormalMap", &Nz::Material::HasNormalMap); - material.BindMethod("HasSpecularMap", &Nz::Material::HasSpecularMap); - - material.BindMethod("IsAlphaTestEnabled", &Nz::Material::IsAlphaTestEnabled); - material.BindMethod("IsBlendingEnabled", &Nz::Material::IsBlendingEnabled); - material.BindMethod("IsColorWriteEnabled", &Nz::Material::IsColorWriteEnabled); - material.BindMethod("IsDepthBufferEnabled", &Nz::Material::IsDepthBufferEnabled); - material.BindMethod("IsDepthSortingEnabled", &Nz::Material::IsDepthSortingEnabled); - material.BindMethod("IsDepthWriteEnabled", &Nz::Material::IsDepthWriteEnabled); - material.BindMethod("IsFaceCullingEnabled", &Nz::Material::IsFaceCullingEnabled); - material.BindMethod("IsScissorTestEnabled", &Nz::Material::IsScissorTestEnabled); - material.BindMethod("IsStencilTestEnabled", &Nz::Material::IsStencilTestEnabled); - material.BindMethod("IsShadowCastingEnabled", &Nz::Material::IsShadowCastingEnabled); - material.BindMethod("IsShadowReceiveEnabled", &Nz::Material::IsShadowReceiveEnabled); - - material.BindMethod("LoadFromFile", &Nz::Material::LoadFromFile, Nz::MaterialParams()); - - material.BindMethod("Reset", &Nz::Material::Reset); - - material.BindMethod("SetAlphaThreshold", &Nz::Material::SetAlphaThreshold); - material.BindMethod("SetAmbientColor", &Nz::Material::SetAmbientColor); - material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc); - material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc); - material.BindMethod("SetDepthMaterial", &Nz::Material::SetDepthMaterial); - material.BindMethod("SetDiffuseColor", &Nz::Material::SetDiffuseColor); - //material.BindMethod("SetDiffuseSampler", &Nz::Material::SetDiffuseSampler); - material.BindMethod("SetDstBlend", &Nz::Material::SetDstBlend); - material.BindMethod("SetFaceCulling", &Nz::Material::SetFaceCulling); - material.BindMethod("SetFaceFilling", &Nz::Material::SetFaceFilling); - material.BindMethod("SetLineWidth", &Nz::Material::SetLineWidth); - material.BindMethod("SetPointSize", &Nz::Material::SetPointSize); - material.BindMethod("SetShininess", &Nz::Material::SetShininess); - material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor); - material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor); - //material.BindMethod("SetSpecularSampler", &Nz::Material::SetSpecularSampler); - material.BindMethod("SetSrcBlend", &Nz::Material::SetSrcBlend); - - material.BindStaticMethod("GetDefault", &Nz::Material::GetDefault); - - material.BindMethod("SetAlphaMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Texture")) + material.BindMethod("SetDiffuseMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - instance->SetAlphaMap(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetAlphaMap(lua.Check(&argIndex))); - }); + int argIndex = 2; + if (lua.IsOfType(argIndex, "Texture")) + { + instance->SetDiffuseMap(*static_cast(lua.ToUserdata(argIndex))); + return 0; + } + else + return lua.Push(instance->SetDiffuseMap(lua.Check(&argIndex))); + }); - material.BindMethod("SetDiffuseMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Texture")) + material.BindMethod("SetEmissiveMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - instance->SetDiffuseMap(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetDiffuseMap(lua.Check(&argIndex))); - }); + int argIndex = 2; + if (lua.IsOfType(argIndex, "Texture")) + { + instance->SetEmissiveMap(*static_cast(lua.ToUserdata(argIndex))); + return 0; + } + else + return lua.Push(instance->SetEmissiveMap(lua.Check(&argIndex))); + }); - material.BindMethod("SetEmissiveMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Texture")) + material.BindMethod("SetHeightMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - instance->SetEmissiveMap(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetEmissiveMap(lua.Check(&argIndex))); - }); + int argIndex = 2; + if (lua.IsOfType(argIndex, "Texture")) + { + instance->SetHeightMap(*static_cast(lua.ToUserdata(argIndex))); + return 0; + } + else + return lua.Push(instance->SetHeightMap(lua.Check(&argIndex))); + }); - material.BindMethod("SetHeightMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Texture")) + material.BindMethod("SetNormalMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - instance->SetHeightMap(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetHeightMap(lua.Check(&argIndex))); - }); + int argIndex = 2; + if (lua.IsOfType(argIndex, "Texture")) + { + instance->SetNormalMap(*static_cast(lua.ToUserdata(argIndex))); + return 0; + } + else + return lua.Push(instance->SetNormalMap(lua.Check(&argIndex))); + }); - material.BindMethod("SetNormalMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Texture")) + material.BindMethod("SetShader", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - instance->SetNormalMap(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetNormalMap(lua.Check(&argIndex))); - }); + int argIndex = 2; + if (lua.IsOfType(argIndex, "UberShader")) + { + instance->SetShader(*static_cast(lua.ToUserdata(argIndex))); + return 0; + } + else + return lua.Push(instance->SetShader(lua.Check(&argIndex))); + }); - material.BindMethod("SetShader", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "UberShader")) + material.BindMethod("SetSpecularMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - instance->SetShader(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetShader(lua.Check(&argIndex))); - }); - - material.BindMethod("SetSpecularMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Texture")) - { - instance->SetSpecularMap(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetSpecularMap(lua.Check(&argIndex))); - }); + int argIndex = 2; + if (lua.IsOfType(argIndex, "Texture")) + { + instance->SetSpecularMap(*static_cast(lua.ToUserdata(argIndex))); + return 0; + } + else + return lua.Push(instance->SetSpecularMap(lua.Check(&argIndex))); + }); + } /*********************************** Nz::Model ***********************************/ - model.Inherit(instancedRenderable, [] (Nz::ModelRef* modelRef) -> Nz::InstancedRenderableRef* + model.Reset("Model"); { - return reinterpret_cast(modelRef); //TODO: Make a ObjectRefCast - }); + model.Inherit(instancedRenderable, [] (Nz::ModelRef* modelRef) -> Nz::InstancedRenderableRef* + { + return reinterpret_cast(modelRef); //TODO: Make a ObjectRefCast + }); - model.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::ModelRef* instance, std::size_t /*argumentCount*/) - { - Nz::PlacementNew(instance, Nz::Model::New()); - return true; - }); + model.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::ModelRef* instance, std::size_t /*argumentCount*/) + { + Nz::PlacementNew(instance, Nz::Model::New()); + return true; + }); - //model.BindMethod("GetMaterial", &Nz::Model::GetMaterial); - model.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount); - //modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh); - model.BindMethod("GetSkin", &Nz::Model::GetSkin); - model.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount); + //model.BindMethod("GetMaterial", &Nz::Model::GetMaterial); + model.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount); + //modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh); + model.BindMethod("GetSkin", &Nz::Model::GetSkin); + model.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount); - model.BindMethod("IsAnimated", &Nz::Model::IsAnimated); - model.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters()); + model.BindMethod("IsAnimated", &Nz::Model::IsAnimated); + model.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters()); - model.BindMethod("Reset", &Nz::Model::Reset); + model.BindMethod("Reset", &Nz::Model::Reset); - //model.BindMethod("SetMaterial", &Nz::Model::SetMaterial); - //modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh); - //modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence); - model.BindMethod("SetSkin", &Nz::Model::SetSkin); - model.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount); + //model.BindMethod("SetMaterial", &Nz::Model::SetMaterial); + //modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh); + //modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence); + model.BindMethod("SetSkin", &Nz::Model::SetSkin); + model.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount); + } /*********************************** Nz::Sprite ***********************************/ - sprite.Inherit(instancedRenderable, [] (Nz::SpriteRef* spriteRef) -> Nz::InstancedRenderableRef* + sprite.Reset("Sprite"); { - return reinterpret_cast(spriteRef); //TODO: Make a ObjectRefCast - }); + sprite.Inherit(instancedRenderable, [] (Nz::SpriteRef* spriteRef) -> Nz::InstancedRenderableRef* + { + return reinterpret_cast(spriteRef); //TODO: Make a ObjectRefCast + }); - sprite.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::SpriteRef* instance, std::size_t /*argumentCount*/) - { - Nz::PlacementNew(instance, Nz::Sprite::New()); - return true; - }); + sprite.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::SpriteRef* instance, std::size_t /*argumentCount*/) + { + Nz::PlacementNew(instance, Nz::Sprite::New()); + return true; + }); - sprite.BindMethod("GetColor", &Nz::Sprite::GetColor); - sprite.BindMethod("GetCornerColor", &Nz::Sprite::GetCornerColor); - sprite.BindMethod("GetMaterial", &Nz::Sprite::GetMaterial); - sprite.BindMethod("GetOrigin", &Nz::Sprite::GetOrigin); - sprite.BindMethod("GetSize", &Nz::Sprite::GetSize); - sprite.BindMethod("GetTextureCoords", &Nz::Sprite::GetTextureCoords); + sprite.BindMethod("GetColor", &Nz::Sprite::GetColor); + sprite.BindMethod("GetCornerColor", &Nz::Sprite::GetCornerColor); + sprite.BindMethod("GetMaterial", &Nz::Sprite::GetMaterial); + sprite.BindMethod("GetOrigin", &Nz::Sprite::GetOrigin); + sprite.BindMethod("GetSize", &Nz::Sprite::GetSize); + sprite.BindMethod("GetTextureCoords", &Nz::Sprite::GetTextureCoords); - sprite.BindMethod("SetColor", &Nz::Sprite::SetColor); - sprite.BindMethod("SetCornerColor", &Nz::Sprite::SetCornerColor); - sprite.BindMethod("SetDefaultMaterial", &Nz::Sprite::SetDefaultMaterial); - sprite.BindMethod("SetOrigin", &Nz::Sprite::SetOrigin); - sprite.BindMethod("SetSize", (void(Nz::Sprite::*)(const Nz::Vector2f&)) &Nz::Sprite::SetSize); - sprite.BindMethod("SetTextureCoords", &Nz::Sprite::SetTextureCoords); - sprite.BindMethod("SetTextureRect", &Nz::Sprite::SetTextureRect); + sprite.BindMethod("SetColor", &Nz::Sprite::SetColor); + sprite.BindMethod("SetCornerColor", &Nz::Sprite::SetCornerColor); + sprite.BindMethod("SetDefaultMaterial", &Nz::Sprite::SetDefaultMaterial); + sprite.BindMethod("SetOrigin", &Nz::Sprite::SetOrigin); + sprite.BindMethod("SetSize", (void(Nz::Sprite::*)(const Nz::Vector2f&)) &Nz::Sprite::SetSize); + sprite.BindMethod("SetTextureCoords", &Nz::Sprite::SetTextureCoords); + sprite.BindMethod("SetTextureRect", &Nz::Sprite::SetTextureRect); - sprite.BindMethod("SetMaterial", [] (Nz::LuaInstance& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - bool resizeSprite = lua.CheckBoolean(argIndex + 1, true); + sprite.BindMethod("SetMaterial", [] (Nz::LuaInstance& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int + { + int argIndex = 2; + bool resizeSprite = lua.CheckBoolean(argIndex + 1, true); - if (lua.IsOfType(argIndex, "Material")) - instance->SetMaterial(*static_cast(lua.ToUserdata(argIndex)), resizeSprite); - else - instance->SetMaterial(lua.Check(&argIndex), resizeSprite); + if (lua.IsOfType(argIndex, "Material")) + instance->SetMaterial(*static_cast(lua.ToUserdata(argIndex)), resizeSprite); + else + instance->SetMaterial(lua.Check(&argIndex), resizeSprite); - return 0; - }); + return 0; + }); - sprite.BindMethod("SetTexture", [] (Nz::LuaInstance& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - bool resizeSprite = lua.CheckBoolean(argIndex + 1, true); + sprite.BindMethod("SetTexture", [] (Nz::LuaInstance& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int + { + int argIndex = 2; + bool resizeSprite = lua.CheckBoolean(argIndex + 1, true); - if (lua.IsOfType(argIndex, "Texture")) - instance->SetTexture(*static_cast(lua.ToUserdata(argIndex)), resizeSprite); - else - instance->SetTexture(lua.Check(&argIndex), resizeSprite); + if (lua.IsOfType(argIndex, "Texture")) + instance->SetTexture(*static_cast(lua.ToUserdata(argIndex)), resizeSprite); + else + instance->SetTexture(lua.Check(&argIndex), resizeSprite); - return 0; - }); + return 0; + }); + } /*********************************** Nz::SpriteLibrary ***********************************/ - - spriteLibrary.BindStaticMethod("Get", &Nz::SpriteLibrary::Get); - spriteLibrary.BindStaticMethod("Has", &Nz::SpriteLibrary::Has); - spriteLibrary.BindStaticMethod("Register", &Nz::SpriteLibrary::Register); - spriteLibrary.BindStaticMethod("Query", &Nz::SpriteLibrary::Query); - spriteLibrary.BindStaticMethod("Unregister", &Nz::SpriteLibrary::Unregister); - - /*********************************** Nz::TextureLibrary ***********************************/ - - textureLibrary.BindStaticMethod("Get", &Nz::TextureLibrary::Get); - textureLibrary.BindStaticMethod("Has", &Nz::TextureLibrary::Has); - textureLibrary.BindStaticMethod("Register", &Nz::TextureLibrary::Register); - textureLibrary.BindStaticMethod("Query", &Nz::TextureLibrary::Query); - textureLibrary.BindStaticMethod("Unregister", &Nz::TextureLibrary::Unregister); - - /*********************************** Nz::TextureManager ***********************************/ - - textureManager.BindStaticMethod("Clear", &Nz::TextureManager::Clear); - textureManager.BindStaticMethod("Get", &Nz::TextureManager::Get); - textureManager.BindStaticMethod("GetDefaultParameters", &Nz::TextureManager::GetDefaultParameters); - textureManager.BindStaticMethod("Purge", &Nz::TextureManager::Purge); - textureManager.BindStaticMethod("Register", &Nz::TextureManager::Register); - textureManager.BindStaticMethod("SetDefaultParameters", &Nz::TextureManager::SetDefaultParameters); - textureManager.BindStaticMethod("Unregister", &Nz::TextureManager::Unregister); + spriteLibrary.Reset("SpriteLibrary"); + { + spriteLibrary.BindStaticMethod("Get", &Nz::SpriteLibrary::Get); + spriteLibrary.BindStaticMethod("Has", &Nz::SpriteLibrary::Has); + spriteLibrary.BindStaticMethod("Register", &Nz::SpriteLibrary::Register); + spriteLibrary.BindStaticMethod("Query", &Nz::SpriteLibrary::Query); + spriteLibrary.BindStaticMethod("Unregister", &Nz::SpriteLibrary::Unregister); + } } /*! @@ -357,7 +358,7 @@ namespace Ndk * \param instance Lua instance that will interact with the Graphics classes */ - void LuaBinding::RegisterGraphics(Nz::LuaInstance& instance) + void LuaBinding_Graphics::Register(Nz::LuaInstance& instance) { abstractViewer.Register(instance); instancedRenderable.Register(instance); @@ -365,7 +366,5 @@ namespace Ndk model.Register(instance); sprite.Register(instance); spriteLibrary.Register(instance); - textureLibrary.Register(instance); - textureManager.Register(instance); } } diff --git a/SDK/src/NDK/LuaBinding_Math.cpp b/SDK/src/NDK/LuaBinding_Math.cpp index f777dce7f..bd013151c 100644 --- a/SDK/src/NDK/LuaBinding_Math.cpp +++ b/SDK/src/NDK/LuaBinding_Math.cpp @@ -1,946 +1,965 @@ // This file was automatically generated on 26 May 2014 at 01:05:31 -#include +#include #include #include #include namespace Ndk { - /*! - * \brief Binds Math module to Lua - */ + std::unique_ptr LuaBinding_Base::BindMath(LuaBinding& binding) + { + return std::make_unique(binding); + } - void LuaBinding::BindMath() + LuaBinding_Math::LuaBinding_Math(LuaBinding& binding) : + LuaBinding_Base(binding) { /*********************************** Nz::EulerAngles **********************************/ - eulerAngles.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* instance, std::size_t argumentCount) + eulerAngles.Reset("EulerAngles"); { - std::size_t argCount = std::min(argumentCount, 1U); - - switch (argCount) + eulerAngles.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* instance, std::size_t argumentCount) { - case 0: - Nz::PlacementNew(instance, Nz::EulerAnglesd::Zero()); - return true; + std::size_t argCount = std::min(argumentCount, 1U); - case 1: - Nz::PlacementNew(instance, *static_cast(lua.CheckUserdata(1, "EulerAngles"))); - return true; - - case 3: - Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3)); - return true; - } - - lua.Error("No matching overload for EulerAngles constructor"); - return false; - }); - - eulerAngles.BindMethod("Normalize", &Nz::EulerAnglesd::Normalize); - eulerAngles.BindMethod("ToQuaternion", &Nz::EulerAnglesd::ToQuaternion); - - eulerAngles.BindMethod("__tostring", &Nz::EulerAnglesd::ToString); - - eulerAngles.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance) - { - std::size_t length; - const char* ypr = lua.CheckString(2, &length); - - switch (length) - { - case 1: + switch (argCount) { - switch (ypr[0]) + case 0: + Nz::PlacementNew(instance, Nz::EulerAnglesd::Zero()); + return true; + + case 1: + Nz::PlacementNew(instance, *static_cast(lua.CheckUserdata(1, "EulerAngles"))); + return true; + + case 3: + Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3)); + return true; + } + + lua.Error("No matching overload for EulerAngles constructor"); + return false; + }); + + eulerAngles.BindMethod("Normalize", &Nz::EulerAnglesd::Normalize); + eulerAngles.BindMethod("ToQuaternion", &Nz::EulerAnglesd::ToQuaternion); + + eulerAngles.BindMethod("__tostring", &Nz::EulerAnglesd::ToString); + + eulerAngles.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance) + { + std::size_t length; + const char* ypr = lua.CheckString(2, &length); + + switch (length) + { + case 1: { - case 'p': - lua.Push(instance.pitch); - return true; + switch (ypr[0]) + { + case 'p': + lua.Push(instance.pitch); + return true; - case 'y': - lua.Push(instance.yaw); - return true; + case 'y': + lua.Push(instance.yaw); + return true; - case 'r': - lua.Push(instance.roll); - return true; + case 'r': + lua.Push(instance.roll); + return true; + } + break; } - break; - } - case 3: - { - if (std::memcmp(ypr, "yaw", 3) != 0) - break; - - lua.Push(instance.yaw); - return true; - } - - case 4: - { - if (std::memcmp(ypr, "roll", 4) != 0) - break; - - lua.Push(instance.roll); - return true; - } - - case 5: - { - if (std::memcmp(ypr, "pitch", 5) != 0) - break; - - lua.Push(instance.pitch); - return true; - } - } - - return false; - }); - - eulerAngles.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance) - { - std::size_t length; - const char* ypr = lua.CheckString(2, &length); - double value = lua.CheckNumber(3); - - switch (length) - { - case 1: - { - switch (ypr[0]) + case 3: { - case 'p': - instance.pitch = value; - return true; + if (std::memcmp(ypr, "yaw", 3) != 0) + break; - case 'y': - instance.yaw = value; - return true; - - case 'r': - instance.roll = value; - return true; + lua.Push(instance.yaw); + return true; + } + + case 4: + { + if (std::memcmp(ypr, "roll", 4) != 0) + break; + + lua.Push(instance.roll); + return true; + } + + case 5: + { + if (std::memcmp(ypr, "pitch", 5) != 0) + break; + + lua.Push(instance.pitch); + return true; } - break; } - case 3: + return false; + }); + + eulerAngles.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance) + { + std::size_t length; + const char* ypr = lua.CheckString(2, &length); + double value = lua.CheckNumber(3); + + switch (length) { - if (std::memcmp(ypr, "yaw", 3) != 0) - break; + case 1: + { + switch (ypr[0]) + { + case 'p': + instance.pitch = value; + return true; - instance.yaw = value; - return true; + case 'y': + instance.yaw = value; + return true; + + case 'r': + instance.roll = value; + return true; + } + break; + } + + case 3: + { + if (std::memcmp(ypr, "yaw", 3) != 0) + break; + + instance.yaw = value; + return true; + } + + case 4: + { + if (std::memcmp(ypr, "roll", 4) != 0) + break; + + instance.roll = value; + return true; + } + + case 5: + { + if (std::memcmp(ypr, "pitch", 5) != 0) + break; + + instance.pitch = value; + return true; + } } - case 4: - { - if (std::memcmp(ypr, "roll", 4) != 0) - break; - - instance.roll = value; - return true; - } - - case 5: - { - if (std::memcmp(ypr, "pitch", 5) != 0) - break; - - instance.pitch = value; - return true; - } - } - - return false; - }); - + return false; + }); + } /*********************************** Nz::Matrix4 **********************************/ - matrix4d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Matrix4d* matrix, std::size_t argumentCount) + matrix4d.Reset("Matrix4"); { - std::size_t argCount = std::min(argumentCount, 3U); - - switch (argCount) + matrix4d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Matrix4d* matrix, std::size_t argumentCount) { - case 0: - Nz::PlacementNew(matrix, Nz::Matrix4d::Zero()); - return true; + std::size_t argCount = std::min(argumentCount, 3U); - case 1: - if (lua.IsOfType(1, "Matrix4")) - Nz::PlacementNew(matrix, *static_cast(lua.ToUserdata(1))); - break; - - case 16: + switch (argCount) { - double values[16]; - for (int i = 0; i < 16; ++i) - values[i] = lua.CheckNumber(i); + case 0: + Nz::PlacementNew(matrix, Nz::Matrix4d::Zero()); + return true; - Nz::PlacementNew(matrix, values); + case 1: + if (lua.IsOfType(1, "Matrix4")) + Nz::PlacementNew(matrix, *static_cast(lua.ToUserdata(1))); + break; - return true; + case 16: + { + double values[16]; + for (int i = 0; i < 16; ++i) + values[i] = lua.CheckNumber(i); + + Nz::PlacementNew(matrix, values); + + return true; + } } - } - lua.Error("No matching overload for constructor"); - return false; - }); + lua.Error("No matching overload for constructor"); + return false; + }); - matrix4d.BindMethod("ApplyRotation", &Nz::Matrix4d::ApplyRotation); - matrix4d.BindMethod("ApplyScale", &Nz::Matrix4d::ApplyScale); - matrix4d.BindMethod("ApplyTranslation", &Nz::Matrix4d::ApplyTranslation); + matrix4d.BindMethod("ApplyRotation", &Nz::Matrix4d::ApplyRotation); + matrix4d.BindMethod("ApplyScale", &Nz::Matrix4d::ApplyScale); + matrix4d.BindMethod("ApplyTranslation", &Nz::Matrix4d::ApplyTranslation); - matrix4d.BindMethod("Concatenate", &Nz::Matrix4d::Concatenate); - matrix4d.BindMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine); + matrix4d.BindMethod("Concatenate", &Nz::Matrix4d::Concatenate); + matrix4d.BindMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine); - //matrix4d.BindMethod("GetColumn", &Nz::Matrix4d::GetColumn); - matrix4d.BindMethod("GetDeterminant", &Nz::Matrix4d::GetDeterminant); - matrix4d.BindMethod("GetDeterminantAffine", &Nz::Matrix4d::GetDeterminantAffine); + //matrix4d.BindMethod("GetColumn", &Nz::Matrix4d::GetColumn); + matrix4d.BindMethod("GetDeterminant", &Nz::Matrix4d::GetDeterminant); + matrix4d.BindMethod("GetDeterminantAffine", &Nz::Matrix4d::GetDeterminantAffine); - matrix4d.BindMethod("GetInverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int - { - Nz::Matrix4d result; - if (instance.GetInverse(&result)) - return lua.Push(true, result); - else - return lua.Push(false); - }); - - matrix4d.BindMethod("GetInverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int - { - Nz::Matrix4d result; - if (instance.GetInverseAffine(&result)) - return lua.Push(true, result); - else - return lua.Push(false); - }); - - matrix4d.BindMethod("GetRotation", &Nz::Matrix4d::GetRotation); - - //matrix4d.BindMethod("GetRow", &Nz::Matrix4d::GetRow); - matrix4d.BindMethod("GetScale", &Nz::Matrix4d::GetScale); - matrix4d.BindMethod("GetSquaredScale", &Nz::Matrix4d::GetSquaredScale); - matrix4d.BindMethod("GetTranslation", &Nz::Matrix4d::GetTranslation); - - matrix4d.BindMethod("GetTransposed", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int - { - Nz::Matrix4d result; - instance.GetTransposed(&result); - - return lua.Push(result); - }); - - matrix4d.BindMethod("HasNegativeScale", &Nz::Matrix4d::HasNegativeScale); - matrix4d.BindMethod("HasScale", &Nz::Matrix4d::HasScale); - - matrix4d.BindMethod("Inverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int - { - bool succeeded; - instance.Inverse(&succeeded); - - return lua.Push(succeeded); - }); - - matrix4d.BindMethod("InverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int - { - bool succeeded; - instance.InverseAffine(&succeeded); - - return lua.Push(succeeded); - }); - - matrix4d.BindMethod("IsAffine", &Nz::Matrix4d::IsAffine); - matrix4d.BindMethod("IsIdentity", &Nz::Matrix4d::IsIdentity); - - matrix4d.BindMethod("MakeIdentity", &Nz::Matrix4d::MakeIdentity); - matrix4d.BindMethod("MakeLookAt", &Nz::Matrix4d::MakeLookAt, Nz::Vector3d::Up()); - matrix4d.BindMethod("MakeOrtho", &Nz::Matrix4d::MakeOrtho, -1.0, 1.0); - matrix4d.BindMethod("MakePerspective", &Nz::Matrix4d::MakePerspective); - matrix4d.BindMethod("MakeRotation", &Nz::Matrix4d::MakeRotation); - matrix4d.BindMethod("MakeScale", &Nz::Matrix4d::MakeScale); - matrix4d.BindMethod("MakeTranslation", &Nz::Matrix4d::MakeTranslation); - matrix4d.BindMethod("MakeTransform", (Nz::Matrix4d&(Nz::Matrix4d::*)(const Nz::Vector3d&, const Nz::Quaterniond&, const Nz::Vector3d&)) &Nz::Matrix4d::MakeTransform, Nz::Vector3d::Unit()); - matrix4d.BindMethod("MakeViewMatrix", &Nz::Matrix4d::MakeViewMatrix); - matrix4d.BindMethod("MakeZero", &Nz::Matrix4d::MakeZero); - - matrix4d.BindMethod("Set", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t argumentCount) -> int - { - std::size_t argCount = std::min(argumentCount, 3U); - - int argIndex = 2; - switch (argCount) + matrix4d.BindMethod("GetInverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int { - case 1: - if (lua.IsOfType(argIndex, "Matrix4")) - instance.Set(*static_cast(lua.ToUserdata(argIndex))); - break; + Nz::Matrix4d result; + if (instance.GetInverse(&result)) + return lua.Push(true, result); + else + return lua.Push(false); + }); - case 16: + matrix4d.BindMethod("GetInverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int + { + Nz::Matrix4d result; + if (instance.GetInverseAffine(&result)) + return lua.Push(true, result); + else + return lua.Push(false); + }); + + matrix4d.BindMethod("GetRotation", &Nz::Matrix4d::GetRotation); + + //matrix4d.BindMethod("GetRow", &Nz::Matrix4d::GetRow); + matrix4d.BindMethod("GetScale", &Nz::Matrix4d::GetScale); + matrix4d.BindMethod("GetSquaredScale", &Nz::Matrix4d::GetSquaredScale); + matrix4d.BindMethod("GetTranslation", &Nz::Matrix4d::GetTranslation); + + matrix4d.BindMethod("GetTransposed", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int + { + Nz::Matrix4d result; + instance.GetTransposed(&result); + + return lua.Push(result); + }); + + matrix4d.BindMethod("HasNegativeScale", &Nz::Matrix4d::HasNegativeScale); + matrix4d.BindMethod("HasScale", &Nz::Matrix4d::HasScale); + + matrix4d.BindMethod("Inverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int + { + bool succeeded; + instance.Inverse(&succeeded); + + return lua.Push(succeeded); + }); + + matrix4d.BindMethod("InverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int + { + bool succeeded; + instance.InverseAffine(&succeeded); + + return lua.Push(succeeded); + }); + + matrix4d.BindMethod("IsAffine", &Nz::Matrix4d::IsAffine); + matrix4d.BindMethod("IsIdentity", &Nz::Matrix4d::IsIdentity); + + matrix4d.BindMethod("MakeIdentity", &Nz::Matrix4d::MakeIdentity); + matrix4d.BindMethod("MakeLookAt", &Nz::Matrix4d::MakeLookAt, Nz::Vector3d::Up()); + matrix4d.BindMethod("MakeOrtho", &Nz::Matrix4d::MakeOrtho, -1.0, 1.0); + matrix4d.BindMethod("MakePerspective", &Nz::Matrix4d::MakePerspective); + matrix4d.BindMethod("MakeRotation", &Nz::Matrix4d::MakeRotation); + matrix4d.BindMethod("MakeScale", &Nz::Matrix4d::MakeScale); + matrix4d.BindMethod("MakeTranslation", &Nz::Matrix4d::MakeTranslation); + matrix4d.BindMethod("MakeTransform", (Nz::Matrix4d&(Nz::Matrix4d::*)(const Nz::Vector3d&, const Nz::Quaterniond&, const Nz::Vector3d&)) &Nz::Matrix4d::MakeTransform, Nz::Vector3d::Unit()); + matrix4d.BindMethod("MakeViewMatrix", &Nz::Matrix4d::MakeViewMatrix); + matrix4d.BindMethod("MakeZero", &Nz::Matrix4d::MakeZero); + + matrix4d.BindMethod("Set", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t argumentCount) -> int + { + std::size_t argCount = std::min(argumentCount, 3U); + + int argIndex = 2; + switch (argCount) { - double values[16]; - for (std::size_t i = 0; i < 16; ++i) - values[i] = lua.CheckNumber(argIndex++); + case 1: + if (lua.IsOfType(argIndex, "Matrix4")) + instance.Set(*static_cast(lua.ToUserdata(argIndex))); + break; - instance.Set(values); + case 16: + { + double values[16]; + for (std::size_t i = 0; i < 16; ++i) + values[i] = lua.CheckNumber(argIndex++); - return 0; + instance.Set(values); + + return 0; + } } - } - lua.Error("No matching overload for method Set"); - return 0; - }); + lua.Error("No matching overload for method Set"); + return 0; + }); - matrix4d.BindMethod("SetRotation", &Nz::Matrix4d::SetRotation); - matrix4d.BindMethod("SetScale", &Nz::Matrix4d::SetScale); - matrix4d.BindMethod("SetTranslation", &Nz::Matrix4d::SetTranslation); + matrix4d.BindMethod("SetRotation", &Nz::Matrix4d::SetRotation); + matrix4d.BindMethod("SetScale", &Nz::Matrix4d::SetScale); + matrix4d.BindMethod("SetTranslation", &Nz::Matrix4d::SetTranslation); - matrix4d.BindMethod("Transform", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Vector2")) + matrix4d.BindMethod("Transform", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int { - double z(lua.CheckNumber(argIndex+1, 0.0)); - double w(lua.CheckNumber(argIndex+2, 1.0)); + int argIndex = 2; + if (lua.IsOfType(argIndex, "Vector2")) + { + double z(lua.CheckNumber(argIndex + 1, 0.0)); + double w(lua.CheckNumber(argIndex + 2, 1.0)); - return lua.Push(instance.Transform(*static_cast(lua.ToUserdata(argIndex)), z, w)); - } - else if (lua.IsOfType(argIndex, "Vector3")) + return lua.Push(instance.Transform(*static_cast(lua.ToUserdata(argIndex)), z, w)); + } + else if (lua.IsOfType(argIndex, "Vector3")) + { + double w(lua.CheckNumber(argIndex + 1, 1.0)); + + return lua.Push(instance.Transform(*static_cast(lua.ToUserdata(argIndex)), w)); + } + //else if (lua.IsOfType(2, "Vector4")) + // return lua.Push(instance.Transform(*static_cast(lua.ToUserdata(1)))); + + lua.Error("No matching overload for method Transform"); + return 0; + }); + + matrix4d.BindMethod("Transpose", &Nz::Matrix4d::Transpose); + + matrix4d.BindMethod("__tostring", &Nz::Matrix4d::ToString); + + matrix4d.BindStaticMethod("Concatenate", &Nz::Matrix4d::Concatenate); + matrix4d.BindStaticMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine); + matrix4d.BindStaticMethod("Identity", &Nz::Matrix4d::Identity); + matrix4d.BindStaticMethod("LookAt", &Nz::Matrix4d::LookAt, Nz::Vector3d::Up()); + matrix4d.BindStaticMethod("Ortho", &Nz::Matrix4d::Ortho, -1.0, 1.0); + matrix4d.BindStaticMethod("Perspective", &Nz::Matrix4d::Perspective); + matrix4d.BindStaticMethod("Rotate", &Nz::Matrix4d::Rotate); + matrix4d.BindStaticMethod("Scale", &Nz::Matrix4d::Scale); + matrix4d.BindStaticMethod("Translate", &Nz::Matrix4d::Translate); + matrix4d.BindStaticMethod("Transform", (Nz::Matrix4d(*)(const Nz::Vector3d&, const Nz::Quaterniond&, const Nz::Vector3d&)) &Nz::Matrix4d::Transform, Nz::Vector3d::Unit()); + matrix4d.BindStaticMethod("ViewMatrix", &Nz::Matrix4d::ViewMatrix); + matrix4d.BindStaticMethod("Zero", &Nz::Matrix4d::Zero); + + matrix4d.SetGetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) { - double w(lua.CheckNumber(argIndex+1, 1.0)); + bool succeeded = false; + std::size_t index = static_cast(lua.ToInteger(2, &succeeded)); + if (!succeeded || index < 1 || index > 16) + return false; - return lua.Push(instance.Transform(*static_cast(lua.ToUserdata(argIndex)), w)); - } - //else if (lua.IsOfType(2, "Vector4")) - // return lua.Push(instance.Transform(*static_cast(lua.ToUserdata(1)))); + lua.Push(instance[index - 1]); + return true; + }); - lua.Error("No matching overload for method Transform"); - return 0; - }); + matrix4d.SetSetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) + { + bool succeeded = false; + std::size_t index = static_cast(lua.ToInteger(2, &succeeded)); + if (!succeeded || index < 1 || index > 16) + return false; - matrix4d.BindMethod("Transpose", &Nz::Matrix4d::Transpose); + instance[index - 1] = lua.CheckNumber(3); - matrix4d.BindMethod("__tostring", &Nz::Matrix4d::ToString); - - matrix4d.BindStaticMethod("Concatenate", &Nz::Matrix4d::Concatenate); - matrix4d.BindStaticMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine); - matrix4d.BindStaticMethod("Identity", &Nz::Matrix4d::Identity); - matrix4d.BindStaticMethod("LookAt", &Nz::Matrix4d::LookAt, Nz::Vector3d::Up()); - matrix4d.BindStaticMethod("Ortho", &Nz::Matrix4d::Ortho, -1.0, 1.0); - matrix4d.BindStaticMethod("Perspective", &Nz::Matrix4d::Perspective); - matrix4d.BindStaticMethod("Rotate", &Nz::Matrix4d::Rotate); - matrix4d.BindStaticMethod("Scale", &Nz::Matrix4d::Scale); - matrix4d.BindStaticMethod("Translate", &Nz::Matrix4d::Translate); - matrix4d.BindStaticMethod("Transform", (Nz::Matrix4d(*)(const Nz::Vector3d&, const Nz::Quaterniond&, const Nz::Vector3d&)) &Nz::Matrix4d::Transform, Nz::Vector3d::Unit()); - matrix4d.BindStaticMethod("ViewMatrix", &Nz::Matrix4d::ViewMatrix); - matrix4d.BindStaticMethod("Zero", &Nz::Matrix4d::Zero); - - matrix4d.SetGetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) - { - bool succeeded = false; - std::size_t index = static_cast(lua.ToInteger(2, &succeeded)); - if (!succeeded || index < 1 || index > 16) - return false; - - lua.Push(instance[index - 1]); - return true; - }); - - matrix4d.SetSetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) - { - bool succeeded = false; - std::size_t index = static_cast(lua.ToInteger(2, &succeeded)); - if (!succeeded || index < 1 || index > 16) - return false; - - instance[index - 1] = lua.CheckNumber(3); - - return true; - }); + return true; + }); + } /*********************************** Nz::Rect **********************************/ - rect.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* instance, std::size_t argumentCount) + rect.Reset("Rect"); { - std::size_t argCount = std::min(argumentCount, 4U); - - switch (argCount) + rect.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* instance, std::size_t argumentCount) { - case 0: - case 4: - PlacementNew(instance, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0), lua.CheckNumber(4, 0.0)); - return true; + std::size_t argCount = std::min(argumentCount, 4U); - case 1: + switch (argCount) { - if (lua.IsOfType(1, "Rect")) - PlacementNew(instance, *static_cast(lua.ToUserdata(1))); - else if (lua.IsOfType(1, Nz::LuaType_Table)) + case 0: + case 4: + PlacementNew(instance, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0), lua.CheckNumber(4, 0.0)); + return true; + + case 1: { - // TODO => Faire sans avoir à mettre de nom dans la table et prendre les éléments un à un pour créer le Rectd - PlacementNew(instance, lua.CheckField("x", 1), - lua.CheckField("y", 1), - lua.CheckField("width", 1), - lua.CheckField("height", 1)); - } - else if (lua.IsOfType(1, "Vector2")) - PlacementNew(instance, *static_cast(lua.ToUserdata(1))); - else - break; - - return true; - } - - case 2: - { - if (lua.IsOfType(1, Nz::LuaType_Number) && lua.IsOfType(2, Nz::LuaType_Number)) - PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2)); - else if (lua.IsOfType(1, "Vector2") && lua.IsOfType(2, "Vector2")) - PlacementNew(instance, *static_cast(lua.ToUserdata(1)), *static_cast(lua.ToUserdata(2))); - else - break; - - return true; - } - } - - lua.Error("No matching overload for Rect constructor"); - return false; - }); - - rect.BindMethod("__tostring", &Nz::Rectd::ToString); - - rect.SetGetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance) - { - switch (lua.GetType(2)) - { - case Nz::LuaType_Number: - { - auto index = lua.CheckBoundInteger(2); - if (index < 1 || index > 4) - return false; - - lua.Push(instance[index - 1]); - return true; - } - - case Nz::LuaType_String: - { - std::size_t length; - const char* xywh = lua.CheckString(2, &length); - - if (length != 1) - break; - - switch (xywh[0]) - { - case 'x': - lua.Push(instance.x); - return true; - - case 'y': - lua.Push(instance.y); - return true; - - case 'w': - lua.Push(instance.width); - return true; - - case 'h': - lua.Push(instance.height); - return true; - - default: + if (lua.IsOfType(1, "Rect")) + PlacementNew(instance, *static_cast(lua.ToUserdata(1))); + else if (lua.IsOfType(1, Nz::LuaType_Table)) + { + // TODO => Faire sans avoir à mettre de nom dans la table et prendre les éléments un à un pour créer le Rectd + PlacementNew(instance, lua.CheckField("x", 1), + lua.CheckField("y", 1), + lua.CheckField("width", 1), + lua.CheckField("height", 1)); + } + else if (lua.IsOfType(1, "Vector2")) + PlacementNew(instance, *static_cast(lua.ToUserdata(1))); + else break; + + return true; } - break; - } - default: - break; - } - - return false; - }); - - rect.SetSetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance) - { - switch (lua.GetType(2)) - { - case Nz::LuaType_Number: - { - auto index = lua.CheckBoundInteger(2); - if (index < 1 || index > 4) - return false; - - instance[index - 1] = lua.CheckNumber(2); - return true; - } - - case Nz::LuaType_String: - { - std::size_t length; - const char* xywh = lua.CheckString(2, &length); - - if (length != 1) - break; - - double value = lua.CheckNumber(3); - - switch (xywh[0]) + case 2: { - case 'x': - instance.x = value; - return true; + if (lua.IsOfType(1, Nz::LuaType_Number) && lua.IsOfType(2, Nz::LuaType_Number)) + PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2)); + else if (lua.IsOfType(1, "Vector2") && lua.IsOfType(2, "Vector2")) + PlacementNew(instance, *static_cast(lua.ToUserdata(1)), *static_cast(lua.ToUserdata(2))); + else + break; - case 'y': - instance.y = value; - return true; - - case 'w': - instance.width = value; - return true; - - case 'h': - instance.height = value; - return true; + return true; } - break; } - default: - break; - } + lua.Error("No matching overload for Rect constructor"); + return false; + }); - return false; - }); + rect.BindMethod("__tostring", &Nz::Rectd::ToString); + + rect.SetGetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance) + { + switch (lua.GetType(2)) + { + case Nz::LuaType_Number: + { + auto index = lua.CheckBoundInteger(2); + if (index < 1 || index > 4) + return false; + + lua.Push(instance[index - 1]); + return true; + } + + case Nz::LuaType_String: + { + std::size_t length; + const char* xywh = lua.CheckString(2, &length); + + if (length != 1) + break; + + switch (xywh[0]) + { + case 'x': + lua.Push(instance.x); + return true; + + case 'y': + lua.Push(instance.y); + return true; + + case 'w': + lua.Push(instance.width); + return true; + + case 'h': + lua.Push(instance.height); + return true; + + default: + break; + } + break; + } + + default: + break; + } + + return false; + }); + + rect.SetSetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance) + { + switch (lua.GetType(2)) + { + case Nz::LuaType_Number: + { + auto index = lua.CheckBoundInteger(2); + if (index < 1 || index > 4) + return false; + + instance[index - 1] = lua.CheckNumber(2); + return true; + } + + case Nz::LuaType_String: + { + std::size_t length; + const char* xywh = lua.CheckString(2, &length); + + if (length != 1) + break; + + double value = lua.CheckNumber(3); + + switch (xywh[0]) + { + case 'x': + instance.x = value; + return true; + + case 'y': + instance.y = value; + return true; + + case 'w': + instance.width = value; + return true; + + case 'h': + instance.height = value; + return true; + } + break; + } + + default: + break; + } + + return false; + }); + } /*********************************** Nz::Quaternion **********************************/ - quaternion.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* instance, std::size_t argumentCount) + quaternion.Reset("Quaternion"); { - std::size_t argCount = std::min(argumentCount, 4U); - - switch (argCount) + quaternion.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* instance, std::size_t argumentCount) { - case 0: - Nz::PlacementNew(instance, Nz::Quaterniond::Zero()); - return true; + std::size_t argCount = std::min(argumentCount, 4U); - case 1: + switch (argCount) { - if (lua.IsOfType(1, "EulerAngles")) - Nz::PlacementNew(instance, *static_cast(lua.ToUserdata(1))); - else if (lua.IsOfType(1, "Quaternion")) - Nz::PlacementNew(instance, *static_cast(lua.ToUserdata(1))); - else - break; + case 0: + Nz::PlacementNew(instance, Nz::Quaterniond::Zero()); + return true; - return true; + case 1: + { + if (lua.IsOfType(1, "EulerAngles")) + Nz::PlacementNew(instance, *static_cast(lua.ToUserdata(1))); + else if (lua.IsOfType(1, "Quaternion")) + Nz::PlacementNew(instance, *static_cast(lua.ToUserdata(1))); + else + break; + + return true; + } + + case 2: + Nz::PlacementNew(instance, lua.CheckNumber(1), *static_cast(lua.CheckUserdata(2, "Vector3"))); + return true; + + case 4: + Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4)); + return true; + + default: + break; } - case 2: - Nz::PlacementNew(instance, lua.CheckNumber(1), *static_cast(lua.CheckUserdata(2, "Vector3"))); - return true; - - case 4: - Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4)); - return true; - - default: - break; - } - - lua.Error("No matching overload for Quaternion constructor"); - return false; - }); - - quaternion.BindMethod("ComputeW", &Nz::Quaterniond::ComputeW); - quaternion.BindMethod("Conjugate", &Nz::Quaterniond::Conjugate); - quaternion.BindMethod("DotProduct", &Nz::Quaterniond::DotProduct); - quaternion.BindMethod("GetConjugate", &Nz::Quaterniond::GetConjugate); - quaternion.BindMethod("GetInverse", &Nz::Quaterniond::GetInverse); - - quaternion.BindMethod("Inverse", &Nz::Quaterniond::Inverse); - quaternion.BindMethod("Magnitude", &Nz::Quaterniond::Magnitude); - - quaternion.BindMethod("SquaredMagnitude", &Nz::Quaterniond::SquaredMagnitude); - quaternion.BindMethod("ToEulerAngles", &Nz::Quaterniond::ToEulerAngles); - - quaternion.BindMethod("__tostring", &Nz::Quaterniond::ToString); - - quaternion.BindStaticMethod("Lerp", &Nz::Quaterniond::Lerp); - quaternion.BindStaticMethod("RotationBetween", &Nz::Quaterniond::RotationBetween); - quaternion.BindStaticMethod("Slerp", &Nz::Quaterniond::Slerp); - - quaternion.BindMethod("GetNormal", [] (Nz::LuaInstance& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int - { - double length; - - lua.Push(instance.GetNormal(&length)); - lua.Push(length); - - return 2; - }); - - quaternion.BindMethod("Normalize", [] (Nz::LuaInstance& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int - { - double length; - - instance.Normalize(&length); - lua.Push(1); //< instance - lua.Push(length); - - return 2; - }); - - quaternion.BindStaticMethod("Normalize", [] (Nz::LuaInstance& instance) -> int - { - int argIndex = 1; - Nz::Quaterniond quat = instance.Check(&argIndex); - - double length; - - instance.Push(Nz::Quaterniond::Normalize(quat, &length)); - instance.Push(length); - - return 2; - }); - - quaternion.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance) - { - std::size_t length; - const char* wxyz = lua.CheckString(2, &length); - - if (length != 1) + lua.Error("No matching overload for Quaternion constructor"); return false; + }); - switch (wxyz[0]) + quaternion.BindMethod("ComputeW", &Nz::Quaterniond::ComputeW); + quaternion.BindMethod("Conjugate", &Nz::Quaterniond::Conjugate); + quaternion.BindMethod("DotProduct", &Nz::Quaterniond::DotProduct); + quaternion.BindMethod("GetConjugate", &Nz::Quaterniond::GetConjugate); + quaternion.BindMethod("GetInverse", &Nz::Quaterniond::GetInverse); + + quaternion.BindMethod("Inverse", &Nz::Quaterniond::Inverse); + quaternion.BindMethod("Magnitude", &Nz::Quaterniond::Magnitude); + + quaternion.BindMethod("SquaredMagnitude", &Nz::Quaterniond::SquaredMagnitude); + quaternion.BindMethod("ToEulerAngles", &Nz::Quaterniond::ToEulerAngles); + + quaternion.BindMethod("__tostring", &Nz::Quaterniond::ToString); + + quaternion.BindStaticMethod("Lerp", &Nz::Quaterniond::Lerp); + quaternion.BindStaticMethod("RotationBetween", &Nz::Quaterniond::RotationBetween); + quaternion.BindStaticMethod("Slerp", &Nz::Quaterniond::Slerp); + + quaternion.BindMethod("GetNormal", [] (Nz::LuaInstance& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int { - case 'w': - lua.Push(instance.w); - return true; + double length; - case 'x': - lua.Push(instance.x); - return true; + lua.Push(instance.GetNormal(&length)); + lua.Push(length); - case 'y': - lua.Push(instance.y); - return true; + return 2; + }); - case 'z': - lua.Push(instance.z); - return true; - } + quaternion.BindMethod("Normalize", [] (Nz::LuaInstance& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int + { + double length; - return false; - }); + instance.Normalize(&length); + lua.Push(1); //< instance + lua.Push(length); - quaternion.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance) - { - std::size_t length; - const char* wxyz = lua.CheckString(2, &length); + return 2; + }); + + quaternion.BindStaticMethod("Normalize", [] (Nz::LuaInstance& instance) -> int + { + int argIndex = 1; + Nz::Quaterniond quat = instance.Check(&argIndex); + + double length; + + instance.Push(Nz::Quaterniond::Normalize(quat, &length)); + instance.Push(length); + + return 2; + }); + + quaternion.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance) + { + std::size_t length; + const char* wxyz = lua.CheckString(2, &length); + + if (length != 1) + return false; + + switch (wxyz[0]) + { + case 'w': + lua.Push(instance.w); + return true; + + case 'x': + lua.Push(instance.x); + return true; + + case 'y': + lua.Push(instance.y); + return true; + + case 'z': + lua.Push(instance.z); + return true; + } - if (length != 1) return false; + }); - double value = lua.CheckNumber(3); - - switch (wxyz[0]) + quaternion.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance) { - case 'w': - instance.w = value; - return true; + std::size_t length; + const char* wxyz = lua.CheckString(2, &length); - case 'x': - instance.x = value; - return true; + if (length != 1) + return false; - case 'y': - instance.y = value; - return true; + double value = lua.CheckNumber(3); - case 'z': - instance.z = value; - return true; + switch (wxyz[0]) + { + case 'w': + instance.w = value; + return true; - default: - break; - } + case 'x': + instance.x = value; + return true; - return false; - }); + case 'y': + instance.y = value; + return true; + + case 'z': + instance.z = value; + return true; + + default: + break; + } + + return false; + }); + } /*********************************** Nz::Vector2 **********************************/ - vector2d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector2d* vector, std::size_t argumentCount) + vector2d.Reset("Vector2"); { - std::size_t argCount = std::min(argumentCount, 2U); - - switch (argCount) + vector2d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector2d* vector, std::size_t argumentCount) { - case 0: - case 2: - Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0)); - return true; + std::size_t argCount = std::min(argumentCount, 2U); - case 1: + switch (argCount) { - if (lua.IsOfType(1, Nz::LuaType_Number)) - Nz::PlacementNew(vector, lua.CheckNumber(1)); - else if (lua.IsOfType(1, "Vector2")) - Nz::PlacementNew(vector, *static_cast(lua.ToUserdata(1))); - else - break; + case 0: + case 2: + Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0)); + return true; - return true; - } - } - - lua.Error("No matching overload for Vector2 constructor"); - return false; - }); - - vector2d.BindMethod("__tostring", &Nz::Vector2d::ToString); - - vector2d.SetGetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance) - { - switch (lua.GetType(2)) - { - case Nz::LuaType_Number: - { - long long index = lua.CheckInteger(2); - if (index < 1 || index > 2) - return false; - - lua.Push(instance[index - 1]); - return true; - } - - case Nz::LuaType_String: - { - std::size_t length; - const char* xy = lua.CheckString(2, &length); - - if (length != 1) - break; - - switch (xy[0]) + case 1: { - case 'x': - lua.Push(instance.x); - return true; - - case 'y': - lua.Push(instance.y); - return true; - - default: + if (lua.IsOfType(1, Nz::LuaType_Number)) + Nz::PlacementNew(vector, lua.CheckNumber(1)); + else if (lua.IsOfType(1, "Vector2")) + Nz::PlacementNew(vector, *static_cast(lua.ToUserdata(1))); + else break; + + return true; } - break; } - default: - break; - } + lua.Error("No matching overload for Vector2 constructor"); + return false; + }); - return false; - }); + vector2d.BindMethod("__tostring", &Nz::Vector2d::ToString); - vector2d.SetSetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance) - { - switch (lua.GetType(2)) + vector2d.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector2d& instance) { - case Nz::LuaType_Number: + switch (lua.GetType(2)) { - long long index = lua.CheckInteger(2); - if (index < 1 || index > 2) - return false; - - instance[index - 1] = lua.CheckNumber(3); - return true; - } - - case Nz::LuaType_String: - { - std::size_t length; - const char* xy = lua.CheckString(2, &length); - - if (length != 1) - break; - - double value = lua.CheckNumber(3); - - switch (xy[0]) + case Nz::LuaType_Number: { - case 'x': - instance.x = value; - return true; + long long index = lua.CheckInteger(2); + if (index < 1 || index > 2) + return false; - case 'y': - instance.y = value; - return true; - - default: - break; + lua.Push(instance[index - 1]); + return true; } - break; + + case Nz::LuaType_String: + { + std::size_t length; + const char* xy = lua.CheckString(2, &length); + + if (length != 1) + break; + + switch (xy[0]) + { + case 'x': + lua.Push(instance.x); + return true; + + case 'y': + lua.Push(instance.y); + return true; + + default: + break; + } + break; + } + + default: + break; } - default: - break; - } + return false; + }); - return false; - }); + vector2d.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector2d& instance) + { + switch (lua.GetType(2)) + { + case Nz::LuaType_Number: + { + long long index = lua.CheckInteger(2); + if (index < 1 || index > 2) + return false; + + instance[index - 1] = lua.CheckNumber(3); + return true; + } + + case Nz::LuaType_String: + { + std::size_t length; + const char* xy = lua.CheckString(2, &length); + + if (length != 1) + break; + + double value = lua.CheckNumber(3); + + switch (xy[0]) + { + case 'x': + instance.x = value; + return true; + + case 'y': + instance.y = value; + return true; + + default: + break; + } + break; + } + + default: + break; + } + + return false; + }); + } /*********************************** Nz::Vector3 **********************************/ - vector3d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector, std::size_t argumentCount) + vector3d.Reset("Vector3"); { - std::size_t argCount = std::min(argumentCount, 3U); - - switch (argCount) + vector3d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector, std::size_t argumentCount) { - case 0: - case 3: - Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0)); - return true; + std::size_t argCount = std::min(argumentCount, 3U); - case 1: + switch (argCount) { - if (lua.IsOfType(1, Nz::LuaType_Number)) - Nz::PlacementNew(vector, lua.CheckNumber(1)); - else if (lua.IsOfType(1, "Vector2")) - Nz::PlacementNew(vector, *static_cast(lua.ToUserdata(1))); - else if (lua.IsOfType(1, "Vector3")) - Nz::PlacementNew(vector, *static_cast(lua.ToUserdata(1))); - else - break; + case 0: + case 3: + Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0)); + return true; - return true; - } - - case 2: - { - if (lua.IsOfType(1, Nz::LuaType_Number)) - Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast(lua.CheckUserdata(2, "Vector2"))); - else if (lua.IsOfType(1, "Vector2")) - Nz::PlacementNew(vector, *static_cast(lua.ToUserdata(1)), lua.CheckNumber(2)); - else - break; - - return true; - } - } - - lua.Error("No matching overload for constructor"); - return false; - }); - - vector3d.BindMethod("__tostring", &Nz::Vector3d::ToString); - - vector3d.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) - { - switch (lua.GetType(2)) - { - case Nz::LuaType_Number: - { - long long index = lua.CheckInteger(2); - if (index < 1 || index > 3) - return false; - - lua.Push(instance[index - 1]); - return true; - } - - case Nz::LuaType_String: - { - std::size_t length; - const char* xyz = lua.CheckString(2, &length); - - if (length != 1) - break; - - switch (xyz[0]) + case 1: { - case 'x': - lua.Push(instance.x); - return true; - - case 'y': - lua.Push(instance.y); - return true; - - case 'z': - lua.Push(instance.z); - return true; - - default: + if (lua.IsOfType(1, Nz::LuaType_Number)) + Nz::PlacementNew(vector, lua.CheckNumber(1)); + else if (lua.IsOfType(1, "Vector2")) + Nz::PlacementNew(vector, *static_cast(lua.ToUserdata(1))); + else if (lua.IsOfType(1, "Vector3")) + Nz::PlacementNew(vector, *static_cast(lua.ToUserdata(1))); + else break; + + return true; } - break; - } - default: - break; - } - - return false; - }); - - vector3d.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) - { - switch (lua.GetType(2)) - { - case Nz::LuaType_Number: - { - long long index = lua.CheckInteger(2); - if (index < 1 || index > 3) - return false; - - instance[index - 1] = lua.CheckNumber(3); - return true; - } - - case Nz::LuaType_String: - { - std::size_t length; - const char* xyz = lua.CheckString(2, &length); - - if (length != 1) - break; - - double value = lua.CheckNumber(3); - - switch (xyz[0]) + case 2: { - case 'x': - instance.x = value; - return true; - - case 'y': - instance.y = value; - return true; - - case 'z': - instance.z = value; - return true; - - default: + if (lua.IsOfType(1, Nz::LuaType_Number)) + Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast(lua.CheckUserdata(2, "Vector2"))); + else if (lua.IsOfType(1, "Vector2")) + Nz::PlacementNew(vector, *static_cast(lua.ToUserdata(1)), lua.CheckNumber(2)); + else break; + + return true; } - break; } - default: - break; - } + lua.Error("No matching overload for constructor"); + return false; + }); - return false; - }); + vector3d.BindMethod("__tostring", &Nz::Vector3d::ToString); + + vector3d.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) + { + switch (lua.GetType(2)) + { + case Nz::LuaType_Number: + { + long long index = lua.CheckInteger(2); + if (index < 1 || index > 3) + return false; + + lua.Push(instance[index - 1]); + return true; + } + + case Nz::LuaType_String: + { + std::size_t length; + const char* xyz = lua.CheckString(2, &length); + + if (length != 1) + break; + + switch (xyz[0]) + { + case 'x': + lua.Push(instance.x); + return true; + + case 'y': + lua.Push(instance.y); + return true; + + case 'z': + lua.Push(instance.z); + return true; + + default: + break; + } + break; + } + + default: + break; + } + + return false; + }); + + vector3d.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) + { + switch (lua.GetType(2)) + { + case Nz::LuaType_Number: + { + long long index = lua.CheckInteger(2); + if (index < 1 || index > 3) + return false; + + instance[index - 1] = lua.CheckNumber(3); + return true; + } + + case Nz::LuaType_String: + { + std::size_t length; + const char* xyz = lua.CheckString(2, &length); + + if (length != 1) + break; + + double value = lua.CheckNumber(3); + + switch (xyz[0]) + { + case 'x': + instance.x = value; + return true; + + case 'y': + instance.y = value; + return true; + + case 'z': + instance.z = value; + return true; + + default: + break; + } + break; + } + + default: + break; + } + + return false; + }); + } } /*! @@ -948,8 +967,7 @@ namespace Ndk * * \param instance Lua instance that will interact with the Math classes */ - - void LuaBinding::RegisterMath(Nz::LuaInstance& instance) + void LuaBinding_Math::Register(Nz::LuaInstance& instance) { eulerAngles.Register(instance); matrix4d.Register(instance); diff --git a/SDK/src/NDK/LuaBinding_Network.cpp b/SDK/src/NDK/LuaBinding_Network.cpp index b51906481..4cccd337e 100644 --- a/SDK/src/NDK/LuaBinding_Network.cpp +++ b/SDK/src/NDK/LuaBinding_Network.cpp @@ -1,139 +1,147 @@ // This file was automatically generated on 26 May 2014 at 01:05:31 -#include +#include #include namespace Ndk { - /*! - * \brief Binds Network module to Lua - */ + std::unique_ptr LuaBinding_Base::BindNetwork(LuaBinding& binding) + { + return std::make_unique(binding); + } - void LuaBinding::BindNetwork() + LuaBinding_Network::LuaBinding_Network(LuaBinding& binding) : + LuaBinding_Base(binding) { /*********************************** Nz::AbstractSocket **********************************/ - abstractSocket.BindMethod("Close", &Nz::AbstractSocket::Close); - abstractSocket.BindMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking); - abstractSocket.BindMethod("GetLastError", &Nz::AbstractSocket::GetLastError); - abstractSocket.BindMethod("GetState", &Nz::AbstractSocket::GetState); - abstractSocket.BindMethod("GetType", &Nz::AbstractSocket::GetType); - abstractSocket.BindMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled); - abstractSocket.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes); + abstractSocket.Reset("AbstractSocket"); + { + abstractSocket.BindMethod("Close", &Nz::AbstractSocket::Close); + abstractSocket.BindMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking); + abstractSocket.BindMethod("GetLastError", &Nz::AbstractSocket::GetLastError); + abstractSocket.BindMethod("GetState", &Nz::AbstractSocket::GetState); + abstractSocket.BindMethod("GetType", &Nz::AbstractSocket::GetType); + abstractSocket.BindMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled); + abstractSocket.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes); + } /*********************************** Nz::IpAddress **********************************/ - ipAddress.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* instance, std::size_t argumentCount) + ipAddress.Reset("IpAddress"); { - std::size_t argCount = std::min(argumentCount, 9U); - - int argIndex = 2; - switch (argCount) + ipAddress.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* instance, std::size_t argumentCount) { - case 0: - Nz::PlacementNew(instance); - return true; + std::size_t argCount = std::min(argumentCount, 9U); - case 1: - Nz::PlacementNew(instance, lua.CheckString(argIndex)); - return true; - - case 4: - case 5: + int argIndex = 2; + switch (argCount) { - Nz::UInt8 a = lua.Check(&argIndex); - Nz::UInt8 b = lua.Check(&argIndex); - Nz::UInt8 c = lua.Check(&argIndex); - Nz::UInt8 d = lua.Check(&argIndex); - Nz::UInt16 port = lua.Check(&argIndex, 0); + case 0: + Nz::PlacementNew(instance); + return true; - Nz::PlacementNew(instance, a, b, c, d, port); - return true; + case 1: + Nz::PlacementNew(instance, lua.CheckString(argIndex)); + return true; + + case 4: + case 5: + { + Nz::UInt8 a = lua.Check(&argIndex); + Nz::UInt8 b = lua.Check(&argIndex); + Nz::UInt8 c = lua.Check(&argIndex); + Nz::UInt8 d = lua.Check(&argIndex); + Nz::UInt16 port = lua.Check(&argIndex, 0); + + Nz::PlacementNew(instance, a, b, c, d, port); + return true; + } + + case 8: + case 9: + { + Nz::UInt16 a = lua.Check(&argIndex); + Nz::UInt16 b = lua.Check(&argIndex); + Nz::UInt16 c = lua.Check(&argIndex); + Nz::UInt16 d = lua.Check(&argIndex); + Nz::UInt16 e = lua.Check(&argIndex); + Nz::UInt16 f = lua.Check(&argIndex); + Nz::UInt16 g = lua.Check(&argIndex); + Nz::UInt16 h = lua.Check(&argIndex); + Nz::UInt16 port = lua.Check(&argIndex, 0); + + Nz::PlacementNew(instance, a, b, c, d, e, f, g, h, port); + return true; + } } - case 8: - case 9: + lua.Error("No matching overload for constructor"); + return false; + }); + + ipAddress.BindMethod("GetPort", &Nz::IpAddress::GetPort); + ipAddress.BindMethod("GetProtocol", &Nz::IpAddress::GetProtocol); + ipAddress.BindMethod("IsLoopback", &Nz::IpAddress::IsLoopback); + ipAddress.BindMethod("IsValid", &Nz::IpAddress::IsValid); + ipAddress.BindMethod("ToUInt32", &Nz::IpAddress::ToUInt32); + ipAddress.BindMethod("__tostring", &Nz::IpAddress::ToString); + + ipAddress.BindStaticMethod("ResolveAddress", [] (Nz::LuaInstance& instance) -> int + { + Nz::String service; + Nz::ResolveError error = Nz::ResolveError_Unknown; + + int argIndex = 2; + Nz::String hostName = Nz::IpAddress::ResolveAddress(instance.Check(&argIndex), &service, &error); + + if (error == Nz::ResolveError_NoError) { - Nz::UInt16 a = lua.Check(&argIndex); - Nz::UInt16 b = lua.Check(&argIndex); - Nz::UInt16 c = lua.Check(&argIndex); - Nz::UInt16 d = lua.Check(&argIndex); - Nz::UInt16 e = lua.Check(&argIndex); - Nz::UInt16 f = lua.Check(&argIndex); - Nz::UInt16 g = lua.Check(&argIndex); - Nz::UInt16 h = lua.Check(&argIndex); - Nz::UInt16 port = lua.Check(&argIndex, 0); - - Nz::PlacementNew(instance, a, b, c, d, e, f, g, h, port); - return true; + instance.Push(hostName); + instance.Push(service); + return 2; } - } - - lua.Error("No matching overload for constructor"); - return false; - }); - - ipAddress.BindMethod("GetPort", &Nz::IpAddress::GetPort); - ipAddress.BindMethod("GetProtocol", &Nz::IpAddress::GetProtocol); - ipAddress.BindMethod("IsLoopback", &Nz::IpAddress::IsLoopback); - ipAddress.BindMethod("IsValid", &Nz::IpAddress::IsValid); - ipAddress.BindMethod("ToUInt32", &Nz::IpAddress::ToUInt32); - ipAddress.BindMethod("__tostring", &Nz::IpAddress::ToString); - - ipAddress.BindStaticMethod("ResolveAddress", [] (Nz::LuaInstance& instance) -> int - { - Nz::String service; - Nz::ResolveError error = Nz::ResolveError_Unknown; - - int argIndex = 2; - Nz::String hostName = Nz::IpAddress::ResolveAddress(instance.Check(&argIndex), &service, &error); - - if (error == Nz::ResolveError_NoError) - { - instance.Push(hostName); - instance.Push(service); - return 2; - } - else - { - instance.PushBoolean(false); - instance.Push(error); - return 2; - } - }); - - ipAddress.BindStaticMethod("ResolveHostname", [] (Nz::LuaInstance& instance) -> int - { - Nz::ResolveError error = Nz::ResolveError_Unknown; - - int argIndex = 2; - Nz::NetProtocol protocol = instance.Check(&argIndex); - Nz::String hostname = instance.Check(&argIndex); - Nz::String service = instance.Check(&argIndex, "http"); - - std::vector addresses = Nz::IpAddress::ResolveHostname(protocol, hostname, service, &error); - if (error == Nz::ResolveError_NoError) - { - int index = 1; - instance.PushTable(addresses.size()); - for (Nz::HostnameInfo& info : addresses) + else { - instance.PushInteger(index++); - instance.PushTable(0, 4); - instance.PushField("Address", std::move(info.address)); - instance.PushField("CanonicalName", std::move(info.canonicalName)); - instance.PushField("Protocol", std::move(info.protocol)); - instance.PushField("SocketType", std::move(info.socketType)); - instance.SetTable(); + instance.PushBoolean(false); + instance.Push(error); + return 2; } + }); - return 1; - } - else + ipAddress.BindStaticMethod("ResolveHostname", [] (Nz::LuaInstance& instance) -> int { - instance.PushBoolean(false); - instance.Push(error); - return 2; - } - }); + Nz::ResolveError error = Nz::ResolveError_Unknown; + + int argIndex = 2; + Nz::NetProtocol protocol = instance.Check(&argIndex); + Nz::String hostname = instance.Check(&argIndex); + Nz::String service = instance.Check(&argIndex, "http"); + + std::vector addresses = Nz::IpAddress::ResolveHostname(protocol, hostname, service, &error); + if (error == Nz::ResolveError_NoError) + { + int index = 1; + instance.PushTable(addresses.size()); + for (Nz::HostnameInfo& info : addresses) + { + instance.PushInteger(index++); + instance.PushTable(0, 4); + instance.PushField("Address", std::move(info.address)); + instance.PushField("CanonicalName", std::move(info.canonicalName)); + instance.PushField("Protocol", std::move(info.protocol)); + instance.PushField("SocketType", std::move(info.socketType)); + instance.SetTable(); + } + + return 1; + } + else + { + instance.PushBoolean(false); + instance.Push(error); + return 2; + } + }); + } } /*! @@ -141,8 +149,7 @@ namespace Ndk * * \param instance Lua instance that will interact with the Network classes */ - - void LuaBinding::RegisterNetwork(Nz::LuaInstance& instance) + void LuaBinding_Network::Register(Nz::LuaInstance& instance) { // Classes abstractSocket.Register(instance); diff --git a/SDK/src/NDK/LuaBinding_Renderer.cpp b/SDK/src/NDK/LuaBinding_Renderer.cpp index 1f1f9479f..12d1d291e 100644 --- a/SDK/src/NDK/LuaBinding_Renderer.cpp +++ b/SDK/src/NDK/LuaBinding_Renderer.cpp @@ -1,67 +1,99 @@ -// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot +// 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 +#include #include +#include +#include namespace Ndk { - /*! - * \brief Binds Renderer module to Lua - */ - void LuaBinding::BindRenderer() + std::unique_ptr LuaBinding_Base::BindRenderer(LuaBinding& binding) { + return std::make_unique(binding); + } + + LuaBinding_Renderer::LuaBinding_Renderer(LuaBinding& binding) : + LuaBinding_Base(binding) + { + LuaBinding_Utility& utility = static_cast(*m_binding.utility); + /*********************************** Nz::Texture ***********************************/ - texture.Inherit(abstractImage, [] (Nz::TextureRef* textureRef) -> Nz::AbstractImageRef* + texture.Reset("Texture"); { - return reinterpret_cast(textureRef); //TODO: Make a ObjectRefCast - }); + texture.Inherit(utility.abstractImage, [] (Nz::TextureRef* textureRef) -> Nz::AbstractImageRef* + { + return reinterpret_cast(textureRef); //TODO: Make a ObjectRefCast + }); - texture.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::TextureRef* instance, std::size_t /*argumentCount*/) + texture.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::TextureRef* instance, std::size_t /*argumentCount*/) + { + Nz::PlacementNew(instance, Nz::Texture::New()); + return true; + }); + + texture.BindMethod("Create", &Nz::Texture::Create, static_cast(1), 1U); + texture.BindMethod("Destroy", &Nz::Texture::Destroy); + + //texture.BindMethod("Download", &Nz::Texture::Download); + + texture.BindMethod("EnableMipmapping", &Nz::Texture::EnableMipmapping); + texture.BindMethod("EnsureMipmapsUpdate", &Nz::Texture::EnsureMipmapsUpdate); + texture.BindMethod("HasMipmaps", &Nz::Texture::HasMipmaps); + texture.BindMethod("InvalidateMipmaps", &Nz::Texture::InvalidateMipmaps); + texture.BindMethod("IsValid", &Nz::Texture::IsValid); + + texture.BindMethod("LoadFromFile", &Nz::Texture::LoadFromFile, true, Nz::ImageParams()); + //bool LoadFromImage(const Image& image, bool generateMipmaps = true); + //bool LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams(), bool generateMipmaps = true); + //bool LoadFromStream(Stream& stream, const ImageParams& params = ImageParams(), bool generateMipmaps = true); + + texture.BindMethod("LoadArrayFromFile", &Nz::Texture::LoadArrayFromFile, Nz::Vector2ui(2, 2), true, Nz::ImageParams()); + //bool LoadArrayFromImage(const Image& image, bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2)); + //bool LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2)); + //bool LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2)); + + //bool LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams()); + //bool LoadCubemapFromImage(const Image& image, bool generateMipmaps = true, const CubemapParams& params = CubemapParams()); + //bool LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams()); + //bool LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams()); + + texture.BindMethod("LoadFaceFromFile", &Nz::Texture::LoadFaceFromFile, Nz::ImageParams()); + //bool LoadFaceFromMemory(CubemapFace face, const void* data, std::size_t size, const ImageParams& params = ImageParams()); + //bool LoadFaceFromStream(CubemapFace face, Stream& stream, const ImageParams& params = ImageParams()); + + texture.BindMethod("SaveToFile", &Nz::Texture::SaveToFile, Nz::ImageParams()); + //bool SaveToStream(Stream& stream, const String& format, const ImageParams& params = ImageParams()); + + texture.BindMethod("SetMipmapRange", &Nz::Texture::SetMipmapRange); + + texture.BindStaticMethod("IsFormatSupported", &Nz::Texture::IsFormatSupported); + texture.BindStaticMethod("IsMipmappingSupported", &Nz::Texture::IsMipmappingSupported); + texture.BindStaticMethod("IsTypeSupported", &Nz::Texture::IsTypeSupported); + } + + /*********************************** Nz::TextureLibrary ***********************************/ + textureLibrary.Reset("TextureLibrary"); { - Nz::PlacementNew(instance, Nz::Texture::New()); - return true; - }); + textureLibrary.BindStaticMethod("Get", &Nz::TextureLibrary::Get); + textureLibrary.BindStaticMethod("Has", &Nz::TextureLibrary::Has); + textureLibrary.BindStaticMethod("Register", &Nz::TextureLibrary::Register); + textureLibrary.BindStaticMethod("Query", &Nz::TextureLibrary::Query); + textureLibrary.BindStaticMethod("Unregister", &Nz::TextureLibrary::Unregister); + } - texture.BindMethod("Create", &Nz::Texture::Create, static_cast(1), 1U); - texture.BindMethod("Destroy", &Nz::Texture::Destroy); - - //texture.BindMethod("Download", &Nz::Texture::Download); - - texture.BindMethod("EnableMipmapping", &Nz::Texture::EnableMipmapping); - texture.BindMethod("EnsureMipmapsUpdate", &Nz::Texture::EnsureMipmapsUpdate); - texture.BindMethod("HasMipmaps", &Nz::Texture::HasMipmaps); - texture.BindMethod("InvalidateMipmaps", &Nz::Texture::InvalidateMipmaps); - texture.BindMethod("IsValid", &Nz::Texture::IsValid); - - texture.BindMethod("LoadFromFile", &Nz::Texture::LoadFromFile, true, Nz::ImageParams()); - //bool LoadFromImage(const Image& image, bool generateMipmaps = true); - //bool LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams(), bool generateMipmaps = true); - //bool LoadFromStream(Stream& stream, const ImageParams& params = ImageParams(), bool generateMipmaps = true); - - texture.BindMethod("LoadArrayFromFile", &Nz::Texture::LoadArrayFromFile, Nz::Vector2ui(2, 2), true, Nz::ImageParams()); - //bool LoadArrayFromImage(const Image& image, bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2)); - //bool LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2)); - //bool LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2)); - - //bool LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams()); - //bool LoadCubemapFromImage(const Image& image, bool generateMipmaps = true, const CubemapParams& params = CubemapParams()); - //bool LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams()); - //bool LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams()); - - texture.BindMethod("LoadFaceFromFile", &Nz::Texture::LoadFaceFromFile, Nz::ImageParams()); - //bool LoadFaceFromMemory(CubemapFace face, const void* data, std::size_t size, const ImageParams& params = ImageParams()); - //bool LoadFaceFromStream(CubemapFace face, Stream& stream, const ImageParams& params = ImageParams()); - - texture.BindMethod("SaveToFile", &Nz::Texture::SaveToFile, Nz::ImageParams()); - //bool SaveToStream(Stream& stream, const String& format, const ImageParams& params = ImageParams()); - - texture.BindMethod("SetMipmapRange", &Nz::Texture::SetMipmapRange); - - texture.BindStaticMethod("IsFormatSupported", &Nz::Texture::IsFormatSupported); - texture.BindStaticMethod("IsMipmappingSupported", &Nz::Texture::IsMipmappingSupported); - texture.BindStaticMethod("IsTypeSupported", &Nz::Texture::IsTypeSupported); + /*********************************** Nz::TextureManager ***********************************/ + textureManager.Reset("textureManager"); + { + textureManager.BindStaticMethod("Clear", &Nz::TextureManager::Clear); + textureManager.BindStaticMethod("Get", &Nz::TextureManager::Get); + textureManager.BindStaticMethod("GetDefaultParameters", &Nz::TextureManager::GetDefaultParameters); + textureManager.BindStaticMethod("Purge", &Nz::TextureManager::Purge); + textureManager.BindStaticMethod("Register", &Nz::TextureManager::Register); + textureManager.BindStaticMethod("SetDefaultParameters", &Nz::TextureManager::SetDefaultParameters); + textureManager.BindStaticMethod("Unregister", &Nz::TextureManager::Unregister); + } } /*! @@ -69,8 +101,10 @@ namespace Ndk * * \param instance Lua instance that will interact with the Renderer classes */ - void LuaBinding::RegisterRenderer(Nz::LuaInstance& instance) + void LuaBinding_Renderer::Register(Nz::LuaInstance& instance) { texture.Register(instance); + textureLibrary.Register(instance); + textureManager.Register(instance); } } diff --git a/SDK/src/NDK/LuaBinding_SDK.cpp b/SDK/src/NDK/LuaBinding_SDK.cpp index 37c2d71e9..b59d17631 100644 --- a/SDK/src/NDK/LuaBinding_SDK.cpp +++ b/SDK/src/NDK/LuaBinding_SDK.cpp @@ -2,230 +2,263 @@ // This file is part of the "Nazara Development Kit" // For conditions of distribution and use, see copyright notice in Prerequesites.hpp -#include +#include #include +#include +#include + +#ifndef NDK_SERVER +#include +#endif namespace Ndk { - /*! - * \brief Binds SDK module to Lua - */ - - void LuaBinding::BindSDK() + std::unique_ptr LuaBinding_Base::BindSDK(LuaBinding& binding) { - /*********************************** Ndk::Application **********************************/ + return std::make_unique(binding); + } + LuaBinding_SDK::LuaBinding_SDK(LuaBinding& binding) : + LuaBinding_Base(binding) + { #ifndef NDK_SERVER - //application.SetMethod("AddWindow", &Application::AddWindow); - - application.BindMethod("EnableConsole", &Application::EnableConsole); - application.BindMethod("EnableFPSCounter", &Application::EnableFPSCounter); - - application.BindMethod("IsConsoleEnabled", &Application::IsConsoleEnabled); - application.BindMethod("IsFPSCounterEnabled", &Application::IsFPSCounterEnabled); + LuaBinding_Graphics& graphics = static_cast(*m_binding.graphics); #endif - application.BindMethod("AddWorld", [] (Nz::LuaInstance& lua, Application* instance, std::size_t /*argumentCount*/) -> int - { - lua.Push(instance->AddWorld().CreateHandle()); - return 1; - }); + LuaBinding_Utility& utility = static_cast(*m_binding.utility); - application.BindMethod("GetUpdateTime", &Application::GetUpdateTime); - application.BindMethod("Quit", &Application::Quit); + /*********************************** Ndk::Application **********************************/ + application.Reset("Application"); + { + #ifndef NDK_SERVER + //application.SetMethod("AddWindow", &Application::AddWindow); + + application.BindMethod("EnableConsole", &Application::EnableConsole); + application.BindMethod("EnableFPSCounter", &Application::EnableFPSCounter); + + application.BindMethod("IsConsoleEnabled", &Application::IsConsoleEnabled); + application.BindMethod("IsFPSCounterEnabled", &Application::IsFPSCounterEnabled); + #endif + + application.BindMethod("AddWorld", [] (Nz::LuaInstance& lua, Application* instance, std::size_t /*argumentCount*/) -> int + { + lua.Push(instance->AddWorld().CreateHandle()); + return 1; + }); + + application.BindMethod("GetUpdateTime", &Application::GetUpdateTime); + application.BindMethod("Quit", &Application::Quit); + } /*********************************** Ndk::Console **********************************/ #ifndef NDK_SERVER - console.Inherit(node, [] (ConsoleHandle* handle) -> Nz::Node* + console.Reset("Console"); { - return handle->GetObject(); - }); + console.Inherit(utility.node, [] (ConsoleHandle* handle) -> Nz::Node* + { + return handle->GetObject(); + }); - console.BindMethod("AddLine", &Console::AddLine, Nz::Color::White); - console.BindMethod("Clear", &Console::Clear); - console.BindMethod("GetCharacterSize", &Console::GetCharacterSize); - console.BindMethod("GetHistory", &Console::GetHistory); - console.BindMethod("GetHistoryBackground", &Console::GetHistoryBackground); - console.BindMethod("GetInput", &Console::GetInput); - console.BindMethod("GetInputBackground", &Console::GetInputBackground); - console.BindMethod("GetSize", &Console::GetSize); - console.BindMethod("GetTextFont", &Console::GetTextFont); + console.BindMethod("AddLine", &Console::AddLine, Nz::Color::White); + console.BindMethod("Clear", &Console::Clear); + console.BindMethod("GetCharacterSize", &Console::GetCharacterSize); + console.BindMethod("GetHistory", &Console::GetHistory); + console.BindMethod("GetHistoryBackground", &Console::GetHistoryBackground); + console.BindMethod("GetInput", &Console::GetInput); + console.BindMethod("GetInputBackground", &Console::GetInputBackground); + console.BindMethod("GetSize", &Console::GetSize); + console.BindMethod("GetTextFont", &Console::GetTextFont); - console.BindMethod("IsVisible", &Console::IsVisible); + console.BindMethod("IsVisible", &Console::IsVisible); - console.BindMethod("SendCharacter", &Console::SendCharacter); - //consoleClass.SetMethod("SendEvent", &Console::SendEvent); + console.BindMethod("SendCharacter", &Console::SendCharacter); + //consoleClass.SetMethod("SendEvent", &Console::SendEvent); - console.BindMethod("SetCharacterSize", &Console::SetCharacterSize); - console.BindMethod("SetSize", &Console::SetSize); - console.BindMethod("SetTextFont", &Console::SetTextFont); + console.BindMethod("SetCharacterSize", &Console::SetCharacterSize); + console.BindMethod("SetSize", &Console::SetSize); + console.BindMethod("SetTextFont", &Console::SetTextFont); - console.BindMethod("Show", &Console::Show, true); + console.BindMethod("Show", &Console::Show, true); + } #endif /*********************************** Ndk::Entity **********************************/ - entity.BindMethod("Enable", &Entity::Enable, true); - entity.BindMethod("GetId", &Entity::GetId); - entity.BindMethod("GetWorld", &Entity::GetWorld); - entity.BindMethod("Kill", &Entity::Kill); - entity.BindMethod("IsEnabled", &Entity::IsEnabled); - entity.BindMethod("IsValid", &Entity::IsValid); - entity.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents); - entity.BindMethod("__tostring", &EntityHandle::ToString); - - entity.BindMethod("AddComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int + entity.Reset("Entity"); { - ComponentBinding* binding = QueryComponentIndex(instance); + entity.BindMethod("Enable", &Entity::Enable, true); + entity.BindMethod("GetId", &Entity::GetId); + entity.BindMethod("GetWorld", &Entity::GetWorld); + entity.BindMethod("Kill", &Entity::Kill); + entity.BindMethod("IsEnabled", &Entity::IsEnabled); + entity.BindMethod("IsValid", &Entity::IsValid); + entity.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents); + entity.BindMethod("__tostring", &EntityHandle::ToString); - return binding->adder(instance, handle); - }); + entity.BindMethod("AddComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int + { + LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance); - entity.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int - { - ComponentBinding* binding = QueryComponentIndex(instance); + return binding->adder(instance, handle); + }); - return binding->getter(instance, handle->GetComponent(binding->index)); - }); + entity.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int + { + LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance); - entity.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int - { - ComponentBinding* binding = QueryComponentIndex(instance); + return binding->getter(instance, handle->GetComponent(binding->index)); + }); - handle->RemoveComponent(binding->index); - return 0; - }); + entity.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int + { + LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance); + + handle->RemoveComponent(binding->index); + return 0; + }); + } /*********************************** Ndk::NodeComponent **********************************/ - nodeComponent.Inherit(node, [] (NodeComponentHandle* handle) -> Nz::Node* + nodeComponent.Reset("NodeComponent"); { - return handle->GetObject(); - }); + nodeComponent.Inherit(utility.node, [] (NodeComponentHandle* handle) -> Nz::Node* + { + return handle->GetObject(); + }); + } /*********************************** Ndk::VelocityComponent **********************************/ - velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance) + velocityComponent.Reset("VelocityComponent"); { - std::size_t length; - const char* member = lua.CheckString(2, &length); - - if (std::strcmp(member, "Linear") == 0) + velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance) { - lua.Push(instance->linearVelocity); - return true; - } + std::size_t length; + const char* member = lua.CheckString(2, &length); - return false; - }); + if (std::strcmp(member, "Linear") == 0) + { + lua.Push(instance->linearVelocity); + return true; + } - velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance) - { - std::size_t length; - const char* member = lua.CheckString(2, &length); + return false; + }); - int argIndex = 3; - if (std::strcmp(member, "Linear") == 0) + velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance) { - instance->linearVelocity = lua.Check(&argIndex); - return true; - } + std::size_t length; + const char* member = lua.CheckString(2, &length); - return false; - }); + int argIndex = 3; + if (std::strcmp(member, "Linear") == 0) + { + instance->linearVelocity = lua.Check(&argIndex); + return true; + } + + return false; + }); + } /*********************************** Ndk::World **********************************/ - world.BindMethod("CreateEntity", &World::CreateEntity); - world.BindMethod("CreateEntities", &World::CreateEntities); - world.BindMethod("Clear", &World::Clear); - + world.Reset("World"); + { + world.BindMethod("CreateEntity", &World::CreateEntity); + world.BindMethod("CreateEntities", &World::CreateEntities); + world.BindMethod("Clear", &World::Clear); + } #ifndef NDK_SERVER /*********************************** Ndk::CameraComponent **********************************/ - cameraComponent.Inherit(abstractViewer, [] (CameraComponentHandle* handle) -> Nz::AbstractViewer* + cameraComponent.Reset("CameraComponent"); { - return handle->GetObject(); - }); + cameraComponent.Inherit(graphics.abstractViewer, [] (CameraComponentHandle* handle) -> Nz::AbstractViewer* + { + return handle->GetObject(); + }); - cameraComponent.BindMethod("GetFOV", &Ndk::CameraComponent::GetFOV); - cameraComponent.BindMethod("GetLayer", &Ndk::CameraComponent::GetLayer); + cameraComponent.BindMethod("GetFOV", &Ndk::CameraComponent::GetFOV); + cameraComponent.BindMethod("GetLayer", &Ndk::CameraComponent::GetLayer); - cameraComponent.BindMethod("SetFOV", &Ndk::CameraComponent::SetFOV); - cameraComponent.BindMethod("SetLayer", &Ndk::CameraComponent::SetLayer); - cameraComponent.BindMethod("SetProjectionType", &Ndk::CameraComponent::SetProjectionType); - cameraComponent.BindMethod("SetSize", (void(Ndk::CameraComponent::*)(const Nz::Vector2f&)) &Ndk::CameraComponent::SetSize); - //cameraComponent.BindMethod("SetTarget", &Ndk::CameraComponent::SetTarget); - cameraComponent.BindMethod("SetTargetRegion", &Ndk::CameraComponent::SetTargetRegion); - cameraComponent.BindMethod("SetViewport", &Ndk::CameraComponent::SetViewport); - cameraComponent.BindMethod("SetZFar", &Ndk::CameraComponent::SetZFar); - cameraComponent.BindMethod("SetZNear", &Ndk::CameraComponent::SetZNear); + cameraComponent.BindMethod("SetFOV", &Ndk::CameraComponent::SetFOV); + cameraComponent.BindMethod("SetLayer", &Ndk::CameraComponent::SetLayer); + cameraComponent.BindMethod("SetProjectionType", &Ndk::CameraComponent::SetProjectionType); + cameraComponent.BindMethod("SetSize", (void(Ndk::CameraComponent::*)(const Nz::Vector2f&)) &Ndk::CameraComponent::SetSize); + //cameraComponent.BindMethod("SetTarget", &Ndk::CameraComponent::SetTarget); + cameraComponent.BindMethod("SetTargetRegion", &Ndk::CameraComponent::SetTargetRegion); + cameraComponent.BindMethod("SetViewport", &Ndk::CameraComponent::SetViewport); + cameraComponent.BindMethod("SetZFar", &Ndk::CameraComponent::SetZFar); + cameraComponent.BindMethod("SetZNear", &Ndk::CameraComponent::SetZNear); + } /*********************************** Ndk::GraphicsComponent **********************************/ - graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent* instance, std::size_t argumentCount) -> int + graphicsComponent.Reset("GraphicsComponent"); { - /* - void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0); - void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0); - */ - - std::size_t argCount = std::min(argumentCount, 3U); - - switch (argCount) + graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent* instance, std::size_t argumentCount) -> int { - case 1: - { - int argIndex = 2; - instance->Attach(lua.Check(&argIndex)); - return 0; - } + /* + void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0); + void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0); + */ - case 2: - { - int argIndex = 2; - Nz::InstancedRenderableRef renderable = lua.Check(&argIndex); + std::size_t argCount = std::min(argumentCount, 3U); - if (lua.IsOfType(argIndex, Nz::LuaType_Number)) + switch (argCount) + { + case 1: { + int argIndex = 2; + instance->Attach(lua.Check(&argIndex)); + return 0; + } + + case 2: + { + int argIndex = 2; + Nz::InstancedRenderableRef renderable = lua.Check(&argIndex); + + if (lua.IsOfType(argIndex, Nz::LuaType_Number)) + { + int renderOrder = lua.Check(&argIndex); + + instance->Attach(renderable, renderOrder); + } + else if (lua.IsOfType(argIndex, "Matrix4")) + { + Nz::Matrix4f localMatrix = lua.Check(&argIndex); + + instance->Attach(renderable, localMatrix); + } + else + break; + + return 0; + } + + case 3: + { + int argIndex = 2; + Nz::InstancedRenderableRef renderable = lua.Check(&argIndex); + Nz::Matrix4f localMatrix = lua.Check(&argIndex); int renderOrder = lua.Check(&argIndex); - instance->Attach(renderable, renderOrder); + instance->Attach(renderable, localMatrix, renderOrder); + return 0; } - else if (lua.IsOfType(argIndex, "Matrix4")) - { - Nz::Matrix4f localMatrix = lua.Check(&argIndex); - - instance->Attach(renderable, localMatrix); - } - else - break; - - return 0; } - case 3: - { - int argIndex = 2; - Nz::InstancedRenderableRef renderable = lua.Check(&argIndex); - Nz::Matrix4f localMatrix = lua.Check(&argIndex); - int renderOrder = lua.Check(&argIndex); - - instance->Attach(renderable, localMatrix, renderOrder); - return 0; - } - } - - lua.Error("No matching overload for method GetMemoryUsage"); - return 0; - }); + lua.Error("No matching overload for method GetMemoryUsage"); + return 0; + }); + } #endif - // Components functions - m_componentBinding.resize(BaseComponent::GetMaxComponentIndex()); - - BindComponent("Node"); - BindComponent("Velocity"); + m_binding.BindComponent("Node"); + m_binding.BindComponent("Velocity"); #ifndef NDK_SERVER - BindComponent("Camera"); - BindComponent("Graphics"); + m_binding.BindComponent("Camera"); + m_binding.BindComponent("Graphics"); #endif } @@ -234,8 +267,7 @@ namespace Ndk * * \param instance Lua instance that will interact with the SDK classes */ - - void LuaBinding::RegisterSDK(Nz::LuaInstance& instance) + void LuaBinding_SDK::Register(Nz::LuaInstance& instance) { // Classes application.Register(instance); @@ -251,19 +283,6 @@ namespace Ndk #endif // Enums - - // ComponentType (fake enumeration to expose component indexes) - instance.PushTable(0, m_componentBinding.size()); - { - for (const ComponentBinding& entry : m_componentBinding) - { - if (entry.name.IsEmpty()) - continue; - - instance.PushField(entry.name, entry.index); - } - } - instance.SetGlobal("ComponentType"); } /*! @@ -273,7 +292,6 @@ namespace Ndk * \param instance Lua instance that will interact with the component * \param argIndex Index of the component */ - LuaBinding::ComponentBinding* LuaBinding::QueryComponentIndex(Nz::LuaInstance& instance, int argIndex) { switch (instance.GetType(argIndex)) diff --git a/SDK/src/NDK/LuaBinding_Utility.cpp b/SDK/src/NDK/LuaBinding_Utility.cpp index 686182410..744af3a98 100644 --- a/SDK/src/NDK/LuaBinding_Utility.cpp +++ b/SDK/src/NDK/LuaBinding_Utility.cpp @@ -1,16 +1,18 @@ // This file is part of the "Nazara Development Kit" // For conditions of distribution and use, see copyright notice in Prerequesites.hpp -#include +#include #include namespace Ndk { - /*! - * \brief Binds Utility module to Lua - */ + std::unique_ptr LuaBinding_Base::BindUtility(LuaBinding& binding) + { + return std::make_unique(binding); + } - void LuaBinding::BindUtility() + LuaBinding_Utility::LuaBinding_Utility(LuaBinding& binding) : + LuaBinding_Base(binding) { /*********************************** Nz::AbstractImage **********************************/ abstractImage.BindMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel); @@ -321,8 +323,7 @@ namespace Ndk * * \param instance Lua instance that will interact with the Utility classes */ - - void LuaBinding::RegisterUtility(Nz::LuaInstance& instance) + void LuaBinding_Utility::Register(Nz::LuaInstance& instance) { abstractImage.Register(instance); font.Register(instance);