本文整理汇总了C++中MethodBind类的典型用法代码示例。如果您正苦于以下问题:C++ MethodBind类的具体用法?C++ MethodBind怎么用?C++ MethodBind使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MethodBind类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: call_multilevel_reversed
void Object::call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) {
MethodBind *method = ClassDB::get_method(get_class_name(), p_method);
Variant::CallError error;
OBJ_DEBUG_LOCK
if (method) {
method->call(this, p_args, p_argcount, error);
_test_call_error(p_method, error);
}
//Variant ret;
if (script_instance) {
script_instance->call_multilevel_reversed(p_method, p_args, p_argcount);
//_test_call_error(p_method,error);
}
}
示例2: godot_method_bind_call
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;
}
示例3: ERR_EXPLAIN
void Object::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) {
if (p_method == CoreStringNames::get_singleton()->_free) {
#ifdef DEBUG_ENABLED
if (Object::cast_to<Reference>(this)) {
ERR_EXPLAIN("Can't 'free' a reference.");
ERR_FAIL();
return;
}
if (_lock_index.get() > 1) {
ERR_EXPLAIN("Object is locked and can't be freed.");
ERR_FAIL();
return;
}
#endif
//must be here, must be before everything,
memdelete(this);
return;
}
//Variant ret;
OBJ_DEBUG_LOCK
Variant::CallError error;
if (script_instance) {
script_instance->call_multilevel(p_method, p_args, p_argcount);
//_test_call_error(p_method,error);
}
MethodBind *method = ClassDB::get_method(get_class_name(), p_method);
if (method) {
method->call(this, p_args, p_argcount, error);
_test_call_error(p_method, error);
}
}
示例4: while
void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, bool p_no_inheritance, bool p_exclude_from_properties) {
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
if (type->disabled) {
if (p_no_inheritance)
break;
type = type->inherits_ptr;
continue;
}
#ifdef DEBUG_METHODS_ENABLED
for (List<MethodInfo>::Element *E = type->virtual_methods.front(); E; E = E->next()) {
p_methods->push_back(E->get());
}
for (List<StringName>::Element *E = type->method_order.front(); E; E = E->next()) {
MethodBind *method = type->method_map.get(E->get());
MethodInfo minfo;
minfo.name = E->get();
minfo.id = method->get_method_id();
if (p_exclude_from_properties && type->methods_in_properties.has(minfo.name))
continue;
for (int i = 0; i < method->get_argument_count(); i++) {
//Variant::Type t=method->get_argument_type(i);
minfo.arguments.push_back(method->get_argument_info(i));
}
minfo.return_val = method->get_return_info();
minfo.flags = method->get_hint_flags();
for (int i = 0; i < method->get_argument_count(); i++) {
if (method->has_default_argument(i))
minfo.default_arguments.push_back(method->get_default_argument(i));
}
p_methods->push_back(minfo);
}
#else
const StringName *K = NULL;
while ((K = type->method_map.next(K))) {
MethodBind *m = type->method_map[*K];
MethodInfo mi;
mi.name = m->get_name();
p_methods->push_back(mi);
}
#endif
if (p_no_inheritance)
break;
type = type->inherits_ptr;
}
}
示例5: hash_djb2_one_64
uint64_t ClassDB::get_api_hash(APIType p_api) {
OBJTYPE_RLOCK;
#ifdef DEBUG_METHODS_ENABLED
uint64_t hash = hash_djb2_one_64(HashMapHasherDefault::hash(VERSION_FULL_CONFIG));
List<StringName> names;
const StringName *k = NULL;
while ((k = classes.next(k))) {
names.push_back(*k);
}
//must be alphabetically sorted for hash to compute
names.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
ClassInfo *t = classes.getptr(E->get());
ERR_FAIL_COND_V(!t, 0);
if (t->api != p_api || !t->exposed)
continue;
hash = hash_djb2_one_64(t->name.hash(), hash);
hash = hash_djb2_one_64(t->inherits.hash(), hash);
{ //methods
List<StringName> snames;
k = NULL;
while ((k = t->method_map.next(k))) {
snames.push_back(*k);
}
snames.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
MethodBind *mb = t->method_map[F->get()];
hash = hash_djb2_one_64(mb->get_name().hash(), hash);
hash = hash_djb2_one_64(mb->get_argument_count(), hash);
hash = hash_djb2_one_64(mb->get_argument_type(-1), hash); //return
for (int i = 0; i < mb->get_argument_count(); i++) {
const PropertyInfo info = mb->get_argument_info(i);
hash = hash_djb2_one_64(info.type, hash);
hash = hash_djb2_one_64(info.name.hash(), hash);
hash = hash_djb2_one_64(info.hint, hash);
hash = hash_djb2_one_64(info.hint_string.hash(), hash);
}
hash = hash_djb2_one_64(mb->get_default_argument_count(), hash);
for (int i = 0; i < mb->get_default_argument_count(); i++) {
//hash should not change, i hope for tis
Variant da = mb->get_default_argument(i);
hash = hash_djb2_one_64(da.hash(), hash);
}
hash = hash_djb2_one_64(mb->get_hint_flags(), hash);
}
}
{ //constants
List<StringName> snames;
k = NULL;
while ((k = t->constant_map.next(k))) {
snames.push_back(*k);
}
snames.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
hash = hash_djb2_one_64(F->get().hash(), hash);
hash = hash_djb2_one_64(t->constant_map[F->get()], hash);
}
}
{ //signals
List<StringName> snames;
k = NULL;
while ((k = t->signal_map.next(k))) {
snames.push_back(*k);
}
snames.sort_custom<StringName::AlphCompare>();
//.........这里部分代码省略.........
示例6: _write_string
void DocDump::dump(const String &p_file) {
List<StringName> class_list;
ClassDB::get_class_list(&class_list);
class_list.sort_custom<StringName::AlphCompare>();
FileAccess *f = FileAccess::open(p_file, FileAccess::WRITE);
_write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
_write_string(f, 0, "<doc version=\"" + String(VERSION_MKSTRING) + "\" name=\"Engine Types\">");
while (class_list.size()) {
String name = class_list.front()->get();
String header = "<class name=\"" + name + "\"";
String inherits = ClassDB::get_parent_class(name);
if (inherits != "")
header += " inherits=\"" + inherits + "\"";
String category = ClassDB::get_category(name);
if (category == "")
category = "Core";
header += " category=\"" + category + "\"";
header += ">";
_write_string(f, 0, header);
_write_string(f, 1, "<brief_description>");
_write_string(f, 1, "</brief_description>");
_write_string(f, 1, "<description>");
_write_string(f, 1, "</description>");
_write_string(f, 1, "<methods>");
List<MethodInfo> method_list;
ClassDB::get_method_list(name, &method_list, true);
method_list.sort();
for (List<MethodInfo>::Element *E = method_list.front(); E; E = E->next()) {
if (E->get().name == "" || E->get().name[0] == '_')
continue; //hiden
MethodBind *m = ClassDB::get_method(name, E->get().name);
String qualifiers;
if (E->get().flags & METHOD_FLAG_CONST)
qualifiers += "qualifiers=\"const\"";
_write_string(f, 2, "<method name=\"" + _escape_string(E->get().name) + "\" " + qualifiers + " >");
for (int i = -1; i < E->get().arguments.size(); i++) {
PropertyInfo arginfo;
if (i == -1) {
arginfo = E->get().return_val;
String type_name = (arginfo.hint == PROPERTY_HINT_RESOURCE_TYPE) ? arginfo.hint_string : Variant::get_type_name(arginfo.type);
if (arginfo.type == Variant::NIL)
continue;
_write_string(f, 3, "<return type=\"" + type_name + "\">");
} else {
arginfo = E->get().arguments[i];
String type_name;
if (arginfo.hint == PROPERTY_HINT_RESOURCE_TYPE)
type_name = arginfo.hint_string;
else if (arginfo.type == Variant::NIL)
type_name = "var";
else
type_name = Variant::get_type_name(arginfo.type);
if (m && m->has_default_argument(i)) {
Variant default_arg = m->get_default_argument(i);
String default_arg_text = String(_escape_string(m->get_default_argument(i)));
switch (default_arg.get_type()) {
case Variant::NIL:
default_arg_text = "NULL";
break;
// atomic types
case Variant::BOOL:
if (bool(default_arg))
default_arg_text = "true";
else
default_arg_text = "false";
break;
case Variant::INT:
case Variant::REAL:
//keep it
break;
case Variant::STRING: // 15
case Variant::NODE_PATH: // 15
default_arg_text = "\"" + default_arg_text + "\"";
break;
case Variant::TRANSFORM:
if (default_arg.operator Transform() == Transform()) {
default_arg_text = "";
//.........这里部分代码省略.........
示例7: while
void DocData::generate(bool p_basic_types) {
List<StringName> classes;
ObjectTypeDB::get_type_list(&classes);
classes.sort_custom<StringName::AlphCompare>();
while(classes.size()) {
String name=classes.front()->get();
String cname=name;
if (cname.begins_with("_")) //proxy class
cname=cname.substr(1,name.length());
class_list[cname]=ClassDoc();
ClassDoc& c = class_list[cname];
c.name=cname;
c.inherits=ObjectTypeDB::type_inherits_from(name);
c.category=ObjectTypeDB::get_category(name);
List<MethodInfo> method_list;
ObjectTypeDB::get_method_list(name,&method_list,true);
method_list.sort();
for(List<MethodInfo>::Element *E=method_list.front();E;E=E->next()) {
if (E->get().name=="" || (E->get().name[0]=='_' && !(E->get().flags&METHOD_FLAG_VIRTUAL)))
continue; //hiden, dont count
MethodDoc method;
method.name=E->get().name;
MethodBind *m = ObjectTypeDB::get_method(name,E->get().name);
if (E->get().flags&METHOD_FLAG_VIRTUAL)
method.qualifiers="virtual";
if (E->get().flags&METHOD_FLAG_CONST) {
if (method.qualifiers!="")
method.qualifiers+=" ";
method.qualifiers+="const";
}
for(int i=-1;i<E->get().arguments.size();i++) {
PropertyInfo arginfo;
if (i==-1) {
arginfo=E->get().return_val;
#ifdef DEBUG_METHODS_ENABLED
if (m && m->get_return_type()!=StringName())
method.return_type=m->get_return_type();
else if (method.name.find(":")!=-1) {
method.return_type=method.name.get_slice(":",1);
method.name=method.name.get_slice(":",0);
} else if (arginfo.type!=Variant::NIL) // {
#endif
method.return_type=(arginfo.hint==PROPERTY_HINT_RESOURCE_TYPE)?arginfo.hint_string:Variant::get_type_name(arginfo.type);
// }
} else {
ArgumentDoc argument;
arginfo=E->get().arguments[i];
String type_name;
if (arginfo.name.find(":")!=-1) {
type_name=arginfo.name.get_slice(":",1);
arginfo.name=arginfo.name.get_slice(":",0);
} else if (arginfo.hint==PROPERTY_HINT_RESOURCE_TYPE) {
type_name=arginfo.hint_string;
} else if (arginfo.type==Variant::NIL)
type_name="Variant";
else
type_name=Variant::get_type_name(arginfo.type);
if (arginfo.type==Variant::OBJECT) {
//print_line("validate: "+cname+"::"+method.name);
}
if (m && m->has_default_argument(i)) {
Variant default_arg=m->get_default_argument(i);
String default_arg_text=m->get_default_argument(i);
switch(default_arg.get_type()) {
case Variant::NIL:
default_arg_text="NULL";
break;
// atomic types
case Variant::BOOL:
//.........这里部分代码省略.........
示例8: while
void DocData::generate(bool p_basic_types) {
List<StringName> classes;
ClassDB::get_class_list(&classes);
classes.sort_custom<StringName::AlphCompare>();
bool skip_setter_getter_methods = true;
while (classes.size()) {
Set<StringName> setters_getters;
String name = classes.front()->get();
String cname = name;
if (cname.begins_with("_")) //proxy class
cname = cname.substr(1, name.length());
class_list[cname] = ClassDoc();
ClassDoc &c = class_list[cname];
c.name = cname;
c.inherits = ClassDB::get_parent_class(name);
c.category = ClassDB::get_category(name);
List<PropertyInfo> properties;
ClassDB::get_property_list(name, &properties, true);
for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
if (E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_INTERNAL)
continue;
PropertyDoc prop;
StringName setter = ClassDB::get_property_setter(name, E->get().name);
StringName getter = ClassDB::get_property_getter(name, E->get().name);
prop.name = E->get().name;
prop.setter = setter;
prop.getter = getter;
bool found_type = false;
if (getter != StringName()) {
MethodBind *mb = ClassDB::get_method(name, getter);
if (mb) {
PropertyInfo retinfo = mb->get_return_info();
found_type = true;
if (retinfo.type == Variant::INT && retinfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
prop.enumeration = retinfo.class_name;
prop.type = "int";
} else if (retinfo.class_name != StringName()) {
prop.type = retinfo.class_name;
} else if (retinfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
prop.type = retinfo.hint_string;
} else if (retinfo.type == Variant::NIL && retinfo.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
prop.type = "Variant";
} else if (retinfo.type == Variant::NIL) {
prop.type = "void";
} else {
prop.type = Variant::get_type_name(retinfo.type);
}
}
setters_getters.insert(getter);
}
if (setter != StringName()) {
setters_getters.insert(setter);
}
if (!found_type) {
if (E->get().type == Variant::OBJECT && E->get().hint == PROPERTY_HINT_RESOURCE_TYPE)
prop.type = E->get().hint_string;
else
prop.type = Variant::get_type_name(E->get().type);
}
c.properties.push_back(prop);
}
List<MethodInfo> method_list;
ClassDB::get_method_list(name, &method_list, true);
method_list.sort();
for (List<MethodInfo>::Element *E = method_list.front(); E; E = E->next()) {
if (E->get().name == "" || (E->get().name[0] == '_' && !(E->get().flags & METHOD_FLAG_VIRTUAL)))
continue; //hidden, don't count
if (skip_setter_getter_methods && setters_getters.has(E->get().name) && E->get().name.find("/") == -1)
continue;
MethodDoc method;
method.name = E->get().name;
if (E->get().flags & METHOD_FLAG_VIRTUAL)
method.qualifiers = "virtual";
//.........这里部分代码省略.........
示例9: godot_method_bind_ptrcall
void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_object *p_instance, const void **p_args, void *p_ret) {
MethodBind *mb = (MethodBind *)p_method_bind;
Object *o = (Object *)p_instance;
mb->ptrcall(o, p_args, p_ret);
}
示例10: Variant
Variant Object::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
r_error.error = Variant::CallError::CALL_OK;
if (p_method == CoreStringNames::get_singleton()->_free) {
//free must be here, before anything, always ready
#ifdef DEBUG_ENABLED
if (p_argcount != 0) {
r_error.argument = 0;
r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
return Variant();
}
if (Object::cast_to<Reference>(this)) {
r_error.argument = 0;
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
ERR_EXPLAIN("Can't 'free' a reference.");
ERR_FAIL_V(Variant());
}
if (_lock_index.get() > 1) {
r_error.argument = 0;
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
ERR_EXPLAIN("Object is locked and can't be freed.");
ERR_FAIL_V(Variant());
}
#endif
//must be here, must be before everything,
memdelete(this);
r_error.error = Variant::CallError::CALL_OK;
return Variant();
}
Variant ret;
OBJ_DEBUG_LOCK
if (script_instance) {
ret = script_instance->call(p_method, p_args, p_argcount, r_error);
//force jumptable
switch (r_error.error) {
case Variant::CallError::CALL_OK:
return ret;
case Variant::CallError::CALL_ERROR_INVALID_METHOD:
break;
case Variant::CallError::CALL_ERROR_INVALID_ARGUMENT:
case Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS:
case Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS:
return ret;
case Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL: {
}
}
}
MethodBind *method = ClassDB::get_method(get_class_name(), p_method);
if (method) {
ret = method->call(this, p_args, p_argcount, r_error);
} else {
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
}
return ret;
}
示例11: _guess_expression_type
//.........这里部分代码省略.........
r_type.type=tn->vtype;
return true;
} else if (op->arguments[0]->type==GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
const GDParser::BuiltInFunctionNode *bin = static_cast<const GDParser::BuiltInFunctionNode *>(op->arguments[0]);
return _guess_expression_type(context,bin,p_line,r_type);
} else if (op->arguments.size()>1 && op->arguments[1]->type==GDParser::Node::TYPE_IDENTIFIER) {
GDCompletionIdentifier base;
if (!_guess_expression_type(context,op->arguments[0],p_line,base))
return false;
StringName id = static_cast<const GDParser::IdentifierNode *>(op->arguments[1])->name;
if (base.type==Variant::OBJECT) {
if (id.operator String()=="new" && base.value.get_type()==Variant::OBJECT) {
Object *obj = base.value;
if (obj && obj->cast_to<GDNativeClass>()) {
GDNativeClass *gdnc = obj->cast_to<GDNativeClass>();
r_type.type=Variant::OBJECT;
r_type.value=Variant();
r_type.obj_type=gdnc->get_name();
return true;
}
}
if (ObjectTypeDB::has_method(base.obj_type,id)) {
#ifdef TOOLS_ENABLED
MethodBind *mb = ObjectTypeDB::get_method(base.obj_type,id);
PropertyInfo pi = mb->get_argument_info(-1);
//try calling the function if constant and all args are constant, should not crash..
Object *baseptr = base.value;
if (baseptr && mb->is_const() && pi.type==Variant::OBJECT) {
bool all_valid=true;
Vector<Variant> args;
for(int i=2;i<op->arguments.size();i++) {
GDCompletionIdentifier arg;
if (_guess_expression_type(context,op->arguments[i],p_line,arg)) {
if (arg.value.get_type()!=Variant::NIL && arg.value.get_type()!=Variant::OBJECT) { // calling with object seems dangerous, i don' t know
args.push_back(arg.value);
} else {
all_valid=false;
break;
}
} else {
all_valid=false;
}
}
if (all_valid) {
Vector<const Variant*> argptr;
for(int i=0;i<args.size();i++) {
argptr.push_back(&args[i]);
}
Variant::CallError ce;
Variant ret=mb->call(baseptr,argptr.ptr(),argptr.size(),ce);
示例12: _find_type_arguments
static void _find_type_arguments(const GDParser::Node*p_node,int p_line,const StringName& p_method,const GDCompletionIdentifier& id, int p_argidx, Set<String>& result, String& arghint) {
if (id.type==Variant::OBJECT && id.obj_type!=StringName()) {
MethodBind *m = ObjectTypeDB::get_method(id.obj_type,p_method);
if (!m)
return;
if (p_method.operator String()=="connect") {
if (p_argidx==0) {
List<MethodInfo> sigs;
ObjectTypeDB::get_signal_list(id.obj_type,&sigs);
for (List<MethodInfo>::Element *E=sigs.front();E;E=E->next()) {
result.insert("\""+E->get().name+"\"");
}
}
/*if (p_argidx==2) {
ERR_FAIL_COND(p_node->type!=GDParser::Node::TYPE_OPERATOR);
const GDParser::OperatorNode *op=static_cast<const GDParser::OperatorNode *>(p_node);
if (op->arguments.size()>)
}*/
} else {
Object *obj=id.value;
if (obj) {
List<String> options;
obj->get_argument_options(p_method,p_argidx,&options);
for(List<String>::Element *E=options.front();E;E=E->next()) {
result.insert(E->get());
}
}
}
arghint = _get_visual_datatype(m->get_argument_info(-1),false)+" "+p_method.operator String()+String("(");
for(int i=0;i<m->get_argument_count();i++) {
if (i>0)
arghint+=", ";
else
arghint+=" ";
if (i==p_argidx) {
arghint+=String::chr(0xFFFF);
}
String n = m->get_argument_info(i).name;
int dp = n.find(":");
if (dp!=-1)
n=n.substr(0,dp);
arghint+=_get_visual_datatype(m->get_argument_info(i))+" "+n;
int deffrom = m->get_argument_count()-m->get_default_argument_count();
if (i>=deffrom) {
int defidx = i-deffrom;
if (defidx>=0 && defidx<m->get_default_argument_count()) {
Variant v= m->get_default_argument(i);
arghint+="="+v.get_construct_string();
}
}
if (i==p_argidx) {
arghint+=String::chr(0xFFFF);
}
}
if (m->get_argument_count()>0)
arghint+=" ";
arghint+=")";
}
}