50 lines
1.3 KiB
Mako
50 lines
1.3 KiB
Mako
#include "${include_file}"
|
|
|
|
#if __has_include("ecs-lua.h")
|
|
#include "sol/sol.hpp"
|
|
|
|
namespace generated {
|
|
void init(sol::state& lua) {
|
|
sol::table preload = lua["package"]["preload"];
|
|
% for c in components:
|
|
|
|
preload["ecs.${c.name}"] = [&lua] {
|
|
sol::table component = lua.create_table();
|
|
component["_id"] = ecs::ComponentID::id<${c.name}>;
|
|
|
|
component.new_usertype<${c.name}>("${c.name}",
|
|
${', '.join("\"{}\", &{}::{}".format(v.name, c.name, v.name) for v in c.variables if not "hidden" in v.annotations)},
|
|
sol::base_classes, sol::bases<ecs::Component>()
|
|
);
|
|
|
|
% for con in c.constructors:
|
|
% if len(con.parameters) > 0:
|
|
component.set_function("new", sol::factories([](${', '.join("{} {}".format(p.type, p.name) for p in con.parameters)}) {
|
|
return std::make_pair(ecs::ComponentID::id<${c.name}>, new ${c.name}(${', '.join(p.name for p in con.parameters)}));
|
|
}));
|
|
|
|
% endif
|
|
% endfor
|
|
component.set_function("_convert", [] (ecs::Component* component) {
|
|
return static_cast<${c.name}*>(component);
|
|
});
|
|
|
|
return component;
|
|
};
|
|
% endfor
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#if __has_include("ecs-serial.h")
|
|
namespace generated {
|
|
void init() {
|
|
% for c in components:
|
|
ecs::serial::register_component<${c.name}>(
|
|
${', '.join("&{}::{}".format(c.name, v.name) for v in c.variables if not "unserial" in v.annotations)}
|
|
);
|
|
% endfor
|
|
}
|
|
}
|
|
#endif
|
|
|