Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
return comptime blk: {
if (!@hasDecl(root, name))
break :blk null;
break :blk @as(T, @field(root, name));
};
}

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