/**************************************************************************/1/* method_bind.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930// object.h needs to be the first include *before* method_bind.h31// FIXME: Find out why and fix potential cyclical dependencies.32#include "core/object/object.h"3334#include "method_bind.h"3536uint32_t MethodBind::get_hash() const {37MethodInfo mi;38mi.return_val = get_return_info();39mi.flags = get_hint_flags();40for (int i = 0; i < get_argument_count(); i++) {41mi.arguments.push_back(get_argument_info(i));42}43mi.default_arguments = default_arguments;4445return mi.get_compatibility_hash();46}4748PropertyInfo MethodBind::get_argument_info(int p_argument) const {49ERR_FAIL_INDEX_V(p_argument, get_argument_count(), PropertyInfo());5051PropertyInfo info = _gen_argument_type_info(p_argument);52#ifdef DEBUG_ENABLED53if (info.name.is_empty()) {54info.name = p_argument < arg_names.size() ? String(arg_names[p_argument]) : String("_unnamed_arg" + itos(p_argument));55}56#endif // DEBUG_ENABLED57return info;58}5960PropertyInfo MethodBind::get_return_info() const {61return _gen_argument_type_info(-1);62}6364void MethodBind::_set_const(bool p_const) {65_const = p_const;66}6768void MethodBind::_set_static(bool p_static) {69_static = p_static;70}7172void MethodBind::_set_returns(bool p_returns) {73_returns = p_returns;74}7576StringName MethodBind::get_name() const {77return name;78}7980void MethodBind::set_name(const StringName &p_name) {81name = p_name;82}8384#ifdef DEBUG_ENABLED85void MethodBind::set_argument_names(const Vector<StringName> &p_names) {86arg_names = p_names;87}8889Vector<StringName> MethodBind::get_argument_names() const {90return arg_names;91}9293#endif // DEBUG_ENABLED9495void MethodBind::set_default_arguments(const Vector<Variant> &p_defargs) {96default_arguments = p_defargs;97default_argument_count = default_arguments.size();98}99100void MethodBind::_generate_argument_types(int p_count) {101set_argument_count(p_count);102103Variant::Type *argt = memnew_arr(Variant::Type, p_count + 1);104argt[0] = _gen_argument_type(-1); // return type105106for (int i = 0; i < p_count; i++) {107argt[i + 1] = _gen_argument_type(i);108}109110argument_types = argt;111}112113MethodBind::MethodBind() {114static int last_id = 0;115method_id = last_id++;116}117118MethodBind::~MethodBind() {119if (argument_types) {120memdelete_arr(argument_types);121}122}123124125