Skip to content

Instantly share code, notes, and snippets.

@kevinw
Created July 10, 2019 13:00
Show Gist options
  • Select an option

  • Save kevinw/30d653ae23b835183dd9282a341f4856 to your computer and use it in GitHub Desktop.

Select an option

Save kevinw/30d653ae23b835183dd9282a341f4856 to your computer and use it in GitHub Desktop.
comptime type registry zig
var allComponentTypes: []type = undefined;
fn addComponent(comptime T: type) void {
allComponentTypes = allComponentTypes ++ [1]type{T};
}
test "add component" {
const Mover = struct {
foo: bool,
};
addComponent(Mover);
}
>zig test registry.zig
registry.zig:4:25: error: unable to evaluate constant expression
allComponentTypes = allComponentTypes ++ [1]type{T};
^
registry.zig:12:17: note: called from here
addComponent(Mover);
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment