From e2b9c87aa888da76d6bd366fd99d0c8d2d99e756 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Sat, 30 Sep 2017 11:20:35 +0100 Subject: Wrap entry point `main` around the C style `main` in the IR --- core/_preload.odin | 2 +- core/os_linux.odin | 7 +++++-- core/os_x.odin | 12 +++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/_preload.odin b/core/_preload.odin index 014a3c219..3a921e750 100644 --- a/core/_preload.odin +++ b/core/_preload.odin @@ -138,8 +138,8 @@ Type_Info :: struct #ordered { // This will be set by the compiler __type_table: []Type_Info; -__argv__: ^^u8; __argc__: i32; +__argv__: ^^u8; // IMPORTANT NOTE(bill): Must be in this order (as the compiler relies upon it) diff --git a/core/os_linux.odin b/core/os_linux.odin index afbd41f7c..3a4a8d6cf 100644 --- a/core/os_linux.odin +++ b/core/os_linux.odin @@ -267,6 +267,9 @@ dlerror :: proc() -> string { _alloc_command_line_arguments :: proc() -> []string { - // TODO(bill): - return nil; + args := make([]string, __argc__); + for i in 0..__argc__ { + args[i] = strings.to_odin_string((__argv__+i)^); + } + return args; } diff --git a/core/os_x.odin b/core/os_x.odin index ad267e22a..1f41bd884 100644 --- a/core/os_x.odin +++ b/core/os_x.odin @@ -42,7 +42,8 @@ RTLD_NOLOAD :: 0x10; RTLD_FIRST :: 0x100; -args: [dynamic]string; +// "Argv" arguments converted to Odin strings +args := _alloc_command_line_arguments(); _File_Time :: struct #ordered { seconds: i64, @@ -279,3 +280,12 @@ dlclose :: proc(handle: rawptr) -> bool #inline { dlerror :: proc() -> string { return strings.to_odin_string(unix_dlerror()); } + + +_alloc_command_line_arguments :: proc() -> []string { + args := make([]string, __argc__); + for i in 0..__argc__ { + args[i] = strings.to_odin_string((__argv__+i)^); + } + return args; +} -- cgit v1.2.3