Giter Club home page Giter Club logo

godot-cpp's Introduction

godot-cpp

Warning

This repository's master branch is only usable with GDExtension from Godot's master branch.

For users of stable branches, switch to the branch matching your target Godot version:

Or check out the Git tag matching your Godot version (e.g. godot-4.1.1-stable).

For GDNative users (Godot 3.x), switch to the 3.x or the 3.5 branch.

This repository contains the C++ bindings for the Godot Engine's GDExtensions API.

Versioning

This repositories follows the same branch versioning as the main Godot Engine repository:

  • master tracks the current GDExtension development branch for the next Godot 4.x minor release.
  • 3.x tracks the development of the GDNative plugin for the next 3.x minor release.
  • Other versioned branches (e.g. 4.0, 3.5) track the latest stable release in the corresponding branch.

Stable releases are also tagged on this repository: Tags.

For any project built against a stable release of Godot, we recommend using this repository as a Git submodule, checking out the specific tag matching your Godot version.

As the master branch of Godot is constantly getting updated, if you are using godot-cpp against a more current version of Godot, see the instructions in the gdextension folder to update the relevant files.

Compatibility

Warning: The GDExtension API is brand new in Godot 4.0, and is still considered in beta stage, despite Godot 4.0 itself being released.

This applies to both the GDExtension interface header, the API JSON, and this first-party godot-cpp extension.

Some compatibility breakage is to be expected as GDExtension and godot-cpp get more used, documented, and critical issues get resolved. See the Godot issue tracker and the godot-cpp issue tracker for a list of known issues, and be sure to provide feedback on issues and PRs which affect your use of this extension.

Contributing

We greatly appreciate help in maintaining and extending this project. If you wish to help out, ensure you have an account on GitHub and create a "fork" of this repository. See Pull request workflow for instructions.

Please install clang-format and copy the files in misc/hooks into .git/hooks so formatting is done before your changes are submitted.

Getting started

You need the same C++ pre-requisites installed that are required for the godot repository. Follow the official build instructions for your target platform.

Getting started with GDExtensions is a bit similar to what it was for 3.x but also a bit different.

This new approach is much more akin to how core Godot modules are structured.

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 .gdnlib before. See example.gdextension used in the test project:

[configuration]

entry_symbol = "example_library_init"
compatibility_minimum = "4.1"

[libraries]

macos.debug = "res://bin/libgdexample.macos.debug.framework"
macos.release = "res://bin/libgdexample.macos.release.framework"
windows.debug.x86_64 = "res://bin/libgdexample.windows.debug.x86_64.dll"
windows.release.x86_64 = "res://bin/libgdexample.windows.release.x86_64.dll"
linux.debug.x86_64 = "res://bin/libgdexample.linux.debug.x86_64.so"
linux.release.x86_64 = "res://bin/libgdexample.linux.release.x86_64.so"
# Repeat for other architectures to support arm64, rv64, etc.

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

extern "C" {

// Initialization.

GDExtensionBool GDE_EXPORT example_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
	godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);

	init_obj.register_initializer(initialize_example_module);
	init_obj.register_terminator(uninitialize_example_module);
	init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);

	return init_obj.init();
}
}

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

using namespace godot;
void initialize_example_module(ModuleInitializationLevel p_level) {
	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
		return;
	}
	GDREGISTER_CLASS(Example);
}

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

Examples and templates

See the godot-cpp-template project for a generic reusable template.

Or checkout the code for the Summator example as shown in the official documentation.

godot-cpp's People

Contributors

aaronfranke avatar adamscott avatar akien-mga avatar aqnuep avatar asmaloney avatar athousandships avatar bastiaanolij avatar bruvzg avatar calinou avatar daylily-zeleen avatar dependabot[bot] avatar dmaroo avatar dmitriysalnikov avatar dsnopek avatar faless avatar fractaldiane avatar groud avatar karroffel avatar marcelofg55 avatar mihe avatar o01eg avatar rameshravone avatar redwanfox avatar repiteo avatar shatur avatar sheepandshepherd avatar touilleman avatar vnen avatar zhehangd avatar zylann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

godot-cpp's Issues

Build error on Ubuntu 16.04

$ scons godotbinpath="../../godot/bin/" headers="../godot_headers/" p=x11 generate_bindings=yes
scons: Reading SConscript files ...
../../godot/bin/godot.x11.tools.64
OpenGL ES 3.0 Renderer: Mesa DRI Intel(R) Ivybridge Desktop
GLES3: max ubo light: 409
GLES3: max ubo reflections: 455, ubo size: 144
ARVR: Registered interface: Native mobile
scons: done reading SConscript files.
scons: Building targets ...
g++ -o src/core/Array.o -c -I. -I/data/Documents/GitHub/Simplegd-CPP/godot_headers -Iinclude -Iinclude/core src/core/Array.cpp
In file included from include/core/Variant.hpp:9:0,
                 from src/core/Array.cpp:2:
include/core/Basis.hpp:15:21: error: member 'godot::Vector3 godot::Basis::<anonymous union>::elements [3]' with constructor not allowed in union
   Vector3 elements[3];
                     ^
include/core/Basis.hpp:15:21: note: unrestricted unions only available with -std=c++11 or -std=gnu++11
include/core/Basis.hpp:16:11: error: member 'godot::Vector3 godot::Basis::<anonymous union>::x' with constructor not allowed in union
   Vector3 x, y, z;
           ^
include/core/Basis.hpp:16:14: error: member 'godot::Vector3 godot::Basis::<anonymous union>::y' with constructor not allowed in union
   Vector3 x, y, z;
              ^
include/core/Basis.hpp:16:17: error: member 'godot::Vector3 godot::Basis::<anonymous union>::z' with constructor not allowed in union
   Vector3 x, y, z;
                 ^
In file included from src/core/Array.cpp:2:0:
include/core/Variant.hpp: In constructor 'godot::Variant::Variant(short unsigned int)':
include/core/Variant.hpp:129:73: warning: delegating constructors only available with -std=c++11 or -std=gnu++11
  inline Variant(unsigned short p_short) : Variant((unsigned int) p_short) {}
                                                                         ^
include/core/Variant.hpp: In constructor 'godot::Variant::Variant(signed char)':
include/core/Variant.hpp:131:66: warning: delegating constructors only available with -std=c++11 or -std=gnu++11
  inline Variant(signed char p_char) : Variant((signed int) p_char) {}
                                                                  ^
