Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement godot_new to allow instancing of binding types #9721

Closed
wants to merge 1 commit into from

Conversation

endragor
Copy link
Contributor

Previously there was no way to create an object passing a class name
previously registered by a native library. This commit adds
implementation of godot_new in gdnative module. It can instantiate
the native script with the specified name, if the name does not belong
to a native type.

@karroffel
Copy link
Contributor

This PR breaks script inheritance.

Also you already can do that with the regular Godot API.

GDScript for simplified code

var gdnative_class = GDNativeScript.new()
gdnative_class.script_name = "MyClass"
gdnative_class.library = the_library_where_the_class_is

# then later somewhere
var myclass_instance = gdnative_class.new()

@endragor
Copy link
Contributor Author

Could you please clarify regarding script inheritance? If you mean the code removed that traverses data to get base_native_class, then it seemed redundant, because the correct base native class is already assigned when the script is registered: https://github.com/endragor/godot/blob/98010470ebccea8eb9c1c82fe7e0d7c4a7b61d83/modules/gdnative/gdnative.cpp#L658

How does the binding code know the library name? Keep in mind I'd like to make it look like this for the user: gdnew[MyClass](). The code is not aware about library name, because it is assigned to a resource.

if (class_info)
return ((godot_class_constructor)class_info->creation_func)();

const Map<StringName, NativeLibrary *>& libraries = GDNativeScriptLanguage::get_singleton()->initialized_libraries;
Copy link

@ghost ghost Jul 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change >& libraries to > &libraries to pass travis check.

Previously there was no way to create an object passing a class name
previously registered by a native library. This commit adds
implementation of godot_nativescript_new in nativescript module. It can
instantiate the native script with the specified name, if the name does
not belong to a native type.
@karroffel
Copy link
Contributor

@endragor this functionality can now get lifted to the bindings using the new initialization parameter. Can I close this?

@endragor
Copy link
Contributor Author

Yeah, closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants