Hacker News new | ask | show | jobs
by geokon 3008 days ago
How's the interplay btw GodotScript and C++? (and the several other scripting options they give you)

I've played a bit with Unreal, so I'm not very qualified to have opinions, but I really like how the system is mostly a C++ stack. The Blueprints are in effect extending underlying C++ classes. The "FFI", if you want to call that, is pretty clean and easy and if you want to write C++ it works very well with the rest of the system. It definitely could be cleaner... not exactly git-clone, cmake, make, make install... there are magic macros, some C# that does godknowswhat and over all it's messier than I would like.

But with all the scripting that Godot supports it seems like it'd be even messier still? You'll have some assets in C++ some in GodotScript and some in C#. Or am I wrong?

1 comments

(Please correct me if any of the following is imprecise, as I am not a core dev of Godot)

Languages are roughly stacked like this:

1. Internal scripting

Godot internally (C++ source) makes a distinction between core and modules. So many of the functionality that do not necessarily belong to the core engine are modules.

You are free to write your own extension to and modules to the editor (for example custom Node types). There is also an EditorPlugin API so you do not necessarily have to get your hands wet in the engine API itself if not necessary. Btw. the latter API is also exposed in GDScript.

Anything that implements script_language.h as a module is considered part of the editor (e.g. exposed in-editor script support etc.)

In 3.0 that would be GDScript and C#.

2. GDNative

Additionally 3.0 introduced GDNative which in essence is an API that exposes the internal C++ API that makes up the In-Game scripting as C symbols. This has the benefit that C can be bound to anything. Going this route even the C++ API is bindings created through C :-). More details here [1].

It is a relatively new effort but so far the following languages are supported (not making claims about stability/maturity here):

- C (just the API itself via the shipped headers)

- C++ [2]

- D [2]

- Rust [2]

- Python [3]

- Nim [4]

- Possibly others?

Once you have a library that can be hooked into you load it in the editor for each individual platform you try to target.

That being said: There is no heavy boilerplate-magic going on. I've setup a CMake file to handle C++ plugins without big issues. There is no real hot-loading AFAIK but you do not need to restart the editor since it loads the libraries in play mode.

This is a sample of the GDNative API [5].

Here is a manual setup with C [6]. While the tooling improved meanwhile (e.g. in editor tools to set the libraries) it gives you a good overview how the GDNative API works.

Hope that makes sense.

[1] GDNative Architecture https://godotengine.org/article/look-gdnative-architecture

[2] Main GDNative Language Bindings https://github.com/GodotNativeTools

[3] Python via GDNative https://github.com/touilleMan/godot-python

[4] Nim via GDNative https://github.com/pragmagic/godot-nim

[5] GDNative C++ API Sample https://github.com/GodotNativeTools/godot-cpp#creating-simpl...

[6] C example of GDNative (Godot Docs) http://docs.godotengine.org/en/3.0/tutorials/plugins/gdnativ...

I wonder if one could couple it to Swift.