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