Single header GDNative high level API for C/C++.
- Single header: just copy
hgdn.h
to your project, put #define HGDN_IMPLEMENTATION
in a single C/C++ source file before #include
ing it and compile.
- Depends only on godot-headers, so GDNative libraries can be built with a single compiler invocation. No need to generate Godot API bindings if you only use core GDNative stuff.
hgdn_gdnative_init
fetches all current GDNative APIs.
- Useful definitions for all math types, including Vector2, Vector3 and Color.
- Wrappers around strings and pool arrays with pointer and size available.
- Functions to get values from method arguments or native calls argument arrays.
- Functions to create Variants, Strings, Arrays, Pool Arrays and Dictionaries in single calls.
- Overloaded macro/functions to create Variants, available in C11 and C++.
- Macros to assert arguments preconditions, like expected argument count and (TODO) expected argument types.
Documentation
Code is documented using Doxygen and is available online here.
Usage example
For a working example with full Godot project, check out the high-level-gdnative-example repository.
#define HGDN_STATIC
#define HGDN_IMPLEMENTATION
GDN_EXPORT godot_variant get_message(godot_array *args) {
}
GDN_EXPORT godot_variant square(godot_array *args) {
godot_real x = hgdn_array_get_real(args, 0);
}
GDN_EXPORT godot_variant sum_ints(godot_array *args) {
int sum = 0;
for (int i = 0; i < int_array.size; i++) {
sum += int_array.ptr[i];
}
}
GDN_EXPORT void godot_gdnative_init(godot_gdnative_init_options *options) {
hgdn_gdnative_init(options);
hgdn_print("GDNative initialized%s", options->in_editor ? " in editor" : "");
}
GDN_EXPORT void godot_gdnative_terminate(godot_gdnative_terminate_options *options) {
hgdn_gdnative_terminate(options);
}
GDN_EXPORT void godot_nativescript_init(void *desc) {
}
#define HGDN_ASSERT_ARRAY_SIZE(arr, min_size)
If arr doesn't have at least min_size elements, print error message and return nil Variant.
Definition: hgdn.h:367
#define hgdn_new_variant(value)
Overloaded function/macro for creating Variants from any values. Available in C++ and C11.
Definition: hgdn.h:765
hgdn.h – High level GDNative C/C++ API
# example.gd
extends Reference
func _ready() -> void:
var example = GDNative.new()
example.library = preload("res://path_to_gdnativelibrary.gdnlib")
example.initialize() # --> "GDNative initialized"
print(example.call_native("standard_varcall", "get_message", [])) # --> "Hello world!"
print(example.call_native("standard_varcall", "square", [5])) # --> 25
print(example.call_native("standard_varcall", "sum_ints", [[1, 2.5, 3]])) # --> 6