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:
parent
30e07ea2e2
commit
d7b7135e27
|
|
@ -78,9 +78,10 @@ namespace Ndk
|
||||||
});
|
});
|
||||||
|
|
||||||
/*********************************** Nz::SoundBuffer **********************************/
|
/*********************************** 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(lua);
|
||||||
|
NazaraUnused(argumentCount);
|
||||||
|
|
||||||
Nz::PlacementNew(instance, Nz::SoundBuffer::New());
|
Nz::PlacementNew(instance, Nz::SoundBuffer::New());
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace Ndk
|
||||||
void LuaBinding::BindCore()
|
void LuaBinding::BindCore()
|
||||||
{
|
{
|
||||||
/*********************************** Nz::Clock **********************************/
|
/*********************************** 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;
|
int argIndex = 1;
|
||||||
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
||||||
|
|
@ -44,9 +44,9 @@ namespace Ndk
|
||||||
});
|
});
|
||||||
|
|
||||||
/********************************* Nz::Directory ********************************/
|
/********************************* 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;
|
int argIndex = 1;
|
||||||
switch (argCount)
|
switch (argCount)
|
||||||
|
|
@ -138,9 +138,9 @@ namespace Ndk
|
||||||
/*********************************** Nz::File ***********************************/
|
/*********************************** Nz::File ***********************************/
|
||||||
fileClass.Inherit(streamClass);
|
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;
|
int argIndex = 1;
|
||||||
switch (argCount)
|
switch (argCount)
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,10 @@ namespace Ndk
|
||||||
return reinterpret_cast<Nz::InstancedRenderableRef*>(model); //TODO: Make a ObjectRefCast
|
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());
|
Nz::PlacementNew(model, Nz::Model::New());
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,10 @@ namespace Ndk
|
||||||
void LuaBinding::BindMath()
|
void LuaBinding::BindMath()
|
||||||
{
|
{
|
||||||
/*********************************** Nz::EulerAngles **********************************/
|
/*********************************** 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)
|
switch (argCount)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
|
@ -154,9 +155,10 @@ namespace Ndk
|
||||||
});
|
});
|
||||||
|
|
||||||
/*********************************** Nz::Rect **********************************/
|
/*********************************** 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)
|
switch (argCount)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
|
@ -309,9 +311,10 @@ namespace Ndk
|
||||||
});
|
});
|
||||||
|
|
||||||
/*********************************** Nz::Quaternion **********************************/
|
/*********************************** 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)
|
switch (argCount)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
|
@ -337,6 +340,9 @@ namespace Ndk
|
||||||
case 4:
|
case 4:
|
||||||
Nz::PlacementNew(quaternion, 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;
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua.Error("No matching overload for Quaternion constructor");
|
lua.Error("No matching overload for Quaternion constructor");
|
||||||
|
|
@ -411,9 +417,10 @@ namespace Ndk
|
||||||
});
|
});
|
||||||
|
|
||||||
/*********************************** Nz::Vector2 **********************************/
|
/*********************************** 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)
|
switch (argCount)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
|
@ -533,9 +540,10 @@ namespace Ndk
|
||||||
});
|
});
|
||||||
|
|
||||||
/*********************************** Nz::Vector3 **********************************/
|
/*********************************** 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)
|
switch (argCount)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
|
@ -546,7 +554,7 @@ namespace Ndk
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
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"))
|
else if (lua.IsOfType(1, "Vector2"))
|
||||||
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
|
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
|
||||||
else if (lua.IsOfType(1, "Vector3"))
|
else if (lua.IsOfType(1, "Vector3"))
|
||||||
|
|
@ -560,7 +568,7 @@ namespace Ndk
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
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"))
|
else if (lua.IsOfType(1, "Vector2"))
|
||||||
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)), lua.CheckNumber(2));
|
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)), lua.CheckNumber(2));
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@ namespace Ndk
|
||||||
abstractSocketClass.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes);
|
abstractSocketClass.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes);
|
||||||
|
|
||||||
/*********************************** Nz::IpAddress **********************************/
|
/*********************************** 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;
|
int argIndex = 1;
|
||||||
switch (argCount)
|
switch (argCount)
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,10 @@ namespace Ndk
|
||||||
});
|
});
|
||||||
|
|
||||||
/*********************************** Nz::Font **********************************/
|
/*********************************** 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());
|
Nz::PlacementNew(font, Nz::Font::New());
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Nz
|
||||||
public:
|
public:
|
||||||
using ClassFunc = std::function<int(LuaInstance& lua, T& instance)>;
|
using ClassFunc = std::function<int(LuaInstance& lua, T& instance)>;
|
||||||
using ClassIndexFunc = std::function<bool(LuaInstance& lua, T& instance)>;
|
using ClassIndexFunc = std::function<bool(LuaInstance& lua, T& instance)>;
|
||||||
using ConstructorFunc = std::function<bool(LuaInstance& lua, T* instance)>;
|
using ConstructorFunc = std::function<bool(LuaInstance& lua, T* instance, std::size_t argumentCount)>;
|
||||||
template<typename P> using ConvertToParent = std::function<P*(T*)>;
|
template<typename P> using ConvertToParent = std::function<P*(T*)>;
|
||||||
using FinalizerFunc = std::function<bool(LuaInstance& lua, T& instance)>;
|
using FinalizerFunc = std::function<bool(LuaInstance& lua, T& instance)>;
|
||||||
using StaticIndexFunc = std::function<bool(LuaInstance& lua)>;
|
using StaticIndexFunc = std::function<bool(LuaInstance& lua)>;
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,10 @@ namespace Nz
|
||||||
template<class T>
|
template<class T>
|
||||||
inline void LuaClass<T>::BindDefaultConstructor()
|
inline void LuaClass<T>::BindDefaultConstructor()
|
||||||
{
|
{
|
||||||
SetConstructor([] (Nz::LuaInstance& lua, T* instance)
|
SetConstructor([] (Nz::LuaInstance& lua, T* instance, std::size_t argumentCount)
|
||||||
{
|
{
|
||||||
NazaraUnused(lua);
|
NazaraUnused(lua);
|
||||||
|
NazaraUnused(argumentCount);
|
||||||
|
|
||||||
PlacementNew(instance);
|
PlacementNew(instance);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -334,9 +335,11 @@ namespace Nz
|
||||||
|
|
||||||
lua.Remove(1); // On enlève l'argument "table" du stack
|
lua.Remove(1); // On enlève l'argument "table" du stack
|
||||||
|
|
||||||
|
std::size_t argCount = lua.GetStackTop();
|
||||||
|
|
||||||
T* instance = static_cast<T*>(lua.PushUserdata(sizeof(T)));
|
T* instance = static_cast<T*>(lua.PushUserdata(sizeof(T)));
|
||||||
|
|
||||||
if (!constructor(lua, instance))
|
if (!constructor(lua, instance, argCount))
|
||||||
{
|
{
|
||||||
lua.Error("Constructor failed");
|
lua.Error("Constructor failed");
|
||||||
return 0; // Normalement jamais exécuté (l'erreur provoquant une exception)
|
return 0; // Normalement jamais exécuté (l'erreur provoquant une exception)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue