Lua/LuaClass: Reference the destructor only if the class has one
Allows to bind classes with deleted destructors
This commit is contained in:
@@ -66,6 +66,9 @@ namespace Nz
|
|||||||
void SetStaticSetter(StaticIndexFunc getter);
|
void SetStaticSetter(StaticIndexFunc getter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
template<typename T, bool HasDestructor>
|
||||||
|
friend struct LuaClassImplFinalizerSetupProxy;
|
||||||
|
|
||||||
void PushClassInfo(LuaInstance& lua);
|
void PushClassInfo(LuaInstance& lua);
|
||||||
void SetupConstructor(LuaInstance& lua);
|
void SetupConstructor(LuaInstance& lua);
|
||||||
void SetupDefaultToString(LuaInstance& lua);
|
void SetupDefaultToString(LuaInstance& lua);
|
||||||
@@ -75,7 +78,7 @@ namespace Nz
|
|||||||
void SetupMetatable(LuaInstance& lua);
|
void SetupMetatable(LuaInstance& lua);
|
||||||
void SetupMethod(LuaInstance& lua, LuaCFunction proxy, const String& name, std::size_t methodIndex);
|
void SetupMethod(LuaInstance& lua, LuaCFunction proxy, const String& name, std::size_t methodIndex);
|
||||||
void SetupSetter(LuaInstance& lua, LuaCFunction proxy);
|
void SetupSetter(LuaInstance& lua, LuaCFunction proxy);
|
||||||
|
|
||||||
using ParentFunc = std::function<void(LuaInstance& lua, T* instance)>;
|
using ParentFunc = std::function<void(LuaInstance& lua, T* instance)>;
|
||||||
using InstanceGetter = std::function<T*(LuaInstance& lua)>;
|
using InstanceGetter = std::function<T*(LuaInstance& lua)>;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// This file is part of the "Nazara Engine - Lua scripting module"
|
// This file is part of the "Nazara Engine - Lua scripting module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Lua/LuaClass.hpp>
|
||||||
#include <Nazara/Core/Error.hpp>
|
#include <Nazara/Core/Error.hpp>
|
||||||
#include <Nazara/Core/MemoryHelper.hpp>
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -251,9 +252,7 @@ namespace Nz
|
|||||||
template<class T>
|
template<class T>
|
||||||
void LuaClass<T>::SetupFinalizer(LuaInstance& lua)
|
void LuaClass<T>::SetupFinalizer(LuaInstance& lua)
|
||||||
{
|
{
|
||||||
lua.PushValue(1); // ClassInfo
|
LuaClassImplFinalizerSetupProxy<T, std::is_destructible<T>::value>::Setup(lua);
|
||||||
lua.PushCFunction(FinalizerProxy, 1);
|
|
||||||
lua.SetField("__gc");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@@ -353,6 +352,7 @@ namespace Nz
|
|||||||
lua.SetField("__newindex"); // Setter
|
lua.SetField("__newindex"); // Setter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
int LuaClass<T>::ConstructorProxy(lua_State* state)
|
int LuaClass<T>::ConstructorProxy(lua_State* state)
|
||||||
{
|
{
|
||||||
@@ -566,7 +566,28 @@ namespace Nz
|
|||||||
lua.PushString(info->name);
|
lua.PushString(info->name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, bool HasDestructor>
|
||||||
|
struct LuaClassImplFinalizerSetupProxy;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct LuaClassImplFinalizerSetupProxy<T, true>
|
||||||
|
{
|
||||||
|
static void Setup(LuaInstance& lua)
|
||||||
|
{
|
||||||
|
lua.PushValue(1); // ClassInfo
|
||||||
|
lua.PushCFunction(LuaClass<T>::FinalizerProxy, 1);
|
||||||
|
lua.SetField("__gc");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct LuaClassImplFinalizerSetupProxy<T, false>
|
||||||
|
{
|
||||||
|
static void Setup(LuaInstance&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Lua/DebugOff.hpp>
|
#include <Nazara/Lua/DebugOff.hpp>
|
||||||
#include "LuaClass.hpp"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user