Improved generate script
This commit is contained in:
parent
e4adee0e8c
commit
1cb3d5eae8
12
flint.yaml
12
flint.yaml
|
@ -12,6 +12,11 @@ git:
|
||||||
include:
|
include:
|
||||||
- .build/git/io/flint.yaml
|
- .build/git/io/flint.yaml
|
||||||
|
|
||||||
|
scripts:
|
||||||
|
components:
|
||||||
|
step: pre
|
||||||
|
command: python scripts/generate.py
|
||||||
|
|
||||||
targets:
|
targets:
|
||||||
sol2:
|
sol2:
|
||||||
type: lib
|
type: lib
|
||||||
|
@ -57,9 +62,12 @@ targets:
|
||||||
type: exe
|
type: exe
|
||||||
path: test
|
path: test
|
||||||
include:
|
include:
|
||||||
- generated
|
- ../.build/generated/test/components
|
||||||
dependency:
|
dependency:
|
||||||
- ecs
|
- ecs
|
||||||
- ecs-lua
|
- ecs-lua
|
||||||
- ecs_serial
|
- ecs_serial
|
||||||
|
script:
|
||||||
|
components:
|
||||||
|
in: test/include/components.h
|
||||||
|
out: ecs_components.h
|
||||||
|
|
|
@ -63,11 +63,12 @@ def build_components(cursor, filename):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 3:
|
||||||
print("Usage: {} [header filename]".format(argv[0]))
|
print("Usage: {} [header filename] [output filename]".format(argv[0]))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
filename = argv[1]
|
filename = argv[1]
|
||||||
|
output = argv[2]
|
||||||
|
|
||||||
index = clang.cindex.Index.create()
|
index = clang.cindex.Index.create()
|
||||||
tu = index.parse(filename, ['-x', 'c++', '-std=c++2a', '-Iecs/include', '-I.build/git/stduuid/include', '-I/lib/gcc/x86_64-pc-linux-gnu/9.3.0/include'])
|
tu = index.parse(filename, ['-x', 'c++', '-std=c++2a', '-Iecs/include', '-I.build/git/stduuid/include', '-I/lib/gcc/x86_64-pc-linux-gnu/9.3.0/include'])
|
||||||
|
@ -77,7 +78,10 @@ def main(argv):
|
||||||
tpl = Template(filename='template.mako')
|
tpl = Template(filename='template.mako')
|
||||||
|
|
||||||
include_file = filename.split('/')[-1]
|
include_file = filename.split('/')[-1]
|
||||||
print(tpl.render(components=components, include_file=include_file))
|
|
||||||
|
output_file = open(output, "w")
|
||||||
|
output_file.write(tpl.render(components=components, include_file=include_file))
|
||||||
|
output_file.close()
|
||||||
|
|
||||||
# for d in tu.diagnostics:
|
# for d in tu.diagnostics:
|
||||||
# print(d)
|
# print(d)
|
|
@ -1,88 +0,0 @@
|
||||||
#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 static_cast<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 static_cast<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 static_cast<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
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user