From c21f5767ee74ea8d8358298601d67d0642bb0e28 Mon Sep 17 00:00:00 2001 From: Dario48 Date: Sun, 21 Jun 2026 01:02:48 +0200 Subject: [PATCH] added extra_args --- src/main.zig | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.zig b/src/main.zig index 88dca88..9c8608a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -13,8 +13,8 @@ export fn glfw_error_callback(@"error": c_int, description: [*c]const u8) callco pub const std_options: std.Options = .{}; -fn formatArgv(alloc: std.mem.Allocator, format: []const u8, path: []const u8) ![][]u8 { - var outer = std.ArrayList([]u8).empty; +fn formatArgv(alloc: std.mem.Allocator, format: []const u8, path: []const u8, extra_args: ?[]const []const u8) ![][]const u8 { + var outer = std.ArrayList([]const u8).empty; errdefer { for (outer.items) |arr| { alloc.free(arr); @@ -87,6 +87,9 @@ fn formatArgv(alloc: std.mem.Allocator, format: []const u8, path: []const u8) ![ try outer.append(alloc, owned); + if (extra_args) |a| + try outer.appendSlice(alloc, a); + return outer.toOwnedSlice(alloc); } @@ -129,7 +132,7 @@ const map = blk: { const binOptMap = map[0]; const floatOptMap = map[1]; -var argv: ?[][]u8 = null; +var argv: ?[][]const u8 = null; var stackTraceBuf: [32]usize = undefined; // you never know how long the rabbit stack trace goes var stackTrace: std.debug.StackTrace = undefined; @@ -195,6 +198,7 @@ pub fn main(init: std.process.Init) !void { name: []const u8, emu: []const u8, path: []const u8, + extra_args: ?[]const []const u8, }, }, init.arena.allocator(), content, &diag, .{}) catch |err| { std.log.err("{f}", .{diag}); @@ -302,7 +306,7 @@ pub fn main(init: std.process.Init) !void { for (zon.emus) |emu| { std.log.debug(" emu.name: '{s}'", .{emu.name}); if (std.mem.eql(u8, emu.name, rom.emu)) { - argv = formatArgv(init.arena.allocator(), emu.exec_format, rom.path) catch |err| blk: { + argv = formatArgv(init.arena.allocator(), emu.exec_format, rom.path, rom.extra_args) catch |err| blk: { handleErr(err); break :blk null; };