Lua/LuaClass: Fix argument count via GetStackTop (Close #75)

Former-commit-id: 3a0e60a6e7ec7c85ff5f179cc84a468d8c0682f4 [formerly f0712658e69c7ced1fa46f8878f96776d6b36567] [formerly 3035b072473d17863c3c0f6950451ccf582c107e [formerly fe3cbf8a2cf87cf6cc3d3e8577011159bff04387]]
Former-commit-id: df8812d712d28efc2bc83258df53dcb21bbb4b2d [formerly 6d2d8773c96d406690bd5cfc19cef7d1706ff6fc]
Former-commit-id: 461fec0cc2dd99690a3de10436730514712beb73
This commit is contained in:
Lynix
2016-10-03 19:49:43 +02:00
parent 30e07ea2e2
commit d7b7135e27
8 changed files with 41 additions and 25 deletions

View File

@@ -78,9 +78,10 @@ namespace Ndk
});
/*********************************** Nz::SoundBuffer **********************************/
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua, Nz::SoundBufferRef* instance)
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua, Nz::SoundBufferRef* instance, std::size_t argumentCount)
{
NazaraUnused(lua);
NazaraUnused(argumentCount);
Nz::PlacementNew(instance, Nz::SoundBuffer::New());
return true;

View File

@@ -13,7 +13,7 @@ namespace Ndk
void LuaBinding::BindCore()
{
/*********************************** Nz::Clock **********************************/
clockClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* clock)
clockClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* clock, std::size_t argumentCount)
{
int argIndex = 1;
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
@@ -44,9 +44,9 @@ namespace Ndk
});
/********************************* Nz::Directory ********************************/
directoryClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Directory* directory)
directoryClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Directory* directory, std::size_t argumentCount)
{
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
int argIndex = 1;
switch (argCount)
@@ -138,9 +138,9 @@ namespace Ndk
/*********************************** Nz::File ***********************************/
fileClass.Inherit(streamClass);
fileClass.SetConstructor([](Nz::LuaInstance& lua, Nz::File* file)
fileClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* file, std::size_t argumentCount)
{
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
int argIndex = 1;
switch (argCount)

View File

@@ -20,8 +20,10 @@ namespace Ndk
return reinterpret_cast<Nz::InstancedRenderableRef*>(model); //TODO: Make a ObjectRefCast
});
modelClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::ModelRef* model)
modelClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::ModelRef* model, std::size_t argumentCount)
{
NazaraUnused(argumentCount);
Nz::PlacementNew(model, Nz::Model::New());
return true;
});

View File

@@ -14,9 +14,10 @@ namespace Ndk
void LuaBinding::BindMath()
{
/*********************************** Nz::EulerAngles **********************************/
eulerAnglesClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* angles)
eulerAnglesClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* angles, std::size_t argumentCount)
{
unsigned int argCount = std::min(lua.GetStackTop(), 3U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
switch (argCount)
{
case 0:
@@ -154,9 +155,10 @@ namespace Ndk
});
/*********************************** Nz::Rect **********************************/
rectClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* rect)
rectClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* rect, std::size_t argumentCount)
{
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
switch (argCount)
{
case 0:
@@ -309,9 +311,10 @@ namespace Ndk
});
/*********************************** Nz::Quaternion **********************************/
quaternionClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* quaternion)
quaternionClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* quaternion, std::size_t argumentCount)
{
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
switch (argCount)
{
case 0:
@@ -337,6 +340,9 @@ namespace Ndk
case 4:
Nz::PlacementNew(quaternion, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4));
return true;
default:
break;
}
lua.Error("No matching overload for Quaternion constructor");
@@ -411,9 +417,10 @@ namespace Ndk
});
/*********************************** Nz::Vector2 **********************************/
vector2dClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Vector2d* vector)
vector2dClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector2d* vector, std::size_t argumentCount)
{
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
switch (argCount)
{
case 0:
@@ -533,9 +540,10 @@ namespace Ndk
});
/*********************************** Nz::Vector3 **********************************/
vector3dClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector)
vector3dClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector, std::size_t argumentCount)
{
unsigned int argCount = std::min(lua.GetStackTop(), 3U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
switch (argCount)
{
case 0:
@@ -546,7 +554,7 @@ namespace Ndk
case 1:
{
if (lua.IsOfType(1, Nz::LuaType_Number))
Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.CheckUserdata(1, "Vector2")));
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"))
@@ -560,7 +568,7 @@ namespace Ndk
case 2:
{
if (lua.IsOfType(1, Nz::LuaType_Number))
Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.CheckUserdata(1, "Vector2")));
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

View File

@@ -21,9 +21,9 @@ namespace Ndk
abstractSocketClass.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes);
/*********************************** Nz::IpAddress **********************************/
ipAddressClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* address)
ipAddressClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* address, std::size_t argumentCount)
{
unsigned int argCount = std::min(lua.GetStackTop(), 9U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 9U);
int argIndex = 1;
switch (argCount)

View File

@@ -93,8 +93,10 @@ namespace Ndk
});
/*********************************** Nz::Font **********************************/
fontClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::FontRef* font)
fontClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::FontRef* font, std::size_t argumentCount)
{
NazaraUnused(argumentCount);
Nz::PlacementNew(font, Nz::Font::New());
return true;
});