Merge pull request #77164 from dalexeev/gds-re-add-ord
GDScript: Re-add `ord()` function
This commit is contained in:
commit
2ee5d28d9d
@ -1896,7 +1896,7 @@ static void _register_variant_builtin_methods_string() {
|
|||||||
bind_static_method(String, num, sarray("number", "decimals"), varray(-1));
|
bind_static_method(String, num, sarray("number", "decimals"), varray(-1));
|
||||||
bind_static_method(String, num_int64, sarray("number", "base", "capitalize_hex"), varray(10, false));
|
bind_static_method(String, num_int64, sarray("number", "base", "capitalize_hex"), varray(10, false));
|
||||||
bind_static_method(String, num_uint64, sarray("number", "base", "capitalize_hex"), varray(10, false));
|
bind_static_method(String, num_uint64, sarray("number", "base", "capitalize_hex"), varray(10, false));
|
||||||
bind_static_method(String, chr, sarray("char"), varray());
|
bind_static_method(String, chr, sarray("code"), varray());
|
||||||
bind_static_method(String, humanize_size, sarray("size"), varray());
|
bind_static_method(String, humanize_size, sarray("size"), varray());
|
||||||
|
|
||||||
/* StringName */
|
/* StringName */
|
||||||
|
@ -118,13 +118,14 @@
|
|||||||
</method>
|
</method>
|
||||||
<method name="chr" qualifiers="static">
|
<method name="chr" qualifiers="static">
|
||||||
<return type="String" />
|
<return type="String" />
|
||||||
<param index="0" name="char" type="int" />
|
<param index="0" name="code" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns a single Unicode character from the decimal [param char]. You may use [url=https://unicodelookup.com/]unicodelookup.com[/url] or [url=https://www.unicode.org/charts/]unicode.org[/url] as points of reference.
|
Returns a single Unicode character from the integer [param code]. You may use [url=https://unicodelookup.com/]unicodelookup.com[/url] or [url=https://www.unicode.org/charts/]unicode.org[/url] as points of reference.
|
||||||
[codeblock]
|
[codeblock]
|
||||||
print(String.chr(65)) # Prints "A"
|
print(String.chr(65)) # Prints "A"
|
||||||
print(String.chr(129302)) # Prints "🤖" (robot face emoji)
|
print(String.chr(129302)) # Prints "🤖" (robot face emoji)
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
|
See also [method unicode_at], [method @GDScript.char], and [method @GDScript.ord].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="contains" qualifiers="const">
|
<method name="contains" qualifiers="const">
|
||||||
@ -1149,6 +1150,7 @@
|
|||||||
<param index="0" name="at" type="int" />
|
<param index="0" name="at" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns the character code at position [param at].
|
Returns the character code at position [param at].
|
||||||
|
See also [method chr], [method @GDScript.char], and [method @GDScript.ord].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="uri_decode" qualifiers="const">
|
<method name="uri_decode" qualifiers="const">
|
||||||
|
@ -1057,6 +1057,7 @@
|
|||||||
<param index="0" name="at" type="int" />
|
<param index="0" name="at" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns the character code at position [param at].
|
Returns the character code at position [param at].
|
||||||
|
See also [method String.chr], [method @GDScript.char], and [method @GDScript.ord].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="uri_decode" qualifiers="const">
|
<method name="uri_decode" qualifiers="const">
|
||||||
|
@ -48,14 +48,14 @@
|
|||||||
</method>
|
</method>
|
||||||
<method name="char">
|
<method name="char">
|
||||||
<return type="String" />
|
<return type="String" />
|
||||||
<param index="0" name="char" type="int" />
|
<param index="0" name="code" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns a single character (as a [String]) of the given Unicode code point (which is compatible with ASCII code).
|
Returns a single character (as a [String] of length 1) of the given Unicode code point [param code].
|
||||||
[codeblock]
|
[codeblock]
|
||||||
var upper = char(65) # upper is "A"
|
print(char(65)) # Prints "A"
|
||||||
var lower = char(65 + 32) # lower is "a"
|
print(char(129302)) # Prints "🤖" (robot face emoji)
|
||||||
var euro = char(8364) # euro is "€"
|
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
|
This is the inverse of [method ord]. See also [method String.chr] and [method String.unicode_at].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="convert" deprecated="Use [method @GlobalScope.type_convert] instead.">
|
<method name="convert" deprecated="Use [method @GlobalScope.type_convert] instead.">
|
||||||
@ -175,6 +175,18 @@
|
|||||||
[b]Note:[/b] If [member ProjectSettings.editor/export/convert_text_resources_to_binary] is [code]true[/code], [method @GDScript.load] will not be able to read converted files in an exported project. If you rely on run-time loading of files present within the PCK, set [member ProjectSettings.editor/export/convert_text_resources_to_binary] to [code]false[/code].
|
[b]Note:[/b] If [member ProjectSettings.editor/export/convert_text_resources_to_binary] is [code]true[/code], [method @GDScript.load] will not be able to read converted files in an exported project. If you rely on run-time loading of files present within the PCK, set [member ProjectSettings.editor/export/convert_text_resources_to_binary] to [code]false[/code].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="ord">
|
||||||
|
<return type="int" />
|
||||||
|
<param index="0" name="char" type="String" />
|
||||||
|
<description>
|
||||||
|
Returns an integer representing the Unicode code point of the given character [param char], which should be a string of length 1.
|
||||||
|
[codeblock]
|
||||||
|
print(ord("A")) # Prints 65
|
||||||
|
print(ord("🤖")) # Prints 129302
|
||||||
|
[/codeblock]
|
||||||
|
This is the inverse of [method char]. See also [method String.chr] and [method String.unicode_at].
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="preload">
|
<method name="preload">
|
||||||
<return type="Resource" />
|
<return type="Resource" />
|
||||||
<param index="0" name="path" type="String" />
|
<param index="0" name="path" type="String" />
|
||||||
|
@ -120,8 +120,17 @@ struct GDScriptUtilityFunctionsDefinitions {
|
|||||||
static inline void _char(Variant *r_ret, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
|
static inline void _char(Variant *r_ret, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
|
||||||
DEBUG_VALIDATE_ARG_COUNT(1, 1);
|
DEBUG_VALIDATE_ARG_COUNT(1, 1);
|
||||||
DEBUG_VALIDATE_ARG_TYPE(0, Variant::INT);
|
DEBUG_VALIDATE_ARG_TYPE(0, Variant::INT);
|
||||||
char32_t result[2] = { *p_args[0], 0 };
|
const int64_t code = *p_args[0];
|
||||||
*r_ret = String(result);
|
VALIDATE_ARG_CUSTOM(0, Variant::INT, code < 0 || code > UINT32_MAX, RTR("Expected an integer between 0 and 2^32 - 1."));
|
||||||
|
*r_ret = String::chr(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void ord(Variant *r_ret, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
|
||||||
|
DEBUG_VALIDATE_ARG_COUNT(1, 1);
|
||||||
|
DEBUG_VALIDATE_ARG_TYPE(0, Variant::STRING);
|
||||||
|
const String string = *p_args[0];
|
||||||
|
VALIDATE_ARG_CUSTOM(0, Variant::STRING, string.length() != 1, RTR("Expected a string of length 1 (a character)."));
|
||||||
|
*r_ret = string.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void range(Variant *r_ret, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
|
static inline void range(Variant *r_ret, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
|
||||||
@ -575,7 +584,8 @@ void GDScriptUtilityFunctions::register_functions() {
|
|||||||
REGISTER_FUNC( convert, true, RETVAR, ARGS( ARGVAR("what"), ARGTYPE("type") ), false, varray( ));
|
REGISTER_FUNC( convert, true, RETVAR, ARGS( ARGVAR("what"), ARGTYPE("type") ), false, varray( ));
|
||||||
#endif // DISABLE_DEPRECATED
|
#endif // DISABLE_DEPRECATED
|
||||||
REGISTER_FUNC( type_exists, true, RET(BOOL), ARGS( ARG("type", STRING_NAME) ), false, varray( ));
|
REGISTER_FUNC( type_exists, true, RET(BOOL), ARGS( ARG("type", STRING_NAME) ), false, varray( ));
|
||||||
REGISTER_FUNC( _char, true, RET(STRING), ARGS( ARG("char", INT) ), false, varray( ));
|
REGISTER_FUNC( _char, true, RET(STRING), ARGS( ARG("code", INT) ), false, varray( ));
|
||||||
|
REGISTER_FUNC( ord, true, RET(INT), ARGS( ARG("char", STRING) ), false, varray( ));
|
||||||
REGISTER_FUNC( range, false, RET(ARRAY), NOARGS, true, varray( ));
|
REGISTER_FUNC( range, false, RET(ARRAY), NOARGS, true, varray( ));
|
||||||
REGISTER_FUNC( load, false, RETCLS("Resource"), ARGS( ARG("path", STRING) ), false, varray( ));
|
REGISTER_FUNC( load, false, RETCLS("Resource"), ARGS( ARG("path", STRING) ), false, varray( ));
|
||||||
#ifndef DISABLE_DEPRECATED
|
#ifndef DISABLE_DEPRECATED
|
||||||
|
Loading…
x
Reference in New Issue
Block a user