module Lapis::Docs::F_SCRIPTING_AND_INTEROPERABILITY::B_GDSCRIPT_INTEROP

Overview

GDScript Interoperability & Project Bindings

Comprehensive guide to calling GDScript functions from Crystal, invoking Crystal methods from GDScript, and generating strongly-typed wrappers for custom project nodes with lapis bind.

Executive Summary & Key Topics

Topic Method / Anchor Description
Interoperability Modalities .topic_00_interop_modes Dynamic reflection calls vs compile-time strongly-typed project bindings.
Automated Typed Project Bindings (lapis bind) .topic_01_typed_project_bindings Generating strongly-typed Crystal wrappers for GDScript custom nodes.

Related Guides & Source References

Defined in:

libgodot/docs/f_scripting_and_interoperability/b_gdscript_interop.cr

Class Method Summary

Class Method Detail

def self.topic_00_interop_modes : Nil #

Interoperability Modalities: Dynamic reflection calls vs compile-time strongly-typed project bindings.

Key Topics & Information

  • Dynamic calls: node.call("my_method", *args) with Variant marshaling
  • Strongly-typed project bindings: Generated Crystal classes for all project GDScript scripts
  • Cross-language signals: Subscribing to GDScript signals in Crystal and vice versa

def self.topic_01_typed_project_bindings : Nil #

Automated Typed Project Bindings (lapis bind): Generating strongly-typed Crystal wrappers for GDScript custom nodes.

When you run:

lapis bind

Lapis inspects all .gd scripts in your project and generates typed Crystal wrapper classes under src/generated/project_nodes/.

Calling GDScript from Crystal:

# Strongly typed GDScript interop:
inventory = get_node("Inventory").as(GDScript::InventorySystem)
inventory.add_item("potion_health", 5) # Type-checked at compile time!

Calling Crystal from GDScript:

var player = $Player # Crystal node registered in ClassDB
player.take_damage(25) # Calls Crystal def take_damage directly!