what_is_gdextension.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. .. _doc_what_is_gdextension:
  2. What is GDExtension?
  3. ====================
  4. Introduction
  5. ------------
  6. **GDExtension** is a Godot-specific technology that lets the engine interact with
  7. native `shared libraries <https://en.wikipedia.org/wiki/Library_(computing)#Shared_libraries>`__
  8. at runtime. You can use it to run native code without compiling it with the engine.
  9. .. note:: GDExtension is *not* a scripting language and has no relation to
  10. :ref:`GDScript <doc_gdscript>`.
  11. Differences between GDExtension and C++ modules
  12. -----------------------------------------------
  13. You can use both GDExtension and :ref:`C++ modules <doc_custom_modules_in_cpp>` to
  14. run C or C++ code in a Godot project.
  15. They also both allow you to integrate third-party libraries into Godot. The one
  16. you should choose depends on your needs.
  17. .. warning::
  18. Our long-term goal is that GDExtensions targeting an earlier version of
  19. Godot will work in later minor versions, but not vice-versa. For example, a
  20. GDExtension targeting Godot 4.2 should work just fine in Godot 4.3, but one
  21. targeting Godot 4.3 won't work in Godot 4.2.
  22. However, GDExtension is currently *experimental*, which means that we may
  23. break compatibility in order to fix major bugs or include critical features.
  24. For example, GDExtensions created for Godot 4.0 aren't compatible with Godot
  25. 4.1 (see :ref:`updating_your_gdextension_for_godot_4_1`).
  26. Advantages of GDExtension
  27. ^^^^^^^^^^^^^^^^^^^^^^^^^
  28. Unlike modules, GDExtension doesn't require compiling the engine's source code,
  29. making it easier to distribute your work. It gives you access to most of the API
  30. available to GDScript and C#, allowing you to code game logic with full control
  31. regarding performance. It's ideal if you need high-performance code you'd like
  32. to distribute as an add-on in the :ref:`asset library <doc_what_is_assetlib>`.
  33. Also:
  34. - GDExtension is not limited to C and C++. Thanks to :ref:`third-party bindings
  35. <doc_what_is_gdnative_third_party_bindings>`, you can use it with many other
  36. languages.
  37. - You can use the same compiled GDExtension library in the editor and exported
  38. project. With C++ modules, you have to recompile all the export templates you
  39. plan to use if you require its functionality at runtime.
  40. - GDExtension only requires you to compile your library, not the whole engine.
  41. That's unlike C++ modules, which are statically compiled into the engine.
  42. Every time you change a module, you need to recompile the engine. Even with
  43. incremental builds, this process is slower than using GDExtension.
  44. Advantages of C++ modules
  45. ^^^^^^^^^^^^^^^^^^^^^^^^^
  46. We recommend :ref:`C++ modules <doc_custom_modules_in_cpp>` in cases where
  47. GDExtension isn't enough:
  48. - C++ modules provide deeper integration into the engine. GDExtension's access
  49. is not as deep as static modules.
  50. - You can use C++ modules to provide additional features in a project without
  51. carrying native library files around. This extends to exported projects.
  52. .. note::
  53. If you notice that specific systems are not accessible via GDExtension
  54. but are via custom modules, feel free to open an issue on the
  55. `godot-cpp repository <https://github.com/godotengine/godot-cpp>`__
  56. to discuss implementation options for exposing the missing functionality.
  57. Supported languages
  58. -------------------
  59. The Godot developers officially support the following language bindings for
  60. GDExtension:
  61. - C++ :ref:`(tutorial) <doc_gdextension_cpp_example>`
  62. .. note::
  63. There are no plans to support additional languages with GDExtension officially.
  64. That said, the community offers several bindings for other languages (see
  65. below).
  66. .. _doc_what_is_gdnative_third_party_bindings:
  67. The bindings below are developed and maintained by the community:
  68. .. Binding developers: Feel free to open a pull request to add your binding if it's well-developed enough to be used in a project.
  69. .. Please keep languages sorted in alphabetical order.
  70. - `D <https://github.com/godot-dlang/godot-dlang>`__
  71. - `Go <https://github.com/grow-graphics/gd>`__
  72. - `Rust <https://github.com/godot-rust/gdext>`__
  73. - `Swift <https://github.com/migueldeicaza/SwiftGodot>`__
  74. .. note::
  75. Not all bindings mentioned here may be production-ready. Make sure to
  76. research options thoroughly before starting a project with one of those.
  77. Also, double-check whether the binding is compatible with the Godot version
  78. you're using.
  79. Version compatibility
  80. ---------------------
  81. GDExtension add-ons compiled for a given Godot version are only guaranteed to work
  82. with the same minor release series. For example, a GDExtension add-on compiled for
  83. Godot 4.0 will only work with Godot 4.0, 4.0.1, 4.0.2. In addition, GDExtension is
  84. not compatible with Godot 3.x.
  85. GDExtension add-ons are also only compatible with engine builds that use the
  86. level of floating-point precision the extension was compiled for. This means
  87. that if you use an engine build with double-precision floats, the extension must
  88. also be compiled for double-precision floats. See
  89. :ref:`doc_large_world_coordinates` for details.