|
|
@ -61,8 +61,7 @@ namespace Inferno { |
|
|
|
struct NativeScriptComponent { |
|
|
|
struct NativeScriptComponent { |
|
|
|
NativeScript* instance = nullptr; |
|
|
|
NativeScript* instance = nullptr; |
|
|
|
|
|
|
|
|
|
|
|
std::function<void()> initialize = nullptr; |
|
|
|
NativeScript* (*initialize)(); |
|
|
|
std::function<void()> destroy = nullptr; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Dont allow manually setting instance during construction
|
|
|
|
// Dont allow manually setting instance during construction
|
|
|
|
NativeScriptComponent() {} |
|
|
|
NativeScriptComponent() {} |
|
|
@ -70,9 +69,14 @@ namespace Inferno { |
|
|
|
template<typename T> |
|
|
|
template<typename T> |
|
|
|
void bind() |
|
|
|
void bind() |
|
|
|
{ |
|
|
|
{ |
|
|
|
ASSERT(initialize == nullptr && destroy == nullptr, "NativeScript already bound"); |
|
|
|
ASSERT(instance == nullptr, "NativeScript already bound"); |
|
|
|
initialize = [&]() { instance = static_cast<NativeScript*>(new T()); }; |
|
|
|
initialize = []() { return static_cast<NativeScript*>(new T()); }; |
|
|
|
destroy = [&]() { delete instance; instance = nullptr; initialize = nullptr; destroy = nullptr; }; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void destroy() { |
|
|
|
|
|
|
|
ASSERT(instance, "Attempting to destroy an uninitialized NativeScript"); |
|
|
|
|
|
|
|
delete instance; |
|
|
|
|
|
|
|
instance = nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|