Module OOP
Helper metatables for interfacing with Godot's OOP.
None of them are available directly for creation, but are rather returned by the API.
Class ClassWrapper
ClassWrapper.class_name | (string) Class name |
ClassWrapper.constructor | (Object (*)() ) Raw constructor function as returned by GDNative's godot_get_class_constructor . |
ClassWrapper:__index (key) | Returns a MethodBind if class has a method with that name, or an integer constant if there is any. |
ClassWrapper:__tostring () | Returns class_name |
ClassWrapper:get_parent_class () | Returns the parent class. |
ClassWrapper:has_property (name) | Returns whether class has a property named name . |
ClassWrapper:inherits (other) | Returns whether this Class inherits a parent Class. |
ClassWrapper:new (...) | Creates a new instance of a Class, initializing with the given values. |
Class MethodBind
MethodBind:__call (object, ...) | Calls the method in object . |
Class MethodBindByName
MethodBindByName.method_name | (string) Method name. |
MethodBindByName:__call (object, ...) | Returns the result of object:call(self.method_name, ...) . |
MethodBindByName:new (method_name) | Create a new method binding by name. |
Class ClassWrapper
Wrapper for Godot Classes, used to create instances or index constants.
These are constructed by
_G:__index
when indexing a known class name, e.g.: KinematicBody
.
- ClassWrapper.class_name
- (string) Class name
- ClassWrapper.constructor
-
(
Object (*)()
) Raw constructor function as returned by GDNative'sgodot_get_class_constructor
. This is used by new and should probably not be used directly.See also:
- ClassWrapper:__index (key)
-
Returns a MethodBind if class has a method with that name, or an integer
constant if there is any.
Parameters:
- key
Returns:
-
MethodBind
If
ClassDB:class_has_method(self.class_name, key)
Or
-
int
If
ClassDB:class_has_integer_constant(self.class_name, key)
Or
-
nil
- ClassWrapper:__tostring ()
-
Returns class_name
Returns:
- ClassWrapper:get_parent_class ()
-
Returns the parent class.
Returns:
- ClassWrapper:has_property (name)
-
Returns whether class has a property named
name
. Only properties fromClassDB:class_get_property_list()
return true.Parameters:
- name string Property name
Returns:
-
bool
- ClassWrapper:inherits (other)
-
Returns whether this Class inherits a
parent
Class.Parameters:
- other Other class name
Returns:
-
bool
- ClassWrapper:new (...)
-
Creates a new instance of a Class, initializing with the given values.
If Class inherits from Reference, the reference is initialized with
init_ref
and object is marked forunreference
ing at garbage-collection.Parameters:
- ...
Parameters forwarded to a call to
_init
Returns:
- ...
Parameters forwarded to a call to
Class MethodBind
MethodBind metatype, wrapper for
godot_method_bind
.
These are returned by ClassWrapper:__index and GDNative's godot_method_bind_get_method
.
- MethodBind:__call (object, ...)
-
Calls the method in
object
.Parameters:
- object Object
- ...
Returns:
-
Method return value
Class MethodBindByName
A method binding object that calls a method by name, as
object:call(method_name, ...)
.
These are returned by Object.__index if object:has_method(method_name)
is true.
- MethodBindByName.method_name
- (string) Method name.
- MethodBindByName:__call (object, ...)
-
Returns the result of
object:call(self.method_name, ...)
.Parameters:
- MethodBindByName:new (method_name)
-
Create a new method binding by name.
Parameters:
- method_name string
Returns:
Usage:
local method_bind = MethodBindByName:new(method_name) method_bind(object, ...)