Optimize Lua binding

Optimize binding by removing a useless extra indirection and allowing to
move replying variables


Former-commit-id: 76728df1c3ab9a38a4304ae2b9f2fc6a000e0ebb
This commit is contained in:
Lynix
2016-04-24 19:54:46 +02:00
parent 6d66063b2c
commit 24a8fcee01
11 changed files with 190 additions and 107 deletions

View File

@@ -1,6 +1,7 @@
// 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
@@ -10,10 +11,7 @@ namespace Ndk
/*********************************** Nz::Music **********************************/
musicClass.Inherit(soundEmitter);
musicClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Music*
{
return new Nz::Music;
});
musicClass.BindDefaultConstructor();
//musicClass.SetMethod("Create", &Nz::Music::Create);
//musicClass.SetMethod("Destroy", &Nz::Music::Destroy);
@@ -51,10 +49,7 @@ namespace Ndk
/*********************************** Nz::Sound **********************************/
soundClass.Inherit(soundEmitter);
soundClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Sound*
{
return new Nz::Sound;
});
soundClass.BindDefaultConstructor();
soundClass.BindMethod("GetBuffer", &Nz::Sound::GetBuffer);
@@ -79,9 +74,10 @@ namespace Ndk
});
/*********************************** Nz::SoundBuffer **********************************/
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::SoundBufferRef*
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua, Nz::SoundBufferRef* instance)
{
return new Nz::SoundBufferRef(new Nz::SoundBuffer);
Nz::PlacementNew(instance, Nz::SoundBuffer::New());
return true;
});
soundBuffer.BindMethod("Destroy", &Nz::SoundBuffer::Destroy);

View File

@@ -1,6 +1,7 @@
// 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
@@ -8,10 +9,14 @@ namespace Ndk
void LuaBinding::BindCore()
{
/*********************************** Nz::Clock **********************************/
clockClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Clock*
clockClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* clock)
{
int argIndex = 1;
return new Nz::Clock(lua.Check<Nz::Int64>(&argIndex, 0), lua.Check<bool>(&argIndex, false));
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
bool paused = lua.Check<bool>(&argIndex, false);
Nz::PlacementNew(clock, startingValue, paused);
return true;
});
clockClass.BindMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds);
@@ -35,7 +40,7 @@ namespace Ndk
});
/********************************* Nz::Directory ********************************/
directoryClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Directory*
directoryClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Directory* directory)
{
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
@@ -43,13 +48,15 @@ namespace Ndk
switch (argCount)
{
case 0:
return new Nz::Directory;
Nz::PlacementNew(directory);
return true;
case 1:
return new Nz::Directory(lua.Check<Nz::String>(&argIndex));
Nz::PlacementNew(directory, lua.Check<Nz::String>(&argIndex));
return true;
}
return nullptr;
return false;
});
directoryClass.BindMethod("Close", &Nz::Directory::Close);
@@ -127,7 +134,7 @@ namespace Ndk
/*********************************** Nz::File ***********************************/
fileClass.Inherit(streamClass);
fileClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::File*
fileClass.SetConstructor([](Nz::LuaInstance& lua, Nz::File* file)
{
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
@@ -135,20 +142,29 @@ namespace Ndk
switch (argCount)
{
case 0:
return new Nz::File;
Nz::PlacementNew(file);
return true;
case 1:
return new Nz::File(lua.Check<Nz::String>(&argIndex));
{
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
Nz::PlacementNew(file, filePath);
return true;
}
case 2:
{
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&argIndex);
return new Nz::File(filePath, openMode);
Nz::PlacementNew(file, filePath, openMode);
return true;
}
}
return nullptr;
lua.Error("No matching overload for File constructor");
return false;
});
fileClass.BindMethod("Close", &Nz::File::Close);

View File

@@ -16,9 +16,10 @@ namespace Ndk
return reinterpret_cast<Nz::InstancedRenderableRef*>(model); //TODO: Make a ObjectRefCast
});
modelClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::ModelRef*
modelClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::ModelRef* model)
{
return new Nz::ModelRef(new Nz::Model);
Nz::PlacementNew(model, Nz::Model::New());
return true;
});
//modelClass.SetMethod("GetMaterial", &Nz::Model::GetMaterial);

