2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* method_bind.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef METHOD_BIND_H
|
|
|
|
#define METHOD_BIND_H
|
|
|
|
|
2020-02-20 19:32:36 +01:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
#define DEBUG_METHODS_ENABLED
|
|
|
|
#endif
|
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/list.h"
|
|
|
|
#include "core/method_ptrcall.h"
|
|
|
|
#include "core/object.h"
|
2020-02-20 19:32:36 +01:00
|
|
|
#include "core/type_info.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/variant.h"
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
enum MethodFlags {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
METHOD_FLAG_NORMAL = 1,
|
|
|
|
METHOD_FLAG_EDITOR = 2,
|
|
|
|
METHOD_FLAG_NOSCRIPT = 4,
|
|
|
|
METHOD_FLAG_CONST = 8,
|
|
|
|
METHOD_FLAG_REVERSE = 16, // used for events
|
|
|
|
METHOD_FLAG_VIRTUAL = 32,
|
|
|
|
METHOD_FLAG_FROM_SCRIPT = 64,
|
|
|
|
METHOD_FLAG_VARARG = 128,
|
|
|
|
METHOD_FLAGS_DEFAULT = METHOD_FLAG_NORMAL,
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
template <class T>
|
2014-02-10 02:10:30 +01:00
|
|
|
struct VariantCaster {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static _FORCE_INLINE_ T cast(const Variant &p_variant) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
|
|
|
return p_variant;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
template <class T>
|
|
|
|
struct VariantCaster<T &> {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static _FORCE_INLINE_ T cast(const Variant &p_variant) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
|
|
|
return p_variant;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
template <class T>
|
|
|
|
struct VariantCaster<const T &> {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static _FORCE_INLINE_ T cast(const Variant &p_variant) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
|
|
|
return p_variant;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#define _VC(m_idx) \
|
|
|
|
(VariantCaster<P##m_idx>::cast((m_idx - 1) >= p_arg_count ? get_default_argument(m_idx - 1) : *p_args[m_idx - 1]))
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-06-23 04:12:20 +02:00
|
|
|
#ifdef PTRCALL_ENABLED
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#define VARIANT_ENUM_CAST(m_enum) \
|
2017-08-09 11:54:27 +02:00
|
|
|
MAKE_ENUM_TYPE_INFO(m_enum) \
|
2017-03-05 16:44:50 +01:00
|
|
|
template <> \
|
|
|
|
struct VariantCaster<m_enum> { \
|
|
|
|
\
|
|
|
|
static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \
|
|
|
|
return (m_enum)p_variant.operator int(); \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
template <> \
|
|
|
|
struct PtrToArg<m_enum> { \
|
|
|
|
_FORCE_INLINE_ static m_enum convert(const void *p_ptr) { \
|
|
|
|
return m_enum(*reinterpret_cast<const int *>(p_ptr)); \
|
|
|
|
} \
|
|
|
|
_FORCE_INLINE_ static void encode(m_enum p_val, const void *p_ptr) { \
|
|
|
|
*(int *)p_ptr = p_val; \
|
|
|
|
} \
|
|
|
|
};
|
2016-06-23 04:12:20 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#define VARIANT_ENUM_CAST(m_enum) \
|
2017-08-09 11:54:27 +02:00
|
|
|
MAKE_ENUM_TYPE_INFO(m_enum) \
|
2017-03-05 16:44:50 +01:00
|
|
|
template <> \
|
|
|
|
struct VariantCaster<m_enum> { \
|
|
|
|
\
|
|
|
|
static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \
|
|
|
|
return (m_enum)p_variant.operator int(); \
|
|
|
|
} \
|
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-06-23 04:12:20 +02:00
|
|
|
#endif
|
|
|
|
|
2017-08-20 17:45:01 +02:00
|
|
|
// Object enum casts must go here
|
|
|
|
VARIANT_ENUM_CAST(Object::ConnectFlags);
|
|
|
|
|
2018-01-03 12:29:58 +01:00
|
|
|
template <typename T>
|
|
|
|
struct VariantObjectClassChecker {
|
|
|
|
static _FORCE_INLINE_ bool check(const Variant &p_variant) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct VariantObjectClassChecker<Node *> {
|
|
|
|
static _FORCE_INLINE_ bool check(const Variant &p_variant) {
|
|
|
|
Object *obj = p_variant;
|
|
|
|
Node *node = p_variant;
|
|
|
|
return node || !obj;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct VariantObjectClassChecker<Control *> {
|
|
|
|
static _FORCE_INLINE_ bool check(const Variant &p_variant) {
|
|
|
|
Object *obj = p_variant;
|
|
|
|
Control *control = p_variant;
|
|
|
|
return control || !obj;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#define CHECK_ARG(m_arg) \
|
|
|
|
if ((m_arg - 1) < p_arg_count) { \
|
|
|
|
Variant::Type argtype = get_argument_type(m_arg - 1); \
|
2018-01-03 12:29:58 +01:00
|
|
|
if (!Variant::can_convert_strict(p_args[m_arg - 1]->get_type(), argtype) || \
|
|
|
|
!VariantObjectClassChecker<P##m_arg>::check(*p_args[m_arg - 1])) { \
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; \
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error.argument = m_arg - 1; \
|
|
|
|
r_error.expected = argtype; \
|
|
|
|
return Variant(); \
|
|
|
|
} \
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#define CHECK_NOARG(m_arg) \
|
|
|
|
{ \
|
|
|
|
if (p_arg##m_arg.get_type() != Variant::NIL) { \
|
|
|
|
if (r_argerror) *r_argerror = (m_arg - 1); \
|
|
|
|
return CALL_ERROR_EXTRA_ARGUMENT; \
|
|
|
|
} \
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// some helpers
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VARIANT_ENUM_CAST(Vector3::Axis);
|
2017-05-17 12:36:47 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VARIANT_ENUM_CAST(Error);
|
|
|
|
VARIANT_ENUM_CAST(Margin);
|
2017-06-10 20:44:35 +02:00
|
|
|
VARIANT_ENUM_CAST(Corner);
|
2017-03-05 16:44:50 +01:00
|
|
|
VARIANT_ENUM_CAST(Orientation);
|
|
|
|
VARIANT_ENUM_CAST(HAlign);
|
2017-08-20 17:45:01 +02:00
|
|
|
VARIANT_ENUM_CAST(VAlign);
|
|
|
|
VARIANT_ENUM_CAST(PropertyHint);
|
|
|
|
VARIANT_ENUM_CAST(PropertyUsageFlags);
|
|
|
|
VARIANT_ENUM_CAST(MethodFlags);
|
2017-03-05 16:44:50 +01:00
|
|
|
VARIANT_ENUM_CAST(Variant::Type);
|
|
|
|
VARIANT_ENUM_CAST(Variant::Operator);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-20 17:45:01 +02:00
|
|
|
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
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
class MethodBind {
|
|
|
|
|
|
|
|
int method_id;
|
|
|
|
uint32_t hint_flags;
|
|
|
|
StringName name;
|
|
|
|
Vector<Variant> default_arguments;
|
|
|
|
int default_argument_count;
|
|
|
|
int argument_count;
|
2017-08-24 00:10:32 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool _const;
|
2016-08-03 00:11:05 +02:00
|
|
|
bool _returns;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
protected:
|
2017-08-24 00:10:32 +02:00
|
|
|
#ifdef DEBUG_METHODS_ENABLED
|
|
|
|
Variant::Type *argument_types;
|
|
|
|
Vector<StringName> arg_names;
|
|
|
|
#endif
|
2014-02-10 02:10:30 +01:00
|
|
|
void _set_const(bool p_const);
|
2016-08-03 00:11:05 +02:00
|
|
|
void _set_returns(bool p_returns);
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifdef DEBUG_METHODS_ENABLED
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual Variant::Type _gen_argument_type(int p_arg) const = 0;
|
2017-08-24 00:10:32 +02:00
|
|
|
virtual PropertyInfo _gen_argument_type_info(int p_arg) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
void _generate_argument_types(int p_count);
|
2017-08-24 00:10:32 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_argument_count(int p_count) { argument_count = p_count; }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector<Variant> get_default_arguments() const { return default_arguments; }
|
|
|
|
_FORCE_INLINE_ int get_default_argument_count() const { return default_argument_count; }
|
|
|
|
|
|
|
|
_FORCE_INLINE_ Variant has_default_argument(int p_arg) const {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = argument_count - p_arg - 1;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (idx < 0 || idx >= default_arguments.size())
|
2014-02-10 02:10:30 +01:00
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_FORCE_INLINE_ Variant get_default_argument(int p_arg) const {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = argument_count - p_arg - 1;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (idx < 0 || idx >= default_arguments.size())
|
2014-02-10 02:10:30 +01:00
|
|
|
return Variant();
|
|
|
|
else
|
|
|
|
return default_arguments[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_METHODS_ENABLED
|
|
|
|
|
|
|
|
_FORCE_INLINE_ Variant::Type get_argument_type(int p_argument) const {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(p_argument < -1 || p_argument > argument_count, Variant::NIL);
|
|
|
|
return argument_types[p_argument + 1];
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo get_argument_info(int p_argument) const;
|
2017-08-24 00:10:32 +02:00
|
|
|
PropertyInfo get_return_info() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-01-18 21:37:17 +01:00
|
|
|
void set_argument_names(const Vector<StringName> &p_names); //set by class, db, can't be inferred otherwise
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector<StringName> get_argument_names() const;
|
2017-08-09 11:54:27 +02:00
|
|
|
|
2019-04-25 20:24:48 +02:00
|
|
|
virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const = 0;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
2017-03-05 16:44:50 +01:00
|
|
|
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); }
|
|
|
|
virtual String get_instance_class() const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
_FORCE_INLINE_ int get_argument_count() const { return argument_count; };
|
|
|
|
|
2020-02-19 20:27:19 +01:00
|
|
|
virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) = 0;
|
2016-06-23 04:12:20 +02:00
|
|
|
|
|
|
|
#ifdef PTRCALL_ENABLED
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) = 0;
|
2016-06-23 04:12:20 +02:00
|
|
|
#endif
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
StringName get_name() const;
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_name(const StringName &p_name);
|
2014-02-10 02:10:30 +01:00
|
|
|
_FORCE_INLINE_ int get_method_id() const { return method_id; }
|
|
|
|
_FORCE_INLINE_ bool is_const() const { return _const; }
|
2016-08-03 00:11:05 +02:00
|
|
|
_FORCE_INLINE_ bool has_return() const { return _returns; }
|
2016-09-08 00:39:02 +02:00
|
|
|
virtual bool is_vararg() const { return false; }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_default_arguments(const Vector<Variant> &p_defargs);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
MethodBind();
|
|
|
|
virtual ~MethodBind();
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
template <class T>
|
2016-09-08 00:39:02 +02:00
|
|
|
class MethodBindVarArg : public MethodBind {
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
2020-02-19 20:27:19 +01:00
|
|
|
typedef Variant (T::*NativeCall)(const Variant **, int, Callable::CallError &);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
protected:
|
2014-02-10 02:10:30 +01:00
|
|
|
NativeCall call_method;
|
2017-08-24 00:10:32 +02:00
|
|
|
#ifdef DEBUG_METHODS_ENABLED
|
|
|
|
|
|
|
|
MethodInfo arguments;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 00:10:32 +02:00
|
|
|
#endif
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2017-08-24 00:10:32 +02:00
|
|
|
#ifdef DEBUG_METHODS_ENABLED
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 00:10:32 +02:00
|
|
|
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);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-08-24 00:10:32 +02:00
|
|
|
virtual Variant::Type _gen_argument_type(int p_arg) const {
|
|
|
|
return _gen_argument_type_info(p_arg).type;
|
|
|
|
}
|
|
|
|
|
2019-04-25 20:24:48 +02:00
|
|
|
virtual GodotTypeInfo::Metadata get_argument_meta(int) const {
|
|
|
|
return GodotTypeInfo::METADATA_NONE;
|
|
|
|
}
|
|
|
|
|
2017-08-24 00:10:32 +02:00
|
|
|
#else
|
2017-08-09 11:54:27 +02:00
|
|
|
|
2017-08-24 00:10:32 +02:00
|
|
|
virtual Variant::Type _gen_argument_type(int p_arg) const {
|
|
|
|
return Variant::NIL;
|
2017-08-09 11:54:27 +02:00
|
|
|
}
|
|
|
|
|
2017-08-24 00:10:32 +02:00
|
|
|
#endif
|
2020-02-19 20:27:19 +01:00
|
|
|
virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
T *instance = static_cast<T *>(p_object);
|
|
|
|
return (instance->*call_method)(p_args, p_arg_count, r_error);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-08-09 11:54:27 +02:00
|
|
|
|
2020-01-02 09:31:43 +01:00
|
|
|
void set_method_info(const MethodInfo &p_info, bool p_return_nil_is_variant) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
set_argument_count(p_info.arguments.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifdef DEBUG_METHODS_ENABLED
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant::Type *at = memnew_arr(Variant::Type, p_info.arguments.size() + 1);
|
|
|
|
at[0] = p_info.return_val.type;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (p_info.arguments.size()) {
|
|
|
|
|
|
|
|
Vector<StringName> names;
|
|
|
|
names.resize(p_info.arguments.size());
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_info.arguments.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
at[i + 1] = p_info.arguments[i].type;
|
2018-07-25 03:11:03 +02:00
|
|
|
names.write[i] = p_info.arguments[i].name;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
set_argument_names(names);
|
|
|
|
}
|
2017-08-24 00:10:32 +02:00
|
|
|
argument_types = at;
|
|
|
|
arguments = p_info;
|
2020-01-02 09:31:43 +01:00
|
|
|
if (p_return_nil_is_variant) {
|
|
|
|
arguments.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-06-23 04:12:20 +02:00
|
|
|
#ifdef PTRCALL_ENABLED
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
|
2016-09-08 00:39:02 +02:00
|
|
|
ERR_FAIL(); //can't call
|
|
|
|
} //todo
|
2016-06-23 04:12:20 +02:00
|
|
|
#endif
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_method(NativeCall p_method) { call_method = p_method; }
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual bool is_const() const { return false; }
|
2017-01-03 03:03:46 +01:00
|
|
|
virtual String get_instance_class() const { return T::get_class_static(); }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-09-08 00:39:02 +02:00
|
|
|
virtual bool is_vararg() const { return true; }
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
MethodBindVarArg() {
|
2020-04-02 01:20:12 +02:00
|
|
|
call_method = nullptr;
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_returns(true);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
template <class T>
|
2020-02-19 20:27:19 +01:00
|
|
|
MethodBind *create_vararg_method_bind(Variant (T::*p_method)(const Variant **, int, Callable::CallError &), const MethodInfo &p_info, bool p_return_nil_is_variant) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
MethodBindVarArg<T> *a = memnew((MethodBindVarArg<T>));
|
2014-02-10 02:10:30 +01:00
|
|
|
a->set_method(p_method);
|
2020-01-02 09:31:43 +01:00
|
|
|
a->set_method_info(p_info, p_return_nil_is_variant);
|
2014-02-10 02:10:30 +01:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** This amazing hack is based on the FastDelegates theory */
|
|
|
|
|
|
|
|
// tale of an amazing hack.. //
|
|
|
|
|
2017-09-02 16:19:06 +02:00
|
|
|
// if you declare a nonexistent class..
|
2014-02-10 02:10:30 +01:00
|
|
|
class __UnexistingClass;
|
|
|
|
|
2017-06-23 17:03:41 +02:00
|
|
|
#include "method_bind.gen.inc"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-25 11:10:34 +01:00
|
|
|
#endif // METHOD_BIND_H
|