Godot Object Compiler: Code Generator for Godot GDExtensions

8 months ago by LucaTuerk to c/gamedev

A Godot bindings generator for C++ GDExtensions. Contribute to LucaTuerk/godot-object-compiler development by creating an account on GitHub.

Hey all,

the last weeks I have been working away at the Godot Object Compiler, a Unreal Header Tool-esque code generator for Godot GDExtensions.

It allows you to annotate classes and it's members and generates the necessary bindings to register properties, functions and signals to the Godot engine.

Internally it uses a tree-sitter parser and generates a simplified AST so the generators can query f.e. the field and parameter types and automatically create the correct variant type and property hints.

Here's an example how what that can look like:

#include "characters/chicken.generated.h"

GODOT_CLASS();
class Chicken : public CharacterBody3D {
    GODOT_GENERATED_BODY();

public:
    void _physics_process(double p_delta) override;

        GODOT_SIGNAL();
        void goc_goc(float p_volume);

    GODOT_FUNCTION(AnyPeer, CallRemote, Reliable);
    void jump_the_fence();

    GODOT_FUNCTION(ScriptVirtual);
    int pick_food(const Ref<Food>& food);

    GODOT_CATEGORY("Behaviour");
    GODOT_GROUP("Movement");

    GODOT_PROPERTY();
    float speed = 10.0f;

    GODOT_SUBGROUP("Jumping");

    GODOT_PROPERTY();
    float jump_height = 2.0f;

    GODOT_PROPERTY();
    Ref<Curve> jump_curve;

private:
    GODOT_PROPERTY();
    TypedArray<Food> food_in_belly;
};

GODOT_GENERATED_GLOBAL();

The available property hints, usages, variant types, base classes etc are also parsed from the linked godot-cpp headers so it won't break when something changes upstream (to an extent of course). I'm currently testing with the 4.5 branch.

It's still early days, but if you have same feedback I'd love to hear it :)

gamedev
gamedev

@programming.dev

login for more options
6444
732
353

Welcome to the game development community! This is a place to talk about and post anything related to the field of game development.

Community Wiki

go to feed...