Skip to content

Instantly share code, notes, and snippets.

@Frontrider
Created June 28, 2020 17:41
Show Gist options
  • Save Frontrider/7c25b39e71964bf353e8a9613dd9ba7a to your computer and use it in GitHub Desktop.
Save Frontrider/7c25b39e71964bf353e8a9613dd9ba7a to your computer and use it in GitHub Desktop.
use gdnative::*;
use gdnative::Node;
use NativeClass;
/// The HelloWorld "class"
#[derive(NativeClass)]
#[inherit(Node)]
pub struct Test;
// __One__ `impl` block can have the `#[methods]` attribute, which will generate
// code to automatically bind any exported methods to Godot.
#[methods]
impl Test {
/// The "constructor" of the class.
fn new(_owner: Node) -> Self {
Test
}
// To make a method known to Godot, use the #[export] attribute.
// In Godot, script "classes" do not actually inherit the parent class.
// Instead, they are "attached" to the parent object, called the "owner".
//
// In order to enable access to the owner, it is passed as the second
// argument to every single exposed method. As a result, all exposed
// methods MUST have `owner: BaseClass` as their second arguments,
// before all other arguments in the signature.
#[export]
fn _ready(&self, _owner: Node) {
// The `godot_print!` macro works like `println!` but prints to the Godot-editor
// output tab as well.
godot_print!("hello, world.");
}
fn _init(&self){
}
}
// Function that registers all exposed classes to Godot
fn init(handle: gdnative::init::InitHandle) {
handle.add_class::<Test>();
}
// macros that create the entry-points of the dynamic library.
godot_gdnative_init!();
godot_nativescript_init!(init);
godot_gdnative_terminate!();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment