Lua/LuaClass: Add pointer objects support
Former-commit-id: b4cf6fb6674278ed341a27d2a8e432845531a333
This commit is contained in:
parent
2c79e5f4e0
commit
4c72e27784
|
|
@ -25,6 +25,12 @@ namespace Nz
|
||||||
template<typename T> ByteArray ComputeHash(AbstractHash* hash, const T& v);
|
template<typename T> ByteArray ComputeHash(AbstractHash* hash, const T& v);
|
||||||
template<typename T> void HashCombine(std::size_t& seed, const T& v);
|
template<typename T> void HashCombine(std::size_t& seed, const T& v);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct PointedType
|
||||||
|
{
|
||||||
|
using type = void; //< FIXME: I can't make SFINAE work
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct TypeTag {};
|
struct TypeTag {};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,11 @@ namespace Nz
|
||||||
seed = static_cast<std::size_t>(b * kMul);
|
seed = static_cast<std::size_t>(b * kMul);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T> struct PointedType<T*> {typedef T type;};
|
||||||
|
template<typename T> struct PointedType<T* const> {typedef T type;};
|
||||||
|
template<typename T> struct PointedType<T* volatile> {typedef T type;};
|
||||||
|
template<typename T> struct PointedType<T* const volatile> {typedef T type;};
|
||||||
|
|
||||||
inline bool Serialize(SerializationContext& context, bool value)
|
inline bool Serialize(SerializationContext& context, bool value)
|
||||||
{
|
{
|
||||||
if (context.currentBitPos == 8)
|
if (context.currentBitPos == 8)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#define NAZARA_RESOURCEREF_HPP
|
#define NAZARA_RESOURCEREF_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/Algorithm.hpp>
|
||||||
#include <Nazara/Core/RefCounted.hpp>
|
#include <Nazara/Core/RefCounted.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
|
@ -44,6 +45,9 @@ namespace Nz
|
||||||
private:
|
private:
|
||||||
T* m_object;
|
T* m_object;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T> struct PointedType<ObjectRef<T>> {typedef T type;};
|
||||||
|
template<typename T> struct PointedType<ObjectRef<T> const> {typedef T type;};
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Core/ObjectRef.inl>
|
#include <Nazara/Core/ObjectRef.inl>
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#define NAZARA_LUACLASS_HPP
|
#define NAZARA_LUACLASS_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/Algorithm.hpp>
|
||||||
#include <Nazara/Core/String.hpp>
|
#include <Nazara/Core/String.hpp>
|
||||||
#include <Nazara/Lua/LuaInstance.hpp>
|
#include <Nazara/Lua/LuaInstance.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
@ -47,6 +48,8 @@ namespace Nz
|
||||||
void SetMethod(const String& name, ClassFunc method);
|
void SetMethod(const String& name, ClassFunc method);
|
||||||
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, T>::value> SetMethod(const String& name, R(P::*func)(Args...), DefArgs... defArgs);
|
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, T>::value> SetMethod(const String& name, R(P::*func)(Args...), DefArgs... defArgs);
|
||||||
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, T>::value> SetMethod(const String& name, R(P::*func)(Args...) const, DefArgs... defArgs);
|
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, T>::value> SetMethod(const String& name, R(P::*func)(Args...) const, DefArgs... defArgs);
|
||||||
|
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> SetMethod(const String& name, R(P::*func)(Args...), DefArgs... defArgs);
|
||||||
|
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> SetMethod(const String& name, R(P::*func)(Args...) const, DefArgs... defArgs);
|
||||||
void SetSetter(ClassIndexFunc setter);
|
void SetSetter(ClassIndexFunc setter);
|
||||||
void SetStaticGetter(StaticIndexFunc getter);
|
void SetStaticGetter(StaticIndexFunc getter);
|
||||||
void SetStaticMethod(const String& name, StaticFunc func);
|
void SetStaticMethod(const String& name, StaticFunc func);
|
||||||
|
|
@ -63,12 +66,12 @@ namespace Nz
|
||||||
std::vector<ParentFunc> parentGetters;
|
std::vector<ParentFunc> parentGetters;
|
||||||
std::vector<StaticFunc> staticMethods;
|
std::vector<StaticFunc> staticMethods;
|
||||||
std::unordered_map<String, InstanceGetter> instanceGetters;
|
std::unordered_map<String, InstanceGetter> instanceGetters;
|
||||||
ClassIndexFunc getter = nullptr;
|
ClassIndexFunc getter;
|
||||||
ClassIndexFunc setter = nullptr;
|
ClassIndexFunc setter;
|
||||||
ConstructorFunc constructor = nullptr;
|
ConstructorFunc constructor;
|
||||||
FinalizerFunc finalizer = nullptr;
|
FinalizerFunc finalizer;
|
||||||
StaticIndexFunc staticGetter = nullptr;
|
StaticIndexFunc staticGetter;
|
||||||
StaticIndexFunc staticSetter = nullptr;
|
StaticIndexFunc staticSetter;
|
||||||
String name;
|
String name;
|
||||||
int globalTableRef = -1;
|
int globalTableRef = -1;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -225,6 +225,32 @@ namespace Nz
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
template<typename R, typename P, typename... Args, typename... DefArgs>
|
||||||
|
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> LuaClass<T>::SetMethod(const String& name, R(P::*func)(Args...), DefArgs... defArgs)
|
||||||
|
{
|
||||||
|
SetMethod(name, [func, defArgs...](LuaInstance& instance, T& object) -> int
|
||||||
|
{
|
||||||
|
typename LuaImplMethodProxy<T, Args...>::template Impl<DefArgs...> handler(instance, object, defArgs...);
|
||||||
|
handler.ProcessArgs();
|
||||||
|
|
||||||
|
return handler.Invoke(func);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
template<typename R, typename P, typename... Args, typename... DefArgs>
|
||||||
|
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> LuaClass<T>::SetMethod(const String& name, R(P::*func)(Args...) const, DefArgs... defArgs)
|
||||||
|
{
|
||||||
|
SetMethod(name, [func, defArgs...](LuaInstance& instance, T& object) -> int
|
||||||
|
{
|
||||||
|
typename LuaImplMethodProxy<T, Args...>::template Impl<DefArgs...> handler(instance, object, defArgs...);
|
||||||
|
handler.ProcessArgs();
|
||||||
|
|
||||||
|
return handler.Invoke(func);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void LuaClass<T>::SetSetter(ClassIndexFunc setter)
|
void LuaClass<T>::SetSetter(ClassIndexFunc setter)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -344,6 +344,32 @@ namespace Nz
|
||||||
return LuaImplReplyVal(m_instance, std::move(Apply(m_object, func, m_args)), TypeTag<decltype(Apply(m_object, func, m_args))>());
|
return LuaImplReplyVal(m_instance, std::move(Apply(m_object, func, m_args)), TypeTag<decltype(Apply(m_object, func, m_args))>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename P>
|
||||||
|
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(void(P::*func)(Args...))
|
||||||
|
{
|
||||||
|
Apply(*m_object, func, m_args);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename P, typename Ret>
|
||||||
|
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(Ret(P::*func)(Args...))
|
||||||
|
{
|
||||||
|
return LuaImplReplyVal(m_instance, std::move(Apply(*m_object, func, m_args)), TypeTag<decltype(Apply(*m_object, func, m_args))>());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename P>
|
||||||
|
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(void(P::*func)(Args...) const)
|
||||||
|
{
|
||||||
|
Apply(*m_object, func, m_args);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename P, typename Ret>
|
||||||
|
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(Ret(P::*func)(Args...) const)
|
||||||
|
{
|
||||||
|
return LuaImplReplyVal(m_instance, std::move(Apply(*m_object, func, m_args)), TypeTag<decltype(Apply(*m_object, func, m_args))>());
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using ArgContainer = std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...>;
|
using ArgContainer = std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...>;
|
||||||
using DefArgContainer = std::tuple<std::remove_cv_t<std::remove_reference_t<DefArgs>>...>;
|
using DefArgContainer = std::tuple<std::remove_cv_t<std::remove_reference_t<DefArgs>>...>;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue