Sdk/API: Begin Lua Binding

Former-commit-id: b9be6bf7748296c3afc6fe1f32a1fd3fad6af008
This commit is contained in:
Lynix
2016-01-20 14:08:43 +01:00
parent d0ff07d262
commit 3898421f2f
5 changed files with 641 additions and 0 deletions

View 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_LUAINTERFACE_HPP
#define NDK_LUAINTERFACE_HPP
#include <NDK/Prerequesites.hpp>
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 <NDK/LuaAPI.inl>
#endif // NDK_LUAINTERFACE_HPP

View 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
#include <Nazara/Audio/SoundBuffer.hpp>
#include <Nazara/Lua/LuaInstance.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <algorithm>
namespace Nz
{
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, SoundBufferParams* params, TypeTag<SoundBufferParams>)
{
instance.CheckType(index, Nz::LuaType_Table);
params->forceMono = instance.CheckField<bool>("ForceMono", params->forceMono);
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& lua, int index, Vector3d* vec, TypeTag<Vector3d>)
{
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<double>("x", index), lua.CheckField<double>("y", index), lua.CheckField<double>("z", index));
return 3;
default:
vec->Set(*(*static_cast<Vector3d**>(lua.CheckUserdata(index, "Vector3"))));
return 1;
}
}
inline unsigned int LuaImplQueryArg(const LuaInstance& lua, int index, Vector3f* vec, TypeTag<Vector3f>)
{
Vector3d vecDouble;
unsigned int ret = LuaImplQueryArg(lua, index, &vecDouble, TypeTag<Vector3d>());
vec->Set(vecDouble);
return ret;
}
inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag<const SoundBuffer*>)
{
instance.PushInstance<SoundBufferConstRef>("SoundBuffer", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3d val, TypeTag<Vector3d>)
{
instance.PushInstance<Vector3d>("Vector3", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3f val, TypeTag<Vector3f>)
{
instance.PushInstance<Vector3d>("Vector3", val);
return 1;
}
}