
Godot Object Compiler
A downloadable tool for Windows and Linux
The Godot Object Compiler is a code generation tool for GDExtensions. It generates bindings and other builderplate code for efficent development in C++ while maintaining full configurability via expressive macros generated directly from the godot-cpp source used to build your extension.
This is experimental software, please do not use this application in a production environment. Everything is still subject to change.
Example
GOC provides macros that guide the code generator and allows you to expose Godot Object derived classes and their properties, methods and signals to the engine.
Classes
#include "godot_object_compiler/macros.h"
#include "example_node.generated.h"
GODOT_CLASS();
class ExampleNode : public Node3D {
GODOT_GENERATED_BODY();
...
};
A class can be marked as a godot class so it is considered by the generators. Within the class body we add a generated body macro. This hook is used by the GOC to inject definitions into the class, such as getters and setters and other additional methods.
Properties
Next we might want to expose a bunch of properties. If needed we can always provide our own property hints and property usages within the macro parameters.
GODOT_PROPERTY(HintGlobalDir());
String global_path;
GODOT_PROPERTY(HintRange("0.0,1.0,0.01"));
float range;
GOC provides convenience functions for all possible hint and usage values parsed directly from the godot-cpp library your linking to.
While properties are always public within the engine, we can modify the access specifier of the generated getters and setters for access within our extension.
GODOT_PROPERTY(PublicGet, PrivateSet);
int cpp_private_property;
It is also possible to expose Godot Object types and typed collections.
GODOT_PROPERTY();
TypedDictionary<int, Texture2D> textures;
GODOT_PROPERTY();
Ref<Texture2D> texture;
GODOT_PROPERTY();
Node3D *target_node = nullptr;
Signals
If we want to add a signal we add a void method definition and mark it as a signal. This will register the signal with the appropriate method signature and generate an implementation for this method which can be used to emit the signal.
GODOT_SIGNAL();
void example_signal(int p_param);
Functions
GOC can also expose regular functions to the engine, and script virtual functions can be bound with a simple tag.
GODOT_FUNCTION();
Node *exposed_function();
GODOT_FUNCTION(ScriptVirtual);
int virtual_function(Node *p_param);
GODOT_FUNCTION();
static int static_function();
Enums
Lets say we want to add a flags property to our node. We can add a marked enum to the class body, and specify that we would like this enum to be treated as flags in the macro parameters.
GODOT_ENUM(EnumFlags);
enum ExampleFlags {
FLAG_A = 1 << 0,
FLAG_B = 1 << 1,
FLAG_C = 1 << 2,
};
Next we add the property. The GOC queries the enum type and generates appropriate code to expose this property with the property hint to bind the enum names and values.
GODOT_PROPERTY();
ExampleFlags flags = FLAG_A;
Last but not least we add a generated global macro outside the class body. GOC uses this hook to generate code that needs to be added in the global namespace such as the enum variant cast macros.
GODOT_GENERATED_GLOBAL();
Usage
GOC currently ships with integrations for CMake. The tools can be dumped into a local folder by calling the GOC executables init_tools program with a local path argument.
goc init_tools tools
CMake Integration
Include the tools file in your CMakeLists.txt and activate the GOC generator for your GDExtension target by specifying the target name and the sources root directory. GOC will then generate the bindings code for your targets source files.
include(tools/autogoc.cmake)
target_autogoc(${TARGET} src)
SConstruct Integration
tbd
Command Line Usage
You can also use the GOC as a CLI tool to manually generate the sources or build your own integrations. Execute
goc help
To show usage info
Check out the documentation documentation and the source code on github.
| Published | 18 hours ago |
| Status | Prototype |
| Category | Tool |
| Platforms | Windows, Linux |
| Author | Luca Ian Tuerk |
| Tags | cpp, gdextension, Generator, Godot, header, No AI, sourcecode, tool |
Download
Install instructions
Thank you for trying out the Godot Object Compiler!
Check out the documentation and let me know about issues on github. Please understand that this is experimental and under active development.

Leave a comment
Log in with itch.io to leave a comment.