diff options
Diffstat (limited to 'doc/classes/OS.xml')
-rw-r--r-- | doc/classes/OS.xml | 63 |
1 files changed, 47 insertions, 16 deletions
diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index 26110df335..65a815a603 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -7,6 +7,7 @@ Operating System functions. OS wraps the most common functionality to communicate with the host operating system, such as the clipboard, video driver, date and time, timers, environment variables, execution of binaries, command line, etc. </description> <tutorials> + <link title="OS Test Demo">https://godotengine.org/asset-library/asset/677</link> </tutorials> <methods> <method name="can_use_threads" qualifiers="const"> @@ -84,18 +85,36 @@ If [code]blocking[/code] is [code]false[/code], the Godot thread will continue while the new process runs. It is not possible to retrieve the shell output in non-blocking mode, so [code]output[/code] will be empty. The return value also depends on the blocking mode. When blocking, the method will return an exit code of the process. When non-blocking, the method returns a process ID, which you can use to monitor the process (and potentially terminate it with [method kill]). If the process forking (non-blocking) or opening (blocking) fails, the method will return [code]-1[/code] or another exit code. Example of blocking mode and retrieving the shell output: - [codeblock] + [codeblocks] + [gdscript] var output = [] var exit_code = OS.execute("ls", ["-l", "/tmp"], true, output) - [/codeblock] + [/gdscript] + [csharp] + var output = new Godot.Collections.Array(); + int exitCode = OS.Execute("ls", new string[] {"-l", "/tmp"}, true, output); + [/csharp] + [/codeblocks] Example of non-blocking mode, running another instance of the project and storing its process ID: - [codeblock] + [codeblocks] + [gdscript] var pid = OS.execute(OS.get_executable_path(), [], false) - [/codeblock] + [/gdscript] + [csharp] + var pid = OS.Execute(OS.GetExecutablePath(), new string[] {}, false); + [/csharp] + [/codeblocks] If you wish to access a shell built-in or perform a composite command, a platform-specific shell can be invoked. For example: - [codeblock] + [codeblocks] + [gdscript] + var output = [] OS.execute("CMD.exe", ["/C", "cd %TEMP% && dir"], true, output) - [/codeblock] + [/gdscript] + [csharp] + var output = new Godot.Collections.Array(); + OS.Execute("CMD.exe", new string[] {"/C", "cd %TEMP% && dir"}, true, output); + [/csharp] + [/codeblocks] [b]Note:[/b] This method is implemented on Android, iOS, Linux, macOS and Windows. </description> </method> @@ -117,13 +136,26 @@ You can also incorporate environment variables using the [method get_environment] method. You can set [code]editor/main_run_args[/code] in the Project Settings to define command-line arguments to be passed by the editor when running the project. Here's a minimal example on how to parse command-line arguments into a dictionary using the [code]--key=value[/code] form for arguments: - [codeblock] + [codeblocks] + [gdscript] var arguments = {} for argument in OS.get_cmdline_args(): if argument.find("=") > -1: var key_value = argument.split("=") arguments[key_value[0].lstrip("--")] = key_value[1] - [/codeblock] + [/gdscript] + [csharp] + var arguments = new Godot.Collections.Dictionary(); + foreach (var argument in OS.GetCmdlineArgs()) + { + if (argument.Find("=") > -1) + { + string[] keyValue = argument.Split("="); + arguments[keyValue[0].LStrip("--")] = keyValue[1]; + } + } + [/csharp] + [/codeblocks] </description> </method> <method name="get_connected_midi_inputs"> @@ -201,7 +233,12 @@ <return type="String"> </return> <description> - Returns the host OS locale. + Returns the host OS locale as a string of the form [code]language_Script_COUNTRY_VARIANT@extra[/code]. + [code]language[/code] - 2 or 3 letter [url=https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes]language code[/url], in lower case. + [code]Script[/code] - optional, 4 letter [url=https://en.wikipedia.org/wiki/ISO_15924]script code[/url], in title case. + [code]COUNTRY[/code] - optional, 2 or 3 letter [url=https://en.wikipedia.org/wiki/ISO_3166-1]country code[/url], in upper case. + [code]VARIANT[/code] - optional, language variant, region and sort order. Variant can have any number of underscored key words. + [code]extra[/code] - optional, semicolon separated list of additional key words. Currency, calendar, sort order and numbering system information. </description> </method> <method name="get_model_name" qualifiers="const"> @@ -234,13 +271,6 @@ Returns the number of threads available on the host machine. </description> </method> - <method name="get_splash_tick_msec" qualifiers="const"> - <return type="int"> - </return> - <description> - Returns the amount of time in milliseconds it took for the boot logo to appear. - </description> - </method> <method name="get_static_memory_peak_usage" qualifiers="const"> <return type="int"> </return> @@ -326,6 +356,7 @@ </return> <description> Returns the current UNIX epoch timestamp. + [b]Important:[/b] This is the system clock that the user can manully set. [b]Never use[/b] this method for precise time calculation since its results are also subject to automatic adjustments by the operating system. [b]Always use[/b] [method get_ticks_usec] or [method get_ticks_msec] for precise time calculation instead, since they are guaranteed to be monotonic (i.e. never decrease). </description> </method> <method name="get_unix_time_from_datetime" qualifiers="const"> |