Expression.xml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="Expression" inherits="Reference" version="3.4">
  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. <methods>
  27. <method name="execute">
  28. <return type="Variant">
  29. </return>
  30. <argument index="0" name="inputs" type="Array" default="[ ]">
  31. </argument>
  32. <argument index="1" name="base_instance" type="Object" default="null">
  33. </argument>
  34. <argument index="2" name="show_error" type="bool" default="true">
  35. </argument>
  36. <description>
  37. 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].
  38. If you defined input variables in [method parse], you can specify their values in the inputs array, in the same order.
  39. </description>
  40. </method>
  41. <method name="get_error_text" qualifiers="const">
  42. <return type="String">
  43. </return>
  44. <description>
  45. Returns the error text if [method parse] has failed.
  46. </description>
  47. </method>
  48. <method name="has_execute_failed" qualifiers="const">
  49. <return type="bool">
  50. </return>
  51. <description>
  52. Returns [code]true[/code] if [method execute] has failed.
  53. </description>
  54. </method>
  55. <method name="parse">
  56. <return type="int" enum="Error">
  57. </return>
  58. <argument index="0" name="expression" type="String">
  59. </argument>
  60. <argument index="1" name="input_names" type="PoolStringArray" default="PoolStringArray( )">
  61. </argument>
  62. <description>
  63. Parses the expression and returns an [enum Error] code.
  64. 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.
  65. </description>
  66. </method>
  67. </methods>
  68. <constants>
  69. </constants>
  70. </class>