class_funcref.rst 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/FuncRef.xml.
  6. .. _class_FuncRef:
  7. FuncRef
  8. =======
  9. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. Reference to a function in an object.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. In GDScript, functions are not *first-class objects*. This means it is impossible to store them directly as variables, return them from another function, or pass them as arguments.
  15. However, by creating a **FuncRef** using the :ref:`@GDScript.funcref<class_@GDScript_method_funcref>` function, a reference to a function in a given object can be created, passed around and called.
  16. .. rst-class:: classref-reftable-group
  17. Properties
  18. ----------
  19. .. table::
  20. :widths: auto
  21. +-----------------------------+--------------------------------------------------+--------+
  22. | :ref:`String<class_String>` | :ref:`function<class_FuncRef_property_function>` | ``""`` |
  23. +-----------------------------+--------------------------------------------------+--------+
  24. .. rst-class:: classref-reftable-group
  25. Methods
  26. -------
  27. .. table::
  28. :widths: auto
  29. +-------------------------------+---------------------------------------------------------------------------------------------------------+
  30. | :ref:`Variant<class_Variant>` | :ref:`call_func<class_FuncRef_method_call_func>` **(** ... **)** |vararg| |
  31. +-------------------------------+---------------------------------------------------------------------------------------------------------+
  32. | :ref:`Variant<class_Variant>` | :ref:`call_funcv<class_FuncRef_method_call_funcv>` **(** :ref:`Array<class_Array>` arg_array **)** |
  33. +-------------------------------+---------------------------------------------------------------------------------------------------------+
  34. | :ref:`bool<class_bool>` | :ref:`is_valid<class_FuncRef_method_is_valid>` **(** **)** |const| |
  35. +-------------------------------+---------------------------------------------------------------------------------------------------------+
  36. | void | :ref:`set_instance<class_FuncRef_method_set_instance>` **(** :ref:`Object<class_Object>` instance **)** |
  37. +-------------------------------+---------------------------------------------------------------------------------------------------------+
  38. .. rst-class:: classref-section-separator
  39. ----
  40. .. rst-class:: classref-descriptions-group
  41. Property Descriptions
  42. ---------------------
  43. .. _class_FuncRef_property_function:
  44. .. rst-class:: classref-property
  45. :ref:`String<class_String>` **function** = ``""``
  46. .. rst-class:: classref-property-setget
  47. - void **set_function** **(** :ref:`String<class_String>` value **)**
  48. - :ref:`String<class_String>` **get_function** **(** **)**
  49. The name of the referenced function.
  50. .. rst-class:: classref-section-separator
  51. ----
  52. .. rst-class:: classref-descriptions-group
  53. Method Descriptions
  54. -------------------
  55. .. _class_FuncRef_method_call_func:
  56. .. rst-class:: classref-method
  57. :ref:`Variant<class_Variant>` **call_func** **(** ... **)** |vararg|
  58. Calls the referenced function previously set in :ref:`function<class_FuncRef_property_function>` or :ref:`@GDScript.funcref<class_@GDScript_method_funcref>`.
  59. .. rst-class:: classref-item-separator
  60. ----
  61. .. _class_FuncRef_method_call_funcv:
  62. .. rst-class:: classref-method
  63. :ref:`Variant<class_Variant>` **call_funcv** **(** :ref:`Array<class_Array>` arg_array **)**
  64. Calls the referenced function previously set in :ref:`function<class_FuncRef_property_function>` or :ref:`@GDScript.funcref<class_@GDScript_method_funcref>`. Contrarily to :ref:`call_func<class_FuncRef_method_call_func>`, this method does not support a variable number of arguments but expects all parameters to be passed via a single :ref:`Array<class_Array>`.
  65. .. rst-class:: classref-item-separator
  66. ----
  67. .. _class_FuncRef_method_is_valid:
  68. .. rst-class:: classref-method
  69. :ref:`bool<class_bool>` **is_valid** **(** **)** |const|
  70. Returns whether the object still exists and has the function assigned.
  71. .. rst-class:: classref-item-separator
  72. ----
  73. .. _class_FuncRef_method_set_instance:
  74. .. rst-class:: classref-method
  75. void **set_instance** **(** :ref:`Object<class_Object>` instance **)**
  76. The object containing the referenced function. This object must be of a type actually inheriting from :ref:`Object<class_Object>`, not a built-in type such as :ref:`int<class_int>`, :ref:`Vector2<class_Vector2>` or :ref:`Dictionary<class_Dictionary>`.
  77. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  78. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  79. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  80. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`