C++ bindings for the Godot script API

Fabio Alessandrelli 59d38a4119 Add test for extended object creation/deletion. 4 năm trước cách đây
.github bd82460780 CI: Disable test build to prepare for 4.0 extensions merge 4 năm trước cách đây
godot-headers @ 68174528c9 402e33a7dc headers: Track tag godot-3.3.3-stable 4 năm trước cách đây
godot-headers-temp b4632e317d Fix creation (and godot-side deletion) of extended objects. 4 năm trước cách đây
include 42dd64f22f Fix binding of function that takes Object * parameters. 4 năm trước cách đây
misc e4ed48976a Replace bindgins to work with extensions 4 năm trước cách đây
src b21069c573 _err_print_error only output p_message so swapped parameters around 4 năm trước cách đây
test 59d38a4119 Add test for extended object creation/deletion. 4 năm trước cách đây
.clang-format cba90d6301 Update clang-format to version 11 4 năm trước cách đây
.gitattributes 1f36c2307a Getting this to compile on mac os x 8 năm trước cách đây
.gitignore df9164b9bd Added TYPED_METHOD_BIND and c++17 flags to windows build and moved test project files 4 năm trước cách đây
.gitmodules b36df8f86c Rename godot_headers to godot-headers to match upstream rename 4 năm trước cách đây
CMakeLists.txt 50774cf0fb Add alias 4 năm trước cách đây
LICENSE.md 39a0567e81 Update copyright statement to 'Godot Engine contributors' 4 năm trước cách đây
Makefile e4ed48976a Replace bindgins to work with extensions 4 năm trước cách đây
README.md f3dea4b752 Add readme file (stub) 4 năm trước cách đây
SConstruct df9164b9bd Added TYPED_METHOD_BIND and c++17 flags to windows build and moved test project files 4 năm trước cách đây
binding_generator.py 2b1100c878 Use default initialization 4 năm trước cách đây

README.md

godot-cpp

C++ bindings for the Godot extension API.

Note: this is a work in progress for the extension system included in Godot 4.0

Stub

Both this whole bindings system and this document are still work in progress and thus it is still incomplete. It will be improved once the extension API is settled.

How to use

It's a bit similar to what it was for 3.x but also a bit different.

Compiling this repository generates a static library to be linked with your shared lib, just like before.

To use the shared lib in your Godot project you'll need a .gdextension file, which replaces what was the .gdnlibbefore. Follow the example:

[configuration]

entry_symbol = "example_library_init"

[libraries]

Linux.64 = "bin/x11/libgdexample.so"

The entry_symbol is the name of the function that initializes your library. It should be similar to following layout:

extern "C" {
GDNativeBool GDN_EXPORT example_library_init(const GDNativeInterface *p_interface, const GDNativeExtensionClassLibraryPtr p_library, GDNativeInitialization *r_initialization) {
	GDNativeBool result = godot::GDExtensionBinding::init(p_interface, p_library, r_initialization);

	if (result) {
		register_example_types();
	}

	return result;
}
}

The register_example_types() should register the classes in ClassDB, very like a Godot module would do.

using namespace godot;
void register_example_types() {
	ClassDB::register_class<Example>();
}

Extension registering has not yet been added to the Godot editor, so to make it recognize your extension you need to add the following section to your project.godot:

[native_extensions]

paths=["res://example.gdextension"]

Any node and resource you register will be available in the corresponding Create... dialog. Any class will be available to scripting as well.

Example

Check the project in the test folder for an example on how to use and register different things.

This project isn't yet made to run in CI.

Issues

This really needs to be tested and very likely has things missing that weren't noticed yet. Use at your own risk (and contribute back with reports and fixes if you can).