diff --git a/src/image.zig b/src/image.zig index e0fea67..c43f88e 100644 --- a/src/image.zig +++ b/src/image.zig @@ -79,7 +79,7 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { var nam = try allocator.alloc(u8, template.len); std.mem.copy(u8, nam, template); - const seed = @truncate(u64, @bitCast(u128, std.time.nanoTimestamp())); + const seed = @bitCast(u64, std.time.timestamp()); var r = std.rand.DefaultPrng.init(seed); var fill = nam[template_start.len..nam.len]; diff --git a/src/runner.zig b/src/runner.zig index 234e59e..6b9f478 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -49,22 +49,20 @@ pub const Runner = struct { // parse the index from 1 to end var index = try std.fmt.parseInt(usize, load_path[1..], 10); - // if it isn't in the repl, args look like this: - // 'scritcher ./script ./image' - // if it is, it looks like this - // 'scritcher repl ./script ./image' + // don't care about the 'repl' being prepended when we're in repl + if (self.repl) index += 1; - // ':0' should ALWAYS point to the image. - if (self.repl) index += 3 else index += 2; + var args_it = std.process.args(); + _ = args_it.skip(); - var args = try std.process.argsAlloc(self.allocator); - defer std.process.argsFree(self.allocator, args); - std.debug.warn("ARGS!! {} \n", .{args.len}); - for (args) |arg, idx| { - std.debug.warn("arg{} = {}\n", .{ idx, arg }); + var i: usize = 0; + while (i <= index) : (i += 1) { + _ = args_it.skip(); } - std.debug.warn("fetch arg idx={}, val={}\n", .{ index, args[index] }); - return args[index]; + + const arg = try (args_it.next(self.allocator) orelse @panic("expected argument")); + + return arg; } else { return load_path; } @@ -92,7 +90,7 @@ pub const Runner = struct { // krita/gimp and make it export a bmp and while in the program you can // apply filters, etc. if (!std.mem.endsWith(u8, load_path, ".bmp") and !std.mem.endsWith(u8, load_path, ".ppm")) { - std.debug.warn("Only BMP files are allowed to be loaded. Got path '{}'\n", .{load_path}); + std.debug.warn("Only BMP files are allowed to be loaded.\n", .{}); return RunError.NoBMP; }