what_is_gdnative.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. .. _doc_what_is_gdnative:
  2. What is GDNative?
  3. =================
  4. Introduction
  5. ------------
  6. **GDNative** 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:: GDNative is *not* a scripting language and has no relation to
  10. :ref:`GDScript <doc_gdscript>`.
  11. Differences between GDNative and C++ modules
  12. --------------------------------------------
  13. You can use both GDNative and :ref:`C++ modules <doc_custom_modules_in_c++>` 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. Advantages of GDNative
  18. ^^^^^^^^^^^^^^^^^^^^^^
  19. Unlike modules, GDNative doesn't require compiling the engine's source code,
  20. making it easier to distribute your work. It gives you access to most of the API
  21. available to GDScript C#, allowing you to code game logic with full control
  22. regarding performance. It's ideal if you need high-performance code you'd like
  23. to distribute as an add-on in the :ref:`asset library <doc_what_is_assetlib>`.
  24. Also:
  25. - GDNative is not limited to C and C++. Thanks to :ref:`third-party bindings
  26. <doc_what_is_gdnative_third_party_bindings>`, you can use it with many other
  27. languages.
  28. - You can use the same compiled GDNative library in the editor and exported
  29. project. With C++ modules, you have to recompile all the export templates you
  30. plan to use if you require its functionality at run-time.
  31. - GDNative only requires you to compile your library, not the whole engine.
  32. That's unlike C++ modules, which are statically compiled into the engine.
  33. Every time you change a module, you need to recompile the engine. Even with
  34. incremental builds, this process is slower than using GDNative.
  35. Advantages of C++ modules
  36. ^^^^^^^^^^^^^^^^^^^^^^^^^
  37. We recommend :ref:`C++ modules <doc_custom_modules_in_c++>` in cases where
  38. GDNative isn't enough:
  39. - C++ modules provide deeper integration into the engine. GDNative's access is
  40. limited to what the scripting API exposes.
  41. - You can use C++ modules to provide additional features in a project without
  42. carrying native library files around. This extends to exported projects.
  43. - C++ modules are supported on all platforms. In contrast, GDNative has only
  44. limited support on HTML5 (cannot be used together with multi-threading), and
  45. is not supported on Universal Windows Platform (UWP).
  46. - C++ modules can be faster than GDNative, especially when the code requires a
  47. lot of communication through the scripting API.
  48. Supported languages
  49. -------------------
  50. The Godot developers officially support the following language bindings for
  51. GDNative:
  52. - C++ :ref:`(tutorial) <doc_gdnative_cpp_example>`
  53. - C :ref:`(tutorial) <doc_gdnative_c_example>`
  54. .. note::
  55. There are no plans to support additional languages with GDNative officially.
  56. That said, the community offers several bindings for other languages (see
  57. below).
  58. .. _doc_what_is_gdnative_third_party_bindings:
  59. The bindings below are developed and maintained by the community:
  60. .. 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.
  61. .. Please keep languages sorted in alphabetical order.
  62. - `D <https://github.com/godot-d/godot-d>`__
  63. - `Kotlin <https://github.com/utopia-rise/godot-kotlin-jvm>`__
  64. - `Nim <https://github.com/pragmagic/godot-nim>`__
  65. - `Python <https://github.com/touilleMan/godot-python>`__
  66. - `Rust <https://github.com/godot-rust/godot-rust>`__
  67. .. note::
  68. Not all bindings mentioned here may be production-ready. Make sure to
  69. research options thoroughly before starting a project with one of those.
  70. Also, double-check whether the binding is compatible with the Godot version
  71. you're using.
  72. Version compatibility
  73. ---------------------
  74. :ref:`Unlike Godot itself <doc_release_policy>`, GDNative has stricter version
  75. compatibility requirements as it relies on low-level *ptrcalls* to function.
  76. GDNative add-ons compiled for a given Godot version are only guaranteed to work
  77. with the same minor release series. For example, a GDNative add-on compiled for
  78. Godot 3.4 will only work with Godot 3.4, 3.4.1, 3.4.2… but not Godot 3.3 or 3.5.