Use comptime for fully declarative LV2 and Custom commands #14
2 changed files with 11 additions and 7 deletions
|
@ -159,7 +159,7 @@ pub const Command = struct {
|
||||||
pub const Load = struct {
|
pub const Load = struct {
|
||||||
pub const base_tag = Tag.load;
|
pub const base_tag = Tag.load;
|
||||||
base: Command,
|
base: Command,
|
||||||
path: []const u8,
|
path: []u8,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Quicksave = struct {
|
pub const Quicksave = struct {
|
||||||
|
@ -566,6 +566,7 @@ pub const Lang = struct {
|
||||||
usize => try std.fmt.parseInt(usize, arg, 10),
|
usize => try std.fmt.parseInt(usize, arg, 10),
|
||||||
i32 => try std.fmt.parseInt(i32, arg, 10),
|
i32 => try std.fmt.parseInt(i32, arg, 10),
|
||||||
f32 => try std.fmt.parseFloat(f32, arg),
|
f32 => try std.fmt.parseFloat(f32, arg),
|
||||||
|
[]u8 => try self.allocator.dupe(u8, arg),
|
||||||
[]const u8 => try self.allocator.dupe(u8, arg),
|
[]const u8 => try self.allocator.dupe(u8, arg),
|
||||||
else => @compileError("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) ++ "."),
|
||||||
};
|
};
|
||||||
|
|
15
src/main.zig
15
src/main.zig
|
@ -57,13 +57,16 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
|
||||||
} else {
|
} else {
|
||||||
// if there isn't any commands on the file, we load our default
|
// if there isn't any commands on the file, we load our default
|
||||||
// 'load :0' command
|
// 'load :0' command
|
||||||
var loadargs = langs.ArgList.init(allocator);
|
|
||||||
try loadargs.append(":0");
|
|
||||||
|
|
||||||
try cmds.append(langs.Command{
|
// TODO: deliberate memleak here. we only allocate this
|
||||||
.command = .Load,
|
// command once, for the start of the file, so.
|
||||||
.args = loadargs,
|
var load_cmd = try allocator.create(langs.Command.Load);
|
||||||
});
|
std.mem.copy(u8, load_cmd.path, ":0");
|
||||||
|
load_cmd.base.tag = langs.Command.Tag.load;
|
||||||
|
|
||||||
|
// taking address is fine, because load_cmd lives in the lifetime
|
||||||
|
// of the allocator.
|
||||||
|
try cmds.append(&load_cmd.base);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_read_opt) |file_read| {
|
if (file_read_opt) |file_read| {
|
||||||
|
|
Loading…
Reference in a new issue