Merge remote-tracking branch 'refs/remotes/origin/master' into culling
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_CONSOLE_HPP
|
||||
#define NDK_CONSOLE_HPP
|
||||
|
||||
@@ -99,3 +100,4 @@ namespace Ndk
|
||||
#include <NDK/Console.inl>
|
||||
|
||||
#endif // NDK_CONSOLE_HPP
|
||||
#endif // NDK_SERVER
|
||||
|
||||
68
SDK/include/NDK/Lua/LuaBinding.hpp
Normal file
68
SDK/include/NDK/Lua/LuaBinding.hpp
Normal file
@@ -0,0 +1,68 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_LUABINDING_HPP
|
||||
#define NDK_LUABINDING_HPP
|
||||
|
||||
#include <NDK/BaseComponent.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API LuaBinding
|
||||
{
|
||||
friend class LuaBinding_SDK;
|
||||
|
||||
public:
|
||||
LuaBinding();
|
||||
~LuaBinding() = default;
|
||||
|
||||
template<typename T> void BindComponent(const Nz::String& name);
|
||||
|
||||
void RegisterClasses(Nz::LuaInstance& instance);
|
||||
|
||||
std::unique_ptr<LuaBinding_Base> core;
|
||||
std::unique_ptr<LuaBinding_Base> math;
|
||||
std::unique_ptr<LuaBinding_Base> network;
|
||||
std::unique_ptr<LuaBinding_Base> sdk;
|
||||
std::unique_ptr<LuaBinding_Base> utility;
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
std::unique_ptr<LuaBinding_Base> audio;
|
||||
std::unique_ptr<LuaBinding_Base> graphics;
|
||||
std::unique_ptr<LuaBinding_Base> renderer;
|
||||
#endif
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
static int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle);
|
||||
|
||||
template<typename T>
|
||||
static int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component);
|
||||
|
||||
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);
|
||||
using GetComponentFunc = int(*)(Nz::LuaInstance&, BaseComponent&);
|
||||
|
||||
struct ComponentBinding
|
||||
{
|
||||
AddComponentFunc adder;
|
||||
ComponentIndex index;
|
||||
GetComponentFunc getter;
|
||||
Nz::String name;
|
||||
};
|
||||
|
||||
ComponentBinding* QueryComponentIndex(Nz::LuaInstance& lua, int argIndex = 2);
|
||||
|
||||
std::vector<ComponentBinding> m_componentBinding;
|
||||
std::unordered_map<Nz::String, ComponentIndex> m_componentBindingByName;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Lua/LuaBinding.inl>
|
||||
|
||||
#endif // NDK_LUABINDING_HPP
|
||||
@@ -2,7 +2,7 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/Lua/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
@@ -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<typename T>
|
||||
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
|
||||
int LuaBinding::AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::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<typename T>
|
||||
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
|
||||
int LuaBinding::PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
|
||||
33
SDK/include/NDK/Lua/LuaBinding_Audio.hpp
Normal file
33
SDK/include/NDK/Lua/LuaBinding_Audio.hpp
Normal file
@@ -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 <Nazara/Audio/Music.hpp>
|
||||
#include <Nazara/Audio/Sound.hpp>
|
||||
#include <Nazara/Audio/SoundBuffer.hpp>
|
||||
#include <Nazara/Audio/SoundEmitter.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||
|
||||
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<Nz::Music> music;
|
||||
Nz::LuaClass<Nz::Sound> sound;
|
||||
Nz::LuaClass<Nz::SoundBufferRef> soundBuffer;
|
||||
Nz::LuaClass<Nz::SoundEmitter> soundEmitter;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_CORE_HPP
|
||||
53
SDK/include/NDK/Lua/LuaBinding_Base.hpp
Normal file
53
SDK/include/NDK/Lua/LuaBinding_Base.hpp
Normal file
@@ -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 <Nazara/Lua/LuaClass.hpp>
|
||||
#include <Nazara/Lua/LuaInstance.hpp>
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
|
||||
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<LuaBinding_Base> BindCore(LuaBinding& binding);
|
||||
static std::unique_ptr<LuaBinding_Base> BindMath(LuaBinding& binding);
|
||||
static std::unique_ptr<LuaBinding_Base> BindNetwork(LuaBinding& binding);
|
||||
static std::unique_ptr<LuaBinding_Base> BindSDK(LuaBinding& binding);
|
||||
static std::unique_ptr<LuaBinding_Base> BindUtility(LuaBinding& binding);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
static std::unique_ptr<LuaBinding_Base> BindAudio(LuaBinding& binding);
|
||||
static std::unique_ptr<LuaBinding_Base> BindGraphics(LuaBinding& binding);
|
||||
static std::unique_ptr<LuaBinding_Base> BindRenderer(LuaBinding& binding);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
LuaBinding& m_binding;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_BASE_HPP
|
||||
33
SDK/include/NDK/Lua/LuaBinding_Core.hpp
Normal file
33
SDK/include/NDK/Lua/LuaBinding_Core.hpp
Normal file
@@ -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 <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/Directory.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/Stream.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||
|
||||
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<Nz::Clock> clock;
|
||||
Nz::LuaClass<Nz::Directory> directory;
|
||||
Nz::LuaClass<Nz::File> file;
|
||||
Nz::LuaClass<Nz::Stream> stream;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_CORE_HPP
|
||||
36
SDK/include/NDK/Lua/LuaBinding_Graphics.hpp
Normal file
36
SDK/include/NDK/Lua/LuaBinding_Graphics.hpp
Normal file
@@ -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 <Nazara/Graphics/AbstractViewer.hpp>
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Graphics/Model.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||
|
||||
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<Nz::AbstractViewer> abstractViewer;
|
||||
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable;
|
||||
Nz::LuaClass<Nz::MaterialRef> material;
|
||||
Nz::LuaClass<Nz::ModelRef> model;
|
||||
Nz::LuaClass<Nz::SpriteRef> sprite;
|
||||
Nz::LuaClass<Nz::SpriteLibrary> spriteLibrary;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_GRAPHICS_HPP
|
||||
37
SDK/include/NDK/Lua/LuaBinding_Math.hpp
Normal file
37
SDK/include/NDK/Lua/LuaBinding_Math.hpp
Normal file
@@ -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 <Nazara/Math/EulerAngles.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||
|
||||
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<Nz::EulerAnglesd> eulerAngles;
|
||||
Nz::LuaClass<Nz::Matrix4d> matrix4d;
|
||||
Nz::LuaClass<Nz::Quaterniond> quaternion;
|
||||
Nz::LuaClass<Nz::Rectd> rect;
|
||||
Nz::LuaClass<Nz::Vector2d> vector2d;
|
||||
Nz::LuaClass<Nz::Vector3d> vector3d;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_MATH_HPP
|
||||
29
SDK/include/NDK/Lua/LuaBinding_Network.hpp
Normal file
29
SDK/include/NDK/Lua/LuaBinding_Network.hpp
Normal file
@@ -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 <Nazara/Network/AbstractSocket.hpp>
|
||||
#include <Nazara/Network/IpAddress.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||
|
||||
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<Nz::AbstractSocket> abstractSocket;
|
||||
Nz::LuaClass<Nz::IpAddress> ipAddress;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_NETWORK_HPP
|
||||
29
SDK/include/NDK/Lua/LuaBinding_Renderer.hpp
Normal file
29
SDK/include/NDK/Lua/LuaBinding_Renderer.hpp
Normal file
@@ -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 <Nazara/Renderer/Texture.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||
|
||||
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<Nz::TextureRef> texture;
|
||||
Nz::LuaClass<Nz::TextureLibrary> textureLibrary;
|
||||
Nz::LuaClass<Nz::TextureManager> textureManager;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_RENDERER_HPP
|
||||
42
SDK/include/NDK/Lua/LuaBinding_SDK.hpp
Normal file
42
SDK/include/NDK/Lua/LuaBinding_SDK.hpp
Normal file
@@ -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 <NDK/Lua/LuaBinding_Base.hpp>
|
||||
#include <NDK/Components.hpp>
|
||||
#include <NDK/Console.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
|
||||
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*> application;
|
||||
Nz::LuaClass<EntityHandle> entity;
|
||||
Nz::LuaClass<NodeComponentHandle> nodeComponent;
|
||||
Nz::LuaClass<VelocityComponentHandle> velocityComponent;
|
||||
Nz::LuaClass<WorldHandle> world;
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
Nz::LuaClass<CameraComponentHandle> cameraComponent;
|
||||
Nz::LuaClass<ConsoleHandle> console;
|
||||
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent;
|
||||
#endif
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_SDK_HPP
|
||||
34
SDK/include/NDK/Lua/LuaBinding_Utility.hpp
Normal file
34
SDK/include/NDK/Lua/LuaBinding_Utility.hpp
Normal file
@@ -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 <Nazara/Utility/AbstractImage.hpp>
|
||||
#include <Nazara/Utility/Font.hpp>
|
||||
#include <Nazara/Utility/Keyboard.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||
|
||||
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<Nz::AbstractImageRef> abstractImage;
|
||||
Nz::LuaClass<Nz::FontRef> font;
|
||||
Nz::LuaClass<Nz::Keyboard> keyboard;
|
||||
Nz::LuaClass<Nz::Node> node;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_UTILITY_HPP
|
||||
@@ -156,9 +156,10 @@ namespace Nz
|
||||
|
||||
params->animated = instance.CheckField<bool>("Animated", params->animated);
|
||||
params->center = instance.CheckField<bool>("Center", params->center);
|
||||
params->flipUVs = instance.CheckField<bool>("FlipUVs", params->flipUVs);
|
||||
params->matrix = instance.CheckField<Matrix4f>("Matrix", params->matrix);
|
||||
params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
|
||||
params->texCoordOffset = instance.CheckField<Vector2f>("TexCoordOffset", params->texCoordOffset);
|
||||
params->texCoordScale = instance.CheckField<Vector2f>("TexCoordScale", params->texCoordScale);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_LUABINDING_HPP
|
||||
#define NDK_LUABINDING_HPP
|
||||
|
||||
#include <Nazara/Core.hpp>
|
||||
#include <Nazara/Lua.hpp>
|
||||
#include <Nazara/Math.hpp>
|
||||
#include <Nazara/Network.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <NDK/Application.hpp>
|
||||
#include <NDK/Components.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/Systems.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <Nazara/Audio.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <NDK/Console.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API LuaBinding
|
||||
{
|
||||
public:
|
||||
LuaBinding();
|
||||
~LuaBinding() = default;
|
||||
|
||||
template<typename T> void BindComponent(const Nz::String& name);
|
||||
|
||||
void RegisterClasses(Nz::LuaInstance& instance);
|
||||
|
||||
// Core
|
||||
Nz::LuaClass<Nz::Clock> clock;
|
||||
Nz::LuaClass<Nz::Directory> directory;
|
||||
Nz::LuaClass<Nz::File> file;
|
||||
Nz::LuaClass<Nz::Stream> stream;
|
||||
|
||||
// Math
|
||||
Nz::LuaClass<Nz::EulerAnglesd> eulerAngles;
|
||||
Nz::LuaClass<Nz::Matrix4d> matrix4d;
|
||||
Nz::LuaClass<Nz::Quaterniond> quaternion;
|
||||
Nz::LuaClass<Nz::Rectd> rect;
|
||||
Nz::LuaClass<Nz::Vector2d> vector2d;
|
||||
Nz::LuaClass<Nz::Vector3d> vector3d;
|
||||
|
||||
// Network
|
||||
Nz::LuaClass<Nz::AbstractSocket> abstractSocket;
|
||||
Nz::LuaClass<Nz::IpAddress> ipAddress;
|
||||
|
||||
// Utility
|
||||
Nz::LuaClass<Nz::AbstractImageRef> abstractImage;
|
||||
Nz::LuaClass<Nz::FontRef> font;
|
||||
Nz::LuaClass<Nz::Keyboard> keyboard;
|
||||
Nz::LuaClass<Nz::Node> node;
|
||||
|
||||
// SDK
|
||||
Nz::LuaClass<Application*> application;
|
||||
Nz::LuaClass<EntityHandle> entity;
|
||||
Nz::LuaClass<NodeComponentHandle> nodeComponent;
|
||||
Nz::LuaClass<VelocityComponentHandle> velocityComponent;
|
||||
Nz::LuaClass<WorldHandle> world;
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
// Audio
|
||||
Nz::LuaClass<Nz::Music> music;
|
||||
Nz::LuaClass<Nz::Sound> sound;
|
||||
Nz::LuaClass<Nz::SoundBufferRef> soundBuffer;
|
||||
Nz::LuaClass<Nz::SoundEmitter> soundEmitter;
|
||||
|
||||
// Graphics
|
||||
Nz::LuaClass<Nz::AbstractViewer> abstractViewer;
|
||||
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable;
|
||||
Nz::LuaClass<Nz::MaterialRef> material;
|
||||
Nz::LuaClass<Nz::ModelRef> model;
|
||||
Nz::LuaClass<Nz::SpriteRef> sprite;
|
||||
Nz::LuaClass<Nz::SpriteLibrary> spriteLibrary;
|
||||
Nz::LuaClass<Nz::TextureLibrary> textureLibrary;
|
||||
Nz::LuaClass<Nz::TextureManager> textureManager;
|
||||
|
||||
// Renderer
|
||||
Nz::LuaClass<Nz::TextureRef> texture;
|
||||
|
||||
// SDK
|
||||
Nz::LuaClass<CameraComponentHandle> cameraComponent;
|
||||
Nz::LuaClass<ConsoleHandle> console;
|
||||
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent;
|
||||
#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
|
||||
|
||||
|
||||
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);
|
||||
using GetComponentFunc = int(*)(Nz::LuaInstance&, BaseComponent&);
|
||||
|
||||
struct ComponentBinding
|
||||
{
|
||||
AddComponentFunc adder;
|
||||
ComponentIndex index;
|
||||
GetComponentFunc getter;
|
||||
Nz::String name;
|
||||
};
|
||||
|
||||
ComponentBinding* QueryComponentIndex(Nz::LuaInstance& lua, int argIndex = 2);
|
||||
|
||||
std::vector<ComponentBinding> m_componentBinding;
|
||||
std::unordered_map<Nz::String, ComponentIndex> m_componentBindingByName;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle);
|
||||
|
||||
template<typename T>
|
||||
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component);
|
||||
}
|
||||
|
||||
#include <NDK/LuaBinding.inl>
|
||||
|
||||
#endif // NDK_LUABINDING_HPP
|
||||
@@ -152,7 +152,7 @@ namespace Ndk
|
||||
windowDimensions.MakeZero();
|
||||
|
||||
overlay->console = std::make_unique<Console>(*info.overlayWorld, Nz::Vector2f(windowDimensions), overlay->lua);
|
||||
|
||||
|
||||
Console& consoleRef = *overlay->console;
|
||||
|
||||
// Redirect logs toward the console
|
||||
@@ -248,4 +248,4 @@ namespace Ndk
|
||||
#endif
|
||||
|
||||
Application* Application::s_application = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
66
SDK/src/NDK/Lua/LuaBinding.cpp
Normal file
66
SDK/src/NDK/Lua/LuaBinding.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/Lua/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \ingroup NDK
|
||||
* \class Ndk::LuaBinding
|
||||
* \brief NDK class that represents the binding between the engine & the SDK with the Lua scripting
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Binds modules to Lua
|
||||
*/
|
||||
|
||||
LuaBinding::LuaBinding()
|
||||
{
|
||||
core = LuaBinding_Base::BindCore(*this);
|
||||
math = LuaBinding_Base::BindMath(*this);
|
||||
network = LuaBinding_Base::BindNetwork(*this);
|
||||
utility = LuaBinding_Base::BindUtility(*this);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
audio = LuaBinding_Base::BindAudio(*this);
|
||||
renderer = LuaBinding_Base::BindRenderer(*this);
|
||||
graphics = LuaBinding_Base::BindGraphics(*this);
|
||||
#endif
|
||||
|
||||
sdk = LuaBinding_Base::BindSDK(*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the engine & SDK
|
||||
*/
|
||||
|
||||
void LuaBinding::RegisterClasses(Nz::LuaInstance& instance)
|
||||
{
|
||||
core->Register(instance);
|
||||
math->Register(instance);
|
||||
network->Register(instance);
|
||||
sdk->Register(instance);
|
||||
utility->Register(instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
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");
|
||||
}
|
||||
}
|
||||
198
SDK/src/NDK/Lua/LuaBinding_Audio.cpp
Normal file
198
SDK/src/NDK/Lua/LuaBinding_Audio.cpp
Normal file
@@ -0,0 +1,198 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/Lua/LuaBinding_Audio.hpp>
|
||||
#include <Nazara/Core/MemoryHelper.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindAudio(LuaBinding& binding)
|
||||
{
|
||||
return std::make_unique<LuaBinding_Audio>(binding);
|
||||
}
|
||||
|
||||
LuaBinding_Audio::LuaBinding_Audio(LuaBinding& binding) :
|
||||
LuaBinding_Base(binding)
|
||||
{
|
||||
/*********************************** Nz::SoundEmitter **********************************/
|
||||
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("IsLooping", &Nz::SoundEmitter::IsLooping);
|
||||
soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized);
|
||||
|
||||
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("Stop", &Nz::SoundEmitter::Stop);
|
||||
}
|
||||
|
||||
/*********************************** Nz::Music **********************************/
|
||||
music.Reset("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
|
||||
{
|
||||
Nz::StringStream ss("Music(");
|
||||
ss << instance.GetFilePath() << ')';
|
||||
|
||||
lua.PushString(ss);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
/*********************************** Nz::Sound **********************************/
|
||||
sound.Reset("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
|
||||
{
|
||||
Nz::StringStream ss("Sound(");
|
||||
if (const Nz::SoundBuffer* buffer = instance.GetBuffer())
|
||||
ss << buffer;
|
||||
|
||||
ss << ')';
|
||||
|
||||
lua.PushString(ss);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
/*********************************** Nz::SoundBuffer **********************************/
|
||||
soundBuffer.Reset("SoundBuffer");
|
||||
{
|
||||
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua, Nz::SoundBufferRef* instance, std::size_t argumentCount)
|
||||
{
|
||||
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<Nz::AudioFormat>(&index);
|
||||
unsigned int sampleCount = lua.Check<unsigned int>(&index);
|
||||
unsigned int sampleRate = lua.Check<unsigned int>(&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<const Nz::Int16*>(buffer)));
|
||||
return 1;
|
||||
});
|
||||
|
||||
soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
lua.PushString(reinterpret_cast<const char*>(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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the Audio classes
|
||||
*/
|
||||
void LuaBinding_Audio::Register(Nz::LuaInstance& instance)
|
||||
{
|
||||
music.Register(instance);
|
||||
sound.Register(instance);
|
||||
soundBuffer.Register(instance);
|
||||
soundEmitter.Register(instance);
|
||||
}
|
||||
}
|
||||
13
SDK/src/NDK/Lua/LuaBinding_Base.cpp
Normal file
13
SDK/src/NDK/Lua/LuaBinding_Base.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
LuaBinding_Base::LuaBinding_Base(LuaBinding& binding) :
|
||||
m_binding(binding)
|
||||
{
|
||||
}
|
||||
|
||||
LuaBinding_Base::~LuaBinding_Base() = default;
|
||||
}
|
||||
354
SDK/src/NDK/Lua/LuaBinding_Core.cpp
Normal file
354
SDK/src/NDK/Lua/LuaBinding_Core.cpp
Normal file
@@ -0,0 +1,354 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/Lua/LuaBinding_Core.hpp>
|
||||
#include <Nazara/Core/MemoryHelper.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindCore(LuaBinding& binding)
|
||||
{
|
||||
return std::make_unique<LuaBinding_Core>(binding);
|
||||
}
|
||||
|
||||
LuaBinding_Core::LuaBinding_Core(LuaBinding& binding) :
|
||||
LuaBinding_Base(binding)
|
||||
{
|
||||
/*********************************** Nz::Stream ***********************************/
|
||||
stream.Reset("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<std::size_t>(&argIndex);
|
||||
|
||||
std::unique_ptr<char[]> 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;
|
||||
});
|
||||
}
|
||||
|
||||
/*********************************** Nz::Clock **********************************/
|
||||
clock.Reset("Clock");
|
||||
{
|
||||
clock.SetConstructor([] (Nz::LuaInstance& lua, Nz::Clock* instance, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(instance);
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
||||
|
||||
Nz::PlacementNew(instance, startingValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
||||
bool paused = lua.Check<bool>(&argIndex, false);
|
||||
|
||||
Nz::PlacementNew(instance, startingValue, paused);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for Clock constructor");
|
||||
return false;
|
||||
});
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
/********************************* Nz::Directory ********************************/
|
||||
directory.Reset("Directory");
|
||||
{
|
||||
directory.SetConstructor([] (Nz::LuaInstance& lua, Nz::Directory* instance, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(instance);
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
Nz::PlacementNew(instance, lua.Check<Nz::String>(&argIndex));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
// Manual
|
||||
directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& instance, std::size_t /*argumentCount*/) -> int {
|
||||
Nz::StringStream ss("Directory(");
|
||||
ss << instance.GetPath();
|
||||
ss << ')';
|
||||
|
||||
lua.PushString(ss);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
/*********************************** Nz::File ***********************************/
|
||||
file.Reset("Stream");
|
||||
{
|
||||
file.Inherit(stream);
|
||||
|
||||
file.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* instance, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(instance);
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
||||
|
||||
Nz::PlacementNew(instance, filePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
||||
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&argIndex);
|
||||
|
||||
Nz::PlacementNew(instance, filePath, openMode);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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<std::size_t>(argumentCount, 2U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
return lua.Push(instance.Open(lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||
|
||||
case 2:
|
||||
{
|
||||
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
||||
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen);
|
||||
return lua.Push(instance.Open(filePath, openMode));
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method Open");
|
||||
return 0;
|
||||
});
|
||||
|
||||
file.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
return lua.Push(instance.SetCursorPos(lua.Check<Nz::UInt64>(&argIndex)));
|
||||
|
||||
case 2:
|
||||
{
|
||||
Nz::CursorPosition curPos = lua.Check<Nz::CursorPosition>(&argIndex);
|
||||
Nz::Int64 offset = lua.Check<Nz::Int64>(&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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the Core classes
|
||||
*/
|
||||
void LuaBinding_Core::Register(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
clock.Register(instance);
|
||||
directory.Register(instance);
|
||||
file.Register(instance);
|
||||
stream.Register(instance);
|
||||
|
||||
// Enums
|
||||
|
||||
// Nz::CursorPosition
|
||||
static_assert(Nz::CursorPosition_Max + 1 == 3, "Nz::CursorPosition has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 3);
|
||||
{
|
||||
instance.PushField("AtBegin", Nz::CursorPosition_AtBegin);
|
||||
instance.PushField("AtCurrent", Nz::CursorPosition_AtCurrent);
|
||||
instance.PushField("AtEnd", Nz::CursorPosition_AtEnd);
|
||||
}
|
||||
instance.SetGlobal("CursorPosition");
|
||||
|
||||
// Nz::HashType
|
||||
static_assert(Nz::HashType_Max + 1 == 9, "Nz::HashType has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 9);
|
||||
{
|
||||
instance.PushField("CRC32", Nz::HashType_CRC32);
|
||||
instance.PushField("Fletcher16", Nz::HashType_Fletcher16);
|
||||
instance.PushField("MD5", Nz::HashType_MD5);
|
||||
instance.PushField("SHA1", Nz::HashType_SHA1);
|
||||
instance.PushField("SHA224", Nz::HashType_SHA224);
|
||||
instance.PushField("SHA256", Nz::HashType_SHA256);
|
||||
instance.PushField("SHA384", Nz::HashType_SHA384);
|
||||
instance.PushField("SHA512", Nz::HashType_SHA512);
|
||||
instance.PushField("Whirlpool", Nz::HashType_Whirlpool);
|
||||
}
|
||||
instance.SetGlobal("HashType");
|
||||
|
||||
// Nz::OpenMode
|
||||
static_assert(Nz::OpenMode_Max + 1 == 8, "Nz::OpenModeFlags has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, Nz::OpenMode_Max + 1);
|
||||
{
|
||||
instance.PushField("Append", Nz::OpenMode_Append);
|
||||
instance.PushField("NotOpen", Nz::OpenMode_NotOpen);
|
||||
instance.PushField("Lock", Nz::OpenMode_Lock);
|
||||
instance.PushField("ReadOnly", Nz::OpenMode_ReadOnly);
|
||||
instance.PushField("ReadWrite", Nz::OpenMode_ReadWrite);
|
||||
instance.PushField("Text", Nz::OpenMode_Text);
|
||||
instance.PushField("Truncate", Nz::OpenMode_Truncate);
|
||||
instance.PushField("WriteOnly", Nz::OpenMode_WriteOnly);
|
||||
}
|
||||
instance.SetGlobal("OpenMode");
|
||||
}
|
||||
}
|
||||
370
SDK/src/NDK/Lua/LuaBinding_Graphics.cpp
Normal file
370
SDK/src/NDK/Lua/LuaBinding_Graphics.cpp
Normal file
@@ -0,0 +1,370 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Lua/LuaBinding_Graphics.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindGraphics(LuaBinding& binding)
|
||||
{
|
||||
return std::make_unique<LuaBinding_Graphics>(binding);
|
||||
}
|
||||
|
||||
LuaBinding_Graphics::LuaBinding_Graphics(LuaBinding& binding) :
|
||||
LuaBinding_Base(binding)
|
||||
{
|
||||
/*********************************** Nz::AbstractViewer ***********************************/
|
||||
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.Reset("Material");
|
||||
{
|
||||
material.SetConstructor([] (Nz::LuaInstance& lua, Nz::MaterialRef* instance, std::size_t argumentCount)
|
||||
{
|
||||
switch (argumentCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(instance, Nz::Material::New());
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
int argIndex = 1;
|
||||
if (lua.IsOfType(argIndex, "MaterialPipeline"))
|
||||
{
|
||||
Nz::PlacementNew(instance, Nz::Material::New(*static_cast<Nz::MaterialPipelineRef*>(lua.ToUserdata(argIndex))));
|
||||
return true;
|
||||
}
|
||||
else if (lua.IsOfType(argIndex, "Material"))
|
||||
{
|
||||
Nz::PlacementNew(instance, Nz::Material::New(**static_cast<Nz::MaterialRef*>(lua.ToUserdata(argIndex))));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Nz::PlacementNew(instance, Nz::Material::New(lua.Check<Nz::String>(&argIndex)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"))
|
||||
{
|
||||
instance->Configure(*static_cast<Nz::MaterialPipelineRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
lua.Push(instance->Configure(lua.Check<Nz::String>(&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
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
{
|
||||
instance->SetAlphaMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetAlphaMap(lua.Check<Nz::String>(&argIndex)));
|
||||
});
|
||||
|
||||
material.BindMethod("SetDiffuseMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
{
|
||||
instance->SetDiffuseMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetDiffuseMap(lua.Check<Nz::String>(&argIndex)));
|
||||
});
|
||||
|
||||
material.BindMethod("SetEmissiveMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
{
|
||||
instance->SetEmissiveMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetEmissiveMap(lua.Check<Nz::String>(&argIndex)));
|
||||
});
|
||||
|
||||
material.BindMethod("SetHeightMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
{
|
||||
instance->SetHeightMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetHeightMap(lua.Check<Nz::String>(&argIndex)));
|
||||
});
|
||||
|
||||
material.BindMethod("SetNormalMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
{
|
||||
instance->SetNormalMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetNormalMap(lua.Check<Nz::String>(&argIndex)));
|
||||
});
|
||||
|
||||
material.BindMethod("SetShader", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, "UberShader"))
|
||||
{
|
||||
instance->SetShader(*static_cast<Nz::UberShaderRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetShader(lua.Check<Nz::String>(&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<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetSpecularMap(lua.Check<Nz::String>(&argIndex)));
|
||||
});
|
||||
}
|
||||
|
||||
/*********************************** Nz::Model ***********************************/
|
||||
model.Reset("Model");
|
||||
{
|
||||
model.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::ModelRef* modelRef) -> Nz::InstancedRenderableRef*
|
||||
{
|
||||
return reinterpret_cast<Nz::InstancedRenderableRef*>(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.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("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);
|
||||
}
|
||||
|
||||
/*********************************** Nz::Sprite ***********************************/
|
||||
sprite.Reset("Sprite");
|
||||
{
|
||||
sprite.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::SpriteRef* spriteRef) -> Nz::InstancedRenderableRef*
|
||||
{
|
||||
return reinterpret_cast<Nz::InstancedRenderableRef*>(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.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("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<Nz::MaterialRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
||||
else
|
||||
instance->SetMaterial(lua.Check<Nz::String>(&argIndex), resizeSprite);
|
||||
|
||||
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);
|
||||
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
instance->SetTexture(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
||||
else
|
||||
instance->SetTexture(lua.Check<Nz::String>(&argIndex), resizeSprite);
|
||||
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
/*********************************** Nz::SpriteLibrary ***********************************/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the Graphics classes
|
||||
*/
|
||||
|
||||
void LuaBinding_Graphics::Register(Nz::LuaInstance& instance)
|
||||
{
|
||||
abstractViewer.Register(instance);
|
||||
instancedRenderable.Register(instance);
|
||||
material.Register(instance);
|
||||
model.Register(instance);
|
||||
sprite.Register(instance);
|
||||
spriteLibrary.Register(instance);
|
||||
}
|
||||
}
|
||||
986
SDK/src/NDK/Lua/LuaBinding_Math.cpp
Normal file
986
SDK/src/NDK/Lua/LuaBinding_Math.cpp
Normal file
@@ -0,0 +1,986 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/Lua/LuaBinding_Math.hpp>
|
||||
#include <Nazara/Core/MemoryHelper.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <cstring>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindMath(LuaBinding& binding)
|
||||
{
|
||||
return std::make_unique<LuaBinding_Math>(binding);
|
||||
}
|
||||
|
||||
LuaBinding_Math::LuaBinding_Math(LuaBinding& binding) :
|
||||
LuaBinding_Base(binding)
|
||||
{
|
||||
/*********************************** Nz::EulerAngles **********************************/
|
||||
eulerAngles.Reset("EulerAngles");
|
||||
{
|
||||
eulerAngles.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* instance, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(instance, Nz::EulerAnglesd::Zero());
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
Nz::PlacementNew(instance, *static_cast<Nz::EulerAnglesd*>(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 (ypr[0])
|
||||
{
|
||||
case 'p':
|
||||
lua.Push(instance.pitch);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.yaw);
|
||||
return true;
|
||||
|
||||
case 'r':
|
||||
lua.Push(instance.roll);
|
||||
return true;
|
||||
}
|
||||
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 'p':
|
||||
instance.pitch = 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;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/*********************************** Nz::Matrix4 **********************************/
|
||||
matrix4d.Reset("Matrix4");
|
||||
{
|
||||
matrix4d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Matrix4d* matrix, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(matrix, Nz::Matrix4d::Zero());
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
if (lua.IsOfType(1, "Matrix4"))
|
||||
Nz::PlacementNew(matrix, *static_cast<Nz::Matrix4d*>(lua.ToUserdata(1)));
|
||||
break;
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
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("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<std::size_t>(argumentCount, 3U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
if (lua.IsOfType(argIndex, "Matrix4"))
|
||||
instance.Set(*static_cast<Nz::Matrix4d*>(lua.ToUserdata(argIndex)));
|
||||
break;
|
||||
|
||||
case 16:
|
||||
{
|
||||
double values[16];
|
||||
for (std::size_t i = 0; i < 16; ++i)
|
||||
values[i] = lua.CheckNumber(argIndex++);
|
||||
|
||||
instance.Set(values);
|
||||
|
||||
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("Transform", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
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<Nz::Vector2d*>(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<Nz::Vector3d*>(lua.ToUserdata(argIndex)), w));
|
||||
}
|
||||
//else if (lua.IsOfType(2, "Vector4"))
|
||||
// return lua.Push(instance.Transform(*static_cast<Nz::Vector4d*>(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)
|
||||
{
|
||||
bool succeeded = false;
|
||||
std::size_t index = static_cast<std::size_t>(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<std::size_t>(lua.ToInteger(2, &succeeded));
|
||||
if (!succeeded || index < 1 || index > 16)
|
||||
return false;
|
||||
|
||||
instance[index - 1] = lua.CheckNumber(3);
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/*********************************** Nz::Rect **********************************/
|
||||
rect.Reset("Rect");
|
||||
{
|
||||
rect.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* instance, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
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:
|
||||
{
|
||||
if (lua.IsOfType(1, "Rect"))
|
||||
PlacementNew(instance, *static_cast<Nz::Rectd*>(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<double>("x", 1),
|
||||
lua.CheckField<double>("y", 1),
|
||||
lua.CheckField<double>("width", 1),
|
||||
lua.CheckField<double>("height", 1));
|
||||
}
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
PlacementNew(instance, *static_cast<Nz::Vector2d*>(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<Nz::Vector2d*>(lua.ToUserdata(1)), *static_cast<Nz::Vector2d*>(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<std::size_t>(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<std::size_t>(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.Reset("Quaternion");
|
||||
{
|
||||
quaternion.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* instance, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(instance, Nz::Quaterniond::Zero());
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, "EulerAngles"))
|
||||
Nz::PlacementNew(instance, *static_cast<Nz::EulerAnglesd*>(lua.ToUserdata(1)));
|
||||
else if (lua.IsOfType(1, "Quaternion"))
|
||||
Nz::PlacementNew(instance, *static_cast<Nz::Quaterniond*>(lua.ToUserdata(1)));
|
||||
else
|
||||
break;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case 2:
|
||||
Nz::PlacementNew(instance, lua.CheckNumber(1), *static_cast<Nz::Vector3d*>(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<Nz::Quaterniond>(&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;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
quaternion.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* wxyz = lua.CheckString(2, &length);
|
||||
|
||||
if (length != 1)
|
||||
return false;
|
||||
|
||||
double value = lua.CheckNumber(3);
|
||||
|
||||
switch (wxyz[0])
|
||||
{
|
||||
case 'w':
|
||||
instance.w = value;
|
||||
return true;
|
||||
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
|
||||
case 'z':
|
||||
instance.z = value;
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/*********************************** Nz::Vector2 **********************************/
|
||||
vector2d.Reset("Vector2");
|
||||
{
|
||||
vector2d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector2d* vector, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0));
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
Nz::PlacementNew(vector, lua.CheckNumber(1));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
|
||||
else
|
||||
break;
|
||||
|
||||
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 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
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.Reset("Vector3");
|
||||
{
|
||||
vector3d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 3:
|
||||
Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0));
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
Nz::PlacementNew(vector, lua.CheckNumber(1));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
|
||||
else if (lua.IsOfType(1, "Vector3"))
|
||||
Nz::PlacementNew(vector, *static_cast<Nz::Vector3d*>(lua.ToUserdata(1)));
|
||||
else
|
||||
break;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.CheckUserdata(2, "Vector2")));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(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 '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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the Math classes
|
||||
*/
|
||||
void LuaBinding_Math::Register(Nz::LuaInstance& instance)
|
||||
{
|
||||
eulerAngles.Register(instance);
|
||||
matrix4d.Register(instance);
|
||||
quaternion.Register(instance);
|
||||
rect.Register(instance);
|
||||
vector2d.Register(instance);
|
||||
vector3d.Register(instance);
|
||||
|
||||
quaternion.PushGlobalTable(instance);
|
||||
{
|
||||
instance.PushField("Identity", Nz::Quaterniond::Identity());
|
||||
instance.PushField("Zero", Nz::Quaterniond::Zero());
|
||||
}
|
||||
instance.Pop();
|
||||
}
|
||||
}
|
||||
@@ -1,139 +1,147 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Network.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Binds Network module to Lua
|
||||
*/
|
||||
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindNetwork(LuaBinding& binding)
|
||||
{
|
||||
return std::make_unique<LuaBinding_Network>(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<std::size_t>(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<std::size_t>(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<Nz::UInt8>(&argIndex);
|
||||
Nz::UInt8 b = lua.Check<Nz::UInt8>(&argIndex);
|
||||
Nz::UInt8 c = lua.Check<Nz::UInt8>(&argIndex);
|
||||
Nz::UInt8 d = lua.Check<Nz::UInt8>(&argIndex);
|
||||
Nz::UInt16 port = lua.Check<Nz::UInt16>(&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<Nz::UInt8>(&argIndex);
|
||||
Nz::UInt8 b = lua.Check<Nz::UInt8>(&argIndex);
|
||||
Nz::UInt8 c = lua.Check<Nz::UInt8>(&argIndex);
|
||||
Nz::UInt8 d = lua.Check<Nz::UInt8>(&argIndex);
|
||||
Nz::UInt16 port = lua.Check<Nz::UInt16>(&argIndex, 0);
|
||||
|
||||
Nz::PlacementNew(instance, a, b, c, d, port);
|
||||
return true;
|
||||
}
|
||||
|
||||
case 8:
|
||||
case 9:
|
||||
{
|
||||
Nz::UInt16 a = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 b = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 c = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 d = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 e = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 f = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 g = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 h = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 port = lua.Check<Nz::UInt16>(&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<Nz::IpAddress>(&argIndex), &service, &error);
|
||||
|
||||
if (error == Nz::ResolveError_NoError)
|
||||
{
|
||||
Nz::UInt16 a = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 b = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 c = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 d = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 e = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 f = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 g = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 h = lua.Check<Nz::UInt16>(&argIndex);
|
||||
Nz::UInt16 port = lua.Check<Nz::UInt16>(&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<Nz::IpAddress>(&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<Nz::NetProtocol>(&argIndex);
|
||||
Nz::String hostname = instance.Check<Nz::String>(&argIndex);
|
||||
Nz::String service = instance.Check<Nz::String>(&argIndex, "http");
|
||||
|
||||
std::vector<Nz::HostnameInfo> 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<Nz::NetProtocol>(&argIndex);
|
||||
Nz::String hostname = instance.Check<Nz::String>(&argIndex);
|
||||
Nz::String service = instance.Check<Nz::String>(&argIndex, "http");
|
||||
|
||||
std::vector<Nz::HostnameInfo> 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);
|
||||
110
SDK/src/NDK/Lua/LuaBinding_Renderer.cpp
Normal file
110
SDK/src/NDK/Lua/LuaBinding_Renderer.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Lua/LuaBinding_Renderer.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <NDK/Lua/LuaBinding.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Utility.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindRenderer(LuaBinding& binding)
|
||||
{
|
||||
return std::make_unique<LuaBinding_Renderer>(binding);
|
||||
}
|
||||
|
||||
LuaBinding_Renderer::LuaBinding_Renderer(LuaBinding& binding) :
|
||||
LuaBinding_Base(binding)
|
||||
{
|
||||
LuaBinding_Utility& utility = static_cast<LuaBinding_Utility&>(*m_binding.utility);
|
||||
|
||||
/*********************************** Nz::Texture ***********************************/
|
||||
texture.Reset("Texture");
|
||||
{
|
||||
texture.Inherit<Nz::AbstractImageRef>(utility.abstractImage, [] (Nz::TextureRef* textureRef) -> Nz::AbstractImageRef*
|
||||
{
|
||||
return reinterpret_cast<Nz::AbstractImageRef*>(textureRef); //TODO: Make a ObjectRefCast
|
||||
});
|
||||
|
||||
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<Nz::UInt8>(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");
|
||||
{
|
||||
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.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);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the Renderer classes
|
||||
*/
|
||||
void LuaBinding_Renderer::Register(Nz::LuaInstance& instance)
|
||||
{
|
||||
texture.Register(instance);
|
||||
textureLibrary.Register(instance);
|
||||
textureManager.Register(instance);
|
||||
}
|
||||
}
|
||||
338
SDK/src/NDK/Lua/LuaBinding_SDK.cpp
Normal file
338
SDK/src/NDK/Lua/LuaBinding_SDK.cpp
Normal file
@@ -0,0 +1,338 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Lua/LuaBinding_SDK.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <NDK/Lua/LuaBinding.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Utility.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Lua/LuaBinding_Graphics.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindSDK(LuaBinding& binding)
|
||||
{
|
||||
return std::make_unique<LuaBinding_SDK>(binding);
|
||||
}
|
||||
|
||||
LuaBinding_SDK::LuaBinding_SDK(LuaBinding& binding) :
|
||||
LuaBinding_Base(binding)
|
||||
{
|
||||
#ifndef NDK_SERVER
|
||||
LuaBinding_Graphics& graphics = static_cast<LuaBinding_Graphics&>(*m_binding.graphics);
|
||||
#endif
|
||||
|
||||
LuaBinding_Utility& utility = static_cast<LuaBinding_Utility&>(*m_binding.utility);
|
||||
|
||||
/*********************************** 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.Reset("Console");
|
||||
{
|
||||
console.Inherit<Nz::Node>(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("IsVisible", &Console::IsVisible);
|
||||
|
||||
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("Show", &Console::Show, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************** Ndk::Entity **********************************/
|
||||
entity.Reset("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
|
||||
{
|
||||
LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance);
|
||||
|
||||
return binding->adder(instance, handle);
|
||||
});
|
||||
|
||||
entity.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance);
|
||||
|
||||
return binding->getter(instance, handle->GetComponent(binding->index));
|
||||
});
|
||||
|
||||
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.Reset("NodeComponent");
|
||||
{
|
||||
nodeComponent.Inherit<Nz::Node>(utility.node, [] (NodeComponentHandle* handle) -> Nz::Node*
|
||||
{
|
||||
return handle->GetObject();
|
||||
});
|
||||
}
|
||||
|
||||
/*********************************** Ndk::VelocityComponent **********************************/
|
||||
velocityComponent.Reset("VelocityComponent");
|
||||
{
|
||||
velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* member = lua.CheckString(2, &length);
|
||||
|
||||
if (std::strcmp(member, "Linear") == 0)
|
||||
{
|
||||
lua.Push(instance->linearVelocity);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* member = lua.CheckString(2, &length);
|
||||
|
||||
int argIndex = 3;
|
||||
if (std::strcmp(member, "Linear") == 0)
|
||||
{
|
||||
instance->linearVelocity = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/*********************************** Ndk::World **********************************/
|
||||
world.Reset("World");
|
||||
{
|
||||
world.BindMethod("CreateEntity", &World::CreateEntity);
|
||||
world.BindMethod("CreateEntities", &World::CreateEntities);
|
||||
world.BindMethod("Clear", &World::Clear);
|
||||
}
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
/*********************************** Ndk::CameraComponent **********************************/
|
||||
cameraComponent.Reset("CameraComponent");
|
||||
{
|
||||
cameraComponent.Inherit<Nz::AbstractViewer>(graphics.abstractViewer, [] (CameraComponentHandle* handle) -> Nz::AbstractViewer*
|
||||
{
|
||||
return handle->GetObject();
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/*********************************** Ndk::GraphicsComponent **********************************/
|
||||
graphicsComponent.Reset("GraphicsComponent");
|
||||
{
|
||||
graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent* instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
/*
|
||||
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<std::size_t>(argumentCount, 3U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
int argIndex = 2;
|
||||
instance->Attach(lua.Check<Nz::InstancedRenderableRef>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
int argIndex = 2;
|
||||
Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);
|
||||
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
{
|
||||
int renderOrder = lua.Check<int>(&argIndex);
|
||||
|
||||
instance->Attach(renderable, renderOrder);
|
||||
}
|
||||
else if (lua.IsOfType(argIndex, "Matrix4"))
|
||||
{
|
||||
Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);
|
||||
|
||||
instance->Attach(renderable, localMatrix);
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
int argIndex = 2;
|
||||
Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);
|
||||
Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);
|
||||
int renderOrder = lua.Check<int>(&argIndex);
|
||||
|
||||
instance->Attach(renderable, localMatrix, renderOrder);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method GetMemoryUsage");
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
// Components functions
|
||||
m_binding.BindComponent<NodeComponent>("Node");
|
||||
m_binding.BindComponent<VelocityComponent>("Velocity");
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
m_binding.BindComponent<CameraComponent>("Camera");
|
||||
m_binding.BindComponent<GraphicsComponent>("Graphics");
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the SDK classes
|
||||
*/
|
||||
void LuaBinding_SDK::Register(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
application.Register(instance);
|
||||
entity.Register(instance);
|
||||
nodeComponent.Register(instance);
|
||||
velocityComponent.Register(instance);
|
||||
world.Register(instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
cameraComponent.Register(instance);
|
||||
console.Register(instance);
|
||||
graphicsComponent.Register(instance);
|
||||
#endif
|
||||
|
||||
// Enums
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the index of the component
|
||||
* \return A pointer to the binding linked to a component
|
||||
*
|
||||
* \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))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
ComponentIndex componentIndex = instance.Check<ComponentIndex>(&argIndex);
|
||||
if (componentIndex > m_componentBinding.size())
|
||||
{
|
||||
instance.Error("Invalid component index");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ComponentBinding& binding = m_componentBinding[componentIndex];
|
||||
if (binding.name.IsEmpty())
|
||||
{
|
||||
instance.Error("Invalid component index");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &binding;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
const char* key = instance.CheckString(argIndex);
|
||||
auto it = m_componentBindingByName.find(key);
|
||||
if (it == m_componentBindingByName.end())
|
||||
{
|
||||
instance.Error("Invalid component name");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &m_componentBinding[it->second];
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
instance.Error("Invalid component index at #" + Nz::String::Number(argIndex));
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
446
SDK/src/NDK/Lua/LuaBinding_Utility.cpp
Normal file
446
SDK/src/NDK/Lua/LuaBinding_Utility.cpp
Normal file
@@ -0,0 +1,446 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Lua/LuaBinding_Utility.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindUtility(LuaBinding& binding)
|
||||
{
|
||||
return std::make_unique<LuaBinding_Utility>(binding);
|
||||
}
|
||||
|
||||
LuaBinding_Utility::LuaBinding_Utility(LuaBinding& binding) :
|
||||
LuaBinding_Base(binding)
|
||||
{
|
||||
/*********************************** Nz::AbstractImage **********************************/
|
||||
abstractImage.Reset("AbstractImage");
|
||||
{
|
||||
abstractImage.BindMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel);
|
||||
abstractImage.BindMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetFormat", &Nz::AbstractImage::GetFormat);
|
||||
abstractImage.BindMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
||||
abstractImage.BindMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
|
||||
abstractImage.BindMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetType", &Nz::AbstractImage::GetType);
|
||||
abstractImage.BindMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
||||
abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap);
|
||||
|
||||
abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return lua.Push(instance->GetMemoryUsage());
|
||||
|
||||
case 1:
|
||||
{
|
||||
int argIndex = 2;
|
||||
Nz::UInt8 level(lua.Check<Nz::UInt8>(&argIndex));
|
||||
|
||||
return lua.Push(instance->GetMemoryUsage(level));
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method GetMemoryUsage");
|
||||
return 0;
|
||||
});
|
||||
|
||||
abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 6U);
|
||||
int argIndex = 2;
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(lua.CheckString(argIndex++, &bufferSize));
|
||||
|
||||
if (argCount < 2 || lua.IsOfType(2, Nz::LuaType_Number))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(instance->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
/* Disabled until Box and Rect have been ported
|
||||
else if (lua.IsOfType(2, "Box"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Boxui box = lua.Check<Nz::Boxui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
else if (lua.IsOfType(2, "Rect"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Rectui box = lua.Check<Nz::Rectui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}*/
|
||||
|
||||
lua.Error("No matching overload for method Update");
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
/*********************************** Nz::Font **********************************/
|
||||
font.Reset("Font");
|
||||
{
|
||||
font.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::FontRef* instance, std::size_t /*argumentCount*/)
|
||||
{
|
||||
Nz::PlacementNew(instance, Nz::Font::New());
|
||||
return true;
|
||||
});
|
||||
|
||||
font.BindMethod("ClearGlyphCache", &Nz::Font::ClearGlyphCache);
|
||||
font.BindMethod("ClearKerningCache", &Nz::Font::ClearKerningCache);
|
||||
font.BindMethod("ClearSizeInfoCache", &Nz::Font::ClearSizeInfoCache);
|
||||
|
||||
font.BindMethod("Destroy", &Nz::Font::Destroy);
|
||||
|
||||
font.BindMethod("GetCachedGlyphCount", [] (Nz::LuaInstance& lua, Nz::FontRef& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
lua.Push(instance->GetCachedGlyphCount());
|
||||
return 1;
|
||||
|
||||
case 2:
|
||||
{
|
||||
unsigned int characterSize = lua.Check<unsigned int>(&argIndex);
|
||||
Nz::UInt32 style = lua.Check<Nz::UInt32>(&argIndex);
|
||||
|
||||
lua.Push(instance->GetCachedGlyphCount(characterSize, style));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method GetCachedGlyphCount");
|
||||
return 0;
|
||||
});
|
||||
|
||||
font.BindMethod("GetFamilyName", &Nz::Font::GetFamilyName);
|
||||
font.BindMethod("GetKerning", &Nz::Font::GetKerning);
|
||||
font.BindMethod("GetGlyphBorder", &Nz::Font::GetGlyphBorder);
|
||||
font.BindMethod("GetMinimumStepSize", &Nz::Font::GetMinimumStepSize);
|
||||
font.BindMethod("GetSizeInfo", &Nz::Font::GetSizeInfo);
|
||||
font.BindMethod("GetStyleName", &Nz::Font::GetStyleName);
|
||||
|
||||
font.BindMethod("IsValid", &Nz::Font::IsValid);
|
||||
|
||||
font.BindMethod("Precache", (bool(Nz::Font::*)(unsigned int, Nz::UInt32, const Nz::String&) const) &Nz::Font::Precache);
|
||||
|
||||
font.BindMethod("OpenFromFile", &Nz::Font::OpenFromFile, Nz::FontParams());
|
||||
|
||||
font.BindMethod("SetGlyphBorder", &Nz::Font::SetGlyphBorder);
|
||||
font.BindMethod("SetMinimumStepSize", &Nz::Font::SetMinimumStepSize);
|
||||
|
||||
font.BindStaticMethod("GetDefault", &Nz::Font::GetDefault);
|
||||
font.BindStaticMethod("GetDefaultGlyphBorder", &Nz::Font::GetDefaultGlyphBorder);
|
||||
font.BindStaticMethod("GetDefaultMinimumStepSize", &Nz::Font::GetDefaultMinimumStepSize);
|
||||
|
||||
font.BindStaticMethod("SetDefaultGlyphBorder", &Nz::Font::SetDefaultGlyphBorder);
|
||||
font.BindStaticMethod("SetDefaultMinimumStepSize", &Nz::Font::SetDefaultMinimumStepSize);
|
||||
}
|
||||
|
||||
/*********************************** Nz::Keyboard **********************************/
|
||||
keyboard.Reset("Keyboard");
|
||||
{
|
||||
keyboard.BindStaticMethod("GetKeyName", &Nz::Keyboard::GetKeyName);
|
||||
keyboard.BindStaticMethod("IsKeyPressed", &Nz::Keyboard::IsKeyPressed);
|
||||
}
|
||||
|
||||
/*********************************** Nz::Node **********************************/
|
||||
node.Reset("Node");
|
||||
{
|
||||
node.BindMethod("GetBackward", &Nz::Node::GetBackward);
|
||||
//nodeClass.SetMethod("GetChilds", &Nz::Node::GetChilds);
|
||||
node.BindMethod("GetDown", &Nz::Node::GetDown);
|
||||
node.BindMethod("GetForward", &Nz::Node::GetForward);
|
||||
node.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
||||
node.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
||||
node.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
||||
node.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
||||
//nodeClass.SetMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
||||
node.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
||||
node.BindMethod("GetLeft", &Nz::Node::GetLeft);
|
||||
node.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
|
||||
//nodeClass.SetMethod("GetParent", &Nz::Node::GetParent);
|
||||
node.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
||||
node.BindMethod("GetRight", &Nz::Node::GetRight);
|
||||
//nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
||||
node.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
||||
//nodeClass.SetMethod("GetTransformMatrix", &Nz::Node::GetTransformMatrix);
|
||||
node.BindMethod("GetUp", &Nz::Node::GetUp);
|
||||
|
||||
node.BindMethod("HasChilds", &Nz::Node::HasChilds);
|
||||
|
||||
node.BindMethod("GetBackward", &Nz::Node::GetBackward);
|
||||
node.BindMethod("GetDown", &Nz::Node::GetDown);
|
||||
node.BindMethod("GetForward", &Nz::Node::GetForward);
|
||||
node.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
||||
node.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
||||
node.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
||||
node.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
||||
node.BindMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
||||
node.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
||||
node.BindMethod("GetLeft", &Nz::Node::GetLeft);
|
||||
node.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
|
||||
node.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
||||
node.BindMethod("GetRight", &Nz::Node::GetRight);
|
||||
node.BindMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
||||
node.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
||||
node.BindMethod("GetUp", &Nz::Node::GetUp);
|
||||
|
||||
node.BindMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition);
|
||||
node.BindMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation);
|
||||
|
||||
node.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local);
|
||||
node.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local);
|
||||
|
||||
node.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
|
||||
Nz::Vector3f offset = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
instance.Move(offset, coordSys);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
node.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
|
||||
Nz::Quaternionf rotation = lua.Check<Nz::Quaternionf>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
instance.Rotate(rotation, coordSys);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
node.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
instance.Scale(lua.Check<float>(&argIndex));
|
||||
else
|
||||
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 3:
|
||||
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method Scale");
|
||||
return 0;
|
||||
});
|
||||
|
||||
node.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
{
|
||||
float scale = lua.Check<float>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
instance.SetScale(scale, coordSys);
|
||||
}
|
||||
else
|
||||
instance.SetScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 3:
|
||||
case 4:
|
||||
{
|
||||
Nz::Vector3f scale = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
|
||||
instance.SetScale(scale, coordSys);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetScale");
|
||||
return 0;
|
||||
});
|
||||
|
||||
node.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
instance.SetInitialScale(lua.Check<float>(&argIndex));
|
||||
else
|
||||
instance.SetInitialScale(lua.Check<Nz::Vector2f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
instance.SetInitialScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetInitialScale");
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the Utility classes
|
||||
*/
|
||||
void LuaBinding_Utility::Register(Nz::LuaInstance& instance)
|
||||
{
|
||||
abstractImage.Register(instance);
|
||||
font.Register(instance);
|
||||
keyboard.Register(instance);
|
||||
node.Register(instance);
|
||||
|
||||
keyboard.PushGlobalTable(instance);
|
||||
{
|
||||
static_assert(Nz::Keyboard::Count == 121, "Nz::Keyboard::Key has been updated but change was not reflected to Lua binding");
|
||||
|
||||
instance.PushField("Undefined", Nz::Keyboard::Undefined);
|
||||
|
||||
// A-Z
|
||||
for (std::size_t i = 0; i < 26; ++i)
|
||||
instance.PushField(Nz::String('A' + char(i)), Nz::Keyboard::A + i);
|
||||
|
||||
// Numerical
|
||||
for (std::size_t i = 0; i < 10; ++i)
|
||||
{
|
||||
instance.PushField("Num" + Nz::String::Number(i), Nz::Keyboard::Num0 + i);
|
||||
instance.PushField("Numpad" + Nz::String::Number(i), Nz::Keyboard::Numpad0 + i);
|
||||
}
|
||||
|
||||
// F1-F15
|
||||
for (std::size_t i = 0; i < 15; ++i)
|
||||
instance.PushField('F' + Nz::String::Number(i+1), Nz::Keyboard::F1 + i);
|
||||
|
||||
// And all the others...
|
||||
instance.PushField("Down", Nz::Keyboard::Down);
|
||||
instance.PushField("Left", Nz::Keyboard::Left);
|
||||
instance.PushField("Right", Nz::Keyboard::Right);
|
||||
instance.PushField("Up", Nz::Keyboard::Up);
|
||||
|
||||
instance.PushField("Add", Nz::Keyboard::Add);
|
||||
instance.PushField("Decimal", Nz::Keyboard::Decimal);
|
||||
instance.PushField("Divide", Nz::Keyboard::Divide);
|
||||
instance.PushField("Multiply", Nz::Keyboard::Multiply);
|
||||
instance.PushField("Subtract", Nz::Keyboard::Subtract);
|
||||
|
||||
instance.PushField("Backslash", Nz::Keyboard::Backslash);
|
||||
instance.PushField("Backspace", Nz::Keyboard::Backspace);
|
||||
instance.PushField("Clear", Nz::Keyboard::Clear);
|
||||
instance.PushField("Comma", Nz::Keyboard::Comma);
|
||||
instance.PushField("Dash", Nz::Keyboard::Dash);
|
||||
instance.PushField("Delete", Nz::Keyboard::Delete);
|
||||
instance.PushField("End", Nz::Keyboard::End);
|
||||
instance.PushField("Equal", Nz::Keyboard::Equal);
|
||||
instance.PushField("Escape", Nz::Keyboard::Escape);
|
||||
instance.PushField("Home", Nz::Keyboard::Home);
|
||||
instance.PushField("Insert", Nz::Keyboard::Insert);
|
||||
instance.PushField("LAlt", Nz::Keyboard::LAlt);
|
||||
instance.PushField("LBracket", Nz::Keyboard::LBracket);
|
||||
instance.PushField("LControl", Nz::Keyboard::LControl);
|
||||
instance.PushField("LShift", Nz::Keyboard::LShift);
|
||||
instance.PushField("LSystem", Nz::Keyboard::LSystem);
|
||||
instance.PushField("PageDown", Nz::Keyboard::PageDown);
|
||||
instance.PushField("PageUp", Nz::Keyboard::PageUp);
|
||||
instance.PushField("Pause", Nz::Keyboard::Pause);
|
||||
instance.PushField("Period", Nz::Keyboard::Period);
|
||||
instance.PushField("Print", Nz::Keyboard::Print);
|
||||
instance.PushField("PrintScreen", Nz::Keyboard::PrintScreen);
|
||||
instance.PushField("Quote", Nz::Keyboard::Quote);
|
||||
instance.PushField("RAlt", Nz::Keyboard::RAlt);
|
||||
instance.PushField("RBracket", Nz::Keyboard::RBracket);
|
||||
instance.PushField("RControl", Nz::Keyboard::RControl);
|
||||
instance.PushField("Return", Nz::Keyboard::Return);
|
||||
instance.PushField("RShift", Nz::Keyboard::RShift);
|
||||
instance.PushField("RSystem", Nz::Keyboard::RSystem);
|
||||
instance.PushField("Semicolon", Nz::Keyboard::Semicolon);
|
||||
instance.PushField("Slash", Nz::Keyboard::Slash);
|
||||
instance.PushField("Space", Nz::Keyboard::Space);
|
||||
instance.PushField("Tab", Nz::Keyboard::Tab);
|
||||
instance.PushField("Tilde", Nz::Keyboard::Tilde);
|
||||
instance.PushField("Browser_Back", Nz::Keyboard::Browser_Back);
|
||||
instance.PushField("Browser_Favorites", Nz::Keyboard::Browser_Favorites);
|
||||
instance.PushField("Browser_Forward", Nz::Keyboard::Browser_Forward);
|
||||
instance.PushField("Browser_Home", Nz::Keyboard::Browser_Home);
|
||||
instance.PushField("Browser_Refresh", Nz::Keyboard::Browser_Refresh);
|
||||
instance.PushField("Browser_Search", Nz::Keyboard::Browser_Search);
|
||||
instance.PushField("Browser_Stop", Nz::Keyboard::Browser_Stop);
|
||||
instance.PushField("Media_Next", Nz::Keyboard::Media_Next);
|
||||
instance.PushField("Media_Play", Nz::Keyboard::Media_Play);
|
||||
instance.PushField("Media_Previous", Nz::Keyboard::Media_Previous);
|
||||
instance.PushField("Media_Stop", Nz::Keyboard::Media_Stop);
|
||||
instance.PushField("Volume_Down", Nz::Keyboard::Volume_Down);
|
||||
instance.PushField("Volume_Mute", Nz::Keyboard::Volume_Mute);
|
||||
instance.PushField("Volume_Up", Nz::Keyboard::Volume_Up);
|
||||
instance.PushField("CapsLock", Nz::Keyboard::CapsLock);
|
||||
instance.PushField("NumLock", Nz::Keyboard::NumLock);
|
||||
instance.PushField("ScrollLock", Nz::Keyboard::ScrollLock);
|
||||
}
|
||||
instance.Pop();
|
||||
|
||||
static_assert(Nz::WindowStyle_Max + 1 == 6, "Nz::WindowStyle has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, Nz::WindowStyle_Max + 1);
|
||||
{
|
||||
instance.PushField("None", Nz::WindowStyle_None);
|
||||
instance.PushField("Fullscreen", Nz::WindowStyle_Fullscreen);
|
||||
instance.PushField("Closable", Nz::WindowStyle_Closable);
|
||||
instance.PushField("Resizable", Nz::WindowStyle_Resizable);
|
||||
instance.PushField("Titlebar", Nz::WindowStyle_Titlebar);
|
||||
instance.PushField("Threaded", Nz::WindowStyle_Threaded);
|
||||
}
|
||||
instance.SetGlobal("WindowStyle");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/Lua/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \ingroup NDK
|
||||
* \class Ndk::LuaBinding
|
||||
* \brief NDK class that represents the binding between the engine & the SDK with the Lua scripting
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \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
|
||||
{
|
||||
BindCore();
|
||||
BindMath();
|
||||
BindNetwork();
|
||||
BindSDK();
|
||||
BindUtility();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
BindAudio();
|
||||
BindGraphics();
|
||||
BindRenderer();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the engine & SDK
|
||||
*/
|
||||
|
||||
void LuaBinding::RegisterClasses(Nz::LuaInstance& instance)
|
||||
{
|
||||
RegisterCore(instance);
|
||||
RegisterMath(instance);
|
||||
RegisterNetwork(instance);
|
||||
RegisterSDK(instance);
|
||||
RegisterUtility(instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
RegisterAudio(instance);
|
||||
RegisterGraphics(instance);
|
||||
RegisterRenderer(instance);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,185 +0,0 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <Nazara/Core/MemoryHelper.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Binds Audio module to Lua
|
||||
*/
|
||||
|
||||
void LuaBinding::BindAudio()
|
||||
{
|
||||
/*********************************** 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
|
||||
{
|
||||
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
|
||||
{
|
||||
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)
|
||||
{
|
||||
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<Nz::AudioFormat>(&index);
|
||||
unsigned int sampleCount = lua.Check<unsigned int>(&index);
|
||||
unsigned int sampleRate = lua.Check<unsigned int>(&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<const Nz::Int16*>(buffer)));
|
||||
return 1;
|
||||
});
|
||||
|
||||
soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
lua.PushString(reinterpret_cast<const char*>(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.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("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("Stop", &Nz::SoundEmitter::Stop);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the Audio classes
|
||||
*/
|
||||
|
||||
void LuaBinding::RegisterAudio(Nz::LuaInstance& instance)
|
||||
{
|
||||
music.Register(instance);
|
||||
sound.Register(instance);
|
||||
soundBuffer.Register(instance);
|
||||
soundEmitter.Register(instance);
|
||||
}
|
||||
}
|
||||
@@ -1,341 +0,0 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <Nazara/Core/MemoryHelper.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Binds Core module to Lua
|
||||
*/
|
||||
|
||||
void LuaBinding::BindCore()
|
||||
{
|
||||
/*********************************** Nz::Clock **********************************/
|
||||
clock.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* instance, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(instance);
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
||||
|
||||
Nz::PlacementNew(instance, startingValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
||||
bool paused = lua.Check<bool>(&argIndex, false);
|
||||
|
||||
Nz::PlacementNew(instance, startingValue, paused);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for Clock constructor");
|
||||
return false;
|
||||
});
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
/********************************* Nz::Directory ********************************/
|
||||
directory.SetConstructor([](Nz::LuaInstance& lua, Nz::Directory* instance, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(instance);
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
Nz::PlacementNew(instance, lua.Check<Nz::String>(&argIndex));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
// Manual
|
||||
directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& instance, std::size_t /*argumentCount*/) -> int {
|
||||
Nz::StringStream ss("Directory(");
|
||||
ss << instance.GetPath();
|
||||
ss << ')';
|
||||
|
||||
lua.PushString(ss);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** 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<std::size_t>(&argIndex);
|
||||
|
||||
std::unique_ptr<char[]> 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;
|
||||
});
|
||||
|
||||
/*********************************** Nz::File ***********************************/
|
||||
file.Inherit(stream);
|
||||
|
||||
file.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* instance, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(instance);
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
||||
|
||||
Nz::PlacementNew(instance, filePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
||||
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&argIndex);
|
||||
|
||||
Nz::PlacementNew(instance, filePath, openMode);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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<std::size_t>(argumentCount, 2U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
return lua.Push(instance.Open(lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||
|
||||
case 2:
|
||||
{
|
||||
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
||||
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen);
|
||||
return lua.Push(instance.Open(filePath, openMode));
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method Open");
|
||||
return 0;
|
||||
});
|
||||
|
||||
file.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
return lua.Push(instance.SetCursorPos(lua.Check<Nz::UInt64>(&argIndex)));
|
||||
|
||||
case 2:
|
||||
{
|
||||
Nz::CursorPosition curPos = lua.Check<Nz::CursorPosition>(&argIndex);
|
||||
Nz::Int64 offset = lua.Check<Nz::Int64>(&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;
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the Core classes
|
||||
*/
|
||||
|
||||
void LuaBinding::RegisterCore(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
clock.Register(instance);
|
||||
directory.Register(instance);
|
||||
file.Register(instance);
|
||||
stream.Register(instance);
|
||||
|
||||
// Enums
|
||||
|
||||
// Nz::CursorPosition
|
||||
static_assert(Nz::CursorPosition_Max + 1 == 3, "Nz::CursorPosition has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 3);
|
||||
{
|
||||
instance.PushField("AtBegin", Nz::CursorPosition_AtBegin);
|
||||
instance.PushField("AtCurrent", Nz::CursorPosition_AtCurrent);
|
||||
instance.PushField("AtEnd", Nz::CursorPosition_AtEnd);
|
||||
}
|
||||
instance.SetGlobal("CursorPosition");
|
||||
|
||||
// Nz::HashType
|
||||
static_assert(Nz::HashType_Max + 1 == 9, "Nz::HashType has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 9);
|
||||
{
|
||||
instance.PushField("CRC32", Nz::HashType_CRC32);
|
||||
instance.PushField("Fletcher16", Nz::HashType_Fletcher16);
|
||||
instance.PushField("MD5", Nz::HashType_MD5);
|
||||
instance.PushField("SHA1", Nz::HashType_SHA1);
|
||||
instance.PushField("SHA224", Nz::HashType_SHA224);
|
||||
instance.PushField("SHA256", Nz::HashType_SHA256);
|
||||
instance.PushField("SHA384", Nz::HashType_SHA384);
|
||||
instance.PushField("SHA512", Nz::HashType_SHA512);
|
||||
instance.PushField("Whirlpool", Nz::HashType_Whirlpool);
|
||||
}
|
||||
instance.SetGlobal("HashType");
|
||||
|
||||
// Nz::OpenMode
|
||||
static_assert(Nz::OpenMode_Max + 1 == 2 * (64), "Nz::OpenModeFlags has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 8);
|
||||
{
|
||||
instance.PushField("Append", Nz::OpenMode_Append);
|
||||
instance.PushField("NotOpen", Nz::OpenMode_NotOpen);
|
||||
instance.PushField("Lock", Nz::OpenMode_Lock);
|
||||
instance.PushField("ReadOnly", Nz::OpenMode_ReadOnly);
|
||||
instance.PushField("ReadWrite", Nz::OpenMode_ReadWrite);
|
||||
instance.PushField("Text", Nz::OpenMode_Text);
|
||||
instance.PushField("Truncate", Nz::OpenMode_Truncate);
|
||||
instance.PushField("WriteOnly", Nz::OpenMode_WriteOnly);
|
||||
}
|
||||
instance.SetGlobal("OpenMode");
|
||||
}
|
||||
}
|
||||
@@ -1,371 +0,0 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Binds Graphics module to Lua
|
||||
*/
|
||||
|
||||
void LuaBinding::BindGraphics()
|
||||
{
|
||||
/*********************************** 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);
|
||||
|
||||
/*********************************** Nz::InstancedRenderable ***********************************/
|
||||
|
||||
/*********************************** Nz::Material ***********************************/
|
||||
material.SetConstructor([] (Nz::LuaInstance& lua, Nz::MaterialRef* instance, std::size_t argumentCount)
|
||||
{
|
||||
switch (argumentCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(instance, Nz::Material::New());
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
int argIndex = 1;
|
||||
if (lua.IsOfType(argIndex, "MaterialPipeline"))
|
||||
{
|
||||
Nz::PlacementNew(instance, Nz::Material::New(*static_cast<Nz::MaterialPipelineRef*>(lua.ToUserdata(argIndex))));
|
||||
return true;
|
||||
}
|
||||
else if (lua.IsOfType(argIndex, "Material"))
|
||||
{
|
||||
Nz::PlacementNew(instance, Nz::Material::New(**static_cast<Nz::MaterialRef*>(lua.ToUserdata(argIndex))));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Nz::PlacementNew(instance, Nz::Material::New(lua.Check<Nz::String>(&argIndex)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"))
|
||||
{
|
||||
instance->Configure(*static_cast<Nz::MaterialPipelineRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
lua.Push(instance->Configure(lua.Check<Nz::String>(&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
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
{
|
||||
instance->SetAlphaMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetAlphaMap(lua.Check<Nz::String>(&argIndex)));
|
||||
});
|
||||
|
||||
material.BindMethod("SetDiffuseMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
{
|
||||
instance->SetDiffuseMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetDiffuseMap(lua.Check<Nz::String>(&argIndex)));
|
||||
});
|
||||
|
||||
material.BindMethod("SetEmissiveMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
{
|
||||
instance->SetEmissiveMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetEmissiveMap(lua.Check<Nz::String>(&argIndex)));
|
||||
});
|
||||
|
||||
material.BindMethod("SetHeightMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
{
|
||||
instance->SetHeightMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetHeightMap(lua.Check<Nz::String>(&argIndex)));
|
||||
});
|
||||
|
||||
material.BindMethod("SetNormalMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
{
|
||||
instance->SetNormalMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetNormalMap(lua.Check<Nz::String>(&argIndex)));
|
||||
});
|
||||
|
||||
material.BindMethod("SetShader", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, "UberShader"))
|
||||
{
|
||||
instance->SetShader(*static_cast<Nz::UberShaderRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetShader(lua.Check<Nz::String>(&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<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return lua.Push(instance->SetSpecularMap(lua.Check<Nz::String>(&argIndex)));
|
||||
});
|
||||
|
||||
/*********************************** Nz::Model ***********************************/
|
||||
model.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::ModelRef* modelRef) -> Nz::InstancedRenderableRef*
|
||||
{
|
||||
return reinterpret_cast<Nz::InstancedRenderableRef*>(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.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("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);
|
||||
|
||||
/*********************************** Nz::Sprite ***********************************/
|
||||
sprite.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::SpriteRef* spriteRef) -> Nz::InstancedRenderableRef*
|
||||
{
|
||||
return reinterpret_cast<Nz::InstancedRenderableRef*>(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.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("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<Nz::MaterialRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
||||
else
|
||||
instance->SetMaterial(lua.Check<Nz::String>(&argIndex), resizeSprite);
|
||||
|
||||
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);
|
||||
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
instance->SetTexture(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
||||
else
|
||||
instance->SetTexture(lua.Check<Nz::String>(&argIndex), resizeSprite);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the Graphics classes
|
||||
*/
|
||||
|
||||
void LuaBinding::RegisterGraphics(Nz::LuaInstance& instance)
|
||||
{
|
||||
abstractViewer.Register(instance);
|
||||
instancedRenderable.Register(instance);
|
||||
material.Register(instance);
|
||||
model.Register(instance);
|
||||
sprite.Register(instance);
|
||||
spriteLibrary.Register(instance);
|
||||
textureLibrary.Register(instance);
|
||||
textureManager.Register(instance);
|
||||
}
|
||||
}
|
||||
@@ -1,968 +0,0 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <Nazara/Core/MemoryHelper.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <cstring>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Binds Math module to Lua
|
||||
*/
|
||||
|
||||
void LuaBinding::BindMath()
|
||||
{
|
||||
/*********************************** Nz::EulerAngles **********************************/
|
||||
eulerAngles.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* instance, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(instance, Nz::EulerAnglesd::Zero());
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
Nz::PlacementNew(instance, *static_cast<Nz::EulerAnglesd*>(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 (ypr[0])
|
||||
{
|
||||
case 'p':
|
||||
lua.Push(instance.pitch);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.yaw);
|
||||
return true;
|
||||
|
||||
case 'r':
|
||||
lua.Push(instance.roll);
|
||||
return true;
|
||||
}
|
||||
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 'p':
|
||||
instance.pitch = 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;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
/*********************************** Nz::Matrix4 **********************************/
|
||||
matrix4d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Matrix4d* matrix, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(matrix, Nz::Matrix4d::Zero());
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
if (lua.IsOfType(1, "Matrix4"))
|
||||
Nz::PlacementNew(matrix, *static_cast<Nz::Matrix4d*>(lua.ToUserdata(1)));
|
||||
break;
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
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("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<std::size_t>(argumentCount, 3U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
if (lua.IsOfType(argIndex, "Matrix4"))
|
||||
instance.Set(*static_cast<Nz::Matrix4d*>(lua.ToUserdata(argIndex)));
|
||||
break;
|
||||
|
||||
case 16:
|
||||
{
|
||||
double values[16];
|
||||
for (std::size_t i = 0; i < 16; ++i)
|
||||
values[i] = lua.CheckNumber(argIndex++);
|
||||
|
||||
instance.Set(values);
|
||||
|
||||
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("Transform", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
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<Nz::Vector2d*>(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<Nz::Vector3d*>(lua.ToUserdata(argIndex)), w));
|
||||
}
|
||||
//else if (lua.IsOfType(2, "Vector4"))
|
||||
// return lua.Push(instance.Transform(*static_cast<Nz::Vector4d*>(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)
|
||||
{
|
||||
bool succeeded = false;
|
||||
std::size_t index = static_cast<std::size_t>(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<std::size_t>(lua.ToInteger(2, &succeeded));
|
||||
if (!succeeded || index < 1 || index > 16)
|
||||
return false;
|
||||
|
||||
instance[index - 1] = lua.CheckNumber(3);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Rect **********************************/
|
||||
rect.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* instance, std::size_t argumentCount)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
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:
|
||||
{
|
||||
if (lua.IsOfType(1, "Rect"))
|
||||
PlacementNew(instance, *static_cast<Nz::Rectd*>(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<double>("x", 1),
|
||||
lua.CheckField<double>("y", 1),
|
||||
lua.CheckField<double>("width", 1),
|
||||
lua.CheckField<double>("height", 1));
|
||||
}
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
PlacementNew(instance, *static_cast<Nz::Vector2d*>(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<Nz::Vector2d*>(lua.ToUserdata(1)), *static_cast<Nz::Vector2d*>(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<std::size_t>(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<std::size_t>(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)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
Nz::PlacementNew(instance, Nz::Quaterniond::Zero());
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, "EulerAngles"))
|
||||
Nz::PlacementNew(instance, *static_cast<Nz::EulerAnglesd*>(lua.ToUserdata(1)));
|
||||
else if (lua.IsOfType(1, "Quaternion"))
|
||||
Nz::PlacementNew(instance, *static_cast<Nz::Quaterniond*>(lua.ToUserdata(1)));
|
||||
else
|
||||
break;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case 2:
|
||||
Nz::PlacementNew(instance, lua.CheckNumber(1), *static_cast<Nz::Vector3d*>(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<Nz::Quaterniond>(&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;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
quaternion.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* wxyz = lua.CheckString(2, &length);
|
||||
|
||||
if (length != 1)
|
||||
return false;
|
||||
|
||||
double value = lua.CheckNumber(3);
|
||||
|
||||
switch (wxyz[0])
|
||||
{
|
||||
case 'w':
|
||||
instance.w = value;
|
||||
return true;
|
||||
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
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)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0));
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
Nz::PlacementNew(vector, lua.CheckNumber(1));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
|
||||
else
|
||||
break;
|
||||
|
||||
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 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 3:
|
||||
Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0));
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
Nz::PlacementNew(vector, lua.CheckNumber(1));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
|
||||
else if (lua.IsOfType(1, "Vector3"))
|
||||
Nz::PlacementNew(vector, *static_cast<Nz::Vector3d*>(lua.ToUserdata(1)));
|
||||
else
|
||||
break;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.CheckUserdata(2, "Vector2")));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(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 '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;
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the Math classes
|
||||
*/
|
||||
|
||||
void LuaBinding::RegisterMath(Nz::LuaInstance& instance)
|
||||
{
|
||||
eulerAngles.Register(instance);
|
||||
matrix4d.Register(instance);
|
||||
quaternion.Register(instance);
|
||||
rect.Register(instance);
|
||||
vector2d.Register(instance);
|
||||
vector3d.Register(instance);
|
||||
|
||||
quaternion.PushGlobalTable(instance);
|
||||
{
|
||||
instance.PushField("Identity", Nz::Quaterniond::Identity());
|
||||
instance.PushField("Zero", Nz::Quaterniond::Zero());
|
||||
}
|
||||
instance.Pop();
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Binds Renderer module to Lua
|
||||
*/
|
||||
void LuaBinding::BindRenderer()
|
||||
{
|
||||
/*********************************** Nz::Texture ***********************************/
|
||||
texture.Inherit<Nz::AbstractImageRef>(abstractImage, [] (Nz::TextureRef* textureRef) -> Nz::AbstractImageRef*
|
||||
{
|
||||
return reinterpret_cast<Nz::AbstractImageRef*>(textureRef); //TODO: Make a ObjectRefCast
|
||||
});
|
||||
|
||||
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<Nz::UInt8>(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);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the Renderer classes
|
||||
*/
|
||||
void LuaBinding::RegisterRenderer(Nz::LuaInstance& instance)
|
||||
{
|
||||
texture.Register(instance);
|
||||
}
|
||||
}
|
||||
@@ -1,320 +0,0 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Binds SDK module to Lua
|
||||
*/
|
||||
|
||||
void LuaBinding::BindSDK()
|
||||
{
|
||||
/*********************************** Ndk::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<Nz::Node>(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("IsVisible", &Console::IsVisible);
|
||||
|
||||
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("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
|
||||
{
|
||||
ComponentBinding* binding = QueryComponentIndex(instance);
|
||||
|
||||
return binding->adder(instance, handle);
|
||||
});
|
||||
|
||||
entity.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
ComponentBinding* binding = QueryComponentIndex(instance);
|
||||
|
||||
return binding->getter(instance, handle->GetComponent(binding->index));
|
||||
});
|
||||
|
||||
entity.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
ComponentBinding* binding = QueryComponentIndex(instance);
|
||||
|
||||
handle->RemoveComponent(binding->index);
|
||||
return 0;
|
||||
});
|
||||
|
||||
/*********************************** Ndk::NodeComponent **********************************/
|
||||
nodeComponent.Inherit<Nz::Node>(node, [] (NodeComponentHandle* handle) -> Nz::Node*
|
||||
{
|
||||
return handle->GetObject();
|
||||
});
|
||||
|
||||
/*********************************** Ndk::VelocityComponent **********************************/
|
||||
velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* member = lua.CheckString(2, &length);
|
||||
|
||||
if (std::strcmp(member, "Linear") == 0)
|
||||
{
|
||||
lua.Push(instance->linearVelocity);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* member = lua.CheckString(2, &length);
|
||||
|
||||
int argIndex = 3;
|
||||
if (std::strcmp(member, "Linear") == 0)
|
||||
{
|
||||
instance->linearVelocity = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Ndk::World **********************************/
|
||||
world.BindMethod("CreateEntity", &World::CreateEntity);
|
||||
world.BindMethod("CreateEntities", &World::CreateEntities);
|
||||
world.BindMethod("Clear", &World::Clear);
|
||||
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
/*********************************** Ndk::CameraComponent **********************************/
|
||||
cameraComponent.Inherit<Nz::AbstractViewer>(abstractViewer, [] (CameraComponentHandle* handle) -> Nz::AbstractViewer*
|
||||
{
|
||||
return handle->GetObject();
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
/*********************************** Ndk::GraphicsComponent **********************************/
|
||||
graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent* instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
/*
|
||||
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<std::size_t>(argumentCount, 3U);
|
||||
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
int argIndex = 2;
|
||||
instance->Attach(lua.Check<Nz::InstancedRenderableRef>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
int argIndex = 2;
|
||||
Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);
|
||||
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
{
|
||||
int renderOrder = lua.Check<int>(&argIndex);
|
||||
|
||||
instance->Attach(renderable, renderOrder);
|
||||
}
|
||||
else if (lua.IsOfType(argIndex, "Matrix4"))
|
||||
{
|
||||
Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);
|
||||
|
||||
instance->Attach(renderable, localMatrix);
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
int argIndex = 2;
|
||||
Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);
|
||||
Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);
|
||||
int renderOrder = lua.Check<int>(&argIndex);
|
||||
|
||||
instance->Attach(renderable, localMatrix, renderOrder);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method GetMemoryUsage");
|
||||
return 0;
|
||||
});
|
||||
#endif
|
||||
|
||||
|
||||
// Components functions
|
||||
m_componentBinding.resize(BaseComponent::GetMaxComponentIndex());
|
||||
|
||||
BindComponent<NodeComponent>("Node");
|
||||
BindComponent<VelocityComponent>("Velocity");
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
BindComponent<CameraComponent>("Camera");
|
||||
BindComponent<GraphicsComponent>("Graphics");
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the SDK classes
|
||||
*/
|
||||
|
||||
void LuaBinding::RegisterSDK(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
application.Register(instance);
|
||||
entity.Register(instance);
|
||||
nodeComponent.Register(instance);
|
||||
velocityComponent.Register(instance);
|
||||
world.Register(instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
cameraComponent.Register(instance);
|
||||
console.Register(instance);
|
||||
graphicsComponent.Register(instance);
|
||||
#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");
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the index of the component
|
||||
* \return A pointer to the binding linked to a component
|
||||
*
|
||||
* \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))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
ComponentIndex componentIndex = instance.Check<ComponentIndex>(&argIndex);
|
||||
if (componentIndex > m_componentBinding.size())
|
||||
{
|
||||
instance.Error("Invalid component index");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ComponentBinding& binding = m_componentBinding[componentIndex];
|
||||
if (binding.name.IsEmpty())
|
||||
{
|
||||
instance.Error("Invalid component index");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &binding;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
const char* key = instance.CheckString(argIndex);
|
||||
auto it = m_componentBindingByName.find(key);
|
||||
if (it == m_componentBindingByName.end())
|
||||
{
|
||||
instance.Error("Invalid component name");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &m_componentBinding[it->second];
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
instance.Error("Invalid component index at #" + Nz::String::Number(argIndex));
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -1,417 +0,0 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Binds Utility module to Lua
|
||||
*/
|
||||
|
||||
void LuaBinding::BindUtility()
|
||||
{
|
||||
/*********************************** Nz::AbstractImage **********************************/
|
||||
abstractImage.BindMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel);
|
||||
abstractImage.BindMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetFormat", &Nz::AbstractImage::GetFormat);
|
||||
abstractImage.BindMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
||||
abstractImage.BindMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
|
||||
abstractImage.BindMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetType", &Nz::AbstractImage::GetType);
|
||||
abstractImage.BindMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
||||
abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap);
|
||||
|
||||
abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return lua.Push(instance->GetMemoryUsage());
|
||||
|
||||
case 1:
|
||||
{
|
||||
int argIndex = 2;
|
||||
Nz::UInt8 level(lua.Check<Nz::UInt8>(&argIndex));
|
||||
|
||||
return lua.Push(instance->GetMemoryUsage(level));
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method GetMemoryUsage");
|
||||
return 0;
|
||||
});
|
||||
|
||||
abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 6U);
|
||||
int argIndex = 2;
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(lua.CheckString(argIndex++, &bufferSize));
|
||||
|
||||
if (argCount < 2 || lua.IsOfType(2, Nz::LuaType_Number))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(instance->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
/* Disabled until Box and Rect have been ported
|
||||
else if (lua.IsOfType(2, "Box"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Boxui box = lua.Check<Nz::Boxui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
else if (lua.IsOfType(2, "Rect"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Rectui box = lua.Check<Nz::Rectui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}*/
|
||||
|
||||
lua.Error("No matching overload for method Update");
|
||||
return 0;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Font **********************************/
|
||||
font.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::FontRef* instance, std::size_t /*argumentCount*/)
|
||||
{
|
||||
Nz::PlacementNew(instance, Nz::Font::New());
|
||||
return true;
|
||||
});
|
||||
|
||||
font.BindMethod("ClearGlyphCache", &Nz::Font::ClearGlyphCache);
|
||||
font.BindMethod("ClearKerningCache", &Nz::Font::ClearKerningCache);
|
||||
font.BindMethod("ClearSizeInfoCache", &Nz::Font::ClearSizeInfoCache);
|
||||
|
||||
font.BindMethod("Destroy", &Nz::Font::Destroy);
|
||||
|
||||
font.BindMethod("GetCachedGlyphCount", [] (Nz::LuaInstance& lua, Nz::FontRef& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
lua.Push(instance->GetCachedGlyphCount());
|
||||
return 1;
|
||||
|
||||
case 2:
|
||||
{
|
||||
unsigned int characterSize = lua.Check<unsigned int>(&argIndex);
|
||||
Nz::UInt32 style = lua.Check<Nz::UInt32>(&argIndex);
|
||||
|
||||
lua.Push(instance->GetCachedGlyphCount(characterSize, style));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method GetCachedGlyphCount");
|
||||
return 0;
|
||||
});
|
||||
|
||||
font.BindMethod("GetFamilyName", &Nz::Font::GetFamilyName);
|
||||
font.BindMethod("GetKerning", &Nz::Font::GetKerning);
|
||||
font.BindMethod("GetGlyphBorder", &Nz::Font::GetGlyphBorder);
|
||||
font.BindMethod("GetMinimumStepSize", &Nz::Font::GetMinimumStepSize);
|
||||
font.BindMethod("GetSizeInfo", &Nz::Font::GetSizeInfo);
|
||||
font.BindMethod("GetStyleName", &Nz::Font::GetStyleName);
|
||||
|
||||
font.BindMethod("IsValid", &Nz::Font::IsValid);
|
||||
|
||||
font.BindMethod("Precache", (bool(Nz::Font::*)(unsigned int, Nz::UInt32, const Nz::String&) const) &Nz::Font::Precache);
|
||||
|
||||
font.BindMethod("OpenFromFile", &Nz::Font::OpenFromFile, Nz::FontParams());
|
||||
|
||||
font.BindMethod("SetGlyphBorder", &Nz::Font::SetGlyphBorder);
|
||||
font.BindMethod("SetMinimumStepSize", &Nz::Font::SetMinimumStepSize);
|
||||
|
||||
font.BindStaticMethod("GetDefault", &Nz::Font::GetDefault);
|
||||
font.BindStaticMethod("GetDefaultGlyphBorder", &Nz::Font::GetDefaultGlyphBorder);
|
||||
font.BindStaticMethod("GetDefaultMinimumStepSize", &Nz::Font::GetDefaultMinimumStepSize);
|
||||
|
||||
font.BindStaticMethod("SetDefaultGlyphBorder", &Nz::Font::SetDefaultGlyphBorder);
|
||||
font.BindStaticMethod("SetDefaultMinimumStepSize", &Nz::Font::SetDefaultMinimumStepSize);
|
||||
|
||||
/*********************************** Nz::Keyboard **********************************/
|
||||
keyboard.BindStaticMethod("GetKeyName", &Nz::Keyboard::GetKeyName);
|
||||
keyboard.BindStaticMethod("IsKeyPressed", &Nz::Keyboard::IsKeyPressed);
|
||||
|
||||
/*********************************** Nz::Node **********************************/
|
||||
node.BindMethod("GetBackward", &Nz::Node::GetBackward);
|
||||
//nodeClass.SetMethod("GetChilds", &Nz::Node::GetChilds);
|
||||
node.BindMethod("GetDown", &Nz::Node::GetDown);
|
||||
node.BindMethod("GetForward", &Nz::Node::GetForward);
|
||||
node.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
||||
node.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
||||
node.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
||||
node.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
||||
//nodeClass.SetMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
||||
node.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
||||
node.BindMethod("GetLeft", &Nz::Node::GetLeft);
|
||||
node.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
|
||||
//nodeClass.SetMethod("GetParent", &Nz::Node::GetParent);
|
||||
node.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
||||
node.BindMethod("GetRight", &Nz::Node::GetRight);
|
||||
//nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
||||
node.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
||||
//nodeClass.SetMethod("GetTransformMatrix", &Nz::Node::GetTransformMatrix);
|
||||
node.BindMethod("GetUp", &Nz::Node::GetUp);
|
||||
|
||||
node.BindMethod("HasChilds", &Nz::Node::HasChilds);
|
||||
|
||||
node.BindMethod("GetBackward", &Nz::Node::GetBackward);
|
||||
node.BindMethod("GetDown", &Nz::Node::GetDown);
|
||||
node.BindMethod("GetForward", &Nz::Node::GetForward);
|
||||
node.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
||||
node.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
||||
node.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
||||
node.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
||||
node.BindMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
||||
node.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
||||
node.BindMethod("GetLeft", &Nz::Node::GetLeft);
|
||||
node.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
|
||||
node.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
||||
node.BindMethod("GetRight", &Nz::Node::GetRight);
|
||||
node.BindMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
||||
node.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
||||
node.BindMethod("GetUp", &Nz::Node::GetUp);
|
||||
|
||||
node.BindMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition);
|
||||
node.BindMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation);
|
||||
|
||||
node.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local);
|
||||
node.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local);
|
||||
|
||||
node.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
|
||||
Nz::Vector3f offset = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
instance.Move(offset, coordSys);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
node.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
|
||||
Nz::Quaternionf rotation = lua.Check<Nz::Quaternionf>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
instance.Rotate(rotation, coordSys);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
node.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
instance.Scale(lua.Check<float>(&argIndex));
|
||||
else
|
||||
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 3:
|
||||
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method Scale");
|
||||
return 0;
|
||||
});
|
||||
|
||||
node.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
{
|
||||
float scale = lua.Check<float>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
instance.SetScale(scale, coordSys);
|
||||
}
|
||||
else
|
||||
instance.SetScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 3:
|
||||
case 4:
|
||||
{
|
||||
Nz::Vector3f scale = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
|
||||
instance.SetScale(scale, coordSys);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetScale");
|
||||
return 0;
|
||||
});
|
||||
|
||||
node.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||
|
||||
int argIndex = 2;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
instance.SetInitialScale(lua.Check<float>(&argIndex));
|
||||
else
|
||||
instance.SetInitialScale(lua.Check<Nz::Vector2f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
instance.SetInitialScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetInitialScale");
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the Utility classes
|
||||
*/
|
||||
|
||||
void LuaBinding::RegisterUtility(Nz::LuaInstance& instance)
|
||||
{
|
||||
abstractImage.Register(instance);
|
||||
font.Register(instance);
|
||||
keyboard.Register(instance);
|
||||
node.Register(instance);
|
||||
|
||||
keyboard.PushGlobalTable(instance);
|
||||
{
|
||||
instance.PushField("Undefined", Nz::Keyboard::Undefined);
|
||||
|
||||
// A-Z
|
||||
for (std::size_t i = 0; i < 26; ++i)
|
||||
instance.PushField(Nz::String('A' + char(i)), Nz::Keyboard::A + i);
|
||||
|
||||
// Numerical
|
||||
for (std::size_t i = 0; i < 10; ++i)
|
||||
{
|
||||
instance.PushField("Num" + Nz::String::Number(i), Nz::Keyboard::Num0 + i);
|
||||
instance.PushField("Numpad" + Nz::String::Number(i), Nz::Keyboard::Numpad0 + i);
|
||||
}
|
||||
|
||||
// F1-F15
|
||||
for (std::size_t i = 0; i < 15; ++i)
|
||||
instance.PushField('F' + Nz::String::Number(i+1), Nz::Keyboard::F1 + i);
|
||||
|
||||
// And all the others...
|
||||
instance.PushField("Down", Nz::Keyboard::Down);
|
||||
instance.PushField("Left", Nz::Keyboard::Left);
|
||||
instance.PushField("Right", Nz::Keyboard::Right);
|
||||
instance.PushField("Up", Nz::Keyboard::Up);
|
||||
|
||||
instance.PushField("Add", Nz::Keyboard::Add);
|
||||
instance.PushField("Decimal", Nz::Keyboard::Decimal);
|
||||
instance.PushField("Divide", Nz::Keyboard::Divide);
|
||||
instance.PushField("Multiply", Nz::Keyboard::Multiply);
|
||||
instance.PushField("Subtract", Nz::Keyboard::Subtract);
|
||||
|
||||
instance.PushField("Backslash", Nz::Keyboard::Backslash);
|
||||
instance.PushField("Backspace", Nz::Keyboard::Backspace);
|
||||
instance.PushField("Clear", Nz::Keyboard::Clear);
|
||||
instance.PushField("Comma", Nz::Keyboard::Comma);
|
||||
instance.PushField("Dash", Nz::Keyboard::Dash);
|
||||
instance.PushField("Delete", Nz::Keyboard::Delete);
|
||||
instance.PushField("End", Nz::Keyboard::End);
|
||||
instance.PushField("Equal", Nz::Keyboard::Equal);
|
||||
instance.PushField("Escape", Nz::Keyboard::Escape);
|
||||
instance.PushField("Home", Nz::Keyboard::Home);
|
||||
instance.PushField("Insert", Nz::Keyboard::Insert);
|
||||
instance.PushField("LAlt", Nz::Keyboard::LAlt);
|
||||
instance.PushField("LBracket", Nz::Keyboard::LBracket);
|
||||
instance.PushField("LControl", Nz::Keyboard::LControl);
|
||||
instance.PushField("LShift", Nz::Keyboard::LShift);
|
||||
instance.PushField("LSystem", Nz::Keyboard::LSystem);
|
||||
instance.PushField("PageDown", Nz::Keyboard::PageDown);
|
||||
instance.PushField("PageUp", Nz::Keyboard::PageUp);
|
||||
instance.PushField("Pause", Nz::Keyboard::Pause);
|
||||
instance.PushField("Period", Nz::Keyboard::Period);
|
||||
instance.PushField("Print", Nz::Keyboard::Print);
|
||||
instance.PushField("PrintScreen", Nz::Keyboard::PrintScreen);
|
||||
instance.PushField("Quote", Nz::Keyboard::Quote);
|
||||
instance.PushField("RAlt", Nz::Keyboard::RAlt);
|
||||
instance.PushField("RBracket", Nz::Keyboard::RBracket);
|
||||
instance.PushField("RControl", Nz::Keyboard::RControl);
|
||||
instance.PushField("Return", Nz::Keyboard::Return);
|
||||
instance.PushField("RShift", Nz::Keyboard::RShift);
|
||||
instance.PushField("RSystem", Nz::Keyboard::RSystem);
|
||||
instance.PushField("Semicolon", Nz::Keyboard::Semicolon);
|
||||
instance.PushField("Slash", Nz::Keyboard::Slash);
|
||||
instance.PushField("Space", Nz::Keyboard::Space);
|
||||
instance.PushField("Tab", Nz::Keyboard::Tab);
|
||||
instance.PushField("Tilde", Nz::Keyboard::Tilde);
|
||||
instance.PushField("Browser_Back", Nz::Keyboard::Browser_Back);
|
||||
instance.PushField("Browser_Favorites", Nz::Keyboard::Browser_Favorites);
|
||||
instance.PushField("Browser_Forward", Nz::Keyboard::Browser_Forward);
|
||||
instance.PushField("Browser_Home", Nz::Keyboard::Browser_Home);
|
||||
instance.PushField("Browser_Refresh", Nz::Keyboard::Browser_Refresh);
|
||||
instance.PushField("Browser_Search", Nz::Keyboard::Browser_Search);
|
||||
instance.PushField("Browser_Stop", Nz::Keyboard::Browser_Stop);
|
||||
instance.PushField("Media_Next", Nz::Keyboard::Media_Next);
|
||||
instance.PushField("Media_Play", Nz::Keyboard::Media_Play);
|
||||
instance.PushField("Media_Previous", Nz::Keyboard::Media_Previous);
|
||||
instance.PushField("Media_Stop", Nz::Keyboard::Media_Stop);
|
||||
instance.PushField("Volume_Down", Nz::Keyboard::Volume_Down);
|
||||
instance.PushField("Volume_Mute", Nz::Keyboard::Volume_Mute);
|
||||
instance.PushField("Volume_Up", Nz::Keyboard::Volume_Up);
|
||||
instance.PushField("CapsLock", Nz::Keyboard::CapsLock);
|
||||
instance.PushField("NumLock", Nz::Keyboard::NumLock);
|
||||
instance.PushField("ScrollLock", Nz::Keyboard::ScrollLock);
|
||||
}
|
||||
instance.Pop();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user