using different programming language in godot game engine?
Asked Answered
A

2

7

I want to bind a different programming language to the Godot game engine. Is there an instructional document or video on this topic? For example, how was this project done: godot-rust. If I can learn the basics, I can succeed in working in a different language. Thanks.

Aristarchus answered 19/3, 2022 at 2:47 Comment(0)
P
5

In this answer I show you the different approaches to add language support in Godot 3.x (the situation will be somewhat different with Godot 4.0 and GDExtension - which replaces GDNative and hopefully means less custom builds), and I mention some languages that are supported by each of these approaches. However, this is not an exhaustive list of the languages.


First of all, Godot has official build-in support for GDScript and Godot's VisualScript (and Godot's shading language and its visual counterpart if those counts for you).


There are a few ways to use C++:

  • You can use it to create GDNative scripts (which are basically a wrapper around native calls that allow you to use them as scripts in Godot).

  • Or you can create modules (which are static libraries you can add in a custom Godot build).

  • And since Godot source is in C++, you don't have to restrict yourself to making modules if you are making custom builds.


In web builds Godot can interface with JavaScript via the JavaScript class. However, this approach does not allow you to add JavaScript scripts to Nodes, and so on.


Then there are languages that can only be added in custom builds of Godot, which is currently the official support for C#.

There are other non-official custom builds that offer language binding for languages such as Lua, Kotlin, TypeScript and JavaScript (this time allowing you to make scripts).

If you need to add a runtime, you would probably do this.


Some language take advantage of the fact that Godot's has official Mono support in order to support C#. This way you can, for example, use F# and Clojure.

They start by adding a C# project and then modify it so it uses another language. This is viable if your language already compiles to .NET.


Some other languages can be added as plugins that implement the PluginScript class via GDNative. This is the case of Python and Lua (again) which you can get from the asset library.

This is the most user friendly way to add language support to Godot, but it is limited to what you can do with PluginScript.

Addendum: Gil Barbosa Reis, author of the aforementioned Lua bindings, has an article series about its implementation stuffed away in the repository (in English and Portugueses): godot-lua-pluginscript/extras/articles/. It is probably the most comprehensive tutorial to date.


Other languages are added by means of taking advantage of GDNative (They basically mimic what you would do with C++). This is the case of Nim, Rust, D, Haskell, Go, Swift

So that's how godot-rust works: make native libraries using rust and the godot-rust create and add them as if they were made in C++. For any language for which there are the means to make native libraries already, this is a good option.


Finally there is another way to add support for a language: a transpiler from that language to GDScript, which can be automated with an addon that might also be written in GDScript. This is the case of Lisp.

This last approach is mostly used for domain specific languages.

Polysaccharide answered 19/3, 2022 at 7:33 Comment(4)
thanks a lot for your answer.For example, when I want to bind the rust language to the godot game engine, how should I proceed? can you make a sample for me? It doesn't have to be with the rust language. It can also be python, ruby, dart, go.Aristarchus
@Aristarchus I think it is probably best to begin by making GDNative libraries following the official docs: docs.godotengine.org/en/stable/tutorials/scripting/gdnative/…. You are either going to implement a PluginScript that way, or convert it to a Godot module, or getting familiar with GDNative will help you later do the same in another language. Also, being familiar with the EditorPlugin (the same used for GDScript addons) might be useful. As for reference, you can look at some of the other languages bindings, see github.com/Vivraan/godot-lang-supportPolysaccharide
thanks. I learned how to make a plugin by reading the documentation but I still couldn't find an example how to bind a new language. Until I learn it, I guess there will be no language left unadded :)Aristarchus
@Aristarchus See addendum.Polysaccharide
B
1

The official docs here provide your answer:

Godot officially supports GDScript, C/C++, C#.

Some 3rd party languages that can be used are: Rust, D, Python, Nim, and Go.

Bagasse answered 19/3, 2022 at 2:52 Comment(3)
How do they add (bind) 3rd party language? For example, how can I bind the crystal language to godot game engine?Aristarchus
You could use this module here: github.com/kalinon/godot-crystal. Bindings for this module specifically use a binding generator for C++ which is what Godot supports out of the box.Bagasse
thanks a lot for your answer. My goal is not to use it, but to learn how to do it. What is the method I should follow in this project? How is it done, can you give an example?Aristarchus

© 2022 - 2024 — McMap. All rights reserved.