Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finally, learn how generate struct with builtin function in Zig #339

Open
xxleyi opened this issue Mar 14, 2023 · 0 comments
Open

finally, learn how generate struct with builtin function in Zig #339

xxleyi opened this issue Mar 14, 2023 · 0 comments

Comments

@xxleyi
Copy link
Owner

xxleyi commented Mar 14, 2023

const std = @import("std");
const builtin = @import("std").builtin;
const debug = @import("std").debug;

const A = @Type(.{
    .Struct = .{
        .layout = .Auto,
        .fields = &[_]builtin.Type.StructField{
            .{ .name = "one", .field_type = i32, .default_value = null, .is_comptime = false, .alignment = 0 },
        },
        .decls = &[_]builtin.Type.Declaration{},
        .is_tuple = false,
    },
});
test "test generate types" {
    const a: A = .{ .one = 25 };
    debug.assert(a.one == 25);
}

pub fn main() void {
    const a: A = .{ .one = 33 };
    debug.print("a.one is {}\n", .{a.one});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant