diff options
author | George Marques <george@gmarqu.es> | 2021-02-09 15:09:39 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 15:09:39 -0300 |
commit | eafe6d96226da5ebf02ec35ca1599a45dd794cfc (patch) | |
tree | 16a99e0f9f8df68f3590986a92eff65f5615ca11 /test/src | |
parent | e2831ff5fab54a41e57976a529c6a42751a0a6c2 (diff) | |
parent | 279d63d6c53a40ab92a0357661b837e5232a5331 (diff) | |
download | redot-cpp-eafe6d96226da5ebf02ec35ca1599a45dd794cfc.tar.gz |
Merge pull request #477 from o01eg/ci-test-execute-3.2
Test built GDNative plugin with stable Godot
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/init.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/test/src/init.cpp b/test/src/init.cpp new file mode 100644 index 0000000..3eedb05 --- /dev/null +++ b/test/src/init.cpp @@ -0,0 +1,73 @@ +#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. */ + void _init() { + _name = String("SimpleClass"); + _value = 0; + } + + 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" + **/ + register_property<SimpleClass, String>("name", &SimpleClass::_name, String("SimpleClass")); + + /** Alternatively, with getter and setter methods: */ + register_property<SimpleClass, int>("value", &SimpleClass::set_value, &SimpleClass::get_value, 0); + + /** Registering a signal: **/ + register_signal<SimpleClass>("signal_name0"); // windows: error C2668: 'godot::register_signal': ambiguous call to overloaded function + 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>(); +} |