Implement `ClassDB::class_call_static_method`
This commit is contained in:
parent
475248d99d
commit
02fc4bbc2a
|
@ -1478,6 +1478,23 @@ TypedArray<Dictionary> ClassDB::class_get_method_list(const StringName &p_class,
|
|||
return ret;
|
||||
}
|
||||
|
||||
Variant ClassDB::class_call_static_method(const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error) {
|
||||
if (p_argcount < 2) {
|
||||
r_call_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
|
||||
return Variant::NIL;
|
||||
}
|
||||
if (!p_arguments[0]->is_string() || !p_arguments[1]->is_string()) {
|
||||
r_call_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
|
||||
return Variant::NIL;
|
||||
}
|
||||
StringName class_ = *p_arguments[0];
|
||||
StringName method = *p_arguments[1];
|
||||
const MethodBind *bind = ::ClassDB::get_method(class_, method);
|
||||
ERR_FAIL_NULL_V_MSG(bind, Variant::NIL, "Cannot find static method.");
|
||||
ERR_FAIL_COND_V_MSG(!bind->is_static(), Variant::NIL, "Method is not static.");
|
||||
return bind->call(nullptr, p_arguments + 2, p_argcount - 2, r_call_error);
|
||||
}
|
||||
|
||||
PackedStringArray ClassDB::class_get_integer_constant_list(const StringName &p_class, bool p_no_inheritance) const {
|
||||
List<String> constants;
|
||||
::ClassDB::get_integer_constant_list(p_class, &constants, p_no_inheritance);
|
||||
|
@ -1598,6 +1615,8 @@ void ClassDB::_bind_methods() {
|
|||
|
||||
::ClassDB::bind_method(D_METHOD("class_get_method_list", "class", "no_inheritance"), &ClassDB::class_get_method_list, DEFVAL(false));
|
||||
|
||||
::ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "class_call_static_method", &ClassDB::class_call_static_method, MethodInfo("class_call_static_method", PropertyInfo(Variant::STRING_NAME, "class"), PropertyInfo(Variant::STRING_NAME, "method")));
|
||||
|
||||
::ClassDB::bind_method(D_METHOD("class_get_integer_constant_list", "class", "no_inheritance"), &ClassDB::class_get_integer_constant_list, DEFVAL(false));
|
||||
|
||||
::ClassDB::bind_method(D_METHOD("class_has_integer_constant", "class", "name"), &ClassDB::class_has_integer_constant);
|
||||
|
|
|
@ -454,6 +454,7 @@ public:
|
|||
int class_get_method_argument_count(const StringName &p_class, const StringName &p_method, bool p_no_inheritance = false) const;
|
||||
|
||||
TypedArray<Dictionary> class_get_method_list(const StringName &p_class, bool p_no_inheritance = false) const;
|
||||
Variant class_call_static_method(const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error);
|
||||
|
||||
PackedStringArray class_get_integer_constant_list(const StringName &p_class, bool p_no_inheritance = false) const;
|
||||
bool class_has_integer_constant(const StringName &p_class, const StringName &p_name) const;
|
||||
|
|
|
@ -16,6 +16,14 @@
|
|||
Returns [code]true[/code] if objects can be instantiated from the specified [param class], otherwise returns [code]false[/code].
|
||||
</description>
|
||||
</method>
|
||||
<method name="class_call_static_method" qualifiers="vararg">
|
||||
<return type="Variant" />
|
||||
<param index="0" name="class" type="StringName" />
|
||||
<param index="1" name="method" type="StringName" />
|
||||
<description>
|
||||
Calls a static method on a class.
|
||||
</description>
|
||||
</method>
|
||||
<method name="class_exists" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="class" type="StringName" />
|
||||
|
|
Loading…
Reference in New Issue