diff options
author | Karroffel <therzog@mail.de> | 2017-11-03 16:05:21 +0100 |
---|---|---|
committer | Karroffel <therzog@mail.de> | 2017-11-03 16:05:21 +0100 |
commit | 8b11e17f7084511f8c528b79e486bc2d3a02c224 (patch) | |
tree | 713543bc0621847bd6dfeca524221f15592f4c89 | |
parent | 8e145fa1a80bcd860dd8e16d7db684f9905865e8 (diff) |
[GDNative] small API bug fixes
-rw-r--r-- | modules/gdnative/gdnative/basis.cpp | 2 | ||||
-rw-r--r-- | modules/gdnative/gdnative/string.cpp | 24 | ||||
-rw-r--r-- | modules/gdnative/gdnative_api.json | 10 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/basis.h | 2 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/string.h | 1 |
5 files changed, 31 insertions, 8 deletions
diff --git a/modules/gdnative/gdnative/basis.cpp b/modules/gdnative/gdnative/basis.cpp index b1327cdaef..28af93f942 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 905c513d9d..619003083d 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 31b021b751..e19995b5f5 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"] ] }, @@ -3927,6 +3927,14 @@ ] }, { + "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 *", "arguments": [ diff --git a/modules/gdnative/include/gdnative/basis.h b/modules/gdnative/include/gdnative/basis.h index b86b1c17d8..49ca765a01 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 f30fdb8dc7..29510313c9 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); |