| 1963 | StringName mdname = method_name.name; |
| 1964 | #else |
| 1965 | MethodBind *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 | } |
nothing calls this directly
no test coverage detected