diff options
author | Juan Linietsky <reduzio@gmail.com> | 2022-07-29 15:30:52 +0200 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2022-08-01 00:56:59 +0200 |
commit | 0dd65378e7594e8916474613116d8df485870710 (patch) | |
tree | ba77e856d19325ab1be79c19e18c4650e70de249 /core | |
parent | 6d599ed90b396c264486512d5903c209ce729c76 (diff) |
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`
Diffstat (limited to 'core')
-rw-r--r-- | core/core_bind.cpp | 11 | ||||
-rw-r--r-- | core/core_bind.h | 1 | ||||
-rw-r--r-- | core/os/os.cpp | 3 | ||||
-rw-r--r-- | core/os/os.h | 4 |
4 files changed, 17 insertions, 2 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 3f94ff8329..65cc3b4c42 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -331,6 +331,16 @@ Vector<String> OS::get_cmdline_args() { return cmdlinev; } +Vector<String> OS::get_cmdline_user_args() { + List<String> cmdline = ::OS::get_singleton()->get_cmdline_user_args(); + Vector<String> cmdlinev; + for (const String &E : cmdline) { + cmdlinev.push_back(E); + } + + return cmdlinev; +} + String OS::get_locale() const { return ::OS::get_singleton()->get_locale(); } @@ -614,6 +624,7 @@ void OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_name"), &OS::get_name); ClassDB::bind_method(D_METHOD("get_cmdline_args"), &OS::get_cmdline_args); + ClassDB::bind_method(D_METHOD("get_cmdline_user_args"), &OS::get_cmdline_user_args); ClassDB::bind_method(D_METHOD("delay_usec", "usec"), &OS::delay_usec); ClassDB::bind_method(D_METHOD("delay_msec", "msec"), &OS::delay_msec); diff --git a/core/core_bind.h b/core/core_bind.h index 3a4faa3422..8f66dc03ce 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -188,6 +188,7 @@ public: String get_name() const; Vector<String> get_cmdline_args(); + Vector<String> get_cmdline_user_args(); String get_locale() const; String get_locale_language() const; 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<String> &p_args) { +void OS::set_cmdline(const char *p_execpath, const List<String> &p_args, const List<String> &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<String> _cmdline; + List<String> _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<String> &p_args); + virtual void set_cmdline(const char *p_execpath, const List<String> &p_args, const List<String> &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<String> get_cmdline_args() const { return _cmdline; } + virtual List<String> get_cmdline_user_args() const { return _user_args; } virtual List<String> get_cmdline_platform_args() const { return List<String>(); } virtual String get_model_name() const; |