Expression.xml 2.7 KB

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