Use comptime for fully declarative LV2 and Custom commands #14

Merged
luna merged 69 commits from declarative-commands into master 2020-06-02 21:37:47 +00:00
Showing only changes of commit 72379e63ee - Show all commits

View file

@ -551,10 +551,15 @@ pub const Lang = struct {
}
const arg = maybe_arg.?;
if (cmd_field.field_type != f32)
@compileError("LV2 parameter struct can only have f32 fields");
const arg_value = switch (cmd_field.field_type) {
f32 => try std.fmt.parseFloat(f32, arg),
u64 => try std.fmt.parseInt(u64, arg, 10),
usize => try std.fmt.parseInt(usize, arg, 10),
[]const u8 => try self.allocator.dupe(u8, arg),
else => @compileError("parameter struct has unsupported type " ++ @typeName(cmd_field.field_type)),
};
@field(cmd.parameters, cmd_field.name) = try std.fmt.parseFloat(f32, arg);
@field(cmd.parameters, cmd_field.name) = arg_value;
}
} else {
inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| {
@ -569,7 +574,7 @@ pub const Lang = struct {
i32 => try std.fmt.parseInt(i32, arg, 10),
f32 => try std.fmt.parseFloat(f32, arg),
[]const u8 => try self.allocator.dupe(u8, arg),
else => @panic("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."),
else => @compileError("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."),
};
std.debug.warn("parsing {}, arg of type {} => {}\n", .{