gdnative_common/
lib.rs

1#![allow(non_snake_case)] // because of the generated bindings.
2
3extern crate gdnative_core;
4pub extern crate libc;
5
6pub use gdnative_core::*;
7
8use std::sync::{Once, ONCE_INIT};
9use std::ops::*;
10
11include!(concat!(env!("OUT_DIR"), "/common_types.rs"));
12
13impl NativeScript {
14    /// Try to down-cast from a `NativeScript` reference.
15    pub fn to_rust_script<T: NativeClass>(&self) -> Option<NativeRef<T>> {
16        unsafe {
17            // TODO: There's gotta be a better way.
18            let class = self.get_class_name();
19            let gd_name = GodotString::from_str(T::class_name());
20
21            if class != gd_name {
22                return None;
23            }
24
25            return Some(NativeRef::from_sys(self.this));
26        }
27    }
28
29    /// Up-cast to a `NativeScript` reference.
30    pub fn from_rust_script<T: NativeClass>(script: NativeRef<T>) -> NativeScript {
31        unsafe {
32            NativeScript::from_sys(script.sys())
33        }
34    }
35}