summaryrefslogtreecommitdiff
path: root/core/method_bind.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/method_bind.h')
-rw-r--r--core/method_bind.h104
1 files changed, 61 insertions, 43 deletions
diff --git a/core/method_bind.h b/core/method_bind.h
index 3b4ff96a19..75f09b2cd9 100644
--- a/core/method_bind.h
+++ b/core/method_bind.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -124,6 +124,9 @@ struct VariantCaster<const T &> {
#endif
+// Object enum casts must go here
+VARIANT_ENUM_CAST(Object::ConnectFlags);
+
#define CHECK_ARG(m_arg) \
if ((m_arg - 1) < p_arg_count) { \
Variant::Type argtype = get_argument_type(m_arg - 1); \
@@ -148,13 +151,35 @@ struct VariantCaster<const T &> {
VARIANT_ENUM_CAST(Vector3::Axis);
VARIANT_ENUM_CAST(Error);
-VARIANT_ENUM_CAST(wchar_t);
VARIANT_ENUM_CAST(Margin);
+VARIANT_ENUM_CAST(Corner);
VARIANT_ENUM_CAST(Orientation);
VARIANT_ENUM_CAST(HAlign);
+VARIANT_ENUM_CAST(VAlign);
+VARIANT_ENUM_CAST(PropertyHint);
+VARIANT_ENUM_CAST(PropertyUsageFlags);
+VARIANT_ENUM_CAST(MethodFlags);
VARIANT_ENUM_CAST(Variant::Type);
VARIANT_ENUM_CAST(Variant::Operator);
+template <>
+struct VariantCaster<wchar_t> {
+ static _FORCE_INLINE_ wchar_t cast(const Variant &p_variant) {
+ return (wchar_t)p_variant.operator int();
+ }
+};
+#ifdef PTRCALL_ENABLED
+template <>
+struct PtrToArg<wchar_t> {
+ _FORCE_INLINE_ static wchar_t convert(const void *p_ptr) {
+ return wchar_t(*reinterpret_cast<const int *>(p_ptr));
+ }
+ _FORCE_INLINE_ static void encode(wchar_t p_val, const void *p_ptr) {
+ *(int *)p_ptr = p_val;
+ }
+};
+#endif
+
class MethodBind {
int method_id;
@@ -163,23 +188,22 @@ class MethodBind {
Vector<Variant> default_arguments;
int default_argument_count;
int argument_count;
-#ifdef DEBUG_METHODS_ENABLED
- Vector<StringName> arg_names;
- Vector<StringName> arg_type_hints;
- Variant::Type *argument_types;
- StringName ret_type;
-#endif
+
bool _const;
bool _returns;
protected:
+#ifdef DEBUG_METHODS_ENABLED
+ Variant::Type *argument_types;
+ Vector<StringName> arg_names;
+#endif
void _set_const(bool p_const);
void _set_returns(bool p_returns);
#ifdef DEBUG_METHODS_ENABLED
virtual Variant::Type _gen_argument_type(int p_arg) const = 0;
- virtual StringName _gen_argument_type_hint(int p_arg) const = 0;
+ virtual PropertyInfo _gen_argument_type_info(int p_arg) const = 0;
void _generate_argument_types(int p_count);
- void set_argument_types(Variant::Type *p_types) { argument_types = p_types; }
+
#endif
void set_argument_count(int p_count) { argument_count = p_count; }
@@ -209,9 +233,6 @@ public:
#ifdef DEBUG_METHODS_ENABLED
- _FORCE_INLINE_ void set_return_type(const StringName &p_type) { ret_type = p_type; }
- _FORCE_INLINE_ StringName get_return_type() const { return ret_type; }
-
_FORCE_INLINE_ Variant::Type get_argument_type(int p_argument) const {
ERR_FAIL_COND_V(p_argument < -1 || p_argument > argument_count, Variant::NIL);
@@ -219,12 +240,11 @@ public:
}
PropertyInfo get_argument_info(int p_argument) const;
+ PropertyInfo get_return_info() const;
- void set_argument_names(const Vector<StringName> &p_names);
+ void set_argument_names(const Vector<StringName> &p_names); //set by class, db, cant be inferred otherwise
Vector<StringName> get_argument_names() const;
- void set_argument_type_hints(const Vector<StringName> &p_type_hints);
- Vector<StringName> get_argument_type_hints() const;
#endif
void set_hint_flags(uint32_t p_hint) { hint_flags = p_hint; }
uint32_t get_hint_flags() const { return hint_flags | (is_const() ? METHOD_FLAG_CONST : 0) | (is_vararg() ? METHOD_FLAG_VARARG : 0); }
@@ -232,28 +252,6 @@ public:
_FORCE_INLINE_ int get_argument_count() const { return argument_count; };
-#if 0
- _FORCE_INLINE_ Variant call_safe(const Variant** p_args,int p_arg_count, Variant::CallError& r_error) {
-
- r_error.error=Variant::CallError::CALL_OK;
- check_call( p_args, &errorarg );
- if (!err)
- return call(p_object, VARIANT_ARG_PASS );
-
- VARIANT_ARGPTRS
- String errstr;
- String methodname = get_instance_type()+"::"+name;
- if (err==CALL_ERROR_ARGUMENT_TYPE) {
- errstr="Invalid Argument to call: '"+methodname+"'. Cannot convert argument "+itos(errorarg+1)+" from "+Variant::get_type_name(get_argument_type(errorarg))+" to "+Variant::get_type_name(argptr[errorarg]->get_type())+".";
- }
- if (err==CALL_ERROR_EXTRA_ARGUMENT) {
- errstr="Invalid call. Member function '"+methodname+"' takes "+itos(get_argument_count())+" argument, but argument "+itos(errorarg+1)+" was received.";
- }
-
- ERR_PRINT(errstr.ascii().get_data());
- return Variant();
- }
-#endif
virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Variant::CallError &r_error) = 0;
#ifdef PTRCALL_ENABLED
@@ -280,18 +278,36 @@ public:
protected:
NativeCall call_method;
+#ifdef DEBUG_METHODS_ENABLED
+
+ MethodInfo arguments;
+#endif
public:
- virtual Variant::Type _gen_argument_type(int p_arg) const {
+#ifdef DEBUG_METHODS_ENABLED
- return Variant::NIL;
+ virtual PropertyInfo _gen_argument_type_info(int p_arg) const {
+
+ if (p_arg < 0) {
+ return arguments.return_val;
+ } else if (p_arg < arguments.arguments.size()) {
+ return arguments.arguments[p_arg];
+ } else {
+ return PropertyInfo(Variant::NIL, "arg_" + itos(p_arg), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
+ }
+ }
+
+ virtual Variant::Type _gen_argument_type(int p_arg) const {
+ return _gen_argument_type_info(p_arg).type;
}
- virtual StringName _gen_argument_type_hint(int p_arg) const {
+#else
- return "Variant";
+ virtual Variant::Type _gen_argument_type(int p_arg) const {
+ return Variant::NIL;
}
+#endif
virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Variant::CallError &r_error) {
T *instance = static_cast<T *>(p_object);
@@ -316,7 +332,9 @@ public:
set_argument_names(names);
}
- set_argument_types(at);
+ argument_types = at;
+ arguments = p_info;
+ arguments.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
#endif
}