89 lines
2.2 KiB
C++
89 lines
2.2 KiB
C++
#include "components.h"
|
|
|
|
#if __has_include("ecs-lua.h")
|
|
#include "sol.hpp"
|
|
|
|
namespace generated {
|
|
void init(sol::state& lua) {
|
|
sol::table preload = lua["package"]["preload"];
|
|
|
|
preload["ecs.Position"] = [&lua] {
|
|
sol::table component = lua.create_table();
|
|
component["_id"] = ecs::ComponentID::id<Position>;
|
|
|
|
component.new_usertype<Position>("Position",
|
|
"x", &Position::x, "y", &Position::y,
|
|
sol::base_classes, sol::bases<ecs::Component>()
|
|
);
|
|
|
|
component.set_function("new", sol::factories([](float _x, float _y) {
|
|
return std::make_pair(ecs::ComponentID::id<Position>, new Position(_x, _y));
|
|
}));
|
|
|
|
component.set_function("_convert", [] (ecs::Component* component) {
|
|
return (Position*)component;
|
|
});
|
|
|
|
return component;
|
|
};
|
|
|
|
preload["ecs.Velocity"] = [&lua] {
|
|
sol::table component = lua.create_table();
|
|
component["_id"] = ecs::ComponentID::id<Velocity>;
|
|
|
|
component.new_usertype<Velocity>("Velocity",
|
|
"x", &Velocity::x, "y", &Velocity::y,
|
|
sol::base_classes, sol::bases<ecs::Component>()
|
|
);
|
|
|
|
component.set_function("new", sol::factories([](float _x, float _y) {
|
|
return std::make_pair(ecs::ComponentID::id<Velocity>, new Velocity(_x, _y));
|
|
}));
|
|
|
|
component.set_function("_convert", [] (ecs::Component* component) {
|
|
return (Velocity*)component;
|
|
});
|
|
|
|
return component;
|
|
};
|
|
|
|
preload["ecs.Meta"] = [&lua] {
|
|
sol::table component = lua.create_table();
|
|
component["_id"] = ecs::ComponentID::id<Meta>;
|
|
|
|
component.new_usertype<Meta>("Meta",
|
|
"name", &Meta::name,
|
|
sol::base_classes, sol::bases<ecs::Component>()
|
|
);
|
|
|
|
component.set_function("new", sol::factories([](std::string _name) {
|
|
return std::make_pair(ecs::ComponentID::id<Meta>, new Meta(_name));
|
|
}));
|
|
|
|
component.set_function("_convert", [] (ecs::Component* component) {
|
|
return (Meta*)component;
|
|
});
|
|
|
|
return component;
|
|
};
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#if __has_include("ecs-serial.h")
|
|
namespace generated {
|
|
void init() {
|
|
ecs::serial::register_component<Position>(
|
|
&Position::x, &Position::y
|
|
);
|
|
ecs::serial::register_component<Velocity>(
|
|
&Velocity::x, &Velocity::y
|
|
);
|
|
ecs::serial::register_component<Meta>(
|
|
&Meta::name
|
|
);
|
|
}
|
|
}
|
|
#endif
|
|
|