MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / bind_methodfi

Method bind_methodfi

core/object/class_db.cpp:1965–2027  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1963 StringName mdname = method_name.name;
1964#else
1965MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, bool p_compatibility, const char *method_name, const Variant **p_defs, int p_defcount) {
1966 StringName mdname = StringName(method_name);
1967#endif // DEBUG_ENABLED
1968
1969 Locker::Lock lock(Locker::STATE_WRITE);
1970 ERR_FAIL_NULL_V(p_bind, nullptr);
1971 p_bind->set_name(mdname);
1972
1973 String instance_type = p_bind->get_instance_class();
1974
1975#ifdef DEBUG_ENABLED
1976
1977 ERR_FAIL_COND_V_MSG(!p_compatibility && has_method(instance_type, mdname), nullptr, vformat("Class '%s' already has a method '%s'.", String(instance_type), String(mdname)));
1978#endif // DEBUG_ENABLED
1979
1980 ClassInfo *type = classes.getptr(instance_type);
1981 if (!type) {
1982 memdelete(p_bind);
1983 ERR_FAIL_V_MSG(nullptr, vformat("Couldn't bind method '%s' for instance '%s'.", mdname, instance_type));
1984 }
1985
1986 if (!p_compatibility && type->method_map.has(mdname)) {
1987 memdelete(p_bind);
1988 // overloading not supported
1989 ERR_FAIL_V_MSG(nullptr, vformat("Method already bound '%s::%s'.", instance_type, mdname));
1990 }
1991
1992#ifdef DEBUG_ENABLED
1993
1994 if (method_name.args.size() > p_bind->get_argument_count()) {
1995 memdelete(p_bind);
1996 ERR_FAIL_V_MSG(nullptr, vformat("Method definition provides more arguments than the method actually has '%s::%s'.", instance_type, mdname));
1997 }
1998
1999 if (p_defcount > p_bind->get_argument_count()) {
2000 memdelete(p_bind);
2001 ERR_FAIL_V_MSG(nullptr, vformat("Method definition for '%s::%s' provides more default arguments than the method has arguments.", instance_type, mdname));
2002 }
2003
2004 p_bind->set_argument_names(method_name.args);
2005
2006 if (!p_compatibility) {
2007 type->method_order.push_back(mdname);
2008 }
2009#endif // DEBUG_ENABLED
2010
2011 if (p_compatibility) {
2012 _bind_compatibility(type, p_bind);
2013 } else {
2014 type->method_map[mdname] = p_bind;
2015 }
2016
2017 Vector<Variant> defvals;
2018
2019 defvals.resize(p_defcount);
2020 for (int i = 0; i < p_defcount; i++) {
2021 defvals.write[i] = *p_defs[i];
2022 }

Callers

nothing calls this directly

Calls 14

has_methodFunction · 0.85
vformatFunction · 0.85
memdeleteFunction · 0.85
set_argument_namesMethod · 0.80
set_default_argumentsMethod · 0.80
sizeMethod · 0.65
StringNameClass · 0.50
StringClass · 0.50
set_nameMethod · 0.45
getptrMethod · 0.45
hasMethod · 0.45
get_argument_countMethod · 0.45

Tested by

no test coverage detected