Godot

Using Chasm scripts as Godot GDExtension components with the ChasmComponent node.

The Chasm Godot plugin wraps your Chasm script as a GDExtension node (ChasmComponent). Attach it to any Godot node to drive it with Chasm logic.

Installation

1

Build the plugin

From the Chasm repo root:

cd engine/godot
scons

This produces libchasm_godot.dylib (macOS) or .so (Linux) in the bin/ directory.

2

Copy to your Godot project

Copy the entire engine/godot/ directory into your Godot project's addons/chasm/ folder. Godot will detect the GDExtension automatically.

3

Compile your Chasm script

chasm compile --engine godot player.chasm

This produces player.c. Compile it as a shared library alongside the plugin.

ChasmComponent

In the Godot editor, add a ChasmComponent node as a child of any node. Set the script_path property to your compiled .chasm module.

The component calls:

  • on_init(), when the node enters the scene tree
  • on_tick(dt), every _process(delta) call
  • on_draw(), every _draw() call (on CanvasItem nodes)

Accessing Godot from Chasm

The Godot binding provides extern functions for communicating with the host node:

# Read node properties
x = node_get_x()
y = node_get_y()

# Set node properties
node_set_position(new_x, new_y)
node_set_rotation(angle)

# Signals
node_emit_signal("died")

Example

@speed :: script = 150.0
@hp    :: script = 100

def on_tick(dt :: float) do
  dx = 0.0
  if key_down(:right) do dx = @speed  end
  if key_down(:left)  do dx = -@speed end

  x = node_get_x()
  node_set_position(x + dx * dt, node_get_y())

  if @hp <= 0 do
    node_emit_signal("died")
  end
end

Script Lifecycle

Module attributes follow the same lifetime rules as in any Chasm script. persistent attrs survive hot-reload; script attrs reset. The engine calls on_init once when the component is first attached.