GitHub - godot-nim/gdext-nim: Nim for GDExtension — a pure library and CLI tool. (original) (raw)


Quick start

nimble install gdext@0.12.1 mkdir testproject && cd $_ touch project.godot gdextwiz new-extension MyExtension gdextwiz run

Features

Limitations

vs. GDScript

Nim and GDScript have very similar syntax, making porting between them relatively straightforward.

# Nim import gdext import gdext/classes/[gdSprite2D, gdInput] type MySprite2D* {.gdsync.} = ptr object of Sprite2D speed: float = 400 angular_speed: float = PI method process(self: MySprite2D; delta: float64) {.gdsync.} = var direction = 0 if Input.is_action_pressed("ui_left"): direction = -1 if Input.is_action_pressed("ui_right"): direction = 1 self.rotation = self.rotation + self.angular_speed * direction * delta var velocity: Vector2 if Input.is_action_pressed("ui_up"): velocity = Vector2.Up.rotated(self.rotation) * self.speed self.position = self.position + velocity * delta # GDScript extends Sprite2D var speed = 400 var angular_speed = PI func _process(delta): var direction = 0 if Input.is_action_pressed("ui_left"): direction = -1 if Input.is_action_pressed("ui_right"): direction = 1 rotation += angular_speed * direction * delta var velocity = Vector2.ZERO if Input.is_action_pressed("ui_up"): velocity = Vector2.UP.rotated(rotation) * speed position += velocity * delta

gif

Guntur Sarwohadi (@guntur-ctech) reports that optimizing the build configuration for a simple port can yield performance gains of up to 6×.

https://github.com/guntur-ctech/simulation-performance-comparison

Commands

install

Installs the gdext library and its CLI tool gdextwiz.

nimble install gdext@0.12.1

The gdextwiz tool will be installed to ~/.nimble/bin, which is automatically added to your PATH if you've installed Nim via the official method.

uninstall

Removes the library and CLI tool:

CLI Tool: gdextwiz

Use gdextwiz to create, build, and run your GDExtension projects from the command line.

📘 For detailed usage and subcommands, see the gdextwiz manual.

Supported environments

OS

Engine

Nim compiler

Macos


Use Nim installed via Homebrew, not choosenim. This is because Godot requires a native AArch64/ARM64 binary, while choosenim installs an x86_64 version that runs via Rosetta emulation.

Tested by author

Note

Support for other environments depends on community feedback. Please consider contributing your findings!