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] updates to string API and const fixes #15580

Merged
merged 1 commit into from
Jan 11, 2018

Conversation

karroffel
Copy link
Contributor

Hopefully the last time I change the API struct before the release.

cc @sheepandshepherd, @endragor, @touilleMan and also @BastiaanOlij, those should be affected by the changes the most.

@karroffel karroffel added this to the 3.0 milestone Jan 10, 2018
@akien-mga akien-mga added the bug label Jan 11, 2018
@akien-mga akien-mga merged commit 9135e61 into godotengine:master Jan 11, 2018
@akien-mga
Copy link
Member

Note to binding authors: we're likely going to release a RC1 build tomorrow or on Saturday, in case you want to sync your bindings with this breaking change before that.

@endragor
Copy link
Contributor

endragor commented Jan 12, 2018

@karroffel Given a UTF-8 string, how do you construct godot_string with this new API?

godot_string_new_data was removed, even though it's preferable (performance-wise and convenience-wise) to the two-step conversion: first to godot_char_string (performing allocations and copying along the way), then to godot_string. And even char * -> godot_char_string -> godot_string doesn't seem to be possible with this API, unless I missed it.

@karroffel
Copy link
Contributor Author

@endragor,

godot_string str;
api->godot_string_new(&str);
api->godor_string_parse_utf8(&str, some_text);

@endragor
Copy link
Contributor

@karroffel got it, thanks!

@BastiaanOlij
Copy link
Contributor

So far I don't like this change... makes it far harder to do something that should be simple especially has GDNative will do a lot of interfacing with 3rd party apis which all have simple char buffers for strings and we'll be doing this alot.

The parse utf8 works around things, there should be a godot_string_parse_ascii then as well.

What I can't see is how to obtain a char * to the data held within a godot string.

@karroffel
Copy link
Contributor Author

@BastiaanOlij every ASCII text is also valid UTF-8, so there is no need for a parse_ascii function.

To get a char pointer you do this

godot_char_string buf = api->godot_string_utf8(&str);

char *t = api->godot_char_string_get_data(&buf);
int len = api->godot_char_string_length(&buf);

// copy the data or use it otherwise

// free the Godot-allocated buffer
api->godot_char_string_destroy(&buf);

@BastiaanOlij
Copy link
Contributor

Ah.. by ascii you mean text purely using the first 7 bits? the last 128 characters can't be used directly.
I figured it out in the end and got everything working again but I still feel its too many steps for something so often used :)

but hey, it works..

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.

None yet

4 participants