Lua/LuaInstance: Optimize the T& method(...) case
Instead of instancing a new T from Lua, the original userdata is now returned
This commit is contained in:
parent
1d7e1b46ff
commit
9206cf65b5
|
|
@ -412,6 +412,19 @@ namespace Nz
|
||||||
return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag<decltype(Apply(object, func, m_args))>());
|
return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag<decltype(Apply(object, func, m_args))>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, typename P>
|
||||||
|
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaInstance& instance, T& object, T&(P::*func)(Args...)) const
|
||||||
|
{
|
||||||
|
T& r = Apply(object, func, m_args);
|
||||||
|
if (&r == &object)
|
||||||
|
{
|
||||||
|
instance.PushValue(1); //< Userdata
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return LuaImplReplyVal(instance, r, TypeTag<T&>());
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, typename P>
|
template<typename T, typename P>
|
||||||
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaInstance& instance, const T& object, void(P::*func)(Args...) const) const
|
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaInstance& instance, const T& object, void(P::*func)(Args...) const) const
|
||||||
{
|
{
|
||||||
|
|
@ -427,11 +440,22 @@ namespace Nz
|
||||||
return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag<decltype(Apply(object, func, m_args))>());
|
return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag<decltype(Apply(object, func, m_args))>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, typename P>
|
||||||
|
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaInstance& instance, const T& object, const T&(P::*func)(Args...) const) const
|
||||||
|
{
|
||||||
|
const T& r = Apply(object, func, m_args);
|
||||||
|
if (&r == &object)
|
||||||
|
{
|
||||||
|
instance.PushValue(1); //< Userdata
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return LuaImplReplyVal(instance, r, TypeTag<T&>());
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, typename P>
|
template<typename T, typename P>
|
||||||
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, T& object, void(P::*func)(Args...)) const
|
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, T& object, void(P::*func)(Args...)) const
|
||||||
{
|
{
|
||||||
NazaraUnused(instance);
|
|
||||||
|
|
||||||
if (!object)
|
if (!object)
|
||||||
{
|
{
|
||||||
instance.Error("Invalid object");
|
instance.Error("Invalid object");
|
||||||
|
|
@ -454,11 +478,28 @@ namespace Nz
|
||||||
return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag<decltype(Apply(*object, func, m_args))>());
|
return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag<decltype(Apply(*object, func, m_args))>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, typename P>
|
||||||
|
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, T& object, typename PointedType<T>::type&(P::*func)(Args...) const) const
|
||||||
|
{
|
||||||
|
if (!object)
|
||||||
|
{
|
||||||
|
instance.Error("Invalid object");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const typename PointedType<T>::type& r = Apply(*object, func, m_args);
|
||||||
|
if (&r == &*object)
|
||||||
|
{
|
||||||
|
instance.PushValue(1); //< Userdata
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return LuaImplReplyVal(instance, r, TypeTag<T&>());
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, typename P>
|
template<typename T, typename P>
|
||||||
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, const T& object, void(P::*func)(Args...) const) const
|
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, const T& object, void(P::*func)(Args...) const) const
|
||||||
{
|
{
|
||||||
NazaraUnused(instance);
|
|
||||||
|
|
||||||
if (!object)
|
if (!object)
|
||||||
{
|
{
|
||||||
instance.Error("Invalid object");
|
instance.Error("Invalid object");
|
||||||
|
|
@ -481,6 +522,25 @@ namespace Nz
|
||||||
return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag<decltype(Apply(*object, func, m_args))>());
|
return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag<decltype(Apply(*object, func, m_args))>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, typename P>
|
||||||
|
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, const T& object, const typename PointedType<T>::type&(P::*func)(Args...) const) const
|
||||||
|
{
|
||||||
|
if (!object)
|
||||||
|
{
|
||||||
|
instance.Error("Invalid object");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const typename PointedType<T>::type& r = Apply(*object, func, m_args);
|
||||||
|
if (&r == &*object)
|
||||||
|
{
|
||||||
|
instance.PushValue(1); //< Userdata
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return LuaImplReplyVal(instance, r, TypeTag<T&>());
|
||||||
|
}
|
||||||
|
|
||||||
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