Skip to content

Instantly share code, notes, and snippets.

@nical
Created August 31, 2018 15:44
Show Gist options
  • Save nical/3be359b1f180b6d8b6c337b24d533ae1 to your computer and use it in GitHub Desktop.
Save nical/3be359b1f180b6d8b6c337b24d533ae1 to your computer and use it in GitHub Desktop.
gdnative sugar
struct Test {
header: NativeInstanceHeader,
frame_count: u64,
}
impl Test {
fn new(header: NativeInstanceHeader) -> Self {
Test {
header,
frame_count: 0,
}
}
fn _ready(&mut self) {
godot_print!("Hello world!");
}
fn _process(&mut self, delta: f32) {
self.frame_count += 1;
}
}
impl NativeClass for Test {
fn class_name() -> &'static str {
"Test"
}
fn get_header(&self) -> &NativeInstanceHeader {
&self.header
}
}
godot_create_class_register_func!(
// optional namespace
Test,
Test::new, // constructor
fn _ready(&mut self) -> (),
fn _process(&mut self, delta: f32) -> (),
);
fn init(handle: init::InitHandle) {
let class_builder = godot_register_class! {
name: Test,
base_class: Node,
constructor: Test::new,
methods: [
fn _ready(&mut self) -> (),
fn _process(&mut self, delta: f32) -> (),
],
properties: [
// etc.
],
// other things?
};
// can still use the builder here for things the macro does not handle
}
godot_gdnative_init!();
godot_gdnative_terminate!();
godot_nativescript_init!(init);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment