I’m working on a test case that involves marshaling a function call from JavaScript into C. For this reason I’m exposing certain C functions from stdio.h as public decls:
const c = @cImport({
@cInclude("stdio.h");
});
pub const stdin = c.stdin;
pub const stdout = c.stdout;
pub const stderr = c.stderr;
pub const fwrite = c.fwrite;
pub const puts = c.puts;
The code above doesn’t work, since c.stdin
and co aren’t comptime known. Is it possible to expose these C variables so that they’d be treated as though they’re variables of the Zig module?
I have the following as a workaround for now:
pub fn stream(num: u8) ?*c.FILE {
return switch (num) {
0 => c.stdin,
1 => c.stdout,
2 => c.stderr,
else => null,
};
}