View File

@@ -1,6 +1,7 @@
// 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>
@@ -9,23 +10,26 @@ namespace Ndk
void LuaBinding::BindMath()
{
/*********************************** Nz::EulerAngles **********************************/
eulerAnglesClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::EulerAnglesd*
eulerAnglesClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* angles)
{
unsigned int argCount = std::min(lua.GetStackTop(), 3U);
switch (argCount)
{
case 0:
return new Nz::EulerAnglesd(0.0, 0.0, 0.0);
Nz::PlacementNew(angles, Nz::EulerAnglesd::Zero());
return true;
case 1:
return new Nz::EulerAnglesd(*(*static_cast<Nz::EulerAnglesd**>(lua.CheckUserdata(1, "EulerAngles"))));
Nz::PlacementNew(angles, *static_cast<Nz::EulerAnglesd*>(lua.CheckUserdata(1, "EulerAngles")));
return true;
case 3:
return new Nz::EulerAnglesd(lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3));
Nz::PlacementNew(angles, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3));
return true;
}
lua.Error("No matching overload for EulerAngles constructor");
return nullptr;
return false;
});
eulerAnglesClass.BindMethod("__tostring", &Nz::EulerAnglesd::ToString);
@@ -146,31 +150,38 @@ namespace Ndk
});
/*********************************** Nz::Quaternion **********************************/
quaternionClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Quaterniond*
quaternionClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* quaternion)
{
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
switch (argCount)
{
case 0:
return new Nz::Quaterniond(1.0, 0.0, 0.0, 0.0);
Nz::PlacementNew(quaternion, Nz::Quaterniond::Zero());
return true;
case 1:
{
if (lua.IsOfType(1, "EulerAngles"))
return new Nz::Quaterniond(*(*static_cast<Nz::EulerAnglesd**>(lua.ToUserdata(1))));
Nz::PlacementNew(quaternion, *static_cast<Nz::EulerAnglesd*>(lua.ToUserdata(1)));
else if (lua.IsOfType(1, "Quaternion"))
return new Nz::Quaterniond(*(*static_cast<Nz::Quaterniond**>(lua.ToUserdata(1))));
Nz::PlacementNew(quaternion, *static_cast<Nz::Quaterniond*>(lua.ToUserdata(1)));
else
break;
return true;
}
case 2:
return new Nz::Quaterniond(lua.CheckNumber(1), *(*static_cast<Nz::Vector3d**>(lua.CheckUserdata(2, "Vector3"))));
Nz::PlacementNew(quaternion, lua.CheckNumber(1), *(*static_cast<Nz::Vector3d**>(lua.CheckUserdata(2, "Vector3"))));
return true;
case 4:
return new Nz::Quaterniond(lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4));
Nz::PlacementNew(quaternion, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4));
return true;
}
lua.Error("No matching overload for Quaternion constructor");
return nullptr;
return false;
});
quaternionClass.BindMethod("__tostring", &Nz::Quaterniond::ToString);
@@ -238,28 +249,31 @@ namespace Ndk
});
/*********************************** Nz::Vector2 **********************************/
vector2dClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Vector2d*
vector2dClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Vector2d* vector)
{
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
switch (argCount)
{
case 0:
case 2:
return new Nz::Vector2d(lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0));
Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0));
return true;
case 1:
{
if (lua.IsOfType(1, Nz::LuaType_Number))
return new Nz::Vector2d(lua.CheckNumber(1));
Nz::PlacementNew(vector, lua.CheckNumber(1));
else if (lua.IsOfType(1, "Vector2"))
return new Nz::Vector2d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
else
break;
break;
return true;
}
}
lua.Error("No matching overload for Vector2 constructor");
return nullptr;
return false;
});
vector2dClass.BindMethod("__tostring", &Nz::Vector2d::ToString);
@@ -345,40 +359,44 @@ namespace Ndk
});
/*********************************** Nz::Vector3 **********************************/
vector3dClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Vector3d*
vector3dClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector)
{
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));
Nz::PlacementNew(vector, 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<Nz::Vector2d**>(lua.ToUserdata(1))));
Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
else if (lua.IsOfType(1, "Vector2"))
return new Nz::Vector3d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
else if (lua.IsOfType(1, "Vector3"))
return new Nz::Vector3d(*(*static_cast<Nz::Vector3d**>(lua.ToUserdata(1))));
Nz::PlacementNew(vector, *static_cast<Nz::Vector3d*>(lua.ToUserdata(1)));
else
break;
break;
return true;
}
case 2:
{
if (lua.IsOfType(1, Nz::LuaType_Number))
return new Nz::Vector3d(lua.CheckNumber(1), *(*static_cast<Nz::Vector2d**>(lua.CheckUserdata(1, "Vector2"))));
Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.CheckUserdata(1, "Vector2")));
else if (lua.IsOfType(1, "Vector2"))
return new Nz::Vector3d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))), lua.CheckNumber(2));
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)), lua.CheckNumber(2));
else
break;
break;
return true;
}
}
lua.Error("No matching overload for constructor");
return nullptr;
return false;
});
vector3dClass.BindMethod("__tostring", &Nz::Vector3d::ToString);

