abrasion/lib/ecs/src/component.rs

24 lines
456 B
Rust
Raw Normal View History

2020-08-22 14:41:36 +00:00
pub type ID = std::any::TypeId;
2021-04-05 16:34:12 +00:00
pub trait LuaBindings {
fn globals<'a>(&self, lua: &'a mlua::Lua) -> mlua::Table<'a>;
fn id(&self) -> &'static str;
}
2020-08-22 14:41:36 +00:00
pub trait Component: 'static {
2021-04-05 16:34:12 +00:00
fn lua_bindings(&self) -> Option<Box<dyn LuaBindings>> {
None
2021-04-04 20:35:03 +00:00
}
2020-08-22 14:41:36 +00:00
}
2021-01-13 23:10:48 +00:00
pub fn component_id<T: Component>() -> ID {
std::any::TypeId::of::<T>()
}
2021-03-21 16:12:58 +00:00
pub trait Global: 'static {
2021-01-13 23:10:48 +00:00
}
2021-03-21 16:12:58 +00:00
pub fn global_id<T: Global>() -> ID {
2020-08-22 14:41:36 +00:00
std::any::TypeId::of::<T>()
}