Pass arguments to main via runtime.process.Init, dispatched on signature

This commit is contained in:
Daniel Samson
2026-07-11 14:22:48 +01:00
parent d218d93f79
commit 75ccfff171
6 changed files with 112 additions and 39 deletions
+4 -4
View File
@@ -21,8 +21,8 @@ fn burnStack(depth: usize) u8 {
return touch[0] +% burnStack(depth - 1);
}
pub fn main() void {
if (runtime.argumentCount() <= 1) {
pub fn main(init: runtime.process.Init) void {
if (init.arguments.count <= 1) {
// First instance: spawn the second with real arguments, then exit.
_ = runtime.system.spawnWithArguments("args-echo", &.{ "alpha", "beta-42" });
return;
@@ -36,8 +36,8 @@ pub fn main() void {
const prefix = "args:";
@memcpy(buffer[0..prefix.len], prefix);
var len: usize = prefix.len;
for (0..runtime.argumentCount()) |i| {
const argument = runtime.argument(i);
var iterator = init.arguments.iterate();
while (iterator.next()) |argument| {
if (len + 1 + argument.len + 1 > buffer.len) break;
buffer[len] = ' ';
len += 1;