Expression.xml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="Expression" inherits="Reference" category="Core" version="3.1">
  3. <brief_description>
  4. A class that stores an expression you can execute.
  5. </brief_description>
  6. <description>
  7. An expression can be made of any arithmetic operation, built-in math function call, method call of a passed instance, or built-in type construction call.
  8. An example expression text using the built-in math functions could be [code]sqrt(pow(3,2) + pow(4,2))[/code].
  9. In the following example we use a [LineEdit] node to write our expression and show the result.
  10. [codeblock]
  11. onready var expression = Expression.new()
  12. func _ready():
  13. $LineEdit.connect("text_entered", self, "_on_text_entered")
  14. func _on_text_entered(command):
  15. var error = expression.parse(command, [])
  16. if error != OK:
  17. print(expression.get_error_text())
  18. return
  19. var result = expression.execute([], null, true)
  20. if not expression.has_execute_failed():
  21. $LineEdit.text = str(result)
  22. [/codeblock]
  23. </description>
  24. <tutorials>
  25. </tutorials>
  26. <demos>
  27. </demos>
  28. <methods>
  29. <method name="execute">
  30. <return type="Variant">
  31. </return>
  32. <argument index="0" name="inputs" type="Array" default="[ ]">
  33. </argument>
  34. <argument index="1" name="base_instance" type="Object" default="null">
  35. </argument>
  36. <argument index="2" name="show_error" type="bool" default="true">
  37. </argument>
  38. <description>
  39. Executes the expression that was previously parsed by [method parse] and returns the result. Before you use the returned object, you should check if the method failed by calling [method has_execute_failed].
  40. If you defined input variables in [method parse], you can specify their values in the inputs array, in the same order.
  41. </description>
  42. </method>
  43. <method name="get_error_text" qualifiers="const">
  44. <return type="String">
  45. </return>
  46. <description>
  47. Returns the error text if [method parse] has failed.
  48. </description>
  49. </method>
  50. <method name="has_execute_failed" qualifiers="const">
  51. <return type="bool">
  52. </return>
  53. <description>
  54. Returns [code]true[/code] if [method execute] has failed.
  55. </description>
  56. </method>
  57. <method name="parse">
  58. <return type="int" enum="Error">
  59. </return>
  60. <argument index="0" name="expression" type="String">
  61. </argument>
  62. <argument index="1" name="input_names" type="PoolStringArray" default="PoolStringArray( )">
  63. </argument>
  64. <description>
  65. Parses the expression and returns a [enum @GlobalScope.Error].
  66. You can optionally specify names of variables that may appear in the expression with [code]input_names[/code], so that you can bind them when it gets executed.
  67. </description>
  68. </method>
  69. </methods>
  70. <constants>
  71. </constants>
  72. </class>