Trait gdnative::nativescript::NativeClass[][src]

pub trait NativeClass: 'static {
    type Base: GodotObject;
    type UserData: UserData;
    pub fn class_name() -> &'static str;

    pub fn init(_owner: TRef<'_, Self::Base, Shared>) -> Self { ... }
pub fn register_properties(_builder: &ClassBuilder<Self>) { ... }
pub fn new_instance() -> Instance<Self, Unique>
    where
        Self::Base: Instanciable
, { ... }
pub fn emplace(self) -> Instance<Self, Unique>
    where
        Self::Base: Instanciable
, { ... } }

Trait used for describing and initializing a Godot script class.

This trait is used to provide data and functionality to the "data-part" of the class, such as name, initialization and information about exported properties.

A derive macro is available for this trait. See documentation on the NativeClass macro for detailed usage and examples.

For exported methods, see the NativeClassMethods trait.

Associated Types

type Base: GodotObject[src]

Base type of the class.

In Godot, scripting languages can define "script instances" which can be attached to objects. Because of the dynamic nature, the intended "inheritance" is not easily implementable properly.

Instead, delegation is used and most calls to a Godot object query the script instance first. This way, some methods can be "overwritten" and new ones can be exposed.

This only works when using so called "variant calls", since the querying of the script instance is performed there. When not using variant calls, any direct(*) calls have to be made to the Godot object directly.

The base type describes the "most general" type of object this script class can be attached to.

(*): GDNative enables use of "ptrcall"s, which are wrappers for function pointers. Those do not do explicit checks for script implementations unless the method implementation does.

type UserData: UserData[src]

User-data wrapper type of the class.

See module-level documentation on user_data for more info.

Loading content...

Required methods

pub fn class_name() -> &'static str[src]

The name of the class.

In GDNative+NativeScript many classes can be defined in one dynamic library. To identify which class has to be used, a library-unique name has to be given.

Loading content...

Provided methods

pub fn init(_owner: TRef<'_, Self::Base, Shared>) -> Self[src]

Function that creates a value of Self, used for the script-instance. The default implementation simply panics.

This function has a reference to the owner object as a parameter, which can be used to set state on the owner upon creation or to query values

It is possible to declare script classes without zero-argument constructors. Instances of such scripts can only be created from Rust using Instance::emplace. See documentation on Instance::emplace for an example.

pub fn register_properties(_builder: &ClassBuilder<Self>)[src]

Register any exported properties to Godot.

pub fn new_instance() -> Instance<Self, Unique> where
    Self::Base: Instanciable
[src]

Convenience method to create an Instance<Self, Unique>. This is a new Self::Base with the script attached.

If Self::Base is manually-managed, then the resulting Instance must be passed to the engine or manually freed with Instance::free. Otherwise, the base object will be leaked.

Must be called after the library is initialized.

pub fn emplace(self) -> Instance<Self, Unique> where
    Self::Base: Instanciable
[src]

Convenience method to emplace self into an Instance<Self, Unique>. This is a new Self::Base with the script attached.

If Self::Base is manually-managed, then the resulting Instance must be passed to the engine or manually freed with Instance::free. Otherwise, the base object will be leaked.

Must be called after the library is initialized.

Loading content...

Implementors

Loading content...