forked from phisko/kengine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuaSystem.hpp
More file actions
43 lines (35 loc) · 1.19 KB
/
Copy pathLuaSystem.hpp
File metadata and controls
43 lines (35 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include "ScriptSystem.hpp"
#include "data/LuaStateComponent.hpp"
#include "lua/plua.hpp"
#include "EntityCreator.hpp"
namespace kengine {
EntityCreatorFunctor<64> LuaSystem(EntityManager & em);
namespace lua {
template<typename Func>
void registerEntityMember(sol::state & state, const char * name, Func && func) {
state[putils::reflection::get_class_name<Entity>()][name] = FWD(func);
}
template<typename T>
void registerTypeWithState(sol::state & state) {
putils::lua::registerType<T>(state);
ScriptSystem::registerComponent<T>([&](auto && ... args) {
registerEntityMember(state, FWD(args)...);
});
}
template<typename T>
void registerType(EntityManager & em) {
for (const auto & [e, comp] : em.getEntities<LuaStateComponent>())
registerTypeWithState<T>(*comp.state);
}
template<typename Func>
void registerFunctionWithState(sol::state & state, const char * name, Func && func) {
state[name] = FWD(func);
}
template<typename Func>
void registerFunction(EntityManager & em, const char * name, Func && func) {
for (const auto & [e, comp] : em.getEntities<LuaStateComponent>())
registerFunctionWithState(state, name, func);
}
}
}