what_is_gdextension.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 run-time. 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. .. note:: If you notice that specific systems are not accessible via GDExtension
  18. but are via custom modules feel free to open an issue on the
  19. `godot-cpp repository <https://github.com/godotengine/godot-cpp>`__ to discuss
  20. implementation options to expose the missing functionality.
  21. Advantages of GDExtension
  22. ^^^^^^^^^^^^^^^^^^^^^^^^^
  23. Unlike modules, GDExtension doesn't require compiling the engine's source code,
  24. making it easier to distribute your work. It gives you access to most of the API
  25. available to GDScript and C#, allowing you to code game logic with full control
  26. regarding performance. It's ideal if you need high-performance code you'd like
  27. to distribute as an add-on in the :ref:`asset library <doc_what_is_assetlib>`.
  28. Also:
  29. - GDExtension is not limited to C and C++. Thanks to :ref:`third-party bindings
  30. <doc_what_is_gdnative_third_party_bindings>`, you can use it with many other
  31. languages.
  32. - You can use the same compiled GDExtension library in the editor and exported
  33. project. With C++ modules, you have to recompile all the export templates you
  34. plan to use if you require its functionality at run-time.
  35. - GDExtension only requires you to compile your library, not the whole engine.
  36. That's unlike C++ modules, which are statically compiled into the engine.
  37. Every time you change a module, you need to recompile the engine. Even with
  38. incremental builds, this process is slower than using GDExtension.
  39. Advantages of C++ modules
  40. ^^^^^^^^^^^^^^^^^^^^^^^^^
  41. We recommend :ref:`C++ modules <doc_custom_modules_in_cpp>` in cases where
  42. GDExtension isn't enough:
  43. - C++ modules provide deeper integration into the engine. GDExtension's access is not as deep as
  44. static modules
  45. - You can use C++ modules to provide additional features in a project without
  46. carrying native library files around. This extends to exported projects.
  47. Supported languages
  48. -------------------
  49. The Godot developers officially support the following language bindings for
  50. GDExtension:
  51. - C++ :ref:`(tutorial) <doc_gdextension_cpp_example>`
  52. .. note::
  53. There are no plans to support additional languages with GDExtension officially.
  54. That said, the community offers several bindings for other languages (see
  55. below).
  56. .. _doc_what_is_gdnative_third_party_bindings:
  57. The bindings below are developed and maintained by the community:
  58. .. 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.
  59. .. Please keep languages sorted in alphabetical order.
  60. - `Rust <https://github.com/godot-rust/gdextension>`__
  61. .. note::
  62. Not all bindings mentioned here may be production-ready. Make sure to
  63. research options thoroughly before starting a project with one of those.
  64. Also, double-check whether the binding is compatible with the Godot version
  65. you're using.
  66. Version compatibility
  67. ---------------------
  68. GDExtension add-ons compiled for a given Godot version are only guaranteed to work
  69. with the same minor release series. For example, a GDExtension add-on compiled for
  70. Godot 4.0 will only work with Godot 4.0, 4.0.1, 4.0.2. In addition, GDExtension is
  71. not compatible with Godot 3.x.