lang: add arg checks for the other commands

This commit is contained in:
Luna 2019-08-08 20:24:25 -03:00
parent 422cd2502c
commit ab2e8884b8

View file

@ -233,13 +233,17 @@ pub const Lang = struct {
return null;
}
fn expectSingle(self: *Lang, args: ArgList) !void {
if (args.len != 1) {
std.debug.warn("expected 1 argument, found {}\n", args.len);
fn expectAny(self: *Lang, count: usize, args: ArgList) !void {
if (args.len != count) {
std.debug.warn("expected {} arguments, found {}\n", count, args.len);
return error.ArgRequired;
}
}
fn expectSingle(self: *Lang, args: ArgList) !void {
return try self.expectAny(1, args);
}
fn expectFloat(self: *Lang, count: usize, args: ArgList) !void {
var i: usize = 0;
@ -263,6 +267,21 @@ pub const Lang = struct {
.Quicksave, .Noop => {},
.Load, .RunQS => try self.expectSingle(cmd.args),
.Amp => try self.expectFloat(3, cmd.args),
.RFlanger => try self.expectFloat(4, cmd.args),
.Eq => try self.expectFloat(5, cmd.args),
.Phaser => try self.expectFloat(6, cmd.args),
.Mbeq => try self.expectFloat(15, cmd.args),
.Chorus => try self.expectFloat(8, cmd.args),
.PitchScaler => try self.expectFloat(3, cmd.args),
.Reverb => try self.expectFloat(12, cmd.args),
.Highpass => try self.expectFloat(5, cmd.args),
.Delay => try self.expectFloat(12, cmd.args),
.Vinyl => try self.expectFloat(7, cmd.args),
.RevDelay => try self.expectFloat(5, cmd.args),
.Noise => try self.expectFloat(4, cmd.args),
.WildNoise => try self.expectFloat(4, cmd.args),
.Write => try self.expectFloat(3, cmd.args),
.Rotate => try self.expectAny(2, cmd.args),
else => std.debug.warn("WARN unchecked command {}\n", cmd.command),
}
}