class_funcref.rst 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the FuncRef.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_FuncRef:
  6. FuncRef
  7. =======
  8. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. Reference to a function in an object.
  10. Description
  11. -----------
  12. 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.
  13. 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.
  14. Methods
  15. -------
  16. +-------------------------------+---------------------------------------------------------------------------------------------------------+
  17. | :ref:`Variant<class_Variant>` | :ref:`call_func<class_FuncRef_method_call_func>` **(** ... **)** |vararg| |
  18. +-------------------------------+---------------------------------------------------------------------------------------------------------+
  19. | :ref:`Variant<class_Variant>` | :ref:`call_funcv<class_FuncRef_method_call_funcv>` **(** :ref:`Array<class_Array>` arg_array **)** |
  20. +-------------------------------+---------------------------------------------------------------------------------------------------------+
  21. | :ref:`bool<class_bool>` | :ref:`is_valid<class_FuncRef_method_is_valid>` **(** **)** |const| |
  22. +-------------------------------+---------------------------------------------------------------------------------------------------------+
  23. | void | :ref:`set_function<class_FuncRef_method_set_function>` **(** :ref:`String<class_String>` name **)** |
  24. +-------------------------------+---------------------------------------------------------------------------------------------------------+
  25. | void | :ref:`set_instance<class_FuncRef_method_set_instance>` **(** :ref:`Object<class_Object>` instance **)** |
  26. +-------------------------------+---------------------------------------------------------------------------------------------------------+
  27. Method Descriptions
  28. -------------------
  29. .. _class_FuncRef_method_call_func:
  30. - :ref:`Variant<class_Variant>` **call_func** **(** ... **)** |vararg|
  31. Calls the referenced function previously set by :ref:`set_function<class_FuncRef_method_set_function>` or :ref:`@GDScript.funcref<class_@GDScript_method_funcref>`.
  32. ----
  33. .. _class_FuncRef_method_call_funcv:
  34. - :ref:`Variant<class_Variant>` **call_funcv** **(** :ref:`Array<class_Array>` arg_array **)**
  35. Calls the referenced function previously set by :ref:`set_function<class_FuncRef_method_set_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>`.
  36. ----
  37. .. _class_FuncRef_method_is_valid:
  38. - :ref:`bool<class_bool>` **is_valid** **(** **)** |const|
  39. Returns whether the object still exists and has the function assigned.
  40. ----
  41. .. _class_FuncRef_method_set_function:
  42. - void **set_function** **(** :ref:`String<class_String>` name **)**
  43. The name of the referenced function to call on the object, without parentheses or any parameters.
  44. ----
  45. .. _class_FuncRef_method_set_instance:
  46. - void **set_instance** **(** :ref:`Object<class_Object>` instance **)**
  47. 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>`.
  48. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  49. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  50. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`