2020-11-28 09:05:00 +00:00
|
|
|
#include <Godot.hpp>
|
|
|
|
#include <Reference.hpp>
|
|
|
|
|
|
|
|
using namespace godot;
|
|
|
|
|
|
|
|
class SimpleClass : public Reference {
|
|
|
|
GODOT_CLASS(SimpleClass, Reference);
|
|
|
|
|
|
|
|
public:
|
|
|
|
SimpleClass() {}
|
|
|
|
|
|
|
|
/** `_init` must exist as it is called by Godot. */
|
2020-11-28 10:08:17 +00:00
|
|
|
void _init() {
|
|
|
|
_name = String("SimpleClass");
|
|
|
|
_value = 0;
|
|
|
|
}
|
2020-11-28 09:05:00 +00:00
|
|
|
|
|
|
|
void test_void_method() {
|
|
|
|
Godot::print("This is test");
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant method(Variant arg) {
|
|
|
|
Variant ret;
|
|
|
|
ret = arg;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _register_methods() {
|
|
|
|
register_method("method", &SimpleClass::method);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The line below is equivalent to the following GDScript export:
|
|
|
|
* export var _name = "SimpleClass"
|
|
|
|
**/
|
2020-11-28 10:08:17 +00:00
|
|
|
register_property<SimpleClass, String>("name", &SimpleClass::_name, String("SimpleClass"));
|
2020-11-28 09:05:00 +00:00
|
|
|
|
|
|
|
/** Alternatively, with getter and setter methods: */
|
2020-11-28 10:08:17 +00:00
|
|
|
register_property<SimpleClass, int>("value", &SimpleClass::set_value, &SimpleClass::get_value, 0);
|
2020-11-28 09:05:00 +00:00
|
|
|
|
|
|
|
/** Registering a signal: **/
|
2021-02-06 20:19:40 +00:00
|
|
|
register_signal<SimpleClass>("signal_name0"); // windows: error C2668: 'godot::register_signal': ambiguous call to overloaded function
|
2020-11-28 09:05:00 +00:00
|
|
|
register_signal<SimpleClass>("signal_name1", "string_argument", GODOT_VARIANT_TYPE_STRING);
|
|
|
|
}
|
|
|
|
|
|
|
|
String _name;
|
|
|
|
int _value;
|
|
|
|
|
|
|
|
void set_value(int p_value) {
|
|
|
|
_value = p_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_value() const {
|
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** GDNative Initialize **/
|
|
|
|
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
|
|
|
|
godot::Godot::gdnative_init(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** GDNative Terminate **/
|
|
|
|
extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o) {
|
|
|
|
godot::Godot::gdnative_terminate(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** NativeScript Initialize **/
|
|
|
|
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) {
|
|
|
|
godot::Godot::nativescript_init(handle);
|
|
|
|
|
|
|
|
godot::register_class<SimpleClass>();
|
|
|
|
}
|