add support for more types on lv2 parameter structs
This commit is contained in:
parent
690ab89cfd
commit
72379e63ee
1 changed files with 9 additions and 4 deletions
13
src/lang.zig
13
src/lang.zig
|
@ -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", .{
|
||||
|
|
Loading…
Reference in a new issue