diff options
Diffstat (limited to 'modules/gdnative/godot')
-rw-r--r-- | modules/gdnative/godot/godot_variant.cpp | 16 | ||||
-rw-r--r-- | modules/gdnative/godot/godot_variant.h | 33 |
2 files changed, 37 insertions, 12 deletions
diff --git a/modules/gdnative/godot/godot_variant.cpp b/modules/gdnative/godot/godot_variant.cpp index 2214f85056..e9fa4eb8c6 100644 --- a/modules/gdnative/godot/godot_variant.cpp +++ b/modules/gdnative/godot/godot_variant.cpp @@ -457,12 +457,22 @@ godot_pool_color_array GDAPI godot_variant_as_pool_color_array(const godot_varia return pba; } -godot_variant GDAPI godot_variant_call(godot_variant *p_v, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount /*, godot_variant_call_error *r_error */) { +godot_variant GDAPI godot_variant_call(godot_variant *p_v, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount, godot_variant_call_error *p_error) { Variant *v = (Variant *)p_v; String *method = (String *)p_method; - Variant **args = (Variant **)p_args; + const Variant **args = (const Variant **)p_args; godot_variant res; - memnew_placement_custom((Variant *)&res, Variant, Variant(v->call(*method, args, p_argcount))); + godot_variant_new_nil(&res); + + Variant *ret_val = (Variant *)&res; + + Variant::CallError r_error; + *ret_val = v->call(StringName(*method), args, p_argcount, r_error); + if (p_error) { + p_error->error = (godot_variant_call_error_error)r_error.error; + p_error->argument = r_error.argument; + p_error->expected = (godot_variant_type)r_error.expected; + } return res; } diff --git a/modules/gdnative/godot/godot_variant.h b/modules/gdnative/godot/godot_variant.h index 6f98b32363..bf0e2bf64e 100644 --- a/modules/gdnative/godot/godot_variant.h +++ b/modules/gdnative/godot/godot_variant.h @@ -45,13 +45,6 @@ typedef struct godot_variant { struct godot_transform2d; typedef struct godot_transform2d godot_transform2d; -#include "godot_array.h" -#include "godot_dictionary.h" -#include "godot_input_event.h" -#include "godot_node_path.h" -#include "godot_rid.h" -#include "godot_transform2d.h" - typedef enum godot_variant_type { GODOT_VARIANT_TYPE_NIL, @@ -69,7 +62,7 @@ typedef enum godot_variant_type { GODOT_VARIANT_TYPE_TRANSFORM2D, GODOT_VARIANT_TYPE_PLANE, GODOT_VARIANT_TYPE_QUAT, // 10 - GODOT_VARIANT_TYPE_RECT3, //sorry naming convention fail :( not like it's used often + GODOT_VARIANT_TYPE_RECT3, GODOT_VARIANT_TYPE_BASIS, GODOT_VARIANT_TYPE_TRANSFORM, @@ -93,6 +86,28 @@ typedef enum godot_variant_type { GODOT_VARIANT_TYPE_POOL_COLOR_ARRAY, } godot_variant_type; +typedef enum godot_variant_call_error_error { + GODOT_CALL_ERROR_CALL_OK, + GODOT_CALL_ERROR_CALL_ERROR_INVALID_METHOD, + GODOT_CALL_ERROR_CALL_ERROR_INVALID_ARGUMENT, + GODOT_CALL_ERROR_CALL_ERROR_TOO_MANY_ARGUMENTS, + GODOT_CALL_ERROR_CALL_ERROR_TOO_FEW_ARGUMENTS, + GODOT_CALL_ERROR_CALL_ERROR_INSTANCE_IS_NULL, +} godot_variant_call_error_error; + +typedef struct godot_variant_call_error { + godot_variant_call_error_error error; + int argument; + godot_variant_type expected; +} godot_variant_call_error; + +#include "godot_array.h" +#include "godot_dictionary.h" +#include "godot_input_event.h" +#include "godot_node_path.h" +#include "godot_rid.h" +#include "godot_transform2d.h" + godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_v); void GDAPI godot_variant_copy(godot_variant *p_dest, const godot_variant *p_src); @@ -159,7 +174,7 @@ godot_pool_vector2_array GDAPI godot_variant_as_pool_vector2_array(const godot_v godot_pool_vector3_array GDAPI godot_variant_as_pool_vector3_array(const godot_variant *p_v); godot_pool_color_array GDAPI godot_variant_as_pool_color_array(const godot_variant *p_v); -godot_variant GDAPI godot_variant_call(godot_variant *p_v, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount /*, godot_variant_call_error *r_error */); +godot_variant GDAPI godot_variant_call(godot_variant *p_v, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount, godot_variant_call_error *p_error); godot_bool GDAPI godot_variant_has_method(godot_variant *p_v, const godot_string *p_method); |