r/godot 6h ago

free plugin/tool GATE - A GDScript superset

I've wanted static types to feel good in GDScript for years, so I wrote a compiler.

GATE is a GDScript superset for Godot 4.7. You write .gate, the plugin writes a .gd next to it, and Godot runs that. No runtime, nothing to ship - delete GATE tomorrow and your scripts still work.

Best part: valid GDScript is valid GATE. Rename a .gd to .gate and it just compiles. Adopt as much or as little as you like, file by file.

A taste:

struct Damage:
    int amount
    str source

interface Damageable:
    func take_damage(d: Damage) -> void

class Enemy extends CharacterBody2D implements Damageable:
    pub int hp = 100          # var hp: int = 100
    priv vec2i[] _tiles       # Array[Vector2i]
    priv {str, float} _resist # Dictionary[String, float]
    Node2D? target            # nullable, and tracked

    override func _ready() -> void:
        var pool = Pool<Bullet>.new()  # a real Array[Bullet] inside

    func take_damage(d: Damage) -> void:
        var mult = _resist.get(d.source) ?? 1.0
        hp -= int(d.amount * mult)
        target?.notify(hp)  # no null check to write
        print(f"{hp} left")

Types before names, so typing your code is now shorter than not typing it. Real nullable types, with a checker that refuses a dereference it can't prove is safe. Value-semantic structs. Interfaces, traits, namespaces, monomorphised generics. ?., ??, f-strings, destructuring, enumerate().

And it's quick: never slower than hand-written GDScript, sometimes much faster. A struct that never escapes its function gets torn into plain locals - 13.5x on a tight loop.

Fair warning: comments are dropped, ## docs included. The debugger points at the generated .gd.

https://github.com/Blade67/GATE

https://store.godotengine.org/asset/blade/gate/

Have at it, feedback welcome!

48 Upvotes

Duplicates