Skip to content

Instantly share code, notes, and snippets.

@schroffl
Last active January 5, 2019 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schroffl/03b2eee4dfe347d8589574f3f919ce37 to your computer and use it in GitHub Desktop.
Save schroffl/03b2eee4dfe347d8589574f3f919ce37 to your computer and use it in GitHub Desktop.
const std = @import("std");
const c = @cImport({
@cInclude("c-header.h");
});
const MyInputType = struct {
value: u8
};
const MyResultType = struct {
input: type,
pub fn doSomethingWithInputType(comptime self: MyResultType) void {
std.debug.warn("{}\n", @memberName(self.input, 0));
}
};
pub fn main() void {
const a = getResultType(MyInputType);
const b = getResultType(struct { another_input_type: u8 });
a.doSomethingWithInputType();
b.doSomethingWithInputType();
}
fn getResultType(comptime input_type: type) MyResultType {
// As soon as I add the c call, I get 'unable to evaluate constant expression'.
// If you comment the line below this snippet should run properly.
c.some_function();
return MyResultType {
.input = input_type
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment