module: support merging module lists
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
b37ece1b9a
commit
95c9ae5278
9 changed files with 130 additions and 34 deletions
|
|
@ -37,7 +37,7 @@ pub fn Query(comptime component_types_by_name: anytype) type {
|
|||
const namespaces = std.meta.fields(Namespace);
|
||||
var fields: [namespaces.len]std.builtin.Type.UnionField = undefined;
|
||||
for (namespaces, 0..) |namespace, i| {
|
||||
const ns = std.meta.stringToEnum(Namespace, namespace.name).?;
|
||||
const ns = stringToEnum(Namespace, namespace.name).?;
|
||||
fields[i] = .{
|
||||
.name = namespace.name,
|
||||
.type = ComponentList(ns),
|
||||
|
|
@ -61,6 +61,15 @@ pub fn Query(comptime component_types_by_name: anytype) type {
|
|||
};
|
||||
}
|
||||
|
||||
// TODO: cannot use std.meta.stringToEnum for some reason; an issue with its internal comptime map and u0 values
|
||||
pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
|
||||
inline for (@typeInfo(T).Enum.fields) |enumField| {
|
||||
if (std.mem.eql(u8, str, enumField.name)) {
|
||||
return @field(T, enumField.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test "query" {
|
||||
const Location = struct {
|
||||
x: f32 = 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue