godot_string to char* in c (GDNative)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By RastaJoe94

Hello,

I’m working on a GDNative script and want to give the c function a string as parameter, do some calculations and then return a string back to godot. I can use godot_variant_as_string(p_args[0]) to get the first argument as a godot_string, but how do i convert it to a char* usable in c? I saw someone else in a discussion here, who used godot_string_c_str(), but I think this function does not exist anymore (post was from 2017). Does someone know how to use the godot_string in c?

:bust_in_silhouette: Reply From: RastaJoe94

Found the solution:

convert godot_variant to godot_string:
godot_string godot_variant_as_string(p_args[0])

convert godot_string to godot_char_string
godot_char_string godot_string_utf8(godot_string*)

convert godot_char_string to char*
char godot_char_string_get_data(godot_char_string)