|
| 1 | +.. _doc_godot_cpp_core_types: |
| 2 | + |
| 3 | +Core functions and types |
| 4 | +======================== |
| 5 | + |
| 6 | +godot-cpp's API is designed to be as similar as possible to Godot's internal API. |
| 7 | + |
| 8 | +This means that, in general, you can use the :ref:`Engine details <doc_engine_architecture>` section to learn how to |
| 9 | +work with godot-cpp. In addition, it can often be useful to browse the `engine's code <https://github.com/godotengine/godot>`__ |
| 10 | +for examples for how to work with Godot's API. |
| 11 | + |
| 12 | +That being said, there are some differences to be aware of, which are documented here. |
| 13 | + |
| 14 | +Common functions and macros |
| 15 | +--------------------------- |
| 16 | + |
| 17 | +Please refer to :ref:`doc_common_engine_methods_and_macros` for information on this. The functions and macros documented |
| 18 | +there are also available in godot-cpp. |
| 19 | + |
| 20 | +Core types |
| 21 | +---------- |
| 22 | + |
| 23 | +Godot's :ref:`Core types <doc_core_types>` are also available in godot-cpp, and the same recommendations apply |
| 24 | +as described in that article. The types are regularly synchronized with the Godot codebase. |
| 25 | + |
| 26 | +In your own code, you can also use `C++ STL types <https://en.cppreference.com/w/cpp/container.html>`__, or types from |
| 27 | +any library you choose, but they won't be compatible with Godot's APIs. |
| 28 | + |
| 29 | +Packed arrays |
| 30 | +~~~~~~~~~~~~~ |
| 31 | + |
| 32 | +While in Godot, the ``Packed*Array`` types are aliases of ``Vector``, in godot-cpp, they're their own types, using the |
| 33 | +Godot bindings. This is because these types, along with their methods, are exposed through the GDExtension interface, |
| 34 | +which would not be compatible with the templated nature of ``Vector``. |
| 35 | + |
| 36 | +In general though, the ``Packed*Array`` types work the same way as their ``Vector`` aliases. However, you should be |
| 37 | +aware that the ``Variant`` wrappers for ``Packed*Array`` treat them as pass-by-reference, while the ``Packed*Array`` |
| 38 | +types themselves are pass-by-value (implemented as copy-on-write). |
| 39 | + |
| 40 | +In addition, it may be of interest that GDScript calls use the ``Variant`` call interface: Any ``Packed*Array`` |
| 41 | +arguments to your functions will be passed in a ``Variant``, and unpacked from there. This can create copies of the |
| 42 | +types, so the argument you receive may be a copy of the argument that the function was called with. In practice, this |
| 43 | +means you cannot rely on that the argument passed to you can be modified at the caller's site. |
| 44 | + |
| 45 | +Variant class |
| 46 | +------------- |
| 47 | + |
| 48 | +Please refer to :ref:`doc_variant_class` to learn about how to work with ``Variant``. |
| 49 | + |
| 50 | +Most importantly, you should be aware that all functions exposed through the GDExtension API must be compatible with |
| 51 | +``Variant``. |
| 52 | + |
| 53 | +Object class |
| 54 | +------------ |
| 55 | + |
| 56 | +Please refer to :ref:`doc_object_class` to learn how to register and work with your own ``Object`` types. |
| 57 | + |
| 58 | +We are not aware of any major differences between the godot-cpp ``Object`` API and Godot's internal ``Object`` API, |
| 59 | +except that some methods are available in Godot's internal API that are not available in godot-cpp. |
| 60 | + |
| 61 | +You should be aware that the pointer to your godot-cpp ``Object`` is different from the pointer that Godot uses |
| 62 | +internally. This is because the godot-cpp version is an extension instance, allocated separately from the original |
| 63 | +``Object``. However, in practice, this difference is usually not noticeable. |
0 commit comments