42 #define DEBUG_METHODS_ENABLED 49 METHOD_FLAG_NOSCRIPT=4,
51 METHOD_FLAG_REVERSE=16,
52 METHOD_FLAG_VIRTUAL=32,
53 METHOD_FLAG_FROM_SCRIPT=64,
54 METHOD_FLAGS_DEFAULT=METHOD_FLAG_NORMAL,
60 static _FORCE_INLINE_ T cast(
const Variant& p_variant) {
69 static _FORCE_INLINE_ T cast(
const Variant& p_variant) {
78 static _FORCE_INLINE_ T cast(
const Variant& p_variant) {
85 (VariantCaster<P##m_idx>::cast( (m_idx-1)>=p_arg_count?get_default_argument(m_idx-1):*p_args[m_idx-1] )) 88 #define VARIANT_ENUM_CAST( m_enum ) \ 89 SIMPLE_NUMERIC_TYPE( m_enum );\ 91 struct VariantCaster<m_enum> {\ 93 static _FORCE_INLINE_ m_enum cast(const Variant& p_variant) {\ 94 return (m_enum)p_variant.operator int();\ 99 #define CHECK_ARG(m_arg)\ 100 if ((m_arg-1)<p_arg_count) {\ 101 Variant::Type argtype=get_argument_type(m_arg-1);\ 102 if (!Variant::can_convert_strict(p_args[m_arg-1]->get_type(),argtype)) {\ 103 r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;\ 104 r_error.argument=m_arg-1;\ 105 r_error.expected=argtype;\ 110 #define CHECK_NOARG(m_arg)\ 112 if (p_arg##m_arg.get_type()!=Variant::NIL) {\ 113 if (r_argerror) *r_argerror=(m_arg-1);\ 114 return CALL_ERROR_EXTRA_ARGUMENT;\ 120 VARIANT_ENUM_CAST( Vector3::Axis );
122 VARIANT_ENUM_CAST( Error );
123 VARIANT_ENUM_CAST(
wchar_t );
124 VARIANT_ENUM_CAST( Margin );
125 VARIANT_ENUM_CAST( Orientation );
126 VARIANT_ENUM_CAST( HAlign );
135 int default_argument_count;
137 #ifdef DEBUG_METHODS_ENABLED 139 Variant::Type *argument_types;
147 void _set_const(
bool p_const);
148 #ifdef DEBUG_METHODS_ENABLED 149 virtual Variant::Type _gen_argument_type(
int p_arg)
const=0;
150 void _generate_argument_types(
int p_count);
151 void set_argument_types(Variant::Type *p_types) { argument_types=p_types; }
153 void set_argument_count(
int p_count) { argument_count=p_count; }
156 Vector<Variant> get_default_arguments()
const {
return default_arguments; }
157 _FORCE_INLINE_
int get_default_argument_count()
const {
return default_argument_count; }
159 _FORCE_INLINE_
Variant has_default_argument(
int p_arg)
const {
161 int idx=argument_count-p_arg-1;
163 if (idx<0 || idx>=default_arguments.size())
169 _FORCE_INLINE_
Variant get_default_argument(
int p_arg)
const {
171 int idx=argument_count-p_arg-1;
173 if (idx<0 || idx>=default_arguments.size())
176 return default_arguments[idx];
179 #ifdef DEBUG_METHODS_ENABLED 181 _FORCE_INLINE_
void set_return_type(
const StringName& p_type) { ret_type=p_type; }
182 _FORCE_INLINE_
StringName get_return_type()
const {
return ret_type; }
184 _FORCE_INLINE_ Variant::Type get_argument_type(
int p_argument)
const {
186 ERR_FAIL_COND_V(p_argument<-1 || p_argument>argument_count,Variant::NIL);
187 return argument_types[p_argument+1];
196 void set_hint_flags(uint32_t p_hint) { hint_flags=p_hint; }
197 uint32_t get_hint_flags()
const {
return hint_flags|(is_const()?METHOD_FLAG_CONST:0); }
198 virtual String get_instance_type()
const=0;
200 _FORCE_INLINE_
int get_argument_count()
const {
return argument_count; };
205 r_error.error=Variant::CallError::CALL_OK;
206 check_call( p_args, &errorarg );
208 return call(p_object, VARIANT_ARG_PASS );
212 String methodname = get_instance_type()+
"::"+name;
213 if (err==CALL_ERROR_ARGUMENT_TYPE) {
214 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())+
".";
216 if (err==CALL_ERROR_EXTRA_ARGUMENT) {
217 errstr=
"Invalid call. Member function '"+methodname+
"' takes "+itos(get_argument_count())+
" argument, but argument "+itos(errorarg+1)+
" was received.";
220 ERR_PRINT(errstr.ascii().get_data());
227 _FORCE_INLINE_
int get_method_id()
const {
return method_id; }
228 _FORCE_INLINE_
bool is_const()
const {
return _const; }
244 NativeCall call_method;
247 virtual Variant::Type _gen_argument_type(
int p_arg)
const {
254 T* instance=
static_cast<T*
>(p_object);
255 return (instance->*call_method)(p_args,p_arg_count,r_error);
257 void set_method_info(
const MethodInfo& p_info) {
260 set_argument_count( p_info.arguments.size() );
261 #ifdef DEBUG_METHODS_ENABLED 262 Variant::Type *at = memnew_arr( Variant::Type , p_info.arguments.size()+1 );
263 at[0]=p_info.return_val.type;
264 if (p_info.arguments.size()) {
267 names.resize(p_info.arguments.size());
268 for(
int i=0;i<p_info.arguments.size();i++) {
270 at[i+1]=p_info.arguments[i].type;
271 names[i]=p_info.arguments[i].name;
274 set_argument_names(names);
276 set_argument_types(at);
280 void set_method(NativeCall p_method) { call_method=p_method; }
281 virtual bool is_const()
const {
return false; }
282 virtual String get_instance_type()
const {
return T::get_type_static(); }
292 a->set_method(p_method);
293 a->set_method_info(p_info);
303 class __UnexistingClass;
306 #include "method_bind.inc" Definition: method_bind.h:58
Format
Definition: image.h:57
Definition: string_db.h:48
Definition: method_bind.h:128
Definition: method_bind.h:239
Definition: variant.h:379