Lua/LuaInstance: Add PushInstance
Former-commit-id: 0e65124d5920a1b5ea3c644e496ae58ddee1cd8e
This commit is contained in:
parent
83bd028e8f
commit
2c79e5f4e0
|
|
@ -15,15 +15,6 @@ namespace Nz
|
||||||
{
|
{
|
||||||
m_info->name = name;
|
m_info->name = name;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
template<class T>
|
|
||||||
void LuaClass<T>::Inherit(LuaClass<P>& parent)
|
|
||||||
{
|
|
||||||
static_assert(std::is_base_of<P, T>::value, "P must be a base of T");
|
|
||||||
|
|
||||||
m_info->parentInfo = parent.m_info;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
template<class P>
|
template<class P>
|
||||||
|
|
@ -288,10 +279,7 @@ namespace Nz
|
||||||
return 0; // Normalement jamais exécuté (l'erreur provoquant une exception)
|
return 0; // Normalement jamais exécuté (l'erreur provoquant une exception)
|
||||||
}
|
}
|
||||||
|
|
||||||
T** ud = static_cast<T**>(lua.PushUserdata(sizeof(T*)));
|
lua.PushInstance(info->name.GetConstBuffer(), instance);
|
||||||
*ud = instance;
|
|
||||||
lua.SetMetatable(info->name);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,8 @@ namespace Nz
|
||||||
void PushCFunction(LuaCFunction func, unsigned int upvalueCount = 0);
|
void PushCFunction(LuaCFunction func, unsigned int upvalueCount = 0);
|
||||||
void PushFunction(LuaFunction func);
|
void PushFunction(LuaFunction func);
|
||||||
template<typename R, typename... Args, typename... DefArgs> void PushFunction(R(*func)(Args...), DefArgs... defArgs);
|
template<typename R, typename... Args, typename... DefArgs> void PushFunction(R(*func)(Args...), DefArgs... defArgs);
|
||||||
|
template<typename T> void PushInstance(const char* tname, T* instance);
|
||||||
|
template<typename T, typename... Args> void PushInstance(const char* tname, Args&&... args);
|
||||||
void PushInteger(long long value);
|
void PushInteger(long long value);
|
||||||
void PushLightUserdata(void* value);
|
void PushLightUserdata(void* value);
|
||||||
void PushMetatable(const char* str);
|
void PushMetatable(const char* str);
|
||||||
|
|
|
||||||
|
|
@ -404,4 +404,18 @@ namespace Nz
|
||||||
return handler.Invoke(func);
|
return handler.Invoke(func);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void LuaInstance::PushInstance(const char* tname, T* instance)
|
||||||
|
{
|
||||||
|
T** userdata = static_cast<T**>(PushUserdata(sizeof(T*)));
|
||||||
|
*userdata = instance;
|
||||||
|
SetMetatable(tname);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, typename... Args>
|
||||||
|
void LuaInstance::PushInstance(const char* tname, Args&&... args)
|
||||||
|
{
|
||||||
|
PushInstance(tname, new T(std::forward<Args>(args)...));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue