Replaced c style cast with static_cast and fixed generate script
This commit is contained in:
parent
c9f05af6c9
commit
e4adee0e8c
|
@ -77,6 +77,7 @@ namespace ecs::lua {
|
|||
};
|
||||
|
||||
preload["ecs.LuaComponent"] = [&lua] {
|
||||
// @todo Do we want to register this into the global namespace?
|
||||
lua.new_usertype<LuaComponent>("LuaComponent",
|
||||
"__index", [] (LuaComponent* thiz, std::string key) {
|
||||
return thiz->table[key];
|
||||
|
@ -210,7 +211,7 @@ namespace ecs::lua {
|
|||
}));
|
||||
|
||||
component.set_function("_convert", [] (ecs::Component* component) {
|
||||
return (LuaComponent*)component;
|
||||
return static_cast<LuaComponent*>(component);
|
||||
});
|
||||
|
||||
return component;
|
||||
|
|
|
@ -42,13 +42,13 @@ namespace ecs::serial {
|
|||
void register_component(Args... args) {
|
||||
// Serialize component
|
||||
auto serialize = [args...] (std::ostream& os, ecs::Component* component) {
|
||||
T* t = (T*)component;
|
||||
T* t = static_cast<T*>(component);
|
||||
serialize_member(os, t, args...);
|
||||
};
|
||||
|
||||
// Deserialize component
|
||||
auto deserialize = [args...] (std::istream& is, ecs::Component* component) {
|
||||
T* t = (T*)component;
|
||||
T* t = static_cast<T*>(component);
|
||||
deserialize_member(is, t, args...);
|
||||
};
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ namespace ecs {
|
|||
size_t id = ComponentID::id<T>;
|
||||
T* component = new T(args...);
|
||||
|
||||
return (T*)add_component(id, component);
|
||||
return static_cast<T*>(add_component(id, component));
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
|
@ -107,7 +107,7 @@ namespace ecs {
|
|||
T* get_component() const {
|
||||
size_t id = ComponentID::id<T>;
|
||||
|
||||
return (T*)get_component(id);
|
||||
return static_cast<T*>(get_component(id));
|
||||
}
|
||||
|
||||
const std::unordered_map<size_t, Component*> get_components() const {
|
||||
|
|
|
@ -10,6 +10,8 @@ namespace generated {
|
|||
|
||||
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>()
|
||||
|
@ -18,13 +20,13 @@ namespace generated {
|
|||
% 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(new ${c.name}(${', '.join(p.name for p in con.parameters)}), "${c.name}");
|
||||
return std::make_pair(ecs::ComponentID::id<${c.name}>, new ${c.name}(${', '.join(p.name for p in con.parameters)}));
|
||||
}));
|
||||
|
||||
% endif
|
||||
% endfor
|
||||
lua.set_function("_internal_to_${c.name}", [] (ecs::Component* component) {
|
||||
return (${c.name}*)component;
|
||||
component.set_function("_convert", [] (ecs::Component* component) {
|
||||
return static_cast<${c.name}*>(component);
|
||||
});
|
||||
|
||||
return component;
|
||||
|
|
5
test.py
5
test.py
|
@ -70,7 +70,7 @@ def main(argv):
|
|||
filename = argv[1]
|
||||
|
||||
index = clang.cindex.Index.create()
|
||||
tu = index.parse(filename, ['-x', 'c++', '-std=c++17', '-Iecs/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'])
|
||||
|
||||
components = build_components(tu.cursor, filename)
|
||||
|
||||
|
@ -79,5 +79,8 @@ def main(argv):
|
|||
include_file = filename.split('/')[-1]
|
||||
print(tpl.render(components=components, include_file=include_file))
|
||||
|
||||
# for d in tu.diagnostics:
|
||||
# print(d)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace generated {
|
|||
}));
|
||||
|
||||
component.set_function("_convert", [] (ecs::Component* component) {
|
||||
return (Position*)component;
|
||||
return static_cast<Position*>(component);
|
||||
});
|
||||
|
||||
return component;
|
||||
|
@ -41,7 +41,7 @@ namespace generated {
|
|||
}));
|
||||
|
||||
component.set_function("_convert", [] (ecs::Component* component) {
|
||||
return (Velocity*)component;
|
||||
return static_cast<Velocity*>(component);
|
||||
});
|
||||
|
||||
return component;
|
||||
|
@ -61,7 +61,7 @@ namespace generated {
|
|||
}));
|
||||
|
||||
component.set_function("_convert", [] (ecs::Component* component) {
|
||||
return (Meta*)component;
|
||||
return static_cast<Meta*>(component);
|
||||
});
|
||||
|
||||
return component;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local ecs = require "ecs"
|
||||
require "ecs"
|
||||
local Position = require "ecs.Position"
|
||||
local Velocity = require "ecs.Velocity"
|
||||
local Meta = require "ecs.Meta"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local ecs = require "ecs"
|
||||
require "ecs"
|
||||
local LuaComponent = require "ecs.LuaComponent"
|
||||
|
||||
function init()
|
||||
|
|
Loading…
Reference in New Issue
Block a user