include/core/Variant.hpp: In constructor 'godot::Variant::Variant(unsigned char)':
include/core/Variant.hpp:133:70: warning: delegating constructors only available with -std=c++11 or -std=gnu++11
  inline Variant(unsigned char p_char) : Variant((unsigned int) p_char) {}
                                                                      ^
scons: *** [src/core/Array.o] Error 1
scons: building terminated because of errors.

Calling a Godot object function returning a Ref<T> produces a leak

411d2f6

I found this by testing the following in my code:

Causes an ObjectDB leak:

void HeightMap::_notification(int p_what) {
	switch (p_what) {
		case Spatial::NOTIFICATION_ENTER_WORLD:
			owner->get_world();
			break;

Causes no leak:

void HeightMap::_notification(int p_what) {
	switch (p_what) {
		case Spatial::NOTIFICATION_ENTER_WORLD:
			//owner->get_world();
			break;

The same happens if I try with Sprite::get_texture(), when a texture is set.
It appears I can't reproduce it with functions from custom classes.

Passing doubles to methods doesn't seem to work

When trying to call functions that take doubles as arguments (double on the bindings side usually and float internally), the value received by the function in the bindings is correct, but the value received inside the actual function is incorrect. Some examples are: set_rotation_deg, set_rotation, set_rotation_in_degrees. The value received on the engine side is NaN for most functions affected by this. Another affected function is set_anchor. In this case a 0 is received when 1 is passed as the second argument.

My local godot, godot-cpp and godot_headers repositories are up-to-date and I'm on Ubuntu 17.06 using GCC. The issue was also present on Windows 10 using MSVC, before the linking issue on Windows appeared.

Drawing Texture from C++ Causes SIGSEGV

I'm not sure if this is an issue here or in Godot, but any attempt to draw a Ref will cause a segfault. Neither owner->draw_texture nor Ref<Texture>::draw will work. However, all other draw calls work fine (e.g: owner->draw_rect).

register_property doesn't work with const getter

The following code fails to compile if my getter is const:

	godot::register_property(
		"resolution",
		&HeightMapData::set_resolution,
		&HeightMapData::get_resolution,
		DEFAULT_RESOLUTION,
		GODOT_METHOD_RPC_MODE_DISABLED,
		GODOT_PROPERTY_USAGE_EDITOR,
		GODOT_PROPERTY_HINT_NONE);

The compiler is unable to find the overload.

Linking fails

I was told this is a better place to post this than AnswerHub, so the text below is mostly the same as it over there. In the meantime (during past couple of days) another person confirmed he's getting the same errors, we're both using Windows and MSVC. I tried again last night, with all the repos at latest commits, and the issue is still there, for me at least.

Here's a video demonstrating the issue:
https://www.youtube.com/watch?v=43JPCOEBEG0

Here are the linking errors from the output:
https://pastebin.com/zAkXSSgn

Below I posted some of the relevant project settings from a CMake project where I get these errors. The Visual Studio project is set up exactly the same and I get the same linking errors. I believe the includes and libraries are correctly set up as everything worked properly previously. The issue appeared a few days ago (could be something wrong with my setup, but I don't think I changed anything).

These are the includes I use:

${CMAKE_CURRENT_SOURCE_DIR}/../godot_headers
${CMAKE_CURRENT_SOURCE_DIR}/../godot-cpp/include/core
${CMAKE_CURRENT_SOURCE_DIR}/../godot-cpp/include

I link to these two libraries:

${CMAKE_CURRENT_SOURCE_DIR}/../godot/bin/godot.windows.tools.64.lib
${CMAKE_CURRENT_SOURCE_DIR}/../godot-cpp/bin/godot_cpp_bindings.lib

Here's the folder structure:
https://ibb.co/d3kZfb

The "godot_cpp_bindings.lib" and "godot.windows.tools.64.lib" are compiled from the most recent commit from a few hours ago from the godot and godot-cpp repositories. The godot_headers repo was also up-to-date.

I'm on Windows 10, I tried using MSVC2015 and MSVC2017.

Reference leak even without using Ref<T>

In version 51f1d3c

I found out there is a leak even though I reference and dereference an object properly.
EDIT: no, I wasn't. Scroll to next message...

Here is my C++ class:

class Holder : public godot::GodotScript<godot::Node> {
	GODOT_CLASS(Holder)
public:
	godot::Resource *m_data;

	Holder() : m_data(nullptr) {
		DDD("Construct Holder");
	}

	~Holder() {
		DDD("Destruct holder");
		if(m_data) {
			m_data->unreference();
		}
	}

	void set_data(godot::Resource *p_res) {
		m_data = p_res;
		m_data->reference();
	}

	static void _register_methods() {
		godot::register_method("set_data", &Holder::set_data);
	}
};

And that's the GDScript test:

extends Node

const Holder = preload("res://addons/zylann.heightmap/holder.gdns")

func _ready():
	print("---------------------------->>>")
	test2()
	print("----------------------------<<<")


func test2():
	var holder = Holder.new()
	add_child(holder)
	var data = Resource.new()
	holder.set_data(data)

Here is the output when I launch the game, and then close it:

---------------------------->>>
Construct Holder
----------------------------<<<
Destruct holder
WARNING: ObjectDB::cleanup: ObjectDB Instances still exist!
     At: core\object.cpp:1989

Now, if I remove the call to set_data():

---------------------------->>>
Construct Holder
----------------------------<<<
Destruct holder

If I rewrite the Holder destructor like this, I get no leaks either:

	~Holder() {
		DDD("Destruct holder");
		if(m_data) {
			m_data->unreference();
			m_data->unreference();
		}
	}

So the question is:

  • Is GDNative adding a reference before sending the object to the C API?
  • Are the C++ bindings adding a reference when passing the resource to the method arguments?

Both of these things would be wrong IMO.

Compile error: Cannot open include file: 'AABB.hpp': No such file or directory

I'm stuck at compiling native cpp wrapper with Windows machine, here is the build log:

E:\Projects\GodotNative\godot_cpp>scons p=windows generate_bindings=yes
scons: Reading SConscript files ...

scons: warning: No version of Visual Studio compiler found - C/C++ compilers most likely not set correctly
File "E:\Projects\GodotNative\godot_cpp\SConstruct", line 14, in <module>

scons: warning: No version of Visual Studio compiler found - C/C++ compilers most likely not set correctly
File "E:\Projects\GodotNative\godot_cpp\SConstruct", line 16, in <module>
Activated GL 3.3 contextOpenGL ES 3.0 Renderer: GeForce 820M/PCIe/SSE2
GLES3: max ubo light: 409
GLES3: max ubo reflections: 455, ubo size: 144
ARVR: Registered interface: Native mobile
ERROR: VisualScriptLanguage::add_register_func: Condition ' register_funcs.has(p_name) ' is true.
   At: modules\visual_script\visual_script.cpp:2643

scons: warning: No version of Visual Studio compiler found - C/C++ compilers most likely not set correctly
File "E:\Projects\GodotNative\godot_cpp\SConstruct", line 71, in <module>
scons: done reading SConscript files.
scons: Building targets ...
cl /Fosrc\AcceptDialog.obj /c src\AcceptDialog.cpp /TP /nologo -EHsc -D_DEBUG /MDd /I. /IE:\Projects\GodotNative\godot_headers /Iinclude /Iinclude\core
AcceptDialog.cpp
cl /Fosrc\AnimatedSprite.obj /c src\AnimatedSprite.cpp /TP /nologo -EHsc -D_DEBUG /MDd /I. /IE:\Projects\GodotNative\godot_headers /Iinclude /Iinclude\core
AnimatedSprite.cpp
cl /Fosrc\AnimatedSprite3D.obj /c src\AnimatedSprite3D.cpp /TP /nologo -EHsc -D_DEBUG /MDd /I. /IE:\Projects\GodotNative\godot_headers /Iinclude /Iinclude\core
AnimatedSprite3D.cpp
cl /Fosrc\Animation.obj /c src\Animation.cpp /TP /nologo -EHsc -D_DEBUG /MDd /I. /IE:\Projects\GodotNative\godot_headers /Iinclude /Iinclude\core
Animation.cpp
cl /Fosrc\AnimationPlayer.obj /c src\AnimationPlayer.cpp /TP /nologo -EHsc -D_DEBUG /MDd /I. /IE:\Projects\GodotNative\godot_headers /Iinclude /Iinclude\core
AnimationPlayer.cpp
cl /Fosrc\AnimationTreePlayer.obj /c src\AnimationTreePlayer.cpp /TP /nologo -EHsc -D_DEBUG /MDd /I. /IE:\Projects\GodotNative\godot_headers /Iinclude /Iinclude\core
AnimationTreePlayer.cpp
cl /Fosrc\Area.obj /c src\Area.cpp /TP /nologo -EHsc -D_DEBUG /MDd /I. /IE:\Projects\GodotNative\godot_headers /Iinclude /Iinclude\core
Area.cpp
cl /Fosrc\Area2D.obj /c src\Area2D.cpp /TP /nologo -EHsc -D_DEBUG /MDd /I. /IE:\Projects\GodotNative\godot_headers /Iinclude /Iinclude\core
Area2D.cpp
cl /Fosrc\ArrayMesh.obj /c src\ArrayMesh.cpp /TP /nologo -EHsc -D_DEBUG /MDd /I. /IE:\Projects\GodotNative\godot_headers /Iinclude /Iinclude\core
ArrayMesh.cpp
src\ArrayMesh.cpp(13): fatal error C1083: Cannot open include file: 'AABB.hpp': No such file or directory
scons: *** [src\ArrayMesh.obj] Error 2
scons: building terminated because of errors.

GODOT_SUBCLASS macro: "no suitable constructor exists"

Context
Windows 10
Visual Studio 2015 Community Edition

Issue:
when using GODOT_SUBCLASS(NewNode, Node), the line below gives the following error:

inline NewNode(godot_object *o) : Node(o) {} (from cpp_bindings/include/core/Godot.hpp: line 58)

"no suitable constructor exists to convert from "godot_object *" to "godot::Node"

I arrived at this error while attempting to follow through the Player : KinematicBody2D example in the "GDNative is here!" article. Simplifying it to just extending a similar class NewNode from godot::Node caused the same error.

I understand if this isn't something that needs to be addressed at all since this stuff is still in development, technically. Just thought I'd bring it up in case it was unexpected / worthy of attention.

Can't set property for Native Script from Property Editor

After I've set a new value for registered property in Property Editor, I tried to read this value from GDScript.

var simpleclass = load("res://simple.gdns").new()
func _ready():
	print(simpleclass._count);

But received value setted in code (or random value if no initialisation in C++ code).
This is code for registering: register_property("_count", &SimpleClass::_count, int(0));
After some research, I found that addresses for my class object are different when setting from Editor and from GDScript. For example:
Value from _wrapped_setter using Editor: 90942992
Value from _wrapped_getter using GDScript: 90966512
Then I added a log to a constructor and found that my class was created 2 times. So I think this is the root of the problem. To be honestly, I don't know is it a bug or am I doing something wrong :)

[Idea] Run generation from Godot executable ?

Instead of messing with specifying in SConstruct where Godot executable resides not forgetting about trailing slash and also replacing tools.64 with tools.32, it might be more convenient to run binding generation from Godot executable (command line and/or from menu)

Windows 10 Visual Studio 2015 build: LNK2019 with WrappedMethod1, register_class, and register_method.

Context:

Windows 10
Visual Studio 2015 Community Edition
All command line operations executed using "Visual Studio x64 Native Tools Command Prompt"

Issue:

Got all the way through the tutorial on the README.md up to the clang operations. Built a VS project for DLLs and got to the Linker stage, but started running into issues.

Reproducible Steps:

  1. Initial Directory Structure
    . (Current folder)
    = godot (the actual godot engine fork)
    == bin
    = gdtest (the "test" folder we'll be operating in)
    == cpp_bindings (just cloned)
    == godot_headers (just cloned)
    == lib (empty)
    == src (empty)

  2. Go into cpp_bindings, open SConstruct file, change the godot_bin_path and godot_lib_path variables to each have as their value: "../../godot/bin/"

  3. From the cpp_bindings (executes successfully, creating godot_cpp_core.lib/.exp/.dll in cpp_bindings/bin):

    $ scons p=windows

  4. From the cpp_bindings (executes successfully, creating godot_cpp_bindings.lib/.exp/.dll in cpp_bindings/bin):

    $ scons p=windows target=bindings generate_bindings=yes

  5. Open visual studio. File > New > Project... . Select Win32 Application, project name gdtestdll, location is the gdtest directory. Checkbox "Create directory for solution". Select "Next" in the Win32 Application Wizard. Select DLL. Click the "Empty Project" checkbox. Click "Finish".

  6. Right Click "Source Files" in Solution Explorer, Add.. > New item. C++ source file called "init.cpp" to be placed in the project directory (gdnative/gdtestdll/gdtestdll). Copy/Paste the contents of the GitHub version into the file.

  7. Right Click "gdtestdll" in the Solution Explorer, Properties. Ensure that you are using All Configurations and All Platforms at the top.

  • VC++ Directories > Include Directories. Add the path at "gdtest/cpp_bindings/include" and "gdtest/godot_headers"
  • VC++ Directories > Library Directories. Add the path at "gdtest/cpp_bindings/bin"
  • Linker > Input > Additional Dependencies. Add "godot_cpp_code.lib" and "godot_cpp_bindings.lib"
  1. Update various path differences
  • Godot.hpp: lines 10, 11, 12, and 16 need "core/" prepended to the include. That is CoreTypes, Variant, Ref, and GodotGlobal.
  • Object.hpp: lines 17 and 18 need "core/" prepended to the include. That is CoreTypes and Ref.
  • Reference.hpp: lines 17 and 18 need "core/" prepended to the include. That is CoreTypes and Ref.
  1. Remove warnings:
  • transform2d.hpp: line 21, "class Rect2" changed to "struct Rect2" to maintain consistency with previous declaration.
  • transform2d.hpp: line 23, "struct GD_CPP_CORE_API Transform2D {" changed to a class with a "public:" placed right underneath it (for visibility) to maintain consistency with previous declaration.
  1. Change build target to be Debug x64 instead of Debug x86. Removes half of the linker errors.

Remaining errors in the Visual Studio Output:

Error	LNK2019	unresolved external symbol __imp_godot_variant_new_nil referenced in function "public: static struct godot_variant __cdecl godot::_WrappedMethod1<class SimpleClass,class godot::Variant,class godot::Variant>::__wrapped_method(void *,void *,void *,int,struct godot_variant * *)" (?__wrapped_method@?$_WrappedMethod1@VSimpleClass@@VVariant@godot@@V23@@godot@@SA?AUgodot_variant@@PEAX00HPEAPEAU3@@Z)	gdtestdll	D:\Source\GitHub\gdtest\gdtestdll\gdtestdll\init.obj	1	
Error	LNK2019	unresolved external symbol __imp_godot_script_register_class referenced in function "void __cdecl godot::register_class<class SimpleClass>(void)" (??$register_class@VSimpleClass@@@godot@@YAXXZ)	gdtestdll	D:\Source\GitHub\gdtest\gdtestdll\gdtestdll\init.obj	1	
Error	LNK2019	unresolved external symbol __imp_godot_script_register_method referenced in function "void __cdecl godot::register_method<class godot::Variant (__cdecl SimpleClass::*)(class godot::Variant)>(char *,class godot::Variant (__cdecl SimpleClass::*)(class godot::Variant),enum godot_method_rpc_mode)" (??$register_method@P8SimpleClass@@EAA?AVVariant@godot@@V23@@Z@godot@@YAXPEADP8SimpleClass@@EAA?AVVariant@0@V20@@ZW4godot_method_rpc_mode@@@Z)	gdtestdll	D:\Source\GitHub\gdtest\gdtestdll\gdtestdll\init.obj	1	
Error	LNK1120	3 unresolved externals	gdtestdll	D:\Source\GitHub\gdtest\gdtestdll\x64\Debug\gdtestdll.dll	1	

`const` methods cannot be registered

Godot 3.0 pre-alpha master
Windows 10 64 bits MSVC

When making a GDNative library using the C++ kit, I figured out C++ functions declared as const produce compilation errors when used in method bindings. As a result, none can be declared as such (mostly getters, calculations and things that should be guaranteed to be read-only). This is supported when making a module, I expected it to work in GDNative too.

My current workaround is a #define ZCONST that I use likeconst instead, except it's empty so nothing is actually const (and will replace it with const again once this is fixed^^)

CONNECT_DEFERRED already defined on Windows

CONNECT_DEFERRED enum in Object::ConnectFlags is already defined on Windows.

It could be fixed either to giver it some prefix as CF_CONNECT_DEFERRED or use some different coding style for enums as ConnectDeferred.

Arrays are freed too early

Here I registered a property buttons

class NativeMessageDialog : public  GDNativeDialog {
    GODOT_SUBCLASS(NativeMessageDialog, GDNativeDialog);
protected:
    String message;
    Array buttons;

public:
    static void _register_methods() {
        register_property<NativeMessageDialog, String>("message", &NativeMessageDialog::message, "");
        register_property<NativeMessageDialog, Array>("buttons", &NativeMessageDialog::buttons, Array());
    }
};

Then I use this class in GDScript as this.

var msg_dialog = NativeMessageDialog.new()
func _ready():
	msg_dialog.message = "This message is send from GDScript by GDNative"
	msg_dialog.buttons = ["Apply", "Cancel"]
     	msg_dialog.show()

func _on_Show_Message_pressed():
	# BUG: array are freed
        # msg_dialog.buttons = ["Apply", "Cancel"]
	msg_dialog.show()

The function Array.size is called by show to create buttons for the dialog.
The firs call of show works fine.
The second call of show crash my program as it call Array.size but the buttons is already freed.

Can't generate bindings

I downloaded a version of Godot from here:
http://fixnum.org/godot/#latest_complete

And followed your instructions to generate the cpp bindings up to this point:
scons p=linux target=bindings generate_bindings=yes

But get the following errors:

scons: Reading SConscript files ...
GLES3: max extensions: 356
GLES3: max ubo light: 409
GLES3: max ubo reflections: 455, ubo size: 144
ERROR: set_method_flags: Condition ' !check->method_map.has(p_method) ' is true.
At: core/class_db.cpp:1008.
ERROR: set_method_flags: Condition ' !check->method_map.has(p_method) ' is true.
At: core/class_db.cpp:1008.
ERROR: set_method_flags: Condition ' !check->method_map.has(p_method) ' is true.
At: core/class_db.cpp:1008.
ERROR: set_method_flags: Condition ' !check->method_map.has(p_method) ' is true.
At: core/class_db.cpp:1008.
mesege
ERROR: _gl_debug_print: GL ERROR: Source: OpenGL Type: Performance ID: 131218 Severity: Medium Message: Program/shader state performance warning: Vertex shader in program 1 is being recompiled based on GL state.
At: drivers/gles3/rasterizer_gles3.cpp:123.
ERROR: load: No loader found for resource: res://godot_api.json
At: core/io/resource_loader.cpp:213.
ERROR: start: Failed loading scene: res://godot_api.json
At: main/main.cpp:1462.
WARNING: cleanup: ObjectDB Instances still exist!
At: core/object.cpp:1910.
ERROR: cleanup: There are still MemoryPool allocs in use at exit!
At: core/dvector.cpp:69.
IOError: [Errno 2] No such file or directory: 'godot_api.json':
File "/home/pc/Applications/Godot/Godot3.0/SimpleLibrary/cpp_bindings/SConstruct", line 71:
binding_generator.generate_bindings(json_api_file)
File "/home/pc/Applications/Godot/Godot3.0/SimpleLibrary/cpp_bindings/binding_generator.py", line 9:
classes = json.load(open(path))

Troubles setting up on Windows

I have VS2017 and Qt Creator as IDE. No matter how hard I try to launch VsDevCmd.bat before scons, the binding lib seems to be compiled as 64 bit (somehow it even compiles without pre-launching anything, unlike Godot).
When I compile the sample from readme, I get this first:

default

Seems like wchar_t and unsigned short are the same on my platform.

If I comment out one of the operator declarations, I get a bunch of unresolved external symbol errors and the warning hint about 64 bits:
default

Cannot use Ref<T> where T is a GodotScript<T>

I have a custom resource type, but the code won't compile because T has no reference() function, only the owner of GodotScript<T> does. I'm not sure how to solve this...

The workaround I might use is to instead make my property expect a Ref<Resource> and cast the userdata on it to my custom class, which is obviously unsafe, but I don't see a better option at the moment.

GDNative exposes nativescript_api->godot_nativescript_get_userdata(obj) to get the custom classs instance as a void*, however there is not enough info to verify that pointer, unless each library tracks every single pointer it shares with Godot through this API, and fetches it back... basically, rewriting ObjectDB.
Such ObjectDB would also need to be thread-safe as well, unless we don't use Godot threads and rewrite ours.

type tags

As an example, in the Squirrel scripting language, integer typetags are carried along void* pointers, which allows to identify the native types of such userdatas, which makes it safer to retrieve them. Those typetags may come from a memory address, typically a static pointer per class, which by nature will be unique as long as the corresponding library is in memory (that tag could even be generated by GDNative actually). Type check would even easily be thread-safe. But GDNative doesn't have this, so rewriting a thread-safe ObjectDB in each library is the only option for now...

utf8 error spam

Godot 3.0 beta 1, Windows 10
I'm getting Godot #11440 kind of error again. Lots of invalid skip, invalid utf8, overlong rejected, and no space left.

Ref<T> leaks

The following code is leaking objects:

Ref<Image> test(new Image());

Apparently the reference counter is left at 1 and Godot prints Objects are still in ObjectDB.

Ambiguous Conversion Of 'godot::Variant' To 'godot::String' In Godot.hpp

Problem: Was following every step of the README. However, when running
clang -fPIC -o src/init.os -c src/init.cpp -g -O3 -std=c++14 -Icpp_bindings/include -Igodot_headers -Icpp_bindings/include/ a few errors occur.

Most are easy to resolve (unable to find included files due to incorrect path). But then there is following
In file included from src/init.cpp:1: cpp_bindings/include/core/Godot.hpp:64:42: error: ambiguous conversion for static_cast from 'godot::Variant' to 'godot::String' static T _arg_cast(Variant a) { return static_cast<T>(a); }

Same error occurs when using GCC.

Info:

  1. godot3.0 25f742c (from 15 Sept 2017)
  2. godot-cpp e32d7bb (15 Sept 2017)
  3. clang 4.0.1-5 / gcc 7.2.0-2

Wrap all core types

Wrap all the core types in C++ classes.

  • Array
  • Basis
  • Color
  • Dictionary
  • Image
  • InputEvent
  • NodePath
  • Plane
  • PoolArrays
  • Quat
  • Rect2
  • Rect3
  • RID
  • String
  • Transform
  • Transform2D
  • Variant
  • Vector2
  • Vector3

Cpp binding generator fails

call scons godotbinpath="%godot%/bin/godot.windows.tools.64.exe" headers="%godot%/modules/gdnative/include" p=Windows generate_bindings=yes

include\BakedLightmap.hpp(68): error C3646: 'bake': unknown override specifier
include\BakedLightmap.hpp(68): error C2059: syntax error: '('
include\BakedLightmap.hpp(68): error C2238: unexpected token(s) preceding ';'
src\BakedLightmap.cpp(187): error C2039: 'BakeError': is not a member of 'godot::BakedLightmap'
include\BakedLightmap.hpp(18): note: see declaration of 'godot::BakedLightmap'
src\BakedLightmap.cpp(187): error C2039: 'bake': is not a member of 'godot::BakedLightmap'
include\BakedLightmap.hpp(18): note: see declaration of 'godot::BakedLightmap'
src\BakedLightmap.cpp(187): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
src\BakedLightmap.cpp(187): error C2146: syntax error: missing ';' before identifier 'bake'
src\BakedLightmap.cpp(187): error C2143: syntax error: missing ';' before '{'
src\BakedLightmap.cpp(187): error C2447: '{': missing function header (old-style formal list?)
scons: *** [src\BakedLightmap.obj] Error 2
scons: building terminated because of errors.```

Problem with Booleanize,

Boolean from godot core or from the script is always false

To Reproduce create a method in GDNative with boolean arg and pass true from gdscript, recived variable will be false

pretty sure this is cause by 85641c5

Win10 VS2015-built DLL: Fails to load GDNativeLibrary

Context:
Windows 10
Visual Studio 2015 Community Edition
Godot latest as of commit ceded65 from 06/20/2017
Having just compiled a .dll in visual studio (walkthrough in this issue from /cpp_bindings.

Issue:
Built the cpp_bindings tutorial SimpleClass into the .dll. SimpleClass has no parent class it inherits from as far as the scripting language is concerned (?).
Attempting to load the .gdn resource after setting it to point towards the .tres of the GDNativeLibrary appears to fail with the following errors:

EDIT: Correction, this is the actual error (I copy/pasted this from an Issue in godot_headers, my bad)
Can't open dynamic library: [path to project_folder/gdtestdll.dll]. Error: 126
END EDIT

Can't open dynamic library: [path to project_folder/lib/gdtestdll.dll] Error: 126
Condition ' initialize_status != OK ' is true.
Condition ' !native_library->scripts.has(p_name) ' is true. returned: 0
Condition ' !script_data ' is true.

Reproducible Steps:

Created a project that literally just throws everything into the root godot project directory. I have the following:

.import (folder)
default_env.tres
gdtestdll.dll
gdtestdll.exp
gdtestdll.ilk
gdtestdll.lib
gdtestdll.pdb
gdtestdll.tres
godot_cpp_bindings.dll
godot_cpp_bindings.exp
godot_cpp_bindings.lib
godot_cpp_core.dll
godot_cpp_core.exp
godot_cpp_core.lib
icon.png
icon.png.import
main.tscn
project.godot
SimpleClass.gdn

main.tscn has a single Node2D with a Built-in GDScript that simply preload's "res://SimpleClass.gdn"

extends Node2D
var SimpleClass = preload("res://SimpleClass.gdn")

SimpleClass.gdn has Class Name "SimpleClass" and is pointing to res://gdtestdll.tres which in turn has its Windows value set to res://gdtestdll.dll

I set the default GDNativeLibrary in Project Settings to be res://gdtestdll.tres.

Despite all of that, it's still unable to "locate the module" as per Error 126 in Visual Studio

Calling a function taking a Ref<Resource> crashes

I have a set_data function, which does nothing yet:

void HeightMap::set_data(Ref<Resource> new_data_ref) {
}

Which is registered this way:

	godot::register_method("set_data", &HeightMap::set_data);

If I call it in GDScript:

func test():
	var terrain = HeightMap2.new()
	add_child(terrain)
	var data = Resource.new()
	terrain.set_data(data)
	print(terrain.get_data())

It produces a crash as soon as the function ends (the print gets printed before).
It looks like a double-delete.

image

It doesn't reproduce if I try fully in C++:

void test(Ref<Resource> r) {

}

void HeightMap::_register_methods() {

	Ref<Resource> res(memnew(Resource));
	test(res);

Because I am unable to debug I tried putting an assert(0)
image
But that's all I can see about the state of the ref:
image

Ref<T> pointer cast is unsafe

Ref is implemented by doing many casts to (T*), which means any object that don't match T will end up being referenced, produce corruption and crash the engine with no way to check and very little information given to the developper. This can happen either in C++, or even when used in GDScript, where you wouldn't expect such things.

In Godot, the same implementation does a cast too, because downcasting is needed, for example if you use Resource::duplicate(). However it's a safer cast because Object::cast_to is used instead, which produces an empty reference if the cast fails, which can be checked for null.
In GDNative we only have Object::is_class, but it requires a String argument, which is less efficient because we would need to convert class names from UTF-8 everytime a Ref is constructed from a variant (everytime Godot calls a GDNative function, basically). But maybe it's our only option...

In general, I think GDNative safety should be worked on, like checking arguments and object casting in order to at least have a way to null-check references and objects.

Reference design question

I'm a bit confused reading the way this is handled in code, please tell me if I'm wrong:

Currently, the C++ binding for Reference encapsulates a godot_object, right.

Now, let's say you create a Resource in GDScript which will hold 1 reference. Then you pass that Resource to a NativeScript, which will create a Resource wrapper on the heap and hold a 2nd reference.

But what happens if you unref that wrapper?
Two choices:

  1. You delete it, which will also call godot::api->godot_object_destroy on the Resource, which is pretty bad given the refcount may not be zero (due to the var being also in GDScript)

  2. The current option: you don't delete the wrapper, call unref() normally and let the object leave... which however leaves you with a leaking godot::Resource wrapper on the heap.

BUT...
Is that leak avoided by the fact classes actually don't "wrap" a pointer, but in fact ARE the pointer? I see this is casted to godot_object... which means, if the ref doesn't reach zero, Godot will free the memory. And if ref reaches zero, the C++ bindings will free it?
O.O

Compile Error: Godot.hpp:15:10: fatal error: Object.hpp: No such file or directory

I'm building on Windows with the current github master (bde1ce3) and am running into a 'no such file' issue. From the looks of the repo, Object.hpp isn't defined and I can't find it elsewhere in Godot's source or in the godot_headers repo.

Full text of the error (with run command):

D:\Source\TerminusExperiment\CPU_v1>g++ -g -fPIC -std=c++14 src\init.cpp -Icpp_bindings\include -Igodot_headers -ID:\Source\godot\ -ID:\Source\godot\modules\gdnative\include -o lib\init.obj
In file included from src\init.cpp:22:0:
cpp_bindings\include/core/Godot.hpp:15:10: fatal error: Object.hpp: No such file or directory
 #include <Object.hpp>
          ^~~~~~~~~~~~
compilation terminated.

At the time of writing, there is indeed no Object.hpp in the path: https://github.com/GodotNativeTools/godot-cpp/tree/master/include/core

No way to pack a Ref<T> inside a Variant without loosing reference on it

So after having issue #78 (comment), I went on trying to rewrite Ref<T> once again the same way as in Godot... but I found something the initial bindings implementation did not do: RefPtr.

Basically... how do I rewrite this part?

//---------------- Godot implementation ----------------
//	RefPtr get_ref_ptr() const {

//		RefPtr refptr;
//		Ref<Reference> *irr = reinterpret_cast<Ref<Reference> *>(refptr.get_data());
//		*irr = *this;
//		return refptr;
//	};

//	operator Variant() const {

//		return Variant(get_ref_ptr());
//	}
//------------------------------------------------------
	operator Variant() const {
		return Variant(???)
	}

// And the same for unpacking...

The initial implementation was returning Variant((Object *) reference);, but that doesn't hold a reference on the object, isn't it?

Even if I could call reference() to take the extra ref into account, how would Godot take it correctly since it expects a RefPtr?

Example where it would break:

	// Converted to Variant for interfacing with the C API
	Variant test() {
		Ref<Image> image(new Image());
		return image;
		// Aaaand image just got refcount down to zero.
	}

Bindings fail to build on Windows, with errors in Basis.hpp

I'm getting errors when I attempt to build the C++ bindings. I built a current version of Godot, and pointed the SConstruct file at the executable.

When I run this command:
scons headers="../godot_headers/" p=windows generate_bindings=yes

I get the following errors:

OpenGL ES 3.0 Renderer: GeForce GTX 970/PCIe/SSE2
GLES3: max ubo light: 409
GLES3: max ubo reflections: 455, ubo size: 144
ARVR: Registered interface: Native mobile
scons: done reading SConscript files.
scons: Building targets ...
cl /Fosrc\core\Array.obj /c src\core\Array.cpp /TP /nologo -EHsc -D_DEBUG /MDd /I. /IC:\Godot3\SimpleLib\godot_headers /Iinclude /Iinclude\core
Array.cpp
c:\godot3\simplelib\cpp_bindings\include\core\Basis.hpp(15) : error C2620: 'godot::Basis::elements' : illegal union member; type 'godot::Vector3' has a user-defined constructor or non-trivial default constructor
c:\godot3\simplelib\cpp_bindings\include\core\Basis.hpp(16) : error C2620: 'godot::Basis::x' : illegal union member; type 'godot::Vector3' has a user-defined constructor or non-trivial default constructor
c:\godot3\simplelib\cpp_bindings\include\core\Basis.hpp(16) : error C2620: 'godot::Basis::y' : illegal union member; type 'godot::Vector3' has a user-defined constructor or non-trivial default constructor
c:\godot3\simplelib\cpp_bindings\include\core\Basis.hpp(16) : error C2620: 'godot::Basis::z' : illegal union member; type 'godot::Vector3' has a user-defined constructor or non-trivial default constructor
scons: *** [src\core\Array.obj] Error 2
scons: building terminated because of errors.

I've got Visual Studio 2017 installed, so it should be using the associated compiler. Some googling suggested that there may have been a change in the way this type of union is handled in more recent versions of MSVC, but I think it should be fixed in VS2017.

Any ideas?

Godot crashed

Situation:
Cpp bindings and Godot headers are up to date (at this time). Same for Godot - built last night.
cpp:

#include <core/Godot.hpp>
#include <Reference.hpp>

using namespace godot;

class G : public GodotScript<Reference>
	{
	GODOT_CLASS(G);

	public:
		void ready()
			{
			Godot::print("in C++ ready!");
			}

		void process(float delta)
			{
			Godot::print("in C++ process!");
			}

		static void _register_methods()
			{
			register_method("_ready_cpp", &G::ready);
			register_method("_process_cpp", &G::process);
			}
	};

// GDNative initialize
GDNATIVE_INIT(godot_gdnative_init_options *options)
	{

	}

/** GDNative Terminate **/
GDNATIVE_TERMINATE(godot_gdnative_terminate_options *options)
	{

	}

/** NativeScript Initialize **/
NATIVESCRIPT_INIT()
	{
	register_class<G>();
	}

Backtrace:
[0] StringName::StringName (j:___godot_source\godot\core\string_db.cpp:191)
[1] godot_register_native_call_type (j:___godot_source\godot\modules\gdnative\gdnative\gdnative.cpp:115)
[2] <couldn't map PC to fn name>
[3] <couldn't map PC to fn name>
[4] <couldn't map PC to fn name>
[5] <couldn't map PC to fn name>
[6] <couldn't map PC to fn name>
[7] godot_nativescript_init
[8] NativeScriptLanguage::init_library (j:___godot_source\godot\modules\gdnative\nativescript\nativescript.cpp:1020)
[9] NativeScript::set_library (j:___godot_source\godot\modules\gdnative\nativescript\nativescript.cpp:126)
[10] MethodBind1<NativeScript,Ref >::call (j:___godot_source\godot\core\method_bind.gen.inc:815)
[11] ClassDB::set_property (j:___godot_source\godot\core\class_db.cpp:988)
[12] Object::set (j:___godot_source\godot\core\object.cpp:421)
[13] ResourceInteractiveLoaderText::poll (j:___godot_source\godot\scene\resources\scene_format_text.cpp:597)
[14] ResourceFormatLoader::load (j:___godot_source\godot\core\io\resource_loader.cpp:137)
[15] ResourceFormatLoaderNativeScript::load (j:___godot_source\godot\modules\gdnative\nativescript\nativescript.cpp:1181)
[16] ResourceLoader::_load (j:___godot_source\godot\core\io\resource_loader.cpp:172)
[17] ResourceLoader::load (j:___godot_source\godot\core\io\resource_loader.cpp:216)
[18] GDScriptParser::_parse_expression (j:___godot_source\godot\modules\gdscript\gdscript_parser.cpp:463)
[19] GDScriptParser::_parse_and_reduce_expression (j:___godot_source\godot\modules\gdscript\gdscript_parser.cpp:1776)
[20] GDScriptParser::_parse_class (j:___godot_source\godot\modules\gdscript\gdscript_parser.cpp:4029)
[21] GDScriptParser::_parse (j:___godot_source\godot\modules\gdscript\gdscript_parser.cpp:4372)
[22] GDScriptParser::parse (j:___godot_source\godot\modules\gdscript\gdscript_parser.cpp:4428)
[23] GDScript::reload (j:___godot_source\godot\modules\gdscript\gdscript.cpp:576)
[24] ResourceFormatLoaderGDScript::load (j:___godot_source\godot\modules\gdscript\gdscript.cpp:1864)
[25] ResourceLoader::_load (j:___godot_source\godot\core\io\resource_loader.cpp:172)
[26] ResourceLoader::load (j:___godot_source\godot\core\io\resource_loader.cpp:216)
[27] ResourceInteractiveLoaderText::poll (j:___godot_source\godot\scene\resources\scene_format_text.cpp:431)
[28] ResourceFormatLoader::load (j:___godot_source\godot\core\io\resource_loader.cpp:137)
[29] ResourceLoader::_load (j:___godot_source\godot\core\io\resource_loader.cpp:172)
[30] ResourceLoader::load (j:___godot_source\godot\core\io\resource_loader.cpp:216)
[31] Main::start (j:___godot_source\godot\main\main.cpp:1600)
[32] widechar_main (j:___godot_source\godot\platform\windows\godot_win.cpp:147)
[33] _main (j:___godot_source\godot\platform\windows\godot_win.cpp:171)
[34] main (j:___godot_source\godot\platform\windows\godot_win.cpp:183)
[35] __scrt_common_main_seh (f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283)
[36] BaseThreadInitThunk
-- END OF BACKTRACE --

min. project:
Frequency_0_0_1.zip

Trying out todays master

Just grabbed the latest master, got this error when compiling my space-colonization project on Mac OS X:

scons p=osx
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o src/mesh_tree.os -c -g -O3 -std=c++14 -arch x86_64 -fPIC -I/Users/basolij/Development/Godot/GDNative/godot_headers -I/Users/basolij/Development/Godot/GDNative/cpp_bindings/include -I/Users/basolij/Development/Godot/GDNative/cpp_bindings/include/core src/mesh_tree.cpp
g++ -o src/register_classes.os -c -g -O3 -std=c++14 -arch x86_64 -fPIC -I/Users/basolij/Development/Godot/GDNative/godot_headers -I/Users/basolij/Development/Godot/GDNative/cpp_bindings/include -I/Users/basolij/Development/Godot/GDNative/cpp_bindings/include/core src/register_classes.cpp
src/register_classes.cpp:16:19: error: unknown type name 'godot_native_init_options'
GODOT_NATIVE_INIT(godot_native_init_options *options) {
                  ^
src/register_classes.cpp:16:1: error: C++ requires a type specifier for all declarations
GODOT_NATIVE_INIT(godot_native_init_options *options) {
^
src/register_classes.cpp:20:24: error: unknown type name 'godot_native_init_options'
GODOT_NATIVE_TERMINATE(godot_native_init_options *options) {
                       ^
src/register_classes.cpp:20:1: error: C++ requires a type specifier for all declarations
GODOT_NATIVE_TERMINATE(godot_native_init_options *options) {
^
4 errors generated.
scons: *** [src/register_classes.os] Error 1
scons: building terminated because of errors.

I'm guessing I'm now missing godot_native_init_options... ?:)

const conversion in String::erase

I just tried the latest master at 83cc9b8
with the latest godot_headers at 23872837e77e39ba6ab21393f26e531d1ae0a7b6

Compiling the project with both clang and g++ on Ubuntu 16.04 yields the following problem:

: In member function 'void godot::String::erase(int, int) const':
src/core/String.cpp:157:21: error: invalid conversion from 'const godot_string*' to 'godot_string*' [-fpermissive]
  godot_string_erase(&_godot_string, position, chars);
                     ^~~~~~~~~~~~~~
In file included from include/core/String.hpp:4:0,
                 from src/core/String.cpp:1:
/home/mrminimal/Dev/SimpleLibrary/godot_headers/gdnative/string.h:167:12: note:   initializing argument 1 of 'void godot_string_erase(godot_string*, godot_int, godot_int)'
 void GDAPI godot_string_erase(godot_string *p_self, godot_int p_pos, godot_int p_chars);
            ^~~~~~~~~~~~~~~~~~

Any idea on how to fix it? Is it a preprocessor thing?

Recreating starter kit in newest master branch

Hello,
I'm having troubles at recreating starter kit in newest master branch. I've successfully managed to replace both include and lib folders to latest version of bindings and init.cpp file compiles but I get following error in Godot:
undefined symbol: _Z18gdnative_terminateP32godot_gdnative_terminate_options

Here's my init.cpp:
https://pastebin.com/YPPiDRzF (I'm aware that some stuff could be done better, e.g "owner" field but I was looking for simplest solution.
I would appreciate any help :)

Object.hpp: No such file or directory

I been trying to build a simple class

 gcc -fPIC -o src/init.os -c src/init.cpp -g -O3 -std=c++14 -Icpp_bindings/include -Igodot_headers -Icpp_bindings/include/core
In file included from src/init.cpp:1:0:
cpp_bindings/include/core/Godot.hpp:15:10: fatal error: Object.hpp: No such file or directory
 #include <Object.hpp>

I wondering how does godot-cpp build without an object header anywhere.

on another note, -Icpp_bindings/include is mentioned twice in the readme. I would had made a pull request to fix it if I manage to get this thing compiling

fix(README.md): add executable to `godotbinpath`

Note that the changes in 03380c0 now require the godotbinpath argument to specify the executable instead of just the path to the binary to generate the bindings.

I.e. ../godot_fork/bin/godot.x11.tools.64 instead of ../godot_fork/bin/

Please update the readme to accommodate this.

How to reference custom GodotScripts?

Let's say I expose this foo function:

class MyRef GodotScript<Reference> { 
    // ...
}

void NativeTest::foo(MyRef *arg) {
    // stuff
}

How can MyRef be safely referenced? The function is not explicitely adding to the refcount in any way, which means the following situation would either produce a dangling pointer, or a leak:

func _ready():
    native_test.foo(MyRef.new())

Unless this is done to keep the reference alive:

void NativeTest::foo(MyRef *arg) {
    m_myref_holder = Ref<Reference>(arg->owner);
}

The only "transparennt" way I can think of is to modify Ref in such a way it can reference GodotScript, so this could be written:

void NativeTest::foo(Ref<MyRef> arg {
    //...
}

Signals registered from base class are not avialiabe for its sub-classes.

Register classes like this

class BaseClass : public GodotScript<Reference> {
    GODOT_SUBCLASS(BaseClass, Reference);
public:
    static void _register_methods() {

        register_signal<BaseClass>("my_signal");

        register_property("title", &BaseClass::title, String());
    }

    String title;
};

class SubClass : public  BaseClass {
    GODOT_SUBCLASS(SubClass, BaseClass);
};

/** NativeScript Initialize **/
NATIVESCRIPT_INIT() {
    register_class<BaseClass>();
    register_class<SubClass>();
}

It can't work in GDScript

func _ready():
    var script = NativeScript.new()
	script.library = load("res://nativelib.tres")
	script.class_name = "SubClass"

	var inst = script.new()
	inst.connect("my_signal", self, "_callback")

func _callback():
    print("-----------")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.