refactor: obtain arguments through process initialization
This commit is contained in:
@@ -1,18 +1,11 @@
|
||||
# the bootstrap Init currently exposes only io; macOS provides process-lifetime argv storage.
|
||||
@hide:file
|
||||
_NSGetArgc c_func() @c_int
|
||||
|
||||
@hide:file
|
||||
_NSGetArgv c_func() @*[*;0]u8
|
||||
|
||||
argument_count proc() usize {
|
||||
return usize(_NSGetArgc()^)
|
||||
argument_count proc(args Args) usize {
|
||||
return args.values.len
|
||||
}
|
||||
|
||||
#! returns a borrowed, zero-terminated slice; storage lasts for the process lifetime.
|
||||
argument proc(index usize) ?[;0]u8 {
|
||||
if (index >= argument_count()) return null
|
||||
pointer :: _NSGetArgv()^[index]
|
||||
#! returns a borrowed, zero-terminated slice, valid while the supplied argument storage lives.
|
||||
argument proc(args Args, index usize) ?[;0]u8 {
|
||||
if (index >= argument_count(args)) return null
|
||||
pointer :: args.values[index]
|
||||
length := usize(0)
|
||||
while (pointer[length] != 0) length += 1
|
||||
return pointer[..length;0]
|
||||
|
||||
Reference in New Issue
Block a user