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

GDNative defaults on parameters defined as enums broke #50388

Closed
BastiaanOlij opened this issue Jul 12, 2021 · 3 comments
Closed

GDNative defaults on parameters defined as enums broke #50388

BastiaanOlij opened this issue Jul 12, 2021 · 3 comments

Comments

@BastiaanOlij
Copy link
Contributor

Godot version

4.0.dev 7594150

System information

Any

Issue description

Tested on Godot 4.0 but likely a problem in Godot 3.x now as well.

PR #35847 changed the way parameters are included in the api.json file, but it overlooks defaults.

For instance in class Curve:

{
	"name": "add_point",
	"return_type": "int",
	"is_editor": false,
	"is_noscript": false,
	"is_const": false,
	"is_reverse": false,
	"is_virtual": false,
	"has_varargs": false,
	"is_from_script": false,
	"arguments": [
		{
			"name": "position",
			"type": "Vector2",
			"has_default_value": false,
			"default_value": ""
		},
		{
			"name": "left_tangent",
			"type": "float",
			"has_default_value": true,
			"default_value": "0"
		},
		{
			"name": "right_tangent",
			"type": "float",
			"has_default_value": true,
			"default_value": "0"
		},
		{
			"name": "left_mode",
			"type": "enum.Curve::TangentMode",
			"has_default_value": true,
			"default_value": "0"
		},
		{
			"name": "right_mode",
			"type": "enum.Curve::TangentMode",
			"has_default_value": true,
			"default_value": "0"
		}
	]
},

Parameter right_mode now has type enum.Curve::TangentMode which is great, but it's default value is 0 which results in:

D:\Development\xr_plugins\godot_openvr.4.0\godot-cpp\include\gen\Curve.hpp(73): error C2440: 'default argument': cannot convert from 'int' to 'const godot::Curve::TangentMode'
D:\Development\xr_plugins\godot_openvr.4.0\godot-cpp\include\gen\Curve.hpp(73): note: Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)

Steps to reproduce

Try and build godot-cpp using the latest gdnative headers and api.json and vnen's godot 4.0 PR.

Minimal reproduction project

No response

@BastiaanOlij
Copy link
Contributor Author

@raniejade , seeing you made the change and the change itself is splendid, mind having a look and see if you can make the defaults work as well ? :)

@raniejade
Copy link
Contributor

raniejade commented Jul 12, 2021

Yeah, I'll see what I can do. Might need to query ClassDB here https://github.com/raniejade/godot/blob/78f55698f25a9c6f527560e54f6a330e3e463c82/modules/gdnative/nativescript/api_generator.cpp#L376 to convert the int val to the appropriate enum value.

@akien-mga
Copy link
Member

GDNative was replaced by GDExtension in 4.0, and #35847 has not been cherry-picked to 3.x due to this regression, so we can consider it solved.

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

No branches or pull requests

3 participants