From d0ff07d2624a2c216900284da9ba8643e1dc9106 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 20 Jan 2016 14:08:03 +0100 Subject: [PATCH 1/2] Build/SdkServer: Fix Console.cpp being included in the project Former-commit-id: 62d706654c398a60946282e112d7e139107ac745 --- build/scripts/tools/ndk_server.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build/scripts/tools/ndk_server.lua b/build/scripts/tools/ndk_server.lua index c94170dce..cbae533d6 100644 --- a/build/scripts/tools/ndk_server.lua +++ b/build/scripts/tools/ndk_server.lua @@ -23,12 +23,14 @@ TOOL.Files = { -- Exlude client-only files TOOL.FilesExclusion = { "../SDK/**/CameraComponent.*", + "../SDK/**/Console.*", "../SDK/**/GraphicsComponent.*", "../SDK/**/LightComponent.*", "../SDK/**/ListenerComponent.*", "../SDK/**/ListenerSystem.*", "../SDK/**/RenderSystem.*", - "../SDK/**/LuaInterface_Audio.*" + "../SDK/**/LuaAPI_Audio.*", + "../SDK/**/LuaAPI_Graphics.*", } TOOL.Libraries = { From 3898421f2fb82cee8bfd1781162d6cd1c6d83fb7 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 20 Jan 2016 14:08:43 +0100 Subject: [PATCH 2/2] Sdk/API: Begin Lua Binding Former-commit-id: b9be6bf7748296c3afc6fe1f32a1fd3fad6af008 --- SDK/include/NDK/LuaAPI.hpp | 33 +++++ SDK/include/NDK/LuaAPI.inl | 68 +++++++++ SDK/src/NDK/LuaAPI_Audio.cpp | 125 ++++++++++++++++ SDK/src/NDK/LuaAPI_Core.cpp | 280 +++++++++++++++++++++++++++++++++++ SDK/src/NDK/LuaAPI_Math.cpp | 135 +++++++++++++++++ 5 files changed, 641 insertions(+) create mode 100644 SDK/include/NDK/LuaAPI.hpp create mode 100644 SDK/include/NDK/LuaAPI.inl create mode 100644 SDK/src/NDK/LuaAPI_Audio.cpp create mode 100644 SDK/src/NDK/LuaAPI_Core.cpp create mode 100644 SDK/src/NDK/LuaAPI_Math.cpp diff --git a/SDK/include/NDK/LuaAPI.hpp b/SDK/include/NDK/LuaAPI.hpp new file mode 100644 index 000000000..f248e28e8 --- /dev/null +++ b/SDK/include/NDK/LuaAPI.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Development Kit" +// For conditions of distribution and use, see copyright notice in Prerequesites.hpp + +#pragma once + +#ifndef NDK_LUAINTERFACE_HPP +#define NDK_LUAINTERFACE_HPP + +#include + +namespace Nz +{ + class LuaInstance; +} + +namespace Ndk +{ + class NDK_API LuaAPI + { + public: + LuaAPI() = delete; + ~LuaAPI() = delete; + + static void Register_Audio(Nz::LuaInstance& instance); + static void Register_Core(Nz::LuaInstance& instance); + static void Register_Math(Nz::LuaInstance& instance); + }; +} + +#include + +#endif // NDK_LUAINTERFACE_HPP diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl new file mode 100644 index 000000000..205f29440 --- /dev/null +++ b/SDK/include/NDK/LuaAPI.inl @@ -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 + +#include +#include +#include +#include + +namespace Nz +{ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, SoundBufferParams* params, TypeTag) + { + instance.CheckType(index, Nz::LuaType_Table); + + params->forceMono = instance.CheckField("ForceMono", params->forceMono); + + return 1; + } + + inline unsigned int LuaImplQueryArg(const LuaInstance& lua, int index, Vector3d* vec, TypeTag) + { + switch (lua.GetType(index)) + { + case Nz::LuaType_Number: + if (index < 0 && index > -3) + lua.Error("Vector3 expected, three numbers are required to convert it"); + + vec->Set(lua.CheckNumber(index), lua.CheckNumber(index + 1), lua.CheckNumber(index + 2)); + return 3; + + case Nz::LuaType_Table: + vec->Set(lua.CheckField("x", index), lua.CheckField("y", index), lua.CheckField("z", index)); + return 3; + + default: + vec->Set(*(*static_cast(lua.CheckUserdata(index, "Vector3")))); + return 1; + } + } + + inline unsigned int LuaImplQueryArg(const LuaInstance& lua, int index, Vector3f* vec, TypeTag) + { + Vector3d vecDouble; + unsigned int ret = LuaImplQueryArg(lua, index, &vecDouble, TypeTag()); + + vec->Set(vecDouble); + return ret; + } + + inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag) + { + instance.PushInstance("SoundBuffer", val); + return 1; + } + + inline int LuaImplReplyVal(const LuaInstance& instance, Vector3d val, TypeTag) + { + instance.PushInstance("Vector3", val); + return 1; + } + + inline int LuaImplReplyVal(const LuaInstance& instance, Vector3f val, TypeTag) + { + instance.PushInstance("Vector3", val); + return 1; + } +} diff --git a/SDK/src/NDK/LuaAPI_Audio.cpp b/SDK/src/NDK/LuaAPI_Audio.cpp new file mode 100644 index 000000000..07bb9bdec --- /dev/null +++ b/SDK/src/NDK/LuaAPI_Audio.cpp @@ -0,0 +1,125 @@ +// This file was automatically generated on 26 May 2014 at 01:05:31 + +#include +#include +#include + +namespace Ndk +{ + void LuaAPI::Register_Audio(Nz::LuaInstance& instance) + { + /*********************************** Nz::SoundBuffer **********************************/ + Nz::LuaClass soundBuffer("SoundBuffer"); + + soundBuffer.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::SoundBufferRef* { + return new Nz::SoundBufferRef(new Nz::SoundBuffer); + }); + + soundBuffer.SetMethod("Destroy", &Nz::SoundBuffer::Destroy); + soundBuffer.SetMethod("GetDuration", &Nz::SoundBuffer::GetDuration); + soundBuffer.SetMethod("GetFormat", &Nz::SoundBuffer::GetFormat); + soundBuffer.SetMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount); + soundBuffer.SetMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate); + soundBuffer.SetMethod("IsValid", &Nz::SoundBuffer::IsValid); + soundBuffer.SetMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams()); + + soundBuffer.SetStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported); + + // Manual + soundBuffer.SetMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int + { + int index = 1; + Nz::AudioFormat format = lua.Check(&index); + unsigned int sampleCount = lua.Check(&index); + unsigned int sampleRate = lua.Check(&index); + + std::size_t bufferSize = 0; + const char* buffer = lua.CheckString(index, &bufferSize); + NazaraAssert(buffer && bufferSize < sampleCount * sizeof(Nz::Int16), "Invalid buffer"); + + lua.PushBoolean(instance->Create(format, sampleCount, sampleRate, reinterpret_cast(buffer))); + return 1; + }); + + soundBuffer.SetMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int + { + lua.PushString(reinterpret_cast(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16)); + return 1; + }); + + soundBuffer.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& soundBuffer) -> int { + Nz::StringStream stream("SoundBuffer("); + if (soundBuffer->IsValid()) + { + Nz::String filePath = soundBuffer->GetFilePath(); + if (!filePath.IsEmpty()) + stream << "File: " << filePath << ", "; + + stream << "Duration: " << soundBuffer->GetDuration() / 1000.f << "s"; + } + stream << ')'; + + lua.PushString(stream); + return 1; + }); + + soundBuffer.Register(instance); + + /*********************************** Nz::SoundEmitter **********************************/ + Nz::LuaClass soundEmitter("SoundEmitter"); + + soundEmitter.SetMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping); + soundEmitter.SetMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization); + soundEmitter.SetMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation); + soundEmitter.SetMethod("GetDuration", &Nz::SoundEmitter::GetDuration); + soundEmitter.SetMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance); + soundEmitter.SetMethod("GetPitch", &Nz::SoundEmitter::GetPitch); + soundEmitter.SetMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset); + soundEmitter.SetMethod("GetPosition", &Nz::Sound::GetPosition); + soundEmitter.SetMethod("GetStatus", &Nz::SoundEmitter::GetStatus); + soundEmitter.SetMethod("GetVelocity", &Nz::Sound::GetVelocity); + soundEmitter.SetMethod("GetVolume", &Nz::SoundEmitter::GetVolume); + soundEmitter.SetMethod("IsLooping", &Nz::SoundEmitter::IsLooping); + soundEmitter.SetMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized); + soundEmitter.SetMethod("Pause", &Nz::SoundEmitter::Pause); + soundEmitter.SetMethod("Play", &Nz::SoundEmitter::Play); + soundEmitter.SetMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation); + soundEmitter.SetMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance); + soundEmitter.SetMethod("SetPitch", &Nz::SoundEmitter::SetPitch); + soundEmitter.SetMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition); + soundEmitter.SetMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity); + soundEmitter.SetMethod("SetVolume", &Nz::SoundEmitter::SetVolume); + soundEmitter.SetMethod("Stop", &Nz::SoundEmitter::Stop); + + soundEmitter.Register(instance); + + /*********************************** Nz::Sound **********************************/ + Nz::LuaClass soundClass("Sound"); + soundClass.Inherit(soundEmitter); + + // Constructeur + soundClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Sound* { + return new Nz::Sound; + }); + + soundClass.SetMethod("GetBuffer", &Nz::Sound::GetBuffer); + soundClass.SetMethod("IsPlayable", &Nz::Sound::IsPlayable); + soundClass.SetMethod("IsPlaying", &Nz::Sound::IsPlaying); + soundClass.SetMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams()); + soundClass.SetMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset); + + // Nz::Clock::__tostring (Manual) + soundClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int { + Nz::StringStream stream("Sound("); + if (const Nz::SoundBuffer* buffer = sound.GetBuffer()) + stream << buffer; + + stream << ')'; + + lua.PushString(stream); + return 1; + }); + + soundClass.Register(instance); + } +} diff --git a/SDK/src/NDK/LuaAPI_Core.cpp b/SDK/src/NDK/LuaAPI_Core.cpp new file mode 100644 index 000000000..8e626494a --- /dev/null +++ b/SDK/src/NDK/LuaAPI_Core.cpp @@ -0,0 +1,280 @@ +// This file was automatically generated on 26 May 2014 at 01:05:31 + +#include +#include +#include + +namespace Ndk +{ + void LuaAPI::Register_Core(Nz::LuaInstance& instance) + { + /*********************************** Nz::Clock **********************************/ + Nz::LuaClass clockClass("Clock"); + + // Constructeur + clockClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Clock* { + int index = 1; + return new Nz::Clock(lua.Check(&index, 0), lua.Check(&index, false)); + }); + + clockClass.SetMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds); + clockClass.SetMethod("GetMilliseconds", &Nz::Clock::GetMilliseconds); + clockClass.SetMethod("GetSeconds", &Nz::Clock::GetSeconds); + clockClass.SetMethod("IsPaused", &Nz::Clock::IsPaused); + clockClass.SetMethod("Pause", &Nz::Clock::Pause); + clockClass.SetMethod("Restart", &Nz::Clock::Restart); + clockClass.SetMethod("Unpause", &Nz::Clock::Unpause); + + // Nz::Clock::__tostring (Manual) + clockClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock) -> int { + Nz::StringStream stream("Clock(Elapsed: "); + stream << clock.GetSeconds(); + stream << ", Paused: "; + stream << clock.IsPaused(); + stream << ')'; + + lua.PushString(stream); + return 1; + }); + + + clockClass.Register(instance); + + /********************************* Nz::Directory ********************************/ + Nz::LuaClass directoryClass("Directory"); + + // Constructeur + directoryClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Directory* { + unsigned int argCount = std::min(lua.GetStackTop(), 1U); + switch (argCount) + { + case 0: + { + return new Nz::Directory; + } + + case 1: + { + int index = 1; + return new Nz::Directory(lua.Check(&index)); + } + } + + return nullptr; + }); + + directoryClass.SetMethod("Close", &Nz::Directory::Close); + directoryClass.SetMethod("Exists", &Nz::Directory::Exists); + directoryClass.SetMethod("GetPath", &Nz::Directory::GetPath); + directoryClass.SetMethod("GetPattern", &Nz::Directory::GetPattern); + directoryClass.SetMethod("GetResultName", &Nz::Directory::GetResultName); + directoryClass.SetMethod("GetResultPath", &Nz::Directory::GetResultPath); + directoryClass.SetMethod("GetResultSize", &Nz::Directory::GetResultSize); + directoryClass.SetMethod("IsOpen", &Nz::Directory::IsOpen); + directoryClass.SetMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory); + directoryClass.SetMethod("NextResult", &Nz::Directory::NextResult, true); + directoryClass.SetMethod("Open", &Nz::Directory::Open); + directoryClass.SetMethod("SetPath", &Nz::Directory::SetPath); + directoryClass.SetMethod("SetPattern", &Nz::Directory::SetPattern); + + directoryClass.SetStaticMethod("Copy", Nz::Directory::Copy); + directoryClass.SetStaticMethod("Create", Nz::Directory::Create); + directoryClass.SetStaticMethod("Exists", Nz::Directory::Exists); + directoryClass.SetStaticMethod("GetCurrent", Nz::Directory::GetCurrent); + directoryClass.SetStaticMethod("Remove", Nz::Directory::Remove); + directoryClass.SetStaticMethod("SetCurrent", Nz::Directory::SetCurrent); + + // Nz::Directory::__tostring (Manual) + directoryClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory) -> int { + Nz::StringStream stream("Directory("); + stream << directory.GetPath(); + stream << ')'; + + lua.PushString(stream); + return 1; + }); + + + directoryClass.Register(instance); + + /*********************************** Nz::File ***********************************/ + Nz::LuaClass fileClass("File"); + + // Constructeur + fileClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::File* { + unsigned int argCount = std::min(lua.GetStackTop(), 2U); + switch (argCount) + { + case 0: + { + return new Nz::File; + } + + case 1: + { + Nz::String filePath(lua.CheckString(1)); + + return new Nz::File(filePath); + } + + case 2: + { + Nz::String filePath(lua.CheckString(1)); + unsigned long openMode(lua.CheckInteger(2)); + + return new Nz::File(filePath, openMode); + } + } + + return nullptr; + }); + + fileClass.SetMethod("Close", &Nz::File::Close); + fileClass.SetMethod("Copy", &Nz::File::Copy); + fileClass.SetMethod("Delete", &Nz::File::Delete); + fileClass.SetMethod("EndOfFile", &Nz::File::EndOfFile); + fileClass.SetMethod("Exists", &Nz::File::Exists); + fileClass.SetMethod("GetCreationTime", &Nz::File::GetCreationTime); + fileClass.SetMethod("GetFileName", &Nz::File::GetFileName); + fileClass.SetMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime); + fileClass.SetMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); + fileClass.SetMethod("IsOpen", &Nz::File::IsOpen); + fileClass.SetMethod("Rename", &Nz::File::GetLastWriteTime); + fileClass.SetMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); + fileClass.SetMethod("SetFile", &Nz::File::GetLastWriteTime); + + fileClass.SetMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { + unsigned int argCount = std::min(lua.GetStackTop(), 2U); + switch (argCount) + { + case 0: + { + bool _ret = file.Open(); + + lua.PushBoolean(_ret); + return 1; + } + + case 1: + { + if (lua.IsOfType(1, Nz::LuaType_Number)) + { + unsigned long openMode(lua.ToInteger(1)); + + bool _ret = file.Open(openMode); + + lua.PushBoolean(_ret); + return 1; + } + else if (lua.IsOfType(1, Nz::LuaType_String)) + { + Nz::String filePath(lua.ToString(1)); + + bool _ret = file.Open(filePath); + + lua.PushBoolean(_ret); + return 1; + } + } + + case 2: + { + Nz::String filePath(lua.CheckString(1)); + unsigned long openMode(lua.CheckInteger(2)); + + bool _ret = file.Open(filePath, openMode); + + lua.PushBoolean(_ret); + return 1; + } + } + + lua.Error("No matching overload for method Open"); + return 0; + }); + + fileClass.SetMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { + unsigned int argCount = std::min(lua.GetStackTop(), 2U); + switch (argCount) + { + case 1: + { + Nz::UInt64 offset(lua.CheckInteger(1)); + + bool _ret = file.SetCursorPos(offset); + + lua.PushBoolean(_ret); + return 1; + } + + case 2: + { + Nz::CursorPosition pos(static_cast(lua.CheckInteger(1))); + Nz::Int64 offset(lua.CheckInteger(2)); + + bool _ret = file.SetCursorPos(pos, offset); + + lua.PushBoolean(_ret); + return 1; + } + } + + lua.Error("No matching overload for method SetCursorPos"); + return 0; + }); + + // Nz::File::Read (Manual) + fileClass.SetMethod("Read", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { + int length = lua.CheckInteger(1); + lua.ArgCheck(length > 0, 1, "length must be positive"); + + std::unique_ptr buffer(new char[length]); + std::size_t readLength = file.Read(buffer.get(), length); + + lua.PushString(Nz::String(buffer.get(), readLength)); + return 1; + }); + + // Nz::File::ReadLine (Manual) + fileClass.SetMethod("ReadLine", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { + int length = lua.CheckInteger(1, 0); + lua.PushString(file.ReadLine(length)); + return 1; + }); + + // Nz::File::__tostring (Manual) + fileClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { + Nz::StringStream stream("File("); + if (file.IsOpen()) + stream << "Path: " << file.GetPath(); + + stream << ')'; + + lua.PushString(stream); + return 1; + }); + + + fileClass.Register(instance); + + // Énumérations de la classe Nz::File + fileClass.PushGlobalTable(instance); + + // Nz::File::CursorPosition + instance.SetField("AtBegin", Nz::CursorPosition_AtBegin); + instance.SetField("AtCurrent", Nz::CursorPosition_AtCurrent); + instance.SetField("AtEnd", Nz::CursorPosition_AtEnd); + + // Nz::File::OpenMode + instance.SetField("Append", Nz::OpenMode_Append); + instance.SetField("NotOpen", Nz::OpenMode_NotOpen); + instance.SetField("Lock", Nz::OpenMode_Lock); + instance.SetField("ReadOnly", Nz::OpenMode_ReadOnly); + instance.SetField("ReadWrite", Nz::OpenMode_ReadWrite); + instance.SetField("Text", Nz::OpenMode_Text); + instance.SetField("Truncate", Nz::OpenMode_Truncate); + instance.SetField("WriteOnly", Nz::OpenMode_WriteOnly); + + instance.Pop(); + } +} diff --git a/SDK/src/NDK/LuaAPI_Math.cpp b/SDK/src/NDK/LuaAPI_Math.cpp new file mode 100644 index 000000000..de6b35b22 --- /dev/null +++ b/SDK/src/NDK/LuaAPI_Math.cpp @@ -0,0 +1,135 @@ +// This file was automatically generated on 26 May 2014 at 01:05:31 + +#include +#include +#include + +namespace Ndk +{ + void LuaAPI::Register_Math(Nz::LuaInstance& instance) + { + /*********************************** Nz::Vector3 **********************************/ + Nz::LuaClass vectorClass("Vector3"); + + vectorClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Vector3d* { + unsigned int argCount = std::min(lua.GetStackTop(), 3U); + switch (argCount) + { + case 0: + case 3: + return new Nz::Vector3d(lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0)); + + case 1: + { + if (lua.IsOfType(1, Nz::LuaType_Number)) + return new Nz::Vector3d(lua.CheckNumber(1), *static_cast(lua.ToUserdata(1))); + else if (lua.IsOfType(1, "Vector2")) + return new Nz::Vector3d(*(*static_cast(lua.ToUserdata(1)))); + else if (lua.IsOfType(1, "Vector3")) + return new Nz::Vector3d(*(*static_cast(lua.ToUserdata(1)))); + + break; + } + + case 2: + { + if (lua.IsOfType(1, Nz::LuaType_Number)) + return new Nz::Vector3d(lua.CheckNumber(1), *static_cast(lua.CheckUserdata(1, "Vector2"))); + else if (lua.IsOfType(1, "Vector2")) + return new Nz::Vector3d(*(*static_cast(lua.ToUserdata(1))), lua.CheckNumber(2)); + + break; + } + } + + lua.Error("No matching overload for constructor"); + return nullptr; + }); + + vectorClass.SetMethod("__tostring", &Nz::Vector3d::ToString); + + vectorClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) + { + switch (lua.GetType(1)) + { + case Nz::LuaType_Number: + lua.Push(instance[lua.CheckInteger(1)]); + return true; + + case Nz::LuaType_String: + { + std::size_t length; + const char* xyz = lua.CheckString(1, &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; + } + break; + } + } + + return false; + }); + + vectorClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) + { + switch (lua.GetType(1)) + { + case Nz::LuaType_Number: + { + long long index = lua.CheckInteger(1); + if (index < 1 || index > 3) + return false; + + instance[index] = lua.CheckNumber(2); + return true; + } + + case Nz::LuaType_String: + { + std::size_t length; + const char* xyz = lua.CheckString(1, &length); + + if (length != 1) + break; + + double value = lua.CheckNumber(2); + + switch (xyz[0]) + { + case 'x': + instance.x = value; + return true; + + case 'y': + instance.y = value; + return true; + + case 'z': + instance.z = value; + return true; + } + break; + } + } + + return false; + }); + + vectorClass.Register(instance); + } +}