diff options
Diffstat (limited to 'src/core/String.cpp')
-rw-r--r-- | src/core/String.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/core/String.cpp b/src/core/String.cpp index 9a7b96e..494d976 100644 --- a/src/core/String.cpp +++ b/src/core/String.cpp @@ -107,6 +107,22 @@ const wchar_t *String::unicode_str() const { return godot::api->godot_string_unicode_str(&_godot_string); } +char *String::alloc_c_string() const { + int len; + + // figure out the lenght of our string + get_c_string(NULL, &len); + + // allocate our buffer + char * result = (char *)godot::api->godot_alloc(len + 1); + if (result != NULL) { + get_c_string(result, &len); + result[len] = '\0'; + } + + return result; +} + void String::get_c_string(char *p_dest, int *p_size) const { godot::api->godot_string_get_data(&_godot_string, p_dest, p_size); } |