Skip to content

Commit

Permalink
std.meta: make globalOption comptime-only and update its docs
Browse files Browse the repository at this point in the history
Since ziglang#425 is closed, changes in this pr are now valid
  • Loading branch information
wrongnull committed Sep 24, 2023
1 parent fb6fff2 commit 4fad841
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/std/meta.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1091,11 +1091,14 @@ test "ArgsTuple forwarding" {
}
}

/// TODO: https://github.com/ziglang/zig/issues/425
/// Returns the optional value of the declaration `name` in the root source file, casts it to type `T`.
/// This function should only be called at compile time.
pub fn globalOption(comptime name: []const u8, comptime T: type) ?T {
if (!@hasDecl(root, name))
return null;
return @as(T, @field(root, name));
coptime {
if (!@hasDecl(root, name))
return null;
return @as(T, @field(root, name));
}
}

/// Returns whether `error_union` contains an error.
Expand Down

0 comments on commit 4fad841

Please sign in to comment.