View File

@@ -17,7 +17,7 @@ namespace Ndk
abstractSocketClass.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes);
/*********************************** Nz::IpAddress **********************************/
ipAddressClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::IpAddress*
ipAddressClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* address)
{
unsigned int argCount = std::min(lua.GetStackTop(), 9U);
@@ -25,30 +25,54 @@ namespace Ndk
switch (argCount)
{
case 0:
return new Nz::IpAddress;
Nz::PlacementNew(address);
return true;
case 1:
return new Nz::IpAddress(lua.CheckString(argIndex));
Nz::PlacementNew(address, lua.CheckString(argIndex));
return true;
case 4:
case 5:
return new Nz::IpAddress(lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt16>(&argIndex, 0));
{
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(address, a, b, c, d, port);
return true;
}
case 8:
case 9:
return new Nz::IpAddress(lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex),
lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex, 0));
{
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(address, a, b, c, d, e, f, g, h, port);
return true;
}
}
return nullptr;
lua.Error("No matching overload for constructor");
return false;
});
ipAddressClass.BindMethod("GetPort", &Nz::IpAddress::GetPort);
ipAddressClass.BindMethod("GetPort", &Nz::IpAddress::GetPort);
ipAddressClass.BindMethod("GetProtocol", &Nz::IpAddress::GetProtocol);
ipAddressClass.BindMethod("IsLoopback", &Nz::IpAddress::IsLoopback);
ipAddressClass.BindMethod("IsValid", &Nz::IpAddress::IsValid);
ipAddressClass.BindMethod("ToUInt32", &Nz::IpAddress::ToUInt32);
ipAddressClass.BindMethod("__tostring", &Nz::IpAddress::ToString);
ipAddressClass.BindMethod("IsLoopback", &Nz::IpAddress::IsLoopback);
ipAddressClass.BindMethod("IsValid", &Nz::IpAddress::IsValid);
ipAddressClass.BindMethod("ToUInt32", &Nz::IpAddress::ToUInt32);
ipAddressClass.BindMethod("__tostring", &Nz::IpAddress::ToString);
ipAddressClass.BindStaticMethod("ResolveAddress", [] (Nz::LuaInstance& instance) -> int
{
@@ -79,7 +103,7 @@ namespace Ndk
int argIndex = 1;
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");
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)

View File

@@ -89,9 +89,10 @@ namespace Ndk
});
/*********************************** Nz::Font **********************************/
fontClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::FontRef*
fontClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::FontRef* font)
{
return new Nz::FontRef(new Nz::Font);
Nz::PlacementNew(font, Nz::Font::New());
return true;
});
fontClass.BindMethod("ClearGlyphCache", &Nz::Font::ClearGlyphCache);