Author:ptrace Comitter:ptrace Date:2025-11-30 05:48:23 UTC

added program args forwarding

diff --git a/build.jai b/build.jai index 79e54bd..f05bb8b 100644 --- a/build.jai +++ b/build.jai @@ -67,6 +67,9 @@ build :: () {     args_program_run        := array_find(args, "run");     args_build_release      := array_find(args, "release");     // program args     program_args := program_args_collect(args);     defer array_free(program_args);     // -----------------------------------------     w := compiler_create_workspace(); @@ -147,7 +150,7 @@ build :: () {         return;     }     if args_program_run  run_build_result(w);     if args_program_run  run_build_result(w, program_args); } @@ -176,6 +179,13 @@ Options:     run         Runs your program afterwards     release     Builds with release options. If omitted, it builds a debug build. Passing Args to your Program:     If you want to supply args to your program, pass it like that:         `jai build.jai - run :: my_arg1 foo bar abc ABC`     Everything after the `::` get's forwarded to your program. _END_;     log(help_message); } @@ -193,6 +203,15 @@ compiler_message :: () -> success: bool {     return false; } program_args_collect :: (args: []string, divider: string = "::") -> [..]string {     buf: [..]string;     success, match := array_find(args, divider);     if success  for i: match+1..args.count-1  array_add(*buf, args[i]);     return buf; } template_rules_find :: () -> [..]string {     templates: [..]string; diff --git a/templates/lib/template.jai b/templates/lib/template.jai index 8b55bc2..8ca3137 100644 --- a/templates/lib/template.jai +++ b/templates/lib/template.jai @@ -13,6 +13,10 @@ build :: () {     args_program_run        := array_find(args, "run");     args_build_release      := array_find(args, "release");     // program args     program_args := program_args_collect(args);     defer array_free(program_args);     // -----------------------------------------     w := compiler_create_workspace(); @@ -63,7 +67,7 @@ build :: () {         return;     }     if args_program_run  run_build_result(w);     if args_program_run  run_build_result(w, program_args); } build_debug :: (w: Workspace, target_options: *Build_Options) { @@ -91,10 +95,26 @@ Options:     run         Runs your program afterwards     release     Builds with release options. If omitted, it builds a debug build. Passing Args to your Program:     If you want to supply args to your program, pass it like that:         `jai build.jai - run :: my_arg1 foo bar abc ABC`     Everything after the `::` get's forwarded to your program. _END_;     log(help_message); } program_args_collect :: (args: []string, divider: string = "::") -> [..]string {     buf: [..]string;     success, match := array_find(args, divider);     if success  for i: match+1..args.count-1  array_add(*buf, args[i]);     return buf; } message_loop :: () -> success: bool {     while true {         message := compiler_wait_for_message(); diff --git a/templates/with_args/template.jai b/templates/with_args/template.jai index 962c8b3..76f04ad 100644 --- a/templates/with_args/template.jai +++ b/templates/with_args/template.jai @@ -13,6 +13,10 @@ build :: () {     args_program_run        := array_find(args, "run");     args_build_release      := array_find(args, "release");     // program args     program_args := program_args_collect(args);     defer array_free(program_args);     // -----------------------------------------     w := compiler_create_workspace(); @@ -58,7 +62,7 @@ build :: () {         return;     }     if args_program_run  run_build_result(w);     if args_program_run  run_build_result(w, program_args); } build_debug :: (w: Workspace, target_options: *Build_Options) { @@ -86,10 +90,26 @@ Options:     run         Runs your program afterwards     release     Builds with release options. If omitted, it builds a debug build. Passing Args to your Program:     If you want to supply args to your program, pass it like that:         `jai build.jai - run :: my_arg1 foo bar abc ABC`     Everything after the `::` get's forwarded to your program. _END_;     log(help_message); } program_args_collect :: (args: []string, divider: string = "::") -> [..]string {     buf: [..]string;     success, match := array_find(args, divider);     if success  for i: match+1..args.count-1  array_add(*buf, args[i]);     return buf; } message_loop :: () -> success: bool {     while true {         message := compiler_wait_for_message();