Skip to content

Commit

Permalink
Merge pull request #49 from StringNick/fix-std-builtin-type
Browse files Browse the repository at this point in the history
accomodate Zig changes to std.builtin.Type
  • Loading branch information
sam701 authored Sep 4, 2024
2 parents 9a94c48 + c9b9d17 commit 1fbfbdc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
refs/
tryout/
zig-cache/
zig-out/
.zig-cache/
zig-out/
14 changes: 7 additions & 7 deletions src/value_parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ pub const ValueData = struct {

pub fn getValueData(comptime T: type) ValueData {
const ValueType = switch (@typeInfo(T)) {
.Optional => |oinfo| oinfo.child,
.optional => |oinfo| oinfo.child,
else => T,
};
return switch (@typeInfo(ValueType)) {
.Int => intData(ValueType, T),
.Float => floatData(ValueType, T),
.Bool => boolData(T),
.Pointer => |pinfo| {
.int => intData(ValueType, T),
.float => floatData(ValueType, T),
.bool => boolData(T),
.pointer => |pinfo| {
if (pinfo.size == .Slice and pinfo.child == u8) {
return stringData(T);
}
},
.Enum => enumData(ValueType, T),
.@"enum" => enumData(ValueType, T),
else => @compileError("unsupported value type"),
};
}
Expand Down Expand Up @@ -93,7 +93,7 @@ fn stringData(comptime DestinationType: type) ValueData {
}

fn enumData(comptime ValueType: type, comptime DestinationType: type) ValueData {
const edata = @typeInfo(ValueType).Enum;
const edata = @typeInfo(ValueType).@"enum";
return .{
.value_size = @sizeOf(DestinationType),
.value_parser = struct {
Expand Down
4 changes: 2 additions & 2 deletions src/value_ref.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ pub fn allocRef(dest: anytype, alloc: Allocator) *ValueRef {

pub fn mkRef(dest: anytype) ValueRef {
const ti = @typeInfo(@TypeOf(dest));
const t = ti.Pointer.child;
const t = ti.pointer.child;

switch (@typeInfo(t)) {
.Pointer => |pinfo| {
.pointer => |pinfo| {
switch (pinfo.size) {
.Slice => {
if (pinfo.child == u8) {
Expand Down

0 comments on commit 1fbfbdc

Please sign in to comment.