From 0dd65378e7594e8916474613116d8df485870710 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 29 Jul 2022 15:30:52 +0200 Subject: Add support for command-line user arguments. Implements the standard Unix double dash (--) commandline argument: * Arguments after a double dash (--) are ignored by Godot and stored for the user. * User can access them via `OS.get_cmdline_user_args()` Example: `godot.exe scene_to_run.tscn --fullscreen -- --start-level 2` --- core/os/os.cpp | 3 ++- core/os/os.h | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'core/os') diff --git a/core/os/os.cpp b/core/os/os.cpp index 619e3eb06f..1358c926d1 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -362,9 +362,10 @@ String OS::get_model_name() const { return "GenericDevice"; } -void OS::set_cmdline(const char *p_execpath, const List &p_args) { +void OS::set_cmdline(const char *p_execpath, const List &p_args, const List &p_user_args) { _execpath = String::utf8(p_execpath); _cmdline = p_args; + _user_args = p_user_args; } String OS::get_unique_id() const { diff --git a/core/os/os.h b/core/os/os.h index b9f7328929..9152b797ef 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -46,6 +46,7 @@ class OS { static uint64_t target_ticks; String _execpath; List _cmdline; + List _user_args; bool _keep_screen_on = true; // set default value to true, because this had been true before godot 2.0. bool low_processor_usage_mode = false; int low_processor_usage_mode_sleep_usec = 10000; @@ -106,7 +107,7 @@ protected: virtual void finalize() = 0; virtual void finalize_core() = 0; - virtual void set_cmdline(const char *p_execpath, const List &p_args); + virtual void set_cmdline(const char *p_execpath, const List &p_args, const List &p_user_args); virtual bool _check_internal_feature_support(const String &p_feature) = 0; @@ -162,6 +163,7 @@ public: virtual String get_name() const = 0; virtual List get_cmdline_args() const { return _cmdline; } + virtual List get_cmdline_user_args() const { return _user_args; } virtual List get_cmdline_platform_args() const { return List(); } virtual String get_model_name() const; -- cgit v1.2.3