summaryrefslogtreecommitdiff
path: root/modules/gdnative
diff options
context:
space:
mode:
authorKarroffel <therzog@mail.de>2017-05-11 23:06:11 +0200
committerKarroffel <therzog@mail.de>2017-05-11 23:06:11 +0200
commitd137e83c6013f895e8bfbacf65c0fe43443c4174 (patch)
tree99bddf78f9c1c8cc4c15e8a1bef38a1ec897e0d5 /modules/gdnative
parent6d0568d8179f7dcca54b1c87ab199820a468ef2c (diff)
[GDNative] added varcall and print
Diffstat (limited to 'modules/gdnative')
-rw-r--r--modules/gdnative/godot.cpp26
-rw-r--r--modules/gdnative/godot.h3
-rw-r--r--modules/gdnative/godot/godot_variant.cpp16
-rw-r--r--modules/gdnative/godot/godot_variant.h31
4 files changed, 64 insertions, 12 deletions
diff --git a/modules/gdnative/godot.cpp b/modules/gdnative/godot.cpp
index 4b865966fd..bc53eb93f4 100644
--- a/modules/gdnative/godot.cpp
+++ b/modules/gdnative/godot.cpp
@@ -116,6 +116,28 @@ void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_obj
mb->ptrcall(o, p_args, p_ret);
}
+godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error) {
+ MethodBind *mb = (MethodBind *)p_method_bind;
+ Object *o = (Object *)p_instance;
+ const Variant **args = (const Variant **)p_args;
+
+ godot_variant ret;
+ godot_variant_new_nil(&ret);
+
+ Variant *ret_val = (Variant *)&ret;
+
+ Variant::CallError r_error;
+ *ret_val = mb->call(o, args, p_arg_count, r_error);
+
+ if (p_call_error) {
+ p_call_error->error = (godot_variant_call_error_error)r_error.error;
+ p_call_error->argument = r_error.argument;
+ p_call_error->expected = (godot_variant_type)r_error.expected;
+ }
+
+ return ret;
+}
+
// @Todo
/*
void GDAPI godot_method_bind_varcall(godot_method_bind *p_method_bind)
@@ -224,6 +246,10 @@ void GDAPI godot_print_warning(const char *p_description, const char *p_function
_err_print_error(p_function, p_file, p_line, p_description, ERR_HANDLER_WARNING);
}
+void GDAPI godot_print(const godot_string *p_message) {
+ print_line(*(String *)p_message);
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/modules/gdnative/godot.h b/modules/gdnative/godot.h
index e8f0bc0553..7214ce62df 100644
--- a/modules/gdnative/godot.h
+++ b/modules/gdnative/godot.h
@@ -228,7 +228,7 @@ typedef struct godot_method_bind {
godot_method_bind GDAPI *godot_method_bind_get_method(const char *p_classname, const char *p_methodname);
void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_object *p_instance, const void **p_args, void *p_ret);
-
+godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error);
////// Script API
typedef struct godot_native_init_options {
@@ -407,6 +407,7 @@ void GDAPI godot_free(void *p_ptr);
//print using Godot's error handler list
void GDAPI godot_print_error(const char *p_description, const char *p_function, const char *p_file, int p_line);
void GDAPI godot_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line);
+void GDAPI godot_print(const godot_string *p_message);
#ifdef __cplusplus
}
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..0a5771d2f6 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,
@@ -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);