light/modules/ecs/public/components/native_script.hpp

29 lines
485 B
C++
Raw Normal View History

2025-07-05 13:28:41 +03:30
#pragma once
2025-07-11 01:16:52 +03:30
#include <ecs/components/scriptable_entity.hpp>
2025-07-05 13:28:41 +03:30
2025-07-11 00:05:48 +03:30
namespace lt {
2025-07-05 13:28:41 +03:30
struct NativeScriptComponent
{
NativeScript *(*CreateInstance)();
2025-07-05 16:07:51 +03:30
2025-07-05 13:28:41 +03:30
void (*DestroyInstance)(NativeScriptComponent *);
template<typename t>
void bind()
2025-07-05 13:28:41 +03:30
{
CreateInstance = []() {
return static_cast<NativeScript *>(new t());
2025-07-05 13:28:41 +03:30
};
DestroyInstance = [](NativeScriptComponent *nsc) {
delete (t *)(nsc->instance);
2025-07-05 13:28:41 +03:30
nsc->instance = nullptr;
};
}
2025-07-05 16:07:51 +03:30
NativeScript *instance;
2025-07-05 13:28:41 +03:30
};
2025-07-11 00:05:48 +03:30
} // namespace lt