Lua/LuaInstance: Fix crash with invalid objects

Former-commit-id: 398ce80f268308489637c237245dae0ec40366b9
This commit is contained in:
Lynix 2016-03-30 18:05:28 +02:00
parent a8303d8d24
commit bf288e7f06
1 changed files with 24 additions and 0 deletions

View File

@ -329,6 +329,12 @@ namespace Nz
{
NazaraUnused(instance);
if (!object)
{
instance.Error("Invalid object");
return 0;
}
Apply(*object, func, m_args);
return 0;
}
@ -336,6 +342,12 @@ namespace Nz
template<typename T, typename P, typename Ret>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, T& object, Ret(P::*func)(Args...)) const
{
if (!object)
{
instance.Error("Invalid object");
return 0;
}
return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag<decltype(Apply(*object, func, m_args))>());
}
@ -344,6 +356,12 @@ namespace Nz
{
NazaraUnused(instance);
if (!object)
{
instance.Error("Invalid object");
return 0;
}
Apply(*object, func, m_args);
return 0;
}
@ -351,6 +369,12 @@ namespace Nz
template<typename T, typename P, typename Ret>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, const T& object, Ret(P::*func)(Args...) const) const
{
if (!object)
{
instance.Error("Invalid object");
return 0;
}
return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag<decltype(Apply(*object, func, m_args))>());
}