Lua/LuaInstance: Add PushInstance

Former-commit-id: 0e65124d5920a1b5ea3c644e496ae58ddee1cd8e
This commit is contained in:
Lynix
2015-12-13 04:40:50 +01:00
parent 83bd028e8f
commit 2c79e5f4e0
3 changed files with 17 additions and 13 deletions

View File

@@ -404,4 +404,18 @@ namespace Nz
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)...));
}
}