summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/config.py1
-rw-r--r--modules/gdscript/doc_classes/@GDScript.xml1301
-rw-r--r--modules/gdscript/editor/gdscript_highlighter.cpp21
-rw-r--r--modules/gdscript/editor/gdscript_highlighter.h2
-rw-r--r--modules/gdscript/gdscript.cpp24
-rw-r--r--modules/gdscript/gdscript.h7
-rw-r--r--modules/gdscript/gdscript_compiler.cpp8
-rw-r--r--modules/gdscript/gdscript_editor.cpp16
-rw-r--r--modules/gdscript/gdscript_function.cpp62
-rw-r--r--modules/gdscript/gdscript_functions.cpp16
-rw-r--r--modules/gdscript/gdscript_functions.h1
-rw-r--r--modules/gdscript/gdscript_parser.cpp123
-rw-r--r--modules/gdscript/gdscript_parser.h2
-rw-r--r--modules/gdscript/gdscript_tokenizer.cpp27
14 files changed, 1520 insertions, 91 deletions
diff --git a/modules/gdscript/config.py b/modules/gdscript/config.py
index 95b40d90af..a525eedaaa 100644
--- a/modules/gdscript/config.py
+++ b/modules/gdscript/config.py
@@ -6,6 +6,7 @@ def configure(env):
def get_doc_classes():
return [
+ "@GDScript",
"GDScript",
"GDScriptFunctionState",
"GDScriptNativeClass",
diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml
new file mode 100644
index 0000000000..b6de5dbf62
--- /dev/null
+++ b/modules/gdscript/doc_classes/@GDScript.xml
@@ -0,0 +1,1301 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="@GDScript" category="Core" version="3.2">
+ <brief_description>
+ Built-in GDScript functions.
+ </brief_description>
+ <description>
+ List of core built-in GDScript functions. Math functions and other utilities. Everything else is provided by objects. (Keywords: builtin, built in, global functions.)
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ <method name="Color8">
+ <return type="Color">
+ </return>
+ <argument index="0" name="r8" type="int">
+ </argument>
+ <argument index="1" name="g8" type="int">
+ </argument>
+ <argument index="2" name="b8" type="int">
+ </argument>
+ <argument index="3" name="a8" type="int" default="255">
+ </argument>
+ <description>
+ Returns a 32 bit color with red, green, blue and alpha channels. Each channel has 8 bits of information ranging from 0 to 255.
+ [code]r8[/code] red channel
+ [code]g8[/code] green channel
+ [code]b8[/code] blue channel
+ [code]a8[/code] alpha channel
+ [codeblock]
+ red = Color8(255, 0, 0)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="ColorN">
+ <return type="Color">
+ </return>
+ <argument index="0" name="name" type="String">
+ </argument>
+ <argument index="1" name="alpha" type="float" default="1.0">
+ </argument>
+ <description>
+ Returns a color according to the standardised [code]name[/code] with [code]alpha[/code] ranging from 0 to 1.
+ [codeblock]
+ red = ColorN("red", 1)
+ [/codeblock]
+ Supported color names:
+ "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflower", "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen", "darkslateblue", "darkslategray", "darkturquoise", "darkviolet", "deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick", "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold", "goldenrod", "gray", "webgray", "green", "webgreen", "greenyellow", "honeydew", "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender", "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral", "lightcyan", "lightgoldenrod", "lightgray", "lightgreen", "lightpink", "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta", "maroon", "webmaroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise", "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", "navajowhite", "navyblue", "oldlace", "olive", "olivedrab", "orange", "orangered", "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue", "purple", "webpurple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", "snow", "springgreen", "steelblue", "tan", "teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white", "whitesmoke", "yellow", "yellowgreen".
+ </description>
+ </method>
+ <method name="abs">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns the absolute value of parameter [code]s[/code] (i.e. unsigned value, works for integer and float).
+ [codeblock]
+ # a is 1
+ a = abs(-1)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="acos">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns the arc cosine of [code]s[/code] in radians. Use to get the angle of cosine [code]s[/code].
+ [codeblock]
+ # c is 0.523599 or 30 degrees if converted with rad2deg(s)
+ c = acos(0.866025)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="asin">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns the arc sine of [code]s[/code] in radians. Use to get the angle of sine [code]s[/code].
+ [codeblock]
+ # s is 0.523599 or 30 degrees if converted with rad2deg(s)
+ s = asin(0.5)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="assert">
+ <return type="void">
+ </return>
+ <argument index="0" name="condition" type="bool">
+ </argument>
+ <description>
+ Asserts that the [code]condition[/code] is [code]true[/code] . If the [code]condition[/code] is [code]false[/code], an error is generated and the program is halted until you resume it. Only executes in debug builds, or when running the game from the editor. Use it for debugging purposes, to make sure a statement is [code]true[/code] during development.
+ [codeblock]
+ # Imagine we always want speed to be between 0 and 20
+ speed = -10
+ assert(speed &lt; 20) # True, the program will continue
+ assert(speed &gt;= 0) # False, the program will stop
+ assert(speed &gt;= 0 &amp;&amp; speed &lt; 20) # You can also combine the two conditional statements in one check
+ [/codeblock]
+ </description>
+ </method>
+ <method name="atan">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns the arc tangent of [code]s[/code] in radians. Use it to get the angle from an angle's tangent in trigonometry: [code]atan(tan(angle)) == angle[/code].
+ The method cannot know in which quadrant the angle should fall. See [method atan2] if you always want an exact angle.
+ [codeblock]
+ a = atan(0.5) # a is 0.463648
+ [/codeblock]
+ </description>
+ </method>
+ <method name="atan2">
+ <return type="float">
+ </return>
+ <argument index="0" name="y" type="float">
+ </argument>
+ <argument index="1" name="x" type="float">
+ </argument>
+ <description>
+ Returns the arc tangent of [code]y/x[/code] in radians. Use to get the angle of tangent [code]y/x[/code]. To compute the value, the method takes into account the sign of both arguments in order to determine the quadrant.
+ [codeblock]
+ a = atan2(0, -1) # a is 3.141593
+ [/codeblock]
+ </description>
+ </method>
+ <method name="bytes2var">
+ <return type="Variant">
+ </return>
+ <argument index="0" name="bytes" type="PoolByteArray">
+ </argument>
+ <argument index="1" name="allow_objects" type="bool" default="false">
+ </argument>
+ <description>
+ Decodes a byte array back to a value. When [code]allow_objects[/code] is [code]true[/code] decoding objects is allowed.
+ [b]WARNING:[/b] Deserialized object can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threats (remote code execution).
+ </description>
+ </method>
+ <method name="cartesian2polar">
+ <return type="Vector2">
+ </return>
+ <argument index="0" name="x" type="float">
+ </argument>
+ <argument index="1" name="y" type="float">
+ </argument>
+ <description>
+ Converts a 2D point expressed in the cartesian coordinate system (x and y axis) to the polar coordinate system (a distance from the origin and an angle).
+ </description>
+ </method>
+ <method name="ceil">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Rounds [code]s[/code] upward, returning the smallest integral value that is not less than [code]s[/code].
+ [codeblock]
+ i = ceil(1.45) # i is 2
+ i = ceil(1.001) # i is 2
+ [/codeblock]
+ </description>
+ </method>
+ <method name="char">
+ <return type="String">
+ </return>
+ <argument index="0" name="ascii" type="int">
+ </argument>
+ <description>
+ Returns a character as a String of the given ASCII code.
+ [codeblock]
+ # a is 'A'
+ a = char(65)
+ # a is 'a'
+ a = char(65 + 32)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="clamp">
+ <return type="float">
+ </return>
+ <argument index="0" name="value" type="float">
+ </argument>
+ <argument index="1" name="min" type="float">
+ </argument>
+ <argument index="2" name="max" type="float">
+ </argument>
+ <description>
+ Clamps [code]value[/code] and returns a value not less than [code]min[/code] and not more than [code]max[/code].
+ [codeblock]
+ speed = 1000
+ # a is 20
+ a = clamp(speed, 1, 20)
+
+ speed = -10
+ # a is 1
+ a = clamp(speed, 1, 20)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="convert">
+ <return type="Variant">
+ </return>
+ <argument index="0" name="what" type="Variant">
+ </argument>
+ <argument index="1" name="type" type="int">
+ </argument>
+ <description>
+ Converts from a type to another in the best way possible. The [code]type[/code] parameter uses the enum TYPE_* in [@GlobalScope].
+ [codeblock]
+ a = Vector2(1, 0)
+ # prints 1
+ print(a.length())
+ a = convert(a, TYPE_STRING)
+ # prints 6
+ # (1, 0) is 6 characters
+ print(a.length())
+ [/codeblock]
+ </description>
+ </method>
+ <method name="cos">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns the cosine of angle [code]s[/code] in radians.
+ [codeblock]
+ # prints 1 and -1
+ print(cos(PI * 2))
+ print(cos(PI))
+ [/codeblock]
+ </description>
+ </method>
+ <method name="cosh">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns the hyperbolic cosine of [code]s[/code] in radians.
+ [codeblock]
+ # prints 1.543081
+ print(cosh(1))
+ [/codeblock]
+ </description>
+ </method>
+ <method name="db2linear">
+ <return type="float">
+ </return>
+ <argument index="0" name="db" type="float">
+ </argument>
+ <description>
+ Converts from decibels to linear energy (audio).
+ </description>
+ </method>
+ <method name="decimals">
+ <return type="int">
+ </return>
+ <argument index="0" name="step" type="float">
+ </argument>
+ <description>
+ Deprecated alias for "[method step_decimals]".
+ </description>
+ </method>
+ <method name="dectime">
+ <return type="float">
+ </return>
+ <argument index="0" name="value" type="float">
+ </argument>
+ <argument index="1" name="amount" type="float">
+ </argument>
+ <argument index="2" name="step" type="float">
+ </argument>
+ <description>
+ Returns the result of [code]value[/code] decreased by [code]step[/code] * [code]amount[/code].
+ [codeblock]
+ # a = 59
+ a = dectime(60, 10, 0.1))
+ [/codeblock]
+ </description>
+ </method>
+ <method name="deg2rad">
+ <return type="float">
+ </return>
+ <argument index="0" name="deg" type="float">
+ </argument>
+ <description>
+ Returns degrees converted to radians.
+ [codeblock]
+ # r is 3.141593
+ r = deg2rad(180)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="dict2inst">
+ <return type="Object">
+ </return>
+ <argument index="0" name="dict" type="Dictionary">
+ </argument>
+ <description>
+ Converts a previously converted instance to a dictionary, back into an instance. Useful for deserializing.
+ </description>
+ </method>
+ <method name="ease">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <argument index="1" name="curve" type="float">
+ </argument>
+ <description>
+ Easing function, based on exponent. 0 is constant, 1 is linear, 0 to 1 is ease-in, 1+ is ease out. Negative values are in-out/out in.
+ </description>
+ </method>
+ <method name="exp">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ The natural exponential function. It raises the mathematical constant [b]e[/b] to the power of [code]s[/code] and returns it.
+ [b]e[/b] has an approximate value of 2.71828.
+ [codeblock]
+ a = exp(2) # approximately 7.39
+ [/codeblock]
+ </description>
+ </method>
+ <method name="floor">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Rounds [code]s[/code] to the closest smaller integer and returns it.
+ [codeblock]
+ # a is 2
+ a = floor(2.99)
+ # a is -3
+ a = floor(-2.99)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="fmod">
+ <return type="float">
+ </return>
+ <argument index="0" name="x" type="float">
+ </argument>
+ <argument index="1" name="y" type="float">
+ </argument>
+ <description>
+ Returns the floating-point remainder of [code]x/y[/code].
+ [codeblock]
+ # remainder is 1.5
+ var remainder = fmod(7, 5.5)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="fposmod">
+ <return type="float">
+ </return>
+ <argument index="0" name="x" type="float">
+ </argument>
+ <argument index="1" name="y" type="float">
+ </argument>
+ <description>
+ Returns the floating-point remainder of [code]x/y[/code] that wraps equally in positive and negative.
+ [codeblock]
+ var i = -10
+ while i &lt; 0:
+ prints(i, fposmod(i, 10))
+ i += 1
+ [/codeblock]
+ Produces:
+ [codeblock]
+ -10 10
+ -9 1
+ -8 2
+ -7 3
+ -6 4
+ -5 5
+ -4 6
+ -3 7
+ -2 8
+ -1 9
+ [/codeblock]
+ </description>
+ </method>
+ <method name="funcref">
+ <return type="FuncRef">
+ </return>
+ <argument index="0" name="instance" type="Object">
+ </argument>
+ <argument index="1" name="funcname" type="String">
+ </argument>
+ <description>
+ Returns a reference to the specified function [code]funcname[/code] in the [code]instance[/code] node. As functions aren't first-class objects in GDscript, use [code]funcref[/code] to store a [FuncRef] in a variable and call it later.
+ [codeblock]
+ func foo():
+ return("bar")
+
+ a = funcref(self, "foo")
+ print(a.call_func()) # prints bar
+ [/codeblock]
+ </description>
+ </method>
+ <method name="get_stack">
+ <return type="Array">
+ </return>
+ <description>
+ Returns an array of dictionaries representing the current call stack.
+ [codeblock]
+ func _ready():
+ foo()
+
+ func foo():
+ bar()
+
+ func bar():
+ print(get_stack())
+ [/codeblock]
+ would print
+ [codeblock]
+ [{function:bar, line:12, source:res://script.gd}, {function:foo, line:9, source:res://script.gd}, {function:_ready, line:6, source:res://script.gd}]
+ [/codeblock]
+ </description>
+ </method>
+ <method name="hash">
+ <return type="int">
+ </return>
+ <argument index="0" name="var" type="Variant">
+ </argument>
+ <description>
+ Returns the integer hash of the variable passed.
+ [codeblock]
+ print(hash("a")) # prints 177670
+ [/codeblock]
+ </description>
+ </method>
+ <method name="inst2dict">
+ <return type="Dictionary">
+ </return>
+ <argument index="0" name="inst" type="Object">
+ </argument>
+ <description>
+ Returns the passed instance converted to a dictionary (useful for serializing).
+ [codeblock]
+ var foo = "bar"
+ func _ready():
+ var d = inst2dict(self)
+ print(d.keys())
+ print(d.values())
+ [/codeblock]
+ Prints out:
+ [codeblock]
+ [@subpath, @path, foo]
+ [, res://test.gd, bar]
+ [/codeblock]
+ </description>
+ </method>
+ <method name="instance_from_id">
+ <return type="Object">
+ </return>
+ <argument index="0" name="instance_id" type="int">
+ </argument>
+ <description>
+ Returns the Object that corresponds to [code]instance_id[/code]. All Objects have a unique instance ID.
+ [codeblock]
+ var foo = "bar"
+ func _ready():
+ var id = get_instance_id()
+ var inst = instance_from_id(id)
+ print(inst.foo) # prints bar
+ [/codeblock]
+ </description>
+ </method>
+ <method name="inverse_lerp">
+ <return type="float">
+ </return>
+ <argument index="0" name="from" type="float">
+ </argument>
+ <argument index="1" name="to" type="float">
+ </argument>
+ <argument index="2" name="weight" type="float">
+ </argument>
+ <description>
+ Returns a normalized value considering the given range.
+ [codeblock]
+ inverse_lerp(3, 5, 4) # returns 0.5
+ [/codeblock]
+ </description>
+ </method>
+ <method name="is_equal_approx">
+ <return type="bool">
+ </return>
+ <argument index="0" name="a" type="float">
+ </argument>
+ <argument index="1" name="b" type="float">
+ </argument>
+ <description>
+ Returns True/False whether [code]a[/code] and [code]b[/code] are approximately equal to each other.
+ </description>
+ </method>
+ <method name="is_inf">
+ <return type="bool">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns whether [code]s[/code] is an infinity value (either positive infinity or negative infinity).
+ </description>
+ </method>
+ <method name="is_instance_valid">
+ <return type="bool">
+ </return>
+ <argument index="0" name="instance" type="Object">
+ </argument>
+ <description>
+ Returns whether [code]instance[/code] is a valid object (e.g. has not been deleted from memory).
+ </description>
+ </method>
+ <method name="is_nan">
+ <return type="bool">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns whether [code]s[/code] is a NaN (Not-A-Number) value.
+ </description>
+ </method>
+ <method name="is_zero_approx">
+ <return type="bool">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns True/False whether [code]s[/code] is zero or almost zero.
+ </description>
+ </method>
+ <method name="len">
+ <return type="int">
+ </return>
+ <argument index="0" name="var" type="Variant">
+ </argument>
+ <description>
+ Returns length of Variant [code]var[/code]. Length is the character count of String, element count of Array, size of Dictionary, etc.
+ [b]Note:[/b] Generates a fatal error if Variant can not provide a length.
+ [codeblock]
+ a = [1, 2, 3, 4]
+ len(a) # returns 4
+ [/codeblock]
+ </description>
+ </method>
+ <method name="lerp">
+ <return type="Variant">
+ </return>
+ <argument index="0" name="from" type="Variant">
+ </argument>
+ <argument index="1" name="to" type="Variant">
+ </argument>
+ <argument index="2" name="weight" type="float">
+ </argument>
+ <description>
+ Linearly interpolates between two values by a normalized value.
+ If the [code]from[/code] and [code]to[/code] arguments are of type [int] or [float], the return value is a [float].
+ If both are of the same vector type ([Vector2], [Vector3] or [Color]), the return value will be of the same type ([code]lerp[/code] then calls the vector type's [code]linear_interpolate[/code] method).
+ [codeblock]
+ lerp(0, 4, 0.75) # returns 3.0
+ lerp(Vector2(1, 5), Vector2(3, 2), 0.5) # returns Vector2(2, 3.5)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="linear2db">
+ <return type="float">
+ </return>
+ <argument index="0" name="nrg" type="float">
+ </argument>
+ <description>
+ Converts from linear energy to decibels (audio).
+ </description>
+ </method>
+ <method name="load">
+ <return type="Resource">
+ </return>
+ <argument index="0" name="path" type="String">
+ </argument>
+ <description>
+ Loads a resource from the filesystem located at [code]path[/code].
+ [b]Note:[/b] Resource paths can be obtained by right clicking on a resource in the Assets Panel and choosing "Copy Path".
+ [codeblock]
+ # load a scene called main located in the root of the project directory
+ var main = load("res://main.tscn")
+ [/codeblock]
+ </description>
+ </method>
+ <method name="log">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Natural logarithm. The amount of time needed to reach a certain level of continuous growth.
+ [b]Note:[/b] This is not the same as the log function on your calculator which is a base 10 logarithm.
+ [codeblock]
+ log(10) # returns 2.302585
+ [/codeblock]
+ </description>
+ </method>
+ <method name="max">
+ <return type="float">
+ </return>
+ <argument index="0" name="a" type="float">
+ </argument>
+ <argument index="1" name="b" type="float">
+ </argument>
+ <description>
+ Returns the maximum of two values.
+ [codeblock]
+ max(1, 2) # returns 2
+ max(-3.99, -4) # returns -3.99
+ [/codeblock]
+ </description>
+ </method>
+ <method name="min">
+ <return type="float">
+ </return>
+ <argument index="0" name="a" type="float">
+ </argument>
+ <argument index="1" name="b" type="float">
+ </argument>
+ <description>
+ Returns the minimum of two values.
+ [codeblock]
+ min(1, 2) # returns 1
+ min(-3.99, -4) # returns -4
+ [/codeblock]
+ </description>
+ </method>
+ <method name="move_toward">
+ <return type="float">
+ </return>
+ <argument index="0" name="from" type="float">
+ </argument>
+ <argument index="1" name="to" type="float">
+ </argument>
+ <argument index="2" name="delta" type="float">
+ </argument>
+ <description>
+ Moves [code]from[/code] toward [code]to[/code] by the [code]delta[/code] value.
+ Use a negative [code]delta[/code] value to move away.
+ [codeblock]
+ move_toward(10, 5, 4) # returns 6
+ [/codeblock]
+ </description>
+ </method>
+ <method name="nearest_po2">
+ <return type="int">
+ </return>
+ <argument index="0" name="value" type="int">
+ </argument>
+ <description>
+ Returns the nearest larger power of 2 for integer [code]value[/code].
+ [codeblock]
+ nearest_po2(3) # returns 4
+ nearest_po2(4) # returns 4
+ nearest_po2(5) # returns 8
+ [/codeblock]
+ </description>
+ </method>
+ <method name="parse_json">
+ <return type="Variant">
+ </return>
+ <argument index="0" name="json" type="String">
+ </argument>
+ <description>
+ Parse JSON text to a Variant (use [method typeof] to check if it is what you expect).
+ Be aware that the JSON specification does not define integer or float types, but only a number type. Therefore, parsing a JSON text will convert all numerical values to [float] types.
+ Note that JSON objects do not preserve key order like Godot dictionaries, thus you should not rely on keys being in a certain order if a dictionary is constructed from JSON. In contrast, JSON arrays retain the order of their elements:
+ [codeblock]
+ p = parse_json('["a", "b", "c"]')
+ if typeof(p) == TYPE_ARRAY:
+ print(p[0]) # prints a
+ else:
+ print("unexpected results")
+ [/codeblock]
+ </description>
+ </method>
+ <method name="polar2cartesian">
+ <return type="Vector2">
+ </return>
+ <argument index="0" name="r" type="float">
+ </argument>
+ <argument index="1" name="th" type="float">
+ </argument>
+ <description>
+ Converts a 2D point expressed in the polar coordinate system (a distance from the origin [code]r[/code] and an angle [code]th[/code]) to the cartesian coordinate system (x and y axis).
+ </description>
+ </method>
+ <method name="pow">
+ <return type="float">
+ </return>
+ <argument index="0" name="x" type="float">
+ </argument>
+ <argument index="1" name="y" type="float">
+ </argument>
+ <description>
+ Returns the result of [code]x[/code] raised to the power of [code]y[/code].
+ [codeblock]
+ pow(2, 5) # returns 32
+ [/codeblock]
+ </description>
+ </method>
+ <method name="preload">
+ <return type="Resource">
+ </return>
+ <argument index="0" name="path" type="String">
+ </argument>
+ <description>
+ Returns a resource from the filesystem that is loaded during script parsing.
+ [b]Note:[/b] Resource paths can be obtained by right clicking on a resource in the Assets Panel and choosing "Copy Path".
+ [codeblock]
+ # load a scene called main located in the root of the project directory
+ var main = preload("res://main.tscn")
+ [/codeblock]
+ </description>
+ </method>
+ <method name="print" qualifiers="vararg">
+ <return type="void">
+ </return>
+ <description>
+ Converts one or more arguments to strings in the best way possible and prints them to the console.
+ [codeblock]
+ a = [1, 2, 3]
+ print("a", "b", a) # prints ab[1, 2, 3]
+ [/codeblock]
+ </description>
+ </method>
+ <method name="print_debug" qualifiers="vararg">
+ <return type="void">
+ </return>
+ <description>
+ Like [method print], but prints only when used in debug mode.
+ </description>
+ </method>
+ <method name="print_stack">
+ <return type="void">
+ </return>
+ <description>
+ Prints a stack track at code location, only works when running with debugger turned on.
+ Output in the console would look something like this:
+ [codeblock]
+ Frame 0 - res://test.gd:16 in function '_process'
+ [/codeblock]
+ </description>
+ </method>
+ <method name="printerr" qualifiers="vararg">
+ <return type="void">
+ </return>
+ <description>
+ Prints one or more arguments to strings in the best way possible to standard error line.
+ [codeblock]
+ printerr("prints to stderr")
+ [/codeblock]
+ </description>
+ </method>
+ <method name="printraw" qualifiers="vararg">
+ <return type="void">
+ </return>
+ <description>
+ Prints one or more arguments to strings in the best way possible to console. No newline is added at the end.
+ [codeblock]
+ printraw("A")
+ printraw("B")
+ # prints AB
+ [/codeblock]
+ </description>
+ </method>
+ <method name="prints" qualifiers="vararg">
+ <return type="void">
+ </return>
+ <description>
+ Prints one or more arguments to the console with a space between each argument.
+ [codeblock]
+ prints("A", "B", "C") # prints A B C
+ [/codeblock]
+ </description>
+ </method>
+ <method name="printt" qualifiers="vararg">
+ <return type="void">
+ </return>
+ <description>
+ Prints one or more arguments to the console with a tab between each argument.
+ [codeblock]
+ printt("A", "B", "C") # prints A B C
+ [/codeblock]
+ </description>
+ </method>
+ <method name="push_error">
+ <return type="void">
+ </return>
+ <argument index="0" name="message" type="String">
+ </argument>
+ <description>
+ Pushes an error message to Godot's built-in debugger and to the OS terminal.
+ [codeblock]
+ push_error("test error") # prints "test error" to debugger and terminal as error call
+ [/codeblock]
+ </description>
+ </method>
+ <method name="push_warning">
+ <return type="void">
+ </return>
+ <argument index="0" name="message" type="String">
+ </argument>
+ <description>
+ Pushes a warning message to Godot's built-in debugger and to the OS terminal.
+ [codeblock]
+ push_warning("test warning") # prints "test warning" to debugger and terminal as warning call
+ [/codeblock]
+ </description>
+ </method>
+ <method name="rad2deg">
+ <return type="float">
+ </return>
+ <argument index="0" name="rad" type="float">
+ </argument>
+ <description>
+ Converts from radians to degrees.
+ [codeblock]
+ rad2deg(0.523599) # returns 30
+ [/codeblock]
+ </description>
+ </method>
+ <method name="rand_range">
+ <return type="float">
+ </return>
+ <argument index="0" name="from" type="float">
+ </argument>
+ <argument index="1" name="to" type="float">
+ </argument>
+ <description>
+ Random range, any floating point value between [code]from[/code] and [code]to[/code].
+ [codeblock]
+ prints(rand_range(0, 1), rand_range(0, 1)) # prints e.g. 0.135591 0.405263
+ [/codeblock]
+ </description>
+ </method>
+ <method name="rand_seed">
+ <return type="Array">
+ </return>
+ <argument index="0" name="seed" type="int">
+ </argument>
+ <description>
+ Random from seed: pass a [code]seed[/code], and an array with both number and new seed is returned. "Seed" here refers to the internal state of the pseudo random number generator. The internal state of the current implementation is 64 bits.
+ </description>
+ </method>
+ <method name="randf">
+ <return type="float">
+ </return>
+ <description>
+ Returns a random floating point value on the interval [code][0, 1][/code].
+ [codeblock]
+ randf() # returns e.g. 0.375671
+ [/codeblock]
+ </description>
+ </method>
+ <method name="randi">
+ <return type="int">
+ </return>
+ <description>
+ Returns a random unsigned 32 bit integer. Use remainder to obtain a random value in the interval [code][0, N][/code] (where N is smaller than 2^32 -1).
+ [codeblock]
+ randi() # returns random integer between 0 and 2^32 - 1
+ randi() % 20 # returns random integer between 0 and 19
+ randi() % 100 # returns random integer between 0 and 99
+ randi() % 100 + 1 # returns random integer between 1 and 100
+ [/codeblock]
+ </description>
+ </method>
+ <method name="randomize">
+ <return type="void">
+ </return>
+ <description>
+ Randomizes the seed (or the internal state) of the random number generator. Current implementation reseeds using a number based on time.
+ [codeblock]
+ func _ready():
+ randomize()
+ [/codeblock]
+ </description>
+ </method>
+ <method name="range" qualifiers="vararg">
+ <return type="Array">
+ </return>
+ <description>
+ Returns an array with the given range. Range can be 1 argument N (0 to N-1), two arguments (initial, final-1) or three arguments (initial, final-1, increment).
+ [codeblock]
+ for i in range(4):
+ print(i)
+ for i in range(2, 5):
+ print(i)
+ for i in range(0, 6, 2):
+ print(i)
+ [/codeblock]
+ Output:
+ [codeblock]
+ 0
+ 1
+ 2
+ 3
+
+ 2
+ 3
+ 4
+
+ 0
+ 2
+ 4
+ [/codeblock]
+ </description>
+ </method>
+ <method name="range_lerp">
+ <return type="float">
+ </return>
+ <argument index="0" name="value" type="float">
+ </argument>
+ <argument index="1" name="istart" type="float">
+ </argument>
+ <argument index="2" name="istop" type="float">
+ </argument>
+ <argument index="3" name="ostart" type="float">
+ </argument>
+ <argument index="4" name="ostop" type="float">
+ </argument>
+ <description>
+ Maps a [code]value[/code] from range [code][istart, istop][/code] to [code][ostart, ostop][/code].
+ [codeblock]
+ range_lerp(75, 0, 100, -1, 1) # returns 0.5
+ [/codeblock]
+ </description>
+ </method>
+ <method name="round">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns the integral value that is nearest to [code]s[/code], with halfway cases rounded away from zero.
+ [codeblock]
+ round(2.6) # returns 3
+ [/codeblock]
+ </description>
+ </method>
+ <method name="seed">
+ <return type="void">
+ </return>
+ <argument index="0" name="seed" type="int">
+ </argument>
+ <description>
+ Sets seed for the random number generator.
+ [codeblock]
+ my_seed = "Godot Rocks"
+ seed(my_seed.hash())
+ [/codeblock]
+ </description>
+ </method>
+ <method name="sign">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns the sign of [code]s[/code]: -1 or 1. Returns 0 if [code]s[/code] is 0.
+ [codeblock]
+ sign(-6) # returns -1
+ sign(0) # returns 0
+ sign(6) # returns 1
+ [/codeblock]
+ </description>
+ </method>
+ <method name="sin">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns the sine of angle [code]s[/code] in radians.
+ [codeblock]
+ sin(0.523599) # returns 0.5
+ [/codeblock]
+ </description>
+ </method>
+ <method name="sinh">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns the hyperbolic sine of [code]s[/code].
+ [codeblock]
+ a = log(2.0) # returns 0.693147
+ sinh(a) # returns 0.75
+ [/codeblock]
+ </description>
+ </method>
+ <method name="smoothstep">
+ <return type="float">
+ </return>
+ <argument index="0" name="from" type="float">
+ </argument>
+ <argument index="1" name="to" type="float">
+ </argument>
+ <argument index="2" name="weight" type="float">
+ </argument>
+ <description>
+ Returns a number smoothly interpolated between the [code]from[/code] and [code]to[/code], based on the [code]weight[/code]. Similar to [method lerp], but interpolates faster at the beginning and slower at the end.
+ [codeblock]
+ smoothstep(0, 2, 0.5) # returns 0.15
+ smoothstep(0, 2, 1.0) # returns 0.5
+ smoothstep(0, 2, 2.0) # returns 1.0
+ [/codeblock]
+ </description>
+ </method>
+ <method name="sqrt">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns the square root of [code]s[/code].
+ [codeblock]
+ sqrt(9) # returns 3
+ [/codeblock]
+ </description>
+ </method>
+ <method name="step_decimals">
+ <return type="int">
+ </return>
+ <argument index="0" name="step" type="float">
+ </argument>
+ <description>
+ Returns the position of the first non-zero digit, after the decimal point.
+ [codeblock]
+ # n is 0
+ n = step_decimals(5)
+ # n is 4
+ n = step_decimals(1.0005)
+ # n is 9
+ n = step_decimals(0.000000005)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="stepify">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <argument index="1" name="step" type="float">
+ </argument>
+ <description>
+ Snaps float value [code]s[/code] to a given [code]step[/code].
+ </description>
+ </method>
+ <method name="str" qualifiers="vararg">
+ <return type="String">
+ </return>
+ <description>
+ Converts one or more arguments to string in the best way possible.
+ [codeblock]
+ var a = [10, 20, 30]
+ var b = str(a);
+ len(a) # returns 3
+ len(b) # returns 12
+ [/codeblock]
+ </description>
+ </method>
+ <method name="str2var">
+ <return type="Variant">
+ </return>
+ <argument index="0" name="string" type="String">
+ </argument>
+ <description>
+ Converts a formatted string that was returned by [method var2str] to the original value.
+ [codeblock]
+ a = '{ "a": 1, "b": 2 }'
+ b = str2var(a)
+ print(b['a']) # prints 1
+ [/codeblock]
+ </description>
+ </method>
+ <method name="tan">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns the tangent of angle [code]s[/code] in radians.
+ [codeblock]
+ tan(deg2rad(45)) # returns 1
+ [/codeblock]
+ </description>
+ </method>
+ <method name="tanh">
+ <return type="float">
+ </return>
+ <argument index="0" name="s" type="float">
+ </argument>
+ <description>
+ Returns the hyperbolic tangent of [code]s[/code].
+ [codeblock]
+ a = log(2.0) # returns 0.693147
+ tanh(a) # returns 0.6
+ [/codeblock]
+ </description>
+ </method>
+ <method name="to_json">
+ <return type="String">
+ </return>
+ <argument index="0" name="var" type="Variant">
+ </argument>
+ <description>
+ Converts a Variant [code]var[/code] to JSON text and return the result. Useful for serializing data to store or send over the network.
+ [codeblock]
+ a = { 'a': 1, 'b': 2 }
+ b = to_json(a)
+ print(b) # {"a":1, "b":2}
+ [/codeblock]
+ </description>
+ </method>
+ <method name="type_exists">
+ <return type="bool">
+ </return>
+ <argument index="0" name="type" type="String">
+ </argument>
+ <description>
+ Returns whether the given class exists in [ClassDB].
+ [codeblock]
+ type_exists("Sprite") # returns true
+ type_exists("Variant") # returns false
+ [/codeblock]
+ </description>
+ </method>
+ <method name="typeof">
+ <return type="int">
+ </return>
+ <argument index="0" name="what" type="Variant">
+ </argument>
+ <description>
+ Returns the internal type of the given Variant object, using the TYPE_* enum in [@GlobalScope].
+ [codeblock]
+ p = parse_json('["a", "b", "c"]')
+ if typeof(p) == TYPE_ARRAY:
+ print(p[0]) # prints a
+ else:
+ print("unexpected results")
+ [/codeblock]
+ </description>
+ </method>
+ <method name="validate_json">
+ <return type="String">
+ </return>
+ <argument index="0" name="json" type="String">
+ </argument>
+ <description>
+ Checks that [code]json[/code] is valid JSON data. Returns empty string if valid. Returns error message if not valid.
+ [codeblock]
+ j = to_json([1, 2, 3])
+ v = validate_json(j)
+ if not v:
+ print("valid")
+ else:
+ prints("invalid", v)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="var2bytes">
+ <return type="PoolByteArray">
+ </return>
+ <argument index="0" name="var" type="Variant">
+ </argument>
+ <argument index="1" name="full_objects" type="bool" default="false">
+ </argument>
+ <description>
+ Encodes a variable value to a byte array. When [code]full_objects[/code] is [code]true[/code] encoding objects is allowed (and can potentially include code).
+ </description>
+ </method>
+ <method name="var2str">
+ <return type="String">
+ </return>
+ <argument index="0" name="var" type="Variant">
+ </argument>
+ <description>
+ Converts a Variant [code]var[/code] to a formatted string that can later be parsed using [method str2var].
+ [codeblock]
+ a = { 'a': 1, 'b': 2 }
+ print(var2str(a))
+ [/codeblock]
+ prints
+ [codeblock]
+ {
+ "a": 1,
+ "b": 2
+ }
+ [/codeblock]
+ </description>
+ </method>
+ <method name="weakref">
+ <return type="WeakRef">
+ </return>
+ <argument index="0" name="obj" type="Object">
+ </argument>
+ <description>
+ Returns a weak reference to an object.
+ A weak reference to an object is not enough to keep the object alive: when the only remaining references to a referent are weak references, garbage collection is free to destroy the referent and reuse its memory for something else. However, until the object is actually destroyed the weak reference may return the object even if there are no strong references to it.
+ </description>
+ </method>
+ <method name="wrapf">
+ <return type="float">
+ </return>
+ <argument index="0" name="value" type="float">
+ </argument>
+ <argument index="1" name="min" type="float">
+ </argument>
+ <argument index="2" name="max" type="float">
+ </argument>
+ <description>
+ Wraps float [code]value[/code] between [code]min[/code] and [code]max[/code].
+ Usable for creating loop-alike behavior or infinite surfaces.
+ [codeblock]
+ # a is 0.5
+ a = wrapf(10.5, 0.0, 10.0)
+ [/codeblock]
+ [codeblock]
+ # a is 9.5
+ a = wrapf(-0.5, 0.0, 10.0)
+ [/codeblock]
+ [codeblock]
+ # infinite loop between 0.0 and 0.99
+ f = wrapf(f + 0.1, 0.0, 1.0)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="wrapi">
+ <return type="int">
+ </return>
+ <argument index="0" name="value" type="int">
+ </argument>
+ <argument index="1" name="min" type="int">
+ </argument>
+ <argument index="2" name="max" type="int">
+ </argument>
+ <description>
+ Wraps integer [code]value[/code] between [code]min[/code] and [code]max[/code].
+ Usable for creating loop-alike behavior or infinite surfaces.
+ [codeblock]
+ # a is 0
+ a = wrapi(10, 0, 10)
+ [/codeblock]
+ [codeblock]
+ # a is 9
+ a = wrapi(-1, 0, 10)
+ [/codeblock]
+ [codeblock]
+ # infinite loop between 0 and 9
+ frame = wrapi(frame + 1, 0, 10)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="yield">
+ <return type="GDScriptFunctionState">
+ </return>
+ <argument index="0" name="object" type="Object" default="null">
+ </argument>
+ <argument index="1" name="signal" type="String" default="&quot;&quot;">
+ </argument>
+ <description>
+ Stops the function execution and returns the current suspended state to the calling function.
+ From the caller, call [method GDScriptFunctionState.resume] on the state to resume execution. This invalidates the state. Within the resumed function, [code]yield()[/code] returns whatever was passed to the [code]resume()[/code] function call.
+ If passed an object and a signal, the execution is resumed when the object emits the given signal. In this case, [code]yield()[/code] returns the argument passed to [code]emit_signal()[/code] if the signal takes only one argument, or an array containing all the arguments passed to [code]emit_signal()[/code] if the signal takes multiple arguments.
+ </description>
+ </method>
+ </methods>
+ <constants>
+ <constant name="PI" value="3.141593">
+ Constant that represents how many times the diameter of a circle fits around its perimeter.
+ </constant>
+ <constant name="TAU" value="6.283185">
+ The circle constant, the circumference of the unit circle.
+ </constant>
+ <constant name="INF" value="inf">
+ A positive infinity. (For negative infinity, use -INF).
+ </constant>
+ <constant name="NAN" value="nan">
+ Macro constant that expands to an expression of type float that represents a NaN.
+ The NaN values are used to identify undefined or non-representable values for floating-point elements, such as the square root of negative numbers or the result of 0/0.
+ </constant>
+ </constants>
+</class>
diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp
index 4f59b06ae6..62b65fe96b 100644
--- a/modules/gdscript/editor/gdscript_highlighter.cpp
+++ b/modules/gdscript/editor/gdscript_highlighter.cpp
@@ -56,6 +56,10 @@ static bool _is_hex_symbol(CharType c) {
return ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
}
+static bool _is_bin_symbol(CharType c) {
+ return (c == '0' || c == '1');
+}
+
Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) {
Map<int, TextEdit::HighlighterInfo> color_map;
@@ -76,6 +80,7 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_
bool in_member_variable = false;
bool in_node_path = false;
bool is_hex_notation = false;
+ bool is_bin_notation = false;
bool expect_type = false;
Color keyword_color;
Color color;
@@ -118,14 +123,26 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_
is_hex_notation = false;
}
+ // disallow anything not a 0 or 1
+ if (is_bin_notation && (_is_bin_symbol(str[j]))) {
+ is_number = true;
+ } else if (is_bin_notation) {
+ is_bin_notation = false;
+ is_number = false;
+ } else {
+ is_bin_notation = false;
+ }
+
// check for dot or underscore or 'x' for hex notation in floating point number or 'e' for scientific notation
- if ((str[j] == '.' || str[j] == 'x' || str[j] == '_' || str[j] == 'e') && !in_word && prev_is_number && !is_number) {
+ if ((str[j] == '.' || str[j] == 'x' || str[j] == 'b' || str[j] == '_' || str[j] == 'e') && !in_word && prev_is_number && !is_number) {
is_number = true;
is_symbol = false;
is_char = false;
if (str[j] == 'x' && str[j - 1] == '0') {
is_hex_notation = true;
+ } else if (str[j] == 'b' && str[j - 1] == '0') {
+ is_bin_notation = true;
}
}
@@ -330,7 +347,7 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_
return color_map;
}
-String GDScriptSyntaxHighlighter::get_name() {
+String GDScriptSyntaxHighlighter::get_name() const {
return "GDScript";
}
diff --git a/modules/gdscript/editor/gdscript_highlighter.h b/modules/gdscript/editor/gdscript_highlighter.h
index 9dc10a5d1b..9ba2c80552 100644
--- a/modules/gdscript/editor/gdscript_highlighter.h
+++ b/modules/gdscript/editor/gdscript_highlighter.h
@@ -65,7 +65,7 @@ public:
virtual void _update_cache();
virtual Map<int, TextEdit::HighlighterInfo> _get_line_syntax_highlighting(int p_line);
- virtual String get_name();
+ virtual String get_name() const;
virtual List<String> get_supported_languages();
};
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index 33e99cb82f..3fb9268702 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -30,6 +30,7 @@
#include "gdscript.h"
+#include "core/core_string_names.h"
#include "core/engine.h"
#include "core/global_constants.h"
#include "core/io/file_access_encrypted.h"
@@ -1064,7 +1065,7 @@ Variant::Type GDScriptInstance::get_property_type(const StringName &p_name, bool
}
void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
- // exported members, not doen yet!
+ // exported members, not done yet!
const GDScript *sptr = script.ptr();
List<PropertyInfo> props;
@@ -1234,6 +1235,27 @@ void GDScriptInstance::notification(int p_notification) {
}
}
+String GDScriptInstance::to_string(bool *r_valid) {
+ if (has_method(CoreStringNames::get_singleton()->_to_string)) {
+ Variant::CallError ce;
+ Variant ret = call(CoreStringNames::get_singleton()->_to_string, NULL, 0, ce);
+ if (ce.error == Variant::CallError::CALL_OK) {
+ if (ret.get_type() != Variant::STRING) {
+ if (r_valid)
+ *r_valid = false;
+ ERR_EXPLAIN("Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String.");
+ ERR_FAIL_V(String());
+ }
+ if (r_valid)
+ *r_valid = true;
+ return ret.operator String();
+ }
+ }
+ if (r_valid)
+ *r_valid = false;
+ return String();
+}
+
Ref<Script> GDScriptInstance::get_script() const {
return script;
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index 38009b878d..1756f6eabc 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -251,6 +251,7 @@ public:
Variant debug_get_member_by_index(int p_idx) const { return members[p_idx]; }
virtual void notification(int p_notification);
+ String to_string(bool *r_valid);
virtual Ref<Script> get_script() const;
@@ -457,9 +458,9 @@ public:
virtual bool can_inherit_from_file() { return true; }
virtual int find_function(const String &p_function, const String &p_code) const;
virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const;
- virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, bool &r_forced, String &r_call_hint);
+ virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<String> *r_options, bool &r_forced, String &r_call_hint);
#ifdef TOOLS_ENABLED
- virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_base_path, Object *p_owner, LookupResult &r_result);
+ virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result);
#endif
virtual String _get_indentation() const;
virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const;
@@ -508,7 +509,6 @@ public:
};
class ResourceFormatLoaderGDScript : public ResourceFormatLoader {
- GDCLASS(ResourceFormatLoaderGDScript, ResourceFormatLoader)
public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
@@ -518,7 +518,6 @@ public:
};
class ResourceFormatSaverGDScript : public ResourceFormatSaver {
- GDCLASS(ResourceFormatSaverGDScript, ResourceFormatSaver)
public:
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const;
diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp
index f7be0ce37c..189317b163 100644
--- a/modules/gdscript/gdscript_compiler.cpp
+++ b/modules/gdscript/gdscript_compiler.cpp
@@ -1977,12 +1977,12 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar
for (int i = 0; i < p_class->subclasses.size(); i++) {
StringName name = p_class->subclasses[i]->name;
-
- GDScript *subclass = p_script->subclasses[name].ptr();
+ Ref<GDScript> &subclass = p_script->subclasses[name];
+ GDScript *subclass_ptr = subclass.ptr();
// Subclass might still be parsing, just skip it
- if (!parsed_classes.has(subclass) && !parsing_classes.has(subclass)) {
- Error err = _parse_class_level(subclass, p_class->subclasses[i], p_keep_state);
+ if (!parsed_classes.has(subclass_ptr) && !parsing_classes.has(subclass_ptr)) {
+ Error err = _parse_class_level(subclass_ptr, p_class->subclasses[i], p_keep_state);
if (err)
return err;
}
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp
index d91e32249e..6c77968f44 100644
--- a/modules/gdscript/gdscript_editor.cpp
+++ b/modules/gdscript/gdscript_editor.cpp
@@ -2054,7 +2054,7 @@ static void _find_identifiers_in_base(const GDScriptCompletionContext &p_context
if (!p_only_functions) {
List<PropertyInfo> members;
- tmp.get_property_list(&members);
+ p_base.value.get_property_list(&members);
for (List<PropertyInfo>::Element *E = members.front(); E; E = E->next()) {
if (String(E->get().name).find("/") == -1) {
@@ -2461,13 +2461,13 @@ static void _find_call_arguments(GDScriptCompletionContext &p_context, const GDS
r_forced = r_result.size() > 0;
}
-Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, bool &r_forced, String &r_call_hint) {
+Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<String> *r_options, bool &r_forced, String &r_call_hint) {
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";
GDScriptParser parser;
- parser.parse(p_code, p_base_path, false, "", true);
+ parser.parse(p_code, p_path.get_base_dir(), false, p_path, true);
r_forced = false;
Set<String> options;
GDScriptCompletionContext context;
@@ -2478,7 +2478,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base
if (!context._class || context._class->owner == NULL) {
context.base = p_owner;
- context.base_path = p_base_path;
+ context.base_path = p_path.get_base_dir();
}
bool is_function = false;
@@ -2884,7 +2884,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base
#else
-Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, bool &r_forced, String &r_call_hint) {
+Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<String> *r_options, bool &r_forced, String &r_call_hint) {
return OK;
}
@@ -3155,7 +3155,7 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
return ERR_CANT_RESOLVE;
}
-Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol, const String &p_base_path, Object *p_owner, LookupResult &r_result) {
+Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) {
//before parsing, try the usual stuff
if (ClassDB::class_exists(p_symbol)) {
@@ -3197,7 +3197,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol
}
GDScriptParser parser;
- parser.parse(p_code, p_base_path, false, "", true);
+ parser.parse(p_code, p_path.get_base_dir(), false, p_path, true);
if (parser.get_completion_type() == GDScriptParser::COMPLETION_NONE) {
return ERR_CANT_RESOLVE;
@@ -3209,7 +3209,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol
context.block = parser.get_completion_block();
context.line = parser.get_completion_line();
context.base = p_owner;
- context.base_path = p_base_path;
+ context.base_path = p_path.get_base_dir();
if (context._class && context._class->extends_class.size() > 0) {
bool success = false;
diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp
index cff9ba55b8..bae5eca218 100644
--- a/modules/gdscript/gdscript_function.cpp
+++ b/modules/gdscript/gdscript_function.cpp
@@ -133,35 +133,13 @@ Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_insta
return NULL;
}
-String GDScriptFunction::_get_call_error(const Variant::CallError &p_err, const String &p_where, const Variant **argptrs) const {
-
- String err_text;
-
- if (p_err.error == Variant::CallError::CALL_ERROR_INVALID_ARGUMENT) {
- int errorarg = p_err.argument;
- err_text = "Invalid type in " + p_where + ". Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(p_err.expected) + ".";
- } else if (p_err.error == Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) {
- err_text = "Invalid call to " + p_where + ". Expected " + itos(p_err.argument) + " arguments.";
- } else if (p_err.error == Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) {
- err_text = "Invalid call to " + p_where + ". Expected " + itos(p_err.argument) + " arguments.";
- } else if (p_err.error == Variant::CallError::CALL_ERROR_INVALID_METHOD) {
- err_text = "Invalid call. Nonexistent " + p_where + ".";
- } else if (p_err.error == Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL) {
- err_text = "Attempt to call " + p_where + " on a null instance.";
- } else {
- err_text = "Bug, call error: #" + itos(p_err.error);
- }
-
- return err_text;
-}
-
#ifdef DEBUG_ENABLED
-static String _get_var_type(const Variant *p_type) {
+static String _get_var_type(const Variant *p_var) {
String basestr;
- if (p_type->get_type() == Variant::OBJECT) {
- Object *bobj = *p_type;
+ if (p_var->get_type() == Variant::OBJECT) {
+ Object *bobj = *p_var;
if (!bobj) {
basestr = "null instance";
} else {
@@ -176,12 +154,42 @@ static String _get_var_type(const Variant *p_type) {
}
} else {
- basestr = Variant::get_type_name(p_type->get_type());
+ basestr = Variant::get_type_name(p_var->get_type());
}
return basestr;
}
-#endif
+#endif // DEBUG_ENABLED
+
+String GDScriptFunction::_get_call_error(const Variant::CallError &p_err, const String &p_where, const Variant **argptrs) const {
+
+ String err_text;
+
+ if (p_err.error == Variant::CallError::CALL_ERROR_INVALID_ARGUMENT) {
+ int errorarg = p_err.argument;
+ // Handle the Object to Object case separately as we don't have further class details.
+#ifdef DEBUG_ENABLED
+ if (p_err.expected == Variant::OBJECT && argptrs[errorarg]->get_type() == p_err.expected) {
+ err_text = "Invalid type in " + p_where + ". The Object-derived class of argument " + itos(errorarg + 1) + " (" + _get_var_type(argptrs[errorarg]) + ") is not a subclass of the expected argument class.";
+ } else
+#endif // DEBUG_ENABLED
+ {
+ err_text = "Invalid type in " + p_where + ". Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(p_err.expected) + ".";
+ }
+ } else if (p_err.error == Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) {
+ err_text = "Invalid call to " + p_where + ". Expected " + itos(p_err.argument) + " arguments.";
+ } else if (p_err.error == Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) {
+ err_text = "Invalid call to " + p_where + ". Expected " + itos(p_err.argument) + " arguments.";
+ } else if (p_err.error == Variant::CallError::CALL_ERROR_INVALID_METHOD) {
+ err_text = "Invalid call. Nonexistent " + p_where + ".";
+ } else if (p_err.error == Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL) {
+ err_text = "Attempt to call " + p_where + " on a null instance.";
+ } else {
+ err_text = "Bug, call error: #" + itos(p_err.error);
+ }
+
+ return err_text;
+}
#if defined(__GNUC__)
#define OPCODES_TABLE \
diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp
index 5ebcddfd7c..0736f3d010 100644
--- a/modules/gdscript/gdscript_functions.cpp
+++ b/modules/gdscript/gdscript_functions.cpp
@@ -78,6 +78,7 @@ const char *GDScriptFunctions::get_func_name(Function p_func) {
"inverse_lerp",
"range_lerp",
"smoothstep",
+ "move_toward",
"dectime",
"randomize",
"randi",
@@ -341,7 +342,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
VALIDATE_ARG_NUM(0);
r_ret = Math::step_decimals((double)*p_args[0]);
ERR_EXPLAIN("GDScript method 'decimals' is deprecated and has been renamed to 'step_decimals', please update your code accordingly.");
- WARN_DEPRECATED
+ WARN_DEPRECATED;
} break;
case MATH_STEP_DECIMALS: {
VALIDATE_ARG_COUNT(1);
@@ -398,6 +399,13 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
VALIDATE_ARG_NUM(2);
r_ret = Math::smoothstep((double)*p_args[0], (double)*p_args[1], (double)*p_args[2]);
} break;
+ case MATH_MOVE_TOWARD: {
+ VALIDATE_ARG_COUNT(3);
+ VALIDATE_ARG_NUM(0);
+ VALIDATE_ARG_NUM(1);
+ VALIDATE_ARG_NUM(2);
+ r_ret = Math::move_toward((double)*p_args[0], (double)*p_args[1], (double)*p_args[2]);
+ } break;
case MATH_DECTIME: {
VALIDATE_ARG_COUNT(3);
VALIDATE_ARG_NUM(0);
@@ -1466,6 +1474,7 @@ bool GDScriptFunctions::is_deterministic(Function p_func) {
case MATH_INVERSE_LERP:
case MATH_RANGE_LERP:
case MATH_SMOOTHSTEP:
+ case MATH_MOVE_TOWARD:
case MATH_DECTIME:
case MATH_DEG2RAD:
case MATH_RAD2DEG:
@@ -1669,6 +1678,11 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) {
mi.return_val.type = Variant::REAL;
return mi;
} break;
+ case MATH_MOVE_TOWARD: {
+ MethodInfo mi("move_toward", PropertyInfo(Variant::REAL, "from"), PropertyInfo(Variant::REAL, "to"), PropertyInfo(Variant::REAL, "delta"));
+ mi.return_val.type = Variant::REAL;
+ return mi;
+ } break;
case MATH_DECTIME: {
MethodInfo mi("dectime", PropertyInfo(Variant::REAL, "value"), PropertyInfo(Variant::REAL, "amount"), PropertyInfo(Variant::REAL, "step"));
mi.return_val.type = Variant::REAL;
diff --git a/modules/gdscript/gdscript_functions.h b/modules/gdscript/gdscript_functions.h
index c594480ff8..6ad70f2eb4 100644
--- a/modules/gdscript/gdscript_functions.h
+++ b/modules/gdscript/gdscript_functions.h
@@ -69,6 +69,7 @@ public:
MATH_INVERSE_LERP,
MATH_RANGE_LERP,
MATH_SMOOTHSTEP,
+ MATH_MOVE_TOWARD,
MATH_DECTIME,
MATH_RANDOMIZE,
MATH_RAND,
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index 51ec0c1442..ec3e72eef7 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -1995,7 +1995,6 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to
}
}
- ERR_FAIL_V(op);
} break;
default: {
return p_node;
@@ -3369,7 +3368,7 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) {
return;
}
- if (!p_class->constant_expressions.empty() || !p_class->subclasses.empty() || !p_class->functions.empty() || !p_class->variables.empty()) {
+ if (!p_class->constant_expressions.empty() || !p_class->subclasses.empty() || !p_class->functions.empty() || !p_class->variables.empty() || p_class->classname_used) {
_set_error("'extends' must be used before anything else.");
return;
@@ -3497,7 +3496,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
_set_error("'class_name' is only valid for the main class namespace.");
return;
}
- if (self_path.empty()) {
+ if (self_path.begins_with("res://") && self_path.find("::") != -1) {
_set_error("'class_name' not allowed in built-in scripts.");
return;
}
@@ -3506,6 +3505,12 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
_set_error("'class_name' syntax: 'class_name <UniqueName>'");
return;
}
+ if (p_class->classname_used) {
+ _set_error("'class_name' already used for this class.");
+ return;
+ }
+
+ p_class->classname_used = true;
p_class->name = tokenizer->get_token_identifier(1);
@@ -4019,7 +4024,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
ERR_EXPLAIN("Exporting bit flags hint requires string constants.");
- WARN_DEPRECATED
+ WARN_DEPRECATED;
break;
}
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
@@ -4062,6 +4067,50 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
break;
}
+ if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "LAYERS_2D_RENDER") {
+
+ tokenizer->advance();
+ if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
+ _set_error("Expected ')' in layers 2D render hint.");
+ return;
+ }
+ current_export.hint = PROPERTY_HINT_LAYERS_2D_RENDER;
+ break;
+ }
+
+ if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "LAYERS_2D_PHYSICS") {
+
+ tokenizer->advance();
+ if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
+ _set_error("Expected ')' in layers 2D physics hint.");
+ return;
+ }
+ current_export.hint = PROPERTY_HINT_LAYERS_2D_PHYSICS;
+ break;
+ }
+
+ if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "LAYERS_3D_RENDER") {
+
+ tokenizer->advance();
+ if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
+ _set_error("Expected ')' in layers 3D render hint.");
+ return;
+ }
+ current_export.hint = PROPERTY_HINT_LAYERS_3D_RENDER;
+ break;
+ }
+
+ if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "LAYERS_3D_PHYSICS") {
+
+ tokenizer->advance();
+ if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
+ _set_error("Expected ')' in layers 3D physics hint.");
+ return;
+ }
+ current_export.hint = PROPERTY_HINT_LAYERS_3D_PHYSICS;
+ break;
+ }
+
if (tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type() == Variant::STRING) {
//enumeration
current_export.hint = PROPERTY_HINT_ENUM;
@@ -4782,19 +4831,30 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
return;
}
- if (member._export.type != Variant::NIL) {
+ Variant::Type initial_type = member.data_type.has_type ? member.data_type.builtin_type : member._export.type;
+
+ if (initial_type != Variant::NIL && initial_type != Variant::OBJECT) {
IdentifierNode *id = alloc_node<IdentifierNode>();
id->name = member.identifier;
- ConstantNode *cn = alloc_node<ConstantNode>();
+ Node *expr;
- Variant::CallError ce2;
- cn->value = Variant::construct(member._export.type, NULL, 0, ce2);
+ // Make sure arrays and dictionaries are not shared
+ if (initial_type == Variant::ARRAY) {
+ expr = alloc_node<ArrayNode>();
+ } else if (initial_type == Variant::DICTIONARY) {
+ expr = alloc_node<DictionaryNode>();
+ } else {
+ ConstantNode *cn = alloc_node<ConstantNode>();
+ Variant::CallError ce2;
+ cn->value = Variant::construct(initial_type, NULL, 0, ce2);
+ expr = cn;
+ }
OperatorNode *op = alloc_node<OperatorNode>();
op->op = OperatorNode::OP_INIT_ASSIGN;
op->arguments.push_back(id);
- op->arguments.push_back(cn);
+ op->arguments.push_back(expr);
p_class->initializer->statements.push_back(op);
@@ -5237,6 +5297,7 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class) {
if (base_script.is_valid()) {
String ident = base;
+ Ref<GDScript> find_subclass = base_script;
for (int i = extend_iter; i < p_class->extends_class.size(); i++) {
@@ -5246,7 +5307,7 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class) {
if (base_script->get_subclasses().has(subclass)) {
- base_script = base_script->get_subclasses()[subclass];
+ find_subclass = base_script->get_subclasses()[subclass];
} else if (base_script->get_constants().has(subclass)) {
Ref<GDScript> new_base_class = base_script->get_constants()[subclass];
@@ -5254,7 +5315,7 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class) {
_set_error("Constant is not a class: " + ident, p_class->line);
return;
}
- base_script = new_base_class;
+ find_subclass = new_base_class;
} else {
_set_error("Could not find subclass: " + ident, p_class->line);
@@ -5262,7 +5323,7 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class) {
}
}
- script = base_script;
+ script = find_subclass;
} else if (!base_class) {
@@ -6003,7 +6064,11 @@ bool GDScriptParser::_is_type_compatible(const DataType &p_container, const Data
}
GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
+#ifdef DEBUG_ENABLED
+ if (p_node->get_datatype().has_type && p_node->type != Node::TYPE_ARRAY && p_node->type != Node::TYPE_DICTIONARY) {
+#else
if (p_node->get_datatype().has_type) {
+#endif
return p_node->get_datatype();
}
@@ -7462,7 +7527,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
return;
}
- // Replace assignment with implict conversion
+ // Replace assignment with implicit conversion
BuiltInFunctionNode *convert = alloc_node<BuiltInFunctionNode>();
convert->line = v.line;
convert->function = GDScriptFunctions::TYPE_CONVERT;
@@ -7491,30 +7556,6 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
v.data_type = expr_type;
v.data_type.is_constant = false;
}
- } else if (v.data_type.has_type && v.data_type.kind == DataType::BUILTIN) {
- // Create default value based on the type
- IdentifierNode *id = alloc_node<IdentifierNode>();
- id->line = v.line;
- id->name = v.identifier;
-
- ConstantNode *init = alloc_node<ConstantNode>();
- init->line = v.line;
- Variant::CallError err;
- init->value = Variant::construct(v.data_type.builtin_type, NULL, 0, err);
-
- OperatorNode *op = alloc_node<OperatorNode>();
- op->line = v.line;
- op->op = OperatorNode::OP_INIT_ASSIGN;
- op->arguments.push_back(id);
- op->arguments.push_back(init);
-
- p_class->initializer->statements.push_front(op);
- v.initial_assignment = op;
-#ifdef DEBUG_ENABLED
- NewLineNode *nl = alloc_node<NewLineNode>();
- nl->line = v.line - 1;
- p_class->initializer->statements.push_front(nl);
-#endif
}
// Check export hint
@@ -7850,14 +7891,14 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
if (_is_type_compatible(assign_type, lv->datatype)) {
_mark_line_as_unsafe(lv->line);
} else {
- // Try implict conversion
+ // Try implicit conversion
if (lv->datatype.kind != DataType::BUILTIN || !_is_type_compatible(lv->datatype, assign_type, true)) {
_set_error("Assigned value type (" + assign_type.to_string() + ") doesn't match the variable's type (" +
lv->datatype.to_string() + ").",
lv->line);
return;
}
- // Replace assignment with implict conversion
+ // Replace assignment with implicit conversion
BuiltInFunctionNode *convert = alloc_node<BuiltInFunctionNode>();
convert->line = lv->line;
convert->function = GDScriptFunctions::TYPE_CONVERT;
@@ -7981,14 +8022,14 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
if (_is_type_compatible(rh_type, lh_type)) {
_mark_line_as_unsafe(op->line);
} else {
- // Try implict conversion
+ // Try implicit conversion
if (lh_type.kind != DataType::BUILTIN || !_is_type_compatible(lh_type, rh_type, true)) {
_set_error("Assigned value type (" + rh_type.to_string() + ") doesn't match the variable's type (" +
lh_type.to_string() + ").",
op->line);
return;
}
- // Replace assignment with implict conversion
+ // Replace assignment with implicit conversion
BuiltInFunctionNode *convert = alloc_node<BuiltInFunctionNode>();
convert->line = op->line;
convert->function = GDScriptFunctions::TYPE_CONVERT;
diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h
index 809bff8f20..5e4de11357 100644
--- a/modules/gdscript/gdscript_parser.h
+++ b/modules/gdscript/gdscript_parser.h
@@ -149,6 +149,7 @@ public:
bool tool;
StringName name;
bool extends_used;
+ bool classname_used;
StringName extends_file;
Vector<StringName> extends_class;
DataType base_type;
@@ -198,6 +199,7 @@ public:
tool = false;
type = TYPE_CLASS;
extends_used = false;
+ classname_used = false;
end_line = -1;
owner = NULL;
}
diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp
index b8048fb5dd..a93d1ceebb 100644
--- a/modules/gdscript/gdscript_tokenizer.cpp
+++ b/modules/gdscript/gdscript_tokenizer.cpp
@@ -376,6 +376,11 @@ static bool _is_hex(CharType c) {
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
}
+static bool _is_bin(CharType c) {
+
+ return (c == '0' || c == '1');
+}
+
void GDScriptTokenizerText::_make_token(Token p_type) {
TokenData &tk = tk_rb[tk_rb_pos];
@@ -877,6 +882,7 @@ void GDScriptTokenizerText::_advance() {
bool period_found = false;
bool exponent_found = false;
bool hexa_found = false;
+ bool bin_found = false;
bool sign_found = false;
String str;
@@ -887,16 +893,28 @@ void GDScriptTokenizerText::_advance() {
if (period_found || exponent_found) {
_make_error("Invalid numeric constant at '.'");
return;
+ } else if (bin_found) {
+ _make_error("Invalid binary constant at '.'");
+ return;
+ } else if (hexa_found) {
+ _make_error("Invalid hexadecimal constant at '.'");
+ return;
}
period_found = true;
} else if (GETCHAR(i) == 'x') {
- if (hexa_found || str.length() != 1 || !((i == 1 && str[0] == '0') || (i == 2 && str[1] == '0' && str[0] == '-'))) {
+ if (hexa_found || bin_found || str.length() != 1 || !((i == 1 && str[0] == '0') || (i == 2 && str[1] == '0' && str[0] == '-'))) {
_make_error("Invalid numeric constant at 'x'");
return;
}
hexa_found = true;
+ } else if (GETCHAR(i) == 'b') {
+ if (hexa_found || bin_found || str.length() != 1 || !((i == 1 && str[0] == '0') || (i == 2 && str[1] == '0' && str[0] == '-'))) {
+ _make_error("Invalid numeric constant at 'b'");
+ return;
+ }
+ bin_found = true;
} else if (!hexa_found && GETCHAR(i) == 'e') {
- if (exponent_found) {
+ if (exponent_found || bin_found) {
_make_error("Invalid numeric constant at 'e'");
return;
}
@@ -905,6 +923,8 @@ void GDScriptTokenizerText::_advance() {
//all ok
} else if (hexa_found && _is_hex(GETCHAR(i))) {
+ } else if (bin_found && _is_bin(GETCHAR(i))) {
+
} else if ((GETCHAR(i) == '-' || GETCHAR(i) == '+') && exponent_found) {
if (sign_found) {
_make_error("Invalid numeric constant at '-'");
@@ -930,6 +950,9 @@ void GDScriptTokenizerText::_advance() {
if (hexa_found) {
int64_t val = str.hex_to_int64();
_make_constant(val);
+ } else if (bin_found) {
+ int64_t val = str.bin_to_int64();
+ _make_constant(val);
} else if (period_found || exponent_found) {
double val = str.to_double();
_make_constant(val);