diff --git a/modules/gdnative/gdnative/basis.cpp b/modules/gdnative/gdnative/basis.cpp index b1327cdaef2..28af93f9424 100644 --- a/modules/gdnative/gdnative/basis.cpp +++ b/modules/gdnative/gdnative/basis.cpp @@ -172,7 +172,7 @@ void GDAPI godot_basis_new_with_euler_quat(godot_basis *r_dest, const godot_quat } // p_elements is a pointer to an array of 3 (!!) vector3 -void GDAPI godot_basis_get_elements(godot_basis *p_self, godot_vector3 *p_elements) { +void GDAPI godot_basis_get_elements(const godot_basis *p_self, godot_vector3 *p_elements) { const Basis *self = (const Basis *)p_self; Vector3 *elements = (Vector3 *)p_elements; elements[0] = self->elements[0]; diff --git a/modules/gdnative/gdnative/string.cpp b/modules/gdnative/gdnative/string.cpp index 905c513d9dc..619003083d2 100644 --- a/modules/gdnative/gdnative/string.cpp +++ b/modules/gdnative/gdnative/string.cpp @@ -65,11 +65,20 @@ void GDAPI godot_string_new_unicode_data(godot_string *r_dest, const wchar_t *p_ void GDAPI godot_string_get_data(const godot_string *p_self, char *p_dest, int *p_size) { String *self = (String *)p_self; - if (p_size != NULL) { - *p_size = self->utf8().length(); - } - if (p_dest != NULL) { - memcpy(p_dest, self->utf8().get_data(), *p_size); + + if (p_size) { + // we have a length pointer, that means we either want to know + // the length or want to write *p_size bytes into a buffer + + CharString utf8_string = self->utf8(); + + int len = utf8_string.length(); + + if (p_dest) { + memcpy(p_dest, utf8_string.get_data(), *p_size); + } else { + *p_size = len; + } } } @@ -78,6 +87,11 @@ wchar_t GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int return &(self->operator[](p_idx)); } +wchar_t GDAPI godot_string_operator_index_const(const godot_string *p_self, const godot_int p_idx) { + const String *self = (const String *)p_self; + return self->operator[](p_idx); +} + const char GDAPI *godot_string_c_str(const godot_string *p_self) { const String *self = (const String *)p_self; return self->utf8().get_data(); diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 31b021b7510..e19995b5f5e 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -847,7 +847,7 @@ "name": "godot_basis_get_elements", "return_type": "void", "arguments": [ - ["godot_basis *", "p_self"], + ["const godot_basis *", "p_self"], ["godot_vector3 *", "p_elements"] ] }, @@ -3926,6 +3926,14 @@ ["const godot_int", "p_idx"] ] }, + { + "name": "godot_string_operator_index_const", + "return_type": "wchar_t", + "arguments": [ + ["const godot_string *", "p_self"], + ["const godot_int", "p_idx"] + ] + }, { "name": "godot_string_c_str", "return_type": "const char *", diff --git a/modules/gdnative/include/gdnative/basis.h b/modules/gdnative/include/gdnative/basis.h index b86b1c17d8a..49ca765a016 100644 --- a/modules/gdnative/include/gdnative/basis.h +++ b/modules/gdnative/include/gdnative/basis.h @@ -97,7 +97,7 @@ void GDAPI godot_basis_new(godot_basis *r_dest); void GDAPI godot_basis_new_with_euler_quat(godot_basis *r_dest, const godot_quat *p_euler); // p_elements is a pointer to an array of 3 (!!) vector3 -void GDAPI godot_basis_get_elements(godot_basis *p_self, godot_vector3 *p_elements); +void GDAPI godot_basis_get_elements(const godot_basis *p_self, godot_vector3 *p_elements); godot_vector3 GDAPI godot_basis_get_axis(const godot_basis *p_self, const godot_int p_axis); diff --git a/modules/gdnative/include/gdnative/string.h b/modules/gdnative/include/gdnative/string.h index f30fdb8dc7c..29510313c9f 100644 --- a/modules/gdnative/include/gdnative/string.h +++ b/modules/gdnative/include/gdnative/string.h @@ -66,6 +66,7 @@ void GDAPI godot_string_new_unicode_data(godot_string *r_dest, const wchar_t *p_ void GDAPI godot_string_get_data(const godot_string *p_self, char *p_dest, int *p_size); wchar_t GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx); +wchar_t GDAPI godot_string_operator_index_const(const godot_string *p_self, const godot_int p_idx); const char GDAPI *godot_string_c_str(const godot_string *p_self); const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_self);