diff options
Diffstat (limited to 'core')
31 files changed, 383 insertions, 127 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 3e289eeaf3..273ef78669 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -112,8 +112,8 @@ bool _ResourceLoader::has(const String &p_path) { void _ResourceLoader::_bind_methods() { - ClassDB::bind_method(D_METHOD("load_interactive:ResourceInteractiveLoader", "path", "type_hint"), &_ResourceLoader::load_interactive, DEFVAL("")); - ClassDB::bind_method(D_METHOD("load:Resource", "path", "type_hint", "p_no_cache"), &_ResourceLoader::load, DEFVAL(""), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("load_interactive", "path", "type_hint"), &_ResourceLoader::load_interactive, DEFVAL("")); + ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "p_no_cache"), &_ResourceLoader::load, DEFVAL(""), DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &_ResourceLoader::get_recognized_extensions_for_type); ClassDB::bind_method(D_METHOD("set_abort_on_missing_resources", "abort"), &_ResourceLoader::set_abort_on_missing_resources); ClassDB::bind_method(D_METHOD("get_dependencies", "path"), &_ResourceLoader::get_dependencies); @@ -148,8 +148,8 @@ _ResourceSaver *_ResourceSaver::singleton = NULL; void _ResourceSaver::_bind_methods() { - ClassDB::bind_method(D_METHOD("save", "path", "resource:Resource", "flags"), &_ResourceSaver::save, DEFVAL(0)); - ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type:Resource"), &_ResourceSaver::get_recognized_extensions); + ClassDB::bind_method(D_METHOD("save", "path", "resource", "flags"), &_ResourceSaver::save, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &_ResourceSaver::get_recognized_extensions); BIND_CONSTANT(FLAG_RELATIVE_PATHS); BIND_CONSTANT(FLAG_BUNDLE_RESOURCES); @@ -1038,7 +1038,7 @@ void _OS::_bind_methods() { &_OS::get_unix_time_from_datetime); ClassDB::bind_method(D_METHOD("get_system_time_secs"), &_OS::get_system_time_secs); - ClassDB::bind_method(D_METHOD("set_icon", "icon:Image"), &_OS::set_icon); + ClassDB::bind_method(D_METHOD("set_icon", "icon"), &_OS::set_icon); ClassDB::bind_method(D_METHOD("get_exit_code"), &_OS::get_exit_code); ClassDB::bind_method(D_METHOD("set_exit_code", "code"), &_OS::set_exit_code); @@ -1750,7 +1750,7 @@ void _File::_bind_methods() { ClassDB::bind_method(D_METHOD("get_sha256", "path"), &_File::get_sha256); ClassDB::bind_method(D_METHOD("get_endian_swap"), &_File::get_endian_swap); ClassDB::bind_method(D_METHOD("set_endian_swap", "enable"), &_File::set_endian_swap); - ClassDB::bind_method(D_METHOD("get_error:Error"), &_File::get_error); + ClassDB::bind_method(D_METHOD("get_error"), &_File::get_error); ClassDB::bind_method(D_METHOD("get_var"), &_File::get_var); ClassDB::bind_method(D_METHOD("get_csv_line", "delim"), &_File::get_csv_line, DEFVAL(",")); @@ -1954,7 +1954,7 @@ Error _Directory::remove(String p_name) { void _Directory::_bind_methods() { - ClassDB::bind_method(D_METHOD("open:Error", "path"), &_Directory::open); + ClassDB::bind_method(D_METHOD("open", "path"), &_Directory::open); ClassDB::bind_method(D_METHOD("list_dir_begin", "skip_navigational", "skip_hidden"), &_Directory::list_dir_begin, DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_next"), &_Directory::get_next); ClassDB::bind_method(D_METHOD("current_is_dir"), &_Directory::current_is_dir); @@ -1962,17 +1962,17 @@ void _Directory::_bind_methods() { ClassDB::bind_method(D_METHOD("get_drive_count"), &_Directory::get_drive_count); ClassDB::bind_method(D_METHOD("get_drive", "idx"), &_Directory::get_drive); ClassDB::bind_method(D_METHOD("get_current_drive"), &_Directory::get_current_drive); - ClassDB::bind_method(D_METHOD("change_dir:Error", "todir"), &_Directory::change_dir); + ClassDB::bind_method(D_METHOD("change_dir", "todir"), &_Directory::change_dir); ClassDB::bind_method(D_METHOD("get_current_dir"), &_Directory::get_current_dir); - ClassDB::bind_method(D_METHOD("make_dir:Error", "path"), &_Directory::make_dir); - ClassDB::bind_method(D_METHOD("make_dir_recursive:Error", "path"), &_Directory::make_dir_recursive); + ClassDB::bind_method(D_METHOD("make_dir", "path"), &_Directory::make_dir); + ClassDB::bind_method(D_METHOD("make_dir_recursive", "path"), &_Directory::make_dir_recursive); ClassDB::bind_method(D_METHOD("file_exists", "path"), &_Directory::file_exists); ClassDB::bind_method(D_METHOD("dir_exists", "path"), &_Directory::dir_exists); //ClassDB::bind_method(D_METHOD("get_modified_time","file"),&_Directory::get_modified_time); ClassDB::bind_method(D_METHOD("get_space_left"), &_Directory::get_space_left); - ClassDB::bind_method(D_METHOD("copy:Error", "from", "to"), &_Directory::copy); - ClassDB::bind_method(D_METHOD("rename:Error", "from", "to"), &_Directory::rename); - ClassDB::bind_method(D_METHOD("remove:Error", "path"), &_Directory::remove); + ClassDB::bind_method(D_METHOD("copy", "from", "to"), &_Directory::copy); + ClassDB::bind_method(D_METHOD("rename", "from", "to"), &_Directory::rename); + ClassDB::bind_method(D_METHOD("remove", "path"), &_Directory::remove); } _Directory::_Directory() { @@ -2109,14 +2109,14 @@ String _Marshalls::base64_to_utf8(const String &p_str) { void _Marshalls::_bind_methods() { - ClassDB::bind_method(D_METHOD("variant_to_base64:String", "variant"), &_Marshalls::variant_to_base64); - ClassDB::bind_method(D_METHOD("base64_to_variant:Variant", "base64_str"), &_Marshalls::base64_to_variant); + ClassDB::bind_method(D_METHOD("variant_to_base64", "variant"), &_Marshalls::variant_to_base64); + ClassDB::bind_method(D_METHOD("base64_to_variant", "base64_str"), &_Marshalls::base64_to_variant); - ClassDB::bind_method(D_METHOD("raw_to_base64:String", "array"), &_Marshalls::raw_to_base64); - ClassDB::bind_method(D_METHOD("base64_to_raw:PoolByteArray", "base64_str"), &_Marshalls::base64_to_raw); + ClassDB::bind_method(D_METHOD("raw_to_base64", "array"), &_Marshalls::raw_to_base64); + ClassDB::bind_method(D_METHOD("base64_to_raw", "base64_str"), &_Marshalls::base64_to_raw); - ClassDB::bind_method(D_METHOD("utf8_to_base64:String", "utf8_str"), &_Marshalls::utf8_to_base64); - ClassDB::bind_method(D_METHOD("base64_to_utf8:String", "base64_str"), &_Marshalls::base64_to_utf8); + ClassDB::bind_method(D_METHOD("utf8_to_base64", "utf8_str"), &_Marshalls::utf8_to_base64); + ClassDB::bind_method(D_METHOD("base64_to_utf8", "base64_str"), &_Marshalls::base64_to_utf8); }; //////////////// @@ -2133,8 +2133,8 @@ Error _Semaphore::post() { void _Semaphore::_bind_methods() { - ClassDB::bind_method(D_METHOD("wait:Error"), &_Semaphore::wait); - ClassDB::bind_method(D_METHOD("post:Error"), &_Semaphore::post); + ClassDB::bind_method(D_METHOD("wait"), &_Semaphore::wait); + ClassDB::bind_method(D_METHOD("post"), &_Semaphore::post); } _Semaphore::_Semaphore() { @@ -2167,7 +2167,7 @@ void _Mutex::unlock() { void _Mutex::_bind_methods() { ClassDB::bind_method(D_METHOD("lock"), &_Mutex::lock); - ClassDB::bind_method(D_METHOD("try_lock:Error"), &_Mutex::try_lock); + ClassDB::bind_method(D_METHOD("try_lock"), &_Mutex::try_lock); ClassDB::bind_method(D_METHOD("unlock"), &_Mutex::unlock); } @@ -2280,10 +2280,10 @@ Variant _Thread::wait_to_finish() { void _Thread::_bind_methods() { - ClassDB::bind_method(D_METHOD("start:Error", "instance", "method", "userdata", "priority"), &_Thread::start, DEFVAL(Variant()), DEFVAL(PRIORITY_NORMAL)); + ClassDB::bind_method(D_METHOD("start", "instance", "method", "userdata", "priority"), &_Thread::start, DEFVAL(Variant()), DEFVAL(PRIORITY_NORMAL)); ClassDB::bind_method(D_METHOD("get_id"), &_Thread::get_id); ClassDB::bind_method(D_METHOD("is_active"), &_Thread::is_active); - ClassDB::bind_method(D_METHOD("wait_to_finish:Variant"), &_Thread::wait_to_finish); + ClassDB::bind_method(D_METHOD("wait_to_finish"), &_Thread::wait_to_finish); BIND_CONSTANT(PRIORITY_LOW); BIND_CONSTANT(PRIORITY_NORMAL); @@ -2483,15 +2483,15 @@ void _ClassDB::_bind_methods() { ClassDB::bind_method(D_METHOD("class_exists", "class"), &_ClassDB::class_exists); ClassDB::bind_method(D_METHOD("is_parent_class", "class", "inherits"), &_ClassDB::is_parent_class); ClassDB::bind_method(D_METHOD("can_instance", "class"), &_ClassDB::can_instance); - ClassDB::bind_method(D_METHOD("instance:Variant", "class"), &_ClassDB::instance); + ClassDB::bind_method(D_METHOD("instance", "class"), &_ClassDB::instance); ClassDB::bind_method(D_METHOD("class_has_signal", "class", "signal"), &_ClassDB::has_signal); ClassDB::bind_method(D_METHOD("class_get_signal", "class", "signal"), &_ClassDB::get_signal); ClassDB::bind_method(D_METHOD("class_get_signal_list", "class", "no_inheritance"), &_ClassDB::get_signal_list, DEFVAL(false)); ClassDB::bind_method(D_METHOD("class_get_property_list", "class", "no_inheritance"), &_ClassDB::get_property_list, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("class_get_property:Variant", "object", "property"), &_ClassDB::get_property); - ClassDB::bind_method(D_METHOD("class_set_property:Error", "object", "property", "value"), &_ClassDB::set_property); + ClassDB::bind_method(D_METHOD("class_get_property", "object", "property"), &_ClassDB::get_property); + ClassDB::bind_method(D_METHOD("class_set_property", "object", "property", "value"), &_ClassDB::set_property); ClassDB::bind_method(D_METHOD("class_has_method", "class", "method", "no_inheritance"), &_ClassDB::has_method, DEFVAL(false)); @@ -2583,7 +2583,7 @@ void _Engine::_bind_methods() { ClassDB::bind_method(D_METHOD("get_frames_drawn"), &_Engine::get_frames_drawn); ClassDB::bind_method(D_METHOD("get_frames_per_second"), &_Engine::get_frames_per_second); - ClassDB::bind_method(D_METHOD("get_main_loop:MainLoop"), &_Engine::get_main_loop); + ClassDB::bind_method(D_METHOD("get_main_loop"), &_Engine::get_main_loop); ClassDB::bind_method(D_METHOD("get_version_info"), &_Engine::get_version_info); diff --git a/core/class_db.cpp b/core/class_db.cpp index 4db5793f27..0503f7c6fc 100644 --- a/core/class_db.cpp +++ b/core/class_db.cpp @@ -1082,12 +1082,6 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c StringName mdname = StaticCString::create(method_name); #endif - StringName rettype; - if (mdname.operator String().find(":") != -1) { - rettype = mdname.operator String().get_slice(":", 1); - mdname = mdname.operator String().get_slice(":", 0); - } - OBJTYPE_WLOCK; ERR_FAIL_COND_V(!p_bind, NULL); p_bind->set_name(mdname); @@ -1106,7 +1100,7 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c if (!type) { ERR_PRINTS("Couldn't bind method '" + mdname + "' for instance: " + instance_type); memdelete(p_bind); - ERR_FAIL_COND_V(!type, NULL); + ERR_FAIL_V(NULL); } if (type->method_map.has(mdname)) { @@ -1115,11 +1109,20 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c ERR_EXPLAIN("Method already bound: " + instance_type + "::" + mdname); ERR_FAIL_V(NULL); } + #ifdef DEBUG_METHODS_ENABLED + + if (method_name.args.size() > p_bind->get_argument_count()) { + memdelete(p_bind); + ERR_EXPLAIN("Method definition provides more arguments than the method actually has: " + instance_type + "::" + mdname); + ERR_FAIL_V(NULL); + } + p_bind->set_argument_names(method_name.args); - p_bind->set_return_type(rettype); + type->method_order.push_back(mdname); #endif + type->method_map[mdname] = p_bind; Vector<Variant> defvals; diff --git a/core/class_db.h b/core/class_db.h index 05c4b6d932..f73e082c52 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -437,12 +437,6 @@ public: MethodBind *bind = create_vararg_method_bind(p_method, p_info); ERR_FAIL_COND_V(!bind, NULL); - String rettype; - if (p_name.operator String().find(":") != -1) { - rettype = p_name.operator String().get_slice(":", 1); - p_name = p_name.operator String().get_slice(":", 0); - } - bind->set_name(p_name); bind->set_default_arguments(p_default_args); @@ -462,8 +456,7 @@ public: } type->method_map[p_name] = bind; #ifdef DEBUG_METHODS_ENABLED - if (!rettype.empty()) - bind->set_return_type(rettype); + bind->set_return_type("Variant"); type->method_order.push_back(p_name); #endif diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp index 9bdd960424..172249c5d7 100644 --- a/core/compressed_translation.cpp +++ b/core/compressed_translation.cpp @@ -306,7 +306,7 @@ void PHashTranslation::_get_property_list(List<PropertyInfo> *p_list) const { } void PHashTranslation::_bind_methods() { - ClassDB::bind_method(D_METHOD("generate", "from:Translation"), &PHashTranslation::generate); + ClassDB::bind_method(D_METHOD("generate", "from"), &PHashTranslation::generate); } PHashTranslation::PHashTranslation() { diff --git a/core/func_ref.cpp b/core/func_ref.cpp index 2d74efd822..5622a03665 100644 --- a/core/func_ref.cpp +++ b/core/func_ref.cpp @@ -61,7 +61,7 @@ void FuncRef::_bind_methods() { MethodInfo mi; mi.name = "call_func"; Vector<Variant> defargs; - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_func:Variant", &FuncRef::call_func, mi, defargs); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_func", &FuncRef::call_func, mi, defargs); } ClassDB::bind_method(D_METHOD("set_instance", "instance"), &FuncRef::set_instance); diff --git a/core/image.cpp b/core/image.cpp index 50dc9c109d..2db9cb1571 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -2254,16 +2254,16 @@ void Image::_bind_methods() { ClassDB::bind_method(D_METHOD("srgb_to_linear"), &Image::srgb_to_linear); ClassDB::bind_method(D_METHOD("normalmap_to_xy"), &Image::normalmap_to_xy); - ClassDB::bind_method(D_METHOD("blit_rect", "src:Image", "src_rect", "dst"), &Image::blit_rect); - ClassDB::bind_method(D_METHOD("blit_rect_mask", "src:Image", "mask:Image", "src_rect", "dst"), &Image::blit_rect_mask); - ClassDB::bind_method(D_METHOD("blend_rect", "src:Image", "src_rect", "dst"), &Image::blend_rect); - ClassDB::bind_method(D_METHOD("blend_rect_mask", "src:Image", "mask:Image", "src_rect", "dst"), &Image::blend_rect_mask); + ClassDB::bind_method(D_METHOD("blit_rect", "src", "src_rect", "dst"), &Image::blit_rect); + ClassDB::bind_method(D_METHOD("blit_rect_mask", "src", "mask", "src_rect", "dst"), &Image::blit_rect_mask); + ClassDB::bind_method(D_METHOD("blend_rect", "src", "src_rect", "dst"), &Image::blend_rect); + ClassDB::bind_method(D_METHOD("blend_rect_mask", "src", "mask", "src_rect", "dst"), &Image::blend_rect_mask); ClassDB::bind_method(D_METHOD("fill", "color"), &Image::fill); ClassDB::bind_method(D_METHOD("get_used_rect"), &Image::get_used_rect); - ClassDB::bind_method(D_METHOD("get_rect:Image", "rect"), &Image::get_rect); + ClassDB::bind_method(D_METHOD("get_rect", "rect"), &Image::get_rect); - ClassDB::bind_method(D_METHOD("copy_from", "src:Image"), &Image::copy_internals_from); + ClassDB::bind_method(D_METHOD("copy_from", "src"), &Image::copy_internals_from); ClassDB::bind_method(D_METHOD("_set_data", "data"), &Image::_set_data); ClassDB::bind_method(D_METHOD("_get_data"), &Image::_get_data); diff --git a/core/input_map.cpp b/core/input_map.cpp index 85e627f352..8435882325 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -41,11 +41,11 @@ void InputMap::_bind_methods() { ClassDB::bind_method(D_METHOD("add_action", "action"), &InputMap::add_action); ClassDB::bind_method(D_METHOD("erase_action", "action"), &InputMap::erase_action); - ClassDB::bind_method(D_METHOD("action_add_event", "action", "event:InputEvent"), &InputMap::action_add_event); - ClassDB::bind_method(D_METHOD("action_has_event", "action", "event:InputEvent"), &InputMap::action_has_event); - ClassDB::bind_method(D_METHOD("action_erase_event", "action", "event:InputEvent"), &InputMap::action_erase_event); + ClassDB::bind_method(D_METHOD("action_add_event", "action", "event"), &InputMap::action_add_event); + ClassDB::bind_method(D_METHOD("action_has_event", "action", "event"), &InputMap::action_has_event); + ClassDB::bind_method(D_METHOD("action_erase_event", "action", "event"), &InputMap::action_erase_event); ClassDB::bind_method(D_METHOD("get_action_list", "action"), &InputMap::_get_action_list); - ClassDB::bind_method(D_METHOD("event_is_action", "event:InputEvent", "action"), &InputMap::event_is_action); + ClassDB::bind_method(D_METHOD("event_is_action", "event", "action"), &InputMap::event_is_action); ClassDB::bind_method(D_METHOD("load_from_globals"), &InputMap::load_from_globals); } diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 4067899068..edd090adf2 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -205,7 +205,7 @@ Error ConfigFile::load(const String &p_path) { void ConfigFile::_bind_methods() { ClassDB::bind_method(D_METHOD("set_value", "section", "key", "value"), &ConfigFile::set_value); - ClassDB::bind_method(D_METHOD("get_value:Variant", "section", "key", "default"), &ConfigFile::get_value, DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("get_value", "section", "key", "default"), &ConfigFile::get_value, DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("has_section", "section"), &ConfigFile::has_section); ClassDB::bind_method(D_METHOD("has_section_key", "section", "key"), &ConfigFile::has_section_key); @@ -215,8 +215,8 @@ void ConfigFile::_bind_methods() { ClassDB::bind_method(D_METHOD("erase_section", "section"), &ConfigFile::erase_section); - ClassDB::bind_method(D_METHOD("load:Error", "path"), &ConfigFile::load); - ClassDB::bind_method(D_METHOD("save:Error", "path"), &ConfigFile::save); + ClassDB::bind_method(D_METHOD("load", "path"), &ConfigFile::load); + ClassDB::bind_method(D_METHOD("save", "path"), &ConfigFile::save); } ConfigFile::ConfigFile() { diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 0c84a5213f..4d5b88cfa1 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -624,9 +624,9 @@ Error HTTPClient::_get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received void HTTPClient::_bind_methods() { - ClassDB::bind_method(D_METHOD("connect_to_host:Error", "host", "port", "use_ssl", "verify_host"), &HTTPClient::connect_to_host, DEFVAL(false), DEFVAL(true)); - ClassDB::bind_method(D_METHOD("set_connection", "connection:StreamPeer"), &HTTPClient::set_connection); - ClassDB::bind_method(D_METHOD("get_connection:StreamPeer"), &HTTPClient::get_connection); + ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port", "use_ssl", "verify_host"), &HTTPClient::connect_to_host, DEFVAL(false), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("set_connection", "connection"), &HTTPClient::set_connection); + ClassDB::bind_method(D_METHOD("get_connection"), &HTTPClient::get_connection); ClassDB::bind_method(D_METHOD("request_raw", "method", "url", "headers", "body"), &HTTPClient::request_raw); ClassDB::bind_method(D_METHOD("request", "method", "url", "headers", "body"), &HTTPClient::request, DEFVAL(String())); ClassDB::bind_method(D_METHOD("send_body_text", "body"), &HTTPClient::send_body_text); @@ -646,9 +646,9 @@ void HTTPClient::_bind_methods() { ClassDB::bind_method(D_METHOD("is_blocking_mode_enabled"), &HTTPClient::is_blocking_mode_enabled); ClassDB::bind_method(D_METHOD("get_status"), &HTTPClient::get_status); - ClassDB::bind_method(D_METHOD("poll:Error"), &HTTPClient::poll); + ClassDB::bind_method(D_METHOD("poll"), &HTTPClient::poll); - ClassDB::bind_method(D_METHOD("query_string_from_dict:String", "fields"), &HTTPClient::query_string_from_dict); + ClassDB::bind_method(D_METHOD("query_string_from_dict", "fields"), &HTTPClient::query_string_from_dict); BIND_CONSTANT(METHOD_GET); BIND_CONSTANT(METHOD_HEAD); diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index 40082cc481..c028d7d197 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -120,11 +120,11 @@ Error PacketPeer::_get_packet_error() const { void PacketPeer::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_var:Variant"), &PacketPeer::_bnd_get_var); - ClassDB::bind_method(D_METHOD("put_var", "var:Variant"), &PacketPeer::put_var); + ClassDB::bind_method(D_METHOD("get_var"), &PacketPeer::_bnd_get_var); + ClassDB::bind_method(D_METHOD("put_var", "var"), &PacketPeer::put_var); ClassDB::bind_method(D_METHOD("get_packet"), &PacketPeer::_get_packet); - ClassDB::bind_method(D_METHOD("put_packet:Error", "buffer"), &PacketPeer::_put_packet); - ClassDB::bind_method(D_METHOD("get_packet_error:Error"), &PacketPeer::_get_packet_error); + ClassDB::bind_method(D_METHOD("put_packet", "buffer"), &PacketPeer::_put_packet); + ClassDB::bind_method(D_METHOD("get_packet_error"), &PacketPeer::_get_packet_error); ClassDB::bind_method(D_METHOD("get_available_packet_count"), &PacketPeer::get_available_packet_count); }; @@ -138,7 +138,7 @@ void PacketPeerStream::_set_stream_peer(REF p_peer) { void PacketPeerStream::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_stream_peer", "peer:StreamPeer"), &PacketPeerStream::_set_stream_peer); + ClassDB::bind_method(D_METHOD("set_stream_peer", "peer"), &PacketPeerStream::_set_stream_peer); ClassDB::bind_method(D_METHOD("set_input_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_input_buffer_max_size); ClassDB::bind_method(D_METHOD("set_output_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_output_buffer_max_size); } diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index 8bc3241cc5..d1729819a8 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -59,9 +59,9 @@ Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) { void PacketPeerUDP::_bind_methods() { - ClassDB::bind_method(D_METHOD("listen:Error", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::listen, DEFVAL("*"), DEFVAL(65536)); + ClassDB::bind_method(D_METHOD("listen", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::listen, DEFVAL("*"), DEFVAL(65536)); ClassDB::bind_method(D_METHOD("close"), &PacketPeerUDP::close); - ClassDB::bind_method(D_METHOD("wait:Error"), &PacketPeerUDP::wait); + ClassDB::bind_method(D_METHOD("wait"), &PacketPeerUDP::wait); ClassDB::bind_method(D_METHOD("is_listening"), &PacketPeerUDP::is_listening); ClassDB::bind_method(D_METHOD("get_packet_ip"), &PacketPeerUDP::_get_packet_ip); //ClassDB::bind_method(D_METHOD("get_packet_address"),&PacketPeerUDP::_get_packet_address); diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 9b89fa3399..5347cd6ee1 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -84,7 +84,7 @@ void ResourceLoader::get_recognized_extensions_for_type(const String &p_type, Li void ResourceInteractiveLoader::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_resource:Resource"), &ResourceInteractiveLoader::get_resource); + ClassDB::bind_method(D_METHOD("get_resource"), &ResourceInteractiveLoader::get_resource); ClassDB::bind_method(D_METHOD("poll"), &ResourceInteractiveLoader::poll); ClassDB::bind_method(D_METHOD("wait"), &ResourceInteractiveLoader::wait); ClassDB::bind_method(D_METHOD("get_stage"), &ResourceInteractiveLoader::get_stage); diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index 0dbcb3cf56..fdad7c7bdf 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -385,7 +385,7 @@ void StreamPeer::_bind_methods() { ClassDB::bind_method(D_METHOD("put_float", "val"), &StreamPeer::put_float); ClassDB::bind_method(D_METHOD("put_double", "val"), &StreamPeer::put_double); ClassDB::bind_method(D_METHOD("put_utf8_string", "val"), &StreamPeer::put_utf8_string); - ClassDB::bind_method(D_METHOD("put_var", "val:Variant"), &StreamPeer::put_var); + ClassDB::bind_method(D_METHOD("put_var", "val"), &StreamPeer::put_var); ClassDB::bind_method(D_METHOD("get_8"), &StreamPeer::get_8); ClassDB::bind_method(D_METHOD("get_u8"), &StreamPeer::get_u8); @@ -399,7 +399,7 @@ void StreamPeer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_double"), &StreamPeer::get_double); ClassDB::bind_method(D_METHOD("get_string", "bytes"), &StreamPeer::get_string); ClassDB::bind_method(D_METHOD("get_utf8_string", "bytes"), &StreamPeer::get_utf8_string); - ClassDB::bind_method(D_METHOD("get_var:Variant"), &StreamPeer::get_var); + ClassDB::bind_method(D_METHOD("get_var"), &StreamPeer::get_var); } //////////////////////////////// @@ -412,7 +412,7 @@ void StreamPeerBuffer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_data_array", "data"), &StreamPeerBuffer::set_data_array); ClassDB::bind_method(D_METHOD("get_data_array"), &StreamPeerBuffer::get_data_array); ClassDB::bind_method(D_METHOD("clear"), &StreamPeerBuffer::clear); - ClassDB::bind_method(D_METHOD("duplicate:StreamPeerBuffer"), &StreamPeerBuffer::duplicate); + ClassDB::bind_method(D_METHOD("duplicate"), &StreamPeerBuffer::duplicate); } Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) { diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp index 57cffd073a..ef3c264375 100644 --- a/core/io/stream_peer_ssl.cpp +++ b/core/io/stream_peer_ssl.cpp @@ -51,8 +51,8 @@ bool StreamPeerSSL::is_available() { void StreamPeerSSL::_bind_methods() { - ClassDB::bind_method(D_METHOD("accept_stream:Error", "stream:StreamPeer"), &StreamPeerSSL::accept_stream); - ClassDB::bind_method(D_METHOD("connect_to_stream:Error", "stream:StreamPeer", "validate_certs", "for_hostname"), &StreamPeerSSL::connect_to_stream, DEFVAL(false), DEFVAL(String())); + ClassDB::bind_method(D_METHOD("accept_stream", "stream"), &StreamPeerSSL::accept_stream); + ClassDB::bind_method(D_METHOD("connect_to_stream", "stream", "validate_certs", "for_hostname"), &StreamPeerSSL::connect_to_stream, DEFVAL(false), DEFVAL(String())); ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerSSL::get_status); ClassDB::bind_method(D_METHOD("disconnect_from_stream"), &StreamPeerSSL::disconnect_from_stream); BIND_CONSTANT(STATUS_DISCONNECTED); diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 4c891188ee..29a80ecc19 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -49,7 +49,7 @@ void TCP_Server::_bind_methods() { ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &TCP_Server::listen, DEFVAL("*")); ClassDB::bind_method(D_METHOD("is_connection_available"), &TCP_Server::is_connection_available); - ClassDB::bind_method(D_METHOD("take_connection:StreamPeerTCP"), &TCP_Server::take_connection); + ClassDB::bind_method(D_METHOD("take_connection"), &TCP_Server::take_connection); ClassDB::bind_method(D_METHOD("stop"), &TCP_Server::stop); } diff --git a/core/make_binders.py b/core/make_binders.py index 74b5e9fda3..a5cdb78443 100644 --- a/core/make_binders.py +++ b/core/make_binders.py @@ -11,11 +11,18 @@ public: #ifdef DEBUG_METHODS_ENABLED virtual Variant::Type _gen_argument_type(int p_arg) const { return _get_argument_type(p_arg); } Variant::Type _get_argument_type(int p_argument) const { - $ifret if (p_argument==-1) return Variant::get_type_for<R>();$ - $arg if (p_argument==(@-1)) return Variant::get_type_for<P@>(); + $ifret if (p_argument==-1) return (Variant::Type)GetTypeInfo<R>::VARIANT_TYPE;$ + $arg if (p_argument==(@-1)) return (Variant::Type)GetTypeInfo<P@>::VARIANT_TYPE; $ return Variant::NIL; } + virtual StringName _gen_argument_type_name(int p_arg) const { return _gen_argument_type_hint(p_arg); } + StringName _gen_argument_type_hint(int p_argument) const { + $ifret if (p_argument==-1) return GetTypeInfo<R>::get_class_name();$ + $arg if (p_argument==(@-1)) return GetTypeInfo<P@>::get_class_name(); + $ + return StringName(); + } #endif virtual String get_instance_class() const { return T::get_class_static(); @@ -91,11 +98,20 @@ public: virtual Variant::Type _gen_argument_type(int p_arg) const { return _get_argument_type(p_arg); } Variant::Type _get_argument_type(int p_argument) const { - $ifret if (p_argument==-1) return Variant::get_type_for<R>();$ - $arg if (p_argument==(@-1)) return Variant::get_type_for<P@>(); + $ifret if (p_argument==-1) return (Variant::Type)GetTypeInfo<R>::VARIANT_TYPE;$ + $arg if (p_argument==(@-1)) return (Variant::Type)GetTypeInfo<P@>::VARIANT_TYPE; $ return Variant::NIL; } + + virtual StringName _gen_argument_type_name(int p_arg) const { return _gen_argument_type_hint(p_arg); } + + StringName _gen_argument_type_hint(int p_argument) const { + $ifret if (p_argument==-1) return GetTypeInfo<R>::get_class_name();$ + $arg if (p_argument==(@-1)) return GetTypeInfo<P@>::get_class_name(); + $ + return StringName(); + } #endif virtual String get_instance_class() const { return type_name; diff --git a/core/method_bind.cpp b/core/method_bind.cpp index 51c0e72bc7..6792b62703 100644 --- a/core/method_bind.cpp +++ b/core/method_bind.cpp @@ -38,12 +38,16 @@ PropertyInfo MethodBind::get_argument_info(int p_argument) const { if (p_argument >= 0) { - String name = (p_argument < arg_names.size()) ? String(arg_names[p_argument]) : String("arg" + itos(p_argument)); + String name = p_argument < arg_names.size() ? String(arg_names[p_argument]) : String("arg" + itos(p_argument)); PropertyInfo pi(get_argument_type(p_argument), name); - if ((pi.type == Variant::OBJECT) && name.find(":") != -1) { - pi.hint = PROPERTY_HINT_RESOURCE_TYPE; - pi.hint_string = name.get_slicec(':', 1); - pi.name = name.get_slicec(':', 0); + + if (!is_vararg() && pi.type == Variant::OBJECT) { + StringName type_hint = arg_type_hints[p_argument]; + + if (type_hint != StringName()) { + pi.hint = PROPERTY_HINT_RESOURCE_TYPE; + pi.hint_string = type_hint.operator String(); + } } return pi; @@ -87,6 +91,16 @@ Vector<StringName> MethodBind::get_argument_names() const { return arg_names; } +void MethodBind::set_argument_type_hints(const Vector<StringName> &p_type_hints) { + + arg_type_hints = p_type_hints; +} + +Vector<StringName> MethodBind::get_argument_type_hints() const { + + return arg_type_hints; +} + #endif void MethodBind::set_default_arguments(const Vector<Variant> &p_defargs) { @@ -98,11 +112,19 @@ void MethodBind::set_default_arguments(const Vector<Variant> &p_defargs) { void MethodBind::_generate_argument_types(int p_count) { set_argument_count(p_count); + Variant::Type *argt = memnew_arr(Variant::Type, p_count + 1); - argt[0] = _gen_argument_type(-1); + + arg_type_hints.resize(p_count); + + argt[0] = _gen_argument_type(-1); // return type + set_return_type(_gen_argument_type_hint(-1)); + for (int i = 0; i < p_count; i++) { argt[i + 1] = _gen_argument_type(i); + arg_type_hints[i] = _gen_argument_type_hint(i); } + set_argument_types(argt); } diff --git a/core/method_bind.h b/core/method_bind.h index dbc9cca082..3b4ff96a19 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -44,6 +44,8 @@ #define DEBUG_METHODS_ENABLED #endif +#include "type_info.h" + enum MethodFlags { METHOD_FLAG_NORMAL = 1, @@ -87,12 +89,10 @@ struct VariantCaster<const T &> { #define _VC(m_idx) \ (VariantCaster<P##m_idx>::cast((m_idx - 1) >= p_arg_count ? get_default_argument(m_idx - 1) : *p_args[m_idx - 1])) -//SIMPLE_NUMERIC_TYPE is used to avoid a warning on Variant::get_type_for - #ifdef PTRCALL_ENABLED #define VARIANT_ENUM_CAST(m_enum) \ - SIMPLE_NUMERIC_TYPE(m_enum); \ + MAKE_ENUM_TYPE_INFO(m_enum) \ template <> \ struct VariantCaster<m_enum> { \ \ @@ -113,7 +113,7 @@ struct VariantCaster<const T &> { #else #define VARIANT_ENUM_CAST(m_enum) \ - SIMPLE_NUMERIC_TYPE(m_enum); \ + MAKE_ENUM_TYPE_INFO(m_enum) \ template <> \ struct VariantCaster<m_enum> { \ \ @@ -165,6 +165,7 @@ class MethodBind { int argument_count; #ifdef DEBUG_METHODS_ENABLED Vector<StringName> arg_names; + Vector<StringName> arg_type_hints; Variant::Type *argument_types; StringName ret_type; #endif @@ -176,6 +177,7 @@ protected: void _set_returns(bool p_returns); #ifdef DEBUG_METHODS_ENABLED virtual Variant::Type _gen_argument_type(int p_arg) const = 0; + virtual StringName _gen_argument_type_hint(int p_arg) const = 0; void _generate_argument_types(int p_count); void set_argument_types(Variant::Type *p_types) { argument_types = p_types; } #endif @@ -220,6 +222,9 @@ public: void set_argument_names(const Vector<StringName> &p_names); Vector<StringName> get_argument_names() const; + + void set_argument_type_hints(const Vector<StringName> &p_type_hints); + Vector<StringName> get_argument_type_hints() const; #endif void set_hint_flags(uint32_t p_hint) { hint_flags = p_hint; } uint32_t get_hint_flags() const { return hint_flags | (is_const() ? METHOD_FLAG_CONST : 0) | (is_vararg() ? METHOD_FLAG_VARARG : 0); } @@ -282,11 +287,17 @@ public: return Variant::NIL; } + virtual StringName _gen_argument_type_hint(int p_arg) const { + + return "Variant"; + } + virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Variant::CallError &r_error) { T *instance = static_cast<T *>(p_object); return (instance->*call_method)(p_args, p_arg_count, r_error); } + void set_method_info(const MethodInfo &p_info) { set_argument_count(p_info.arguments.size()); diff --git a/core/object.cpp b/core/object.cpp index df3b39072b..62b2b5d545 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1651,17 +1651,17 @@ void Object::_bind_methods() { ClassDB::bind_method(D_METHOD("get_class"), &Object::get_class); ClassDB::bind_method(D_METHOD("is_class", "type"), &Object::is_class); ClassDB::bind_method(D_METHOD("set", "property", "value"), &Object::_set_bind); - ClassDB::bind_method(D_METHOD("get:Variant", "property"), &Object::_get_bind); + ClassDB::bind_method(D_METHOD("get", "property"), &Object::_get_bind); ClassDB::bind_method(D_METHOD("get_property_list"), &Object::_get_property_list_bind); ClassDB::bind_method(D_METHOD("get_method_list"), &Object::_get_method_list_bind); ClassDB::bind_method(D_METHOD("notification", "what", "reversed"), &Object::notification, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_instance_id"), &Object::get_instance_id); - ClassDB::bind_method(D_METHOD("set_script", "script:Script"), &Object::set_script); - ClassDB::bind_method(D_METHOD("get_script:Script"), &Object::get_script); + ClassDB::bind_method(D_METHOD("set_script", "script"), &Object::set_script); + ClassDB::bind_method(D_METHOD("get_script"), &Object::get_script); ClassDB::bind_method(D_METHOD("set_meta", "name", "value"), &Object::set_meta); - ClassDB::bind_method(D_METHOD("get_meta:Variant", "name", "value"), &Object::get_meta); + ClassDB::bind_method(D_METHOD("get_meta", "name"), &Object::get_meta); ClassDB::bind_method(D_METHOD("has_meta", "name"), &Object::has_meta); ClassDB::bind_method(D_METHOD("get_meta_list"), &Object::_get_meta_list_bind); @@ -1687,7 +1687,7 @@ void Object::_bind_methods() { mi.name = "call"; mi.arguments.push_back(PropertyInfo(Variant::STRING, "method")); - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call:Variant", &Object::_call_bind, mi); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call", &Object::_call_bind, mi); } { @@ -1698,7 +1698,7 @@ void Object::_bind_methods() { ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_deferred", &Object::_call_deferred_bind, mi); } - ClassDB::bind_method(D_METHOD("callv:Variant", "method", "arg_array"), &Object::callv); + ClassDB::bind_method(D_METHOD("callv", "method", "arg_array"), &Object::callv); ClassDB::bind_method(D_METHOD("has_method", "method"), &Object::has_method); @@ -1706,9 +1706,9 @@ void Object::_bind_methods() { ClassDB::bind_method(D_METHOD("get_signal_connection_list", "signal"), &Object::_get_signal_connection_list); ClassDB::bind_method(D_METHOD("get_incoming_connections"), &Object::_get_incoming_connections); - ClassDB::bind_method(D_METHOD("connect", "signal", "target:Object", "method", "binds", "flags"), &Object::connect, DEFVAL(Array()), DEFVAL(0)); - ClassDB::bind_method(D_METHOD("disconnect", "signal", "target:Object", "method"), &Object::disconnect); - ClassDB::bind_method(D_METHOD("is_connected", "signal", "target:Object", "method"), &Object::is_connected); + ClassDB::bind_method(D_METHOD("connect", "signal", "target", "method", "binds", "flags"), &Object::connect, DEFVAL(Array()), DEFVAL(0)); + ClassDB::bind_method(D_METHOD("disconnect", "signal", "target", "method"), &Object::disconnect); + ClassDB::bind_method(D_METHOD("is_connected", "signal", "target", "method"), &Object::is_connected); ClassDB::bind_method(D_METHOD("set_block_signals", "enable"), &Object::set_block_signals); ClassDB::bind_method(D_METHOD("is_blocking_signals"), &Object::is_blocking_signals); @@ -1726,7 +1726,7 @@ void Object::_bind_methods() { ADD_SIGNAL(MethodInfo("script_changed")); BIND_VMETHOD(MethodInfo("_notification", PropertyInfo(Variant::INT, "what"))); - BIND_VMETHOD(MethodInfo("_set", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::NIL, "value"))); + BIND_VMETHOD(MethodInfo("_set:bool", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::NIL, "value"))); #ifdef TOOLS_ENABLED MethodInfo miget("_get", PropertyInfo(Variant::STRING, "property")); miget.return_val.name = "Variant"; diff --git a/core/os/input.cpp b/core/os/input.cpp index a90a552d1d..c7b32b939a 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -83,8 +83,8 @@ void Input::_bind_methods() { ClassDB::bind_method(D_METHOD("warp_mouse_pos", "to"), &Input::warp_mouse_pos); ClassDB::bind_method(D_METHOD("action_press", "action"), &Input::action_press); ClassDB::bind_method(D_METHOD("action_release", "action"), &Input::action_release); - ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image:Texture", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(Vector2())); - ClassDB::bind_method(D_METHOD("parse_input_event", "event:InputEvent"), &Input::parse_input_event); + ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(Vector2())); + ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &Input::parse_input_event); BIND_CONSTANT(MOUSE_MODE_VISIBLE); BIND_CONSTANT(MOUSE_MODE_HIDDEN); diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 0a07b6b2b7..fe0e2c2524 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -134,12 +134,12 @@ void InputEvent::_bind_methods() { ClassDB::bind_method(D_METHOD("as_text"), &InputEvent::as_text); - ClassDB::bind_method(D_METHOD("action_match", "event:InputEvent"), &InputEvent::action_match); - ClassDB::bind_method(D_METHOD("shortcut_match", "event:InputEvent"), &InputEvent::shortcut_match); + ClassDB::bind_method(D_METHOD("action_match", "event"), &InputEvent::action_match); + ClassDB::bind_method(D_METHOD("shortcut_match", "event"), &InputEvent::shortcut_match); ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type); - ClassDB::bind_method(D_METHOD("xformed_by:InputEvent", "xform", "local_ofs"), &InputEvent::xformed_by, DEFVAL(Vector2())); + ClassDB::bind_method(D_METHOD("xformed_by", "xform", "local_ofs"), &InputEvent::xformed_by, DEFVAL(Vector2())); ADD_PROPERTY(PropertyInfo(Variant::INT, "device"), "set_device", "get_device"); } diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index 93658c07c2..248f5537c6 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -32,7 +32,7 @@ void MainLoop::_bind_methods() { - ClassDB::bind_method(D_METHOD("input_event", "ev:InputEvent"), &MainLoop::input_event); + ClassDB::bind_method(D_METHOD("input_event", "ev"), &MainLoop::input_event); ClassDB::bind_method(D_METHOD("input_text", "text"), &MainLoop::input_text); ClassDB::bind_method(D_METHOD("init"), &MainLoop::init); ClassDB::bind_method(D_METHOD("iteration", "delta"), &MainLoop::iteration); diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp index 0565d0d3f5..eb4aeb758a 100644 --- a/core/packed_data_container.cpp +++ b/core/packed_data_container.cpp @@ -368,7 +368,7 @@ void PackedDataContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("_iter_init"), &PackedDataContainer::_iter_init); ClassDB::bind_method(D_METHOD("_iter_get"), &PackedDataContainer::_iter_get); ClassDB::bind_method(D_METHOD("_iter_next"), &PackedDataContainer::_iter_next); - ClassDB::bind_method(D_METHOD("pack:Error", "value"), &PackedDataContainer::pack); + ClassDB::bind_method(D_METHOD("pack", "value"), &PackedDataContainer::pack); ClassDB::bind_method(D_METHOD("size"), &PackedDataContainer::size); ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY, "__data__"), "_set_data", "_get_data"); diff --git a/core/project_settings.cpp b/core/project_settings.cpp index f6e0d2e991..4a1b35ea4a 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -900,7 +900,7 @@ void ProjectSettings::_bind_methods() { ClassDB::bind_method(D_METHOD("get_singleton", "name"), &ProjectSettings::get_singleton_object); ClassDB::bind_method(D_METHOD("load_resource_pack", "pack"), &ProjectSettings::_load_resource_pack); ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &ProjectSettings::property_can_revert); - ClassDB::bind_method(D_METHOD("property_get_revert:Variant", "name"), &ProjectSettings::property_get_revert); + ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &ProjectSettings::property_get_revert); ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd); } diff --git a/core/reference.cpp b/core/reference.cpp index 066dc8059e..e9629ee7c0 100644 --- a/core/reference.cpp +++ b/core/reference.cpp @@ -122,7 +122,7 @@ WeakRef::WeakRef() { void WeakRef::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_ref:Object"), &WeakRef::get_ref); + ClassDB::bind_method(D_METHOD("get_ref"), &WeakRef::get_ref); } #if 0 diff --git a/core/reference.h b/core/reference.h index 90f2791f4b..7f48f8323e 100644 --- a/core/reference.h +++ b/core/reference.h @@ -374,5 +374,23 @@ struct PtrToArg<const RefPtr &> { } }; +template <class T> +struct GetTypeInfo<Ref<T> > { + enum { VARIANT_TYPE = Variant::OBJECT }; + + static inline StringName get_class_name() { + return T::get_class_static(); + } +}; + +template <class T> +struct GetTypeInfo<const Ref<T> &> { + enum { VARIANT_TYPE = Variant::OBJECT }; + + static inline StringName get_class_name() { + return T::get_class_static(); + } +}; + #endif #endif // REFERENCE_H diff --git a/core/resource.cpp b/core/resource.cpp index 9bce343cba..a0b0fd24e1 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -337,10 +337,10 @@ void Resource::_bind_methods() { ClassDB::bind_method(D_METHOD("get_rid"), &Resource::get_rid); ClassDB::bind_method(D_METHOD("set_local_to_scene", "enable"), &Resource::set_local_to_scene); ClassDB::bind_method(D_METHOD("is_local_to_scene"), &Resource::is_local_to_scene); - ClassDB::bind_method(D_METHOD("get_local_scene:Node"), &Resource::get_local_scene); + ClassDB::bind_method(D_METHOD("get_local_scene"), &Resource::get_local_scene); ClassDB::bind_method(D_METHOD("setup_local_to_scene"), &Resource::setup_local_to_scene); - ClassDB::bind_method(D_METHOD("duplicate:Resource", "subresources"), &Resource::duplicate, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("duplicate", "subresources"), &Resource::duplicate, DEFVAL(false)); ADD_SIGNAL(MethodInfo("changed")); ADD_GROUP("Resource", "resource_"); ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "resource_local_to_scene"), "set_local_to_scene", "is_local_to_scene"); diff --git a/core/translation.cpp b/core/translation.cpp index a524b10b3b..c38d5d8b4d 100644 --- a/core/translation.cpp +++ b/core/translation.cpp @@ -1124,8 +1124,8 @@ void TranslationServer::_bind_methods() { ClassDB::bind_method(D_METHOD("translate", "message"), &TranslationServer::translate); - ClassDB::bind_method(D_METHOD("add_translation", "translation:Translation"), &TranslationServer::add_translation); - ClassDB::bind_method(D_METHOD("remove_translation", "translation:Translation"), &TranslationServer::remove_translation); + ClassDB::bind_method(D_METHOD("add_translation", "translation"), &TranslationServer::add_translation); + ClassDB::bind_method(D_METHOD("remove_translation", "translation"), &TranslationServer::remove_translation); ClassDB::bind_method(D_METHOD("clear"), &TranslationServer::clear); } diff --git a/core/type_info.h b/core/type_info.h new file mode 100644 index 0000000000..10912fd074 --- /dev/null +++ b/core/type_info.h @@ -0,0 +1,203 @@ +#ifndef GET_TYPE_INFO_H +#define GET_TYPE_INFO_H + +template <bool C, typename T = void> +struct EnableIf { + + typedef T type; +}; + +template <typename T> +struct EnableIf<false, T> { +}; + +template <typename, typename> +struct TypesAreSame { + + static bool const value = false; +}; + +template <typename A> +struct TypesAreSame<A, A> { + + static bool const value = true; +}; + +template <typename B, typename D> +struct TypeInherits { + + static D *get_d(); + + static char (&test(B *))[1]; + static char (&test(...))[2]; + + static bool const value = sizeof(test(get_d())) == sizeof(char) && + !TypesAreSame<B volatile const, void volatile const>::value; +}; + +template <class T, typename = void> +struct GetTypeInfo { + enum { VARIANT_TYPE = Variant::NIL }; + + static inline StringName get_class_name() { + ERR_PRINT("Fallback type info. Bug!"); + return ""; // Not "Nil", this is an error + } +}; + +#define MAKE_TYPE_INFO(m_type, m_var_type) \ + template <> \ + struct GetTypeInfo<m_type> { \ + enum { VARIANT_TYPE = m_var_type }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; \ + template <> \ + struct GetTypeInfo<const m_type &> { \ + enum { VARIANT_TYPE = m_var_type }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; + +MAKE_TYPE_INFO(bool, Variant::BOOL) +MAKE_TYPE_INFO(uint8_t, Variant::INT) +MAKE_TYPE_INFO(int8_t, Variant::INT) +MAKE_TYPE_INFO(uint16_t, Variant::INT) +MAKE_TYPE_INFO(int16_t, Variant::INT) +MAKE_TYPE_INFO(uint32_t, Variant::INT) +MAKE_TYPE_INFO(int32_t, Variant::INT) +MAKE_TYPE_INFO(int64_t, Variant::INT) +MAKE_TYPE_INFO(uint64_t, Variant::INT) +MAKE_TYPE_INFO(float, Variant::REAL) +MAKE_TYPE_INFO(double, Variant::REAL) + +MAKE_TYPE_INFO(String, Variant::STRING) +MAKE_TYPE_INFO(Vector2, Variant::VECTOR2) +MAKE_TYPE_INFO(Rect2, Variant::RECT2) +MAKE_TYPE_INFO(Vector3, Variant::VECTOR3) +MAKE_TYPE_INFO(Transform2D, Variant::TRANSFORM2D) +MAKE_TYPE_INFO(Plane, Variant::PLANE) +MAKE_TYPE_INFO(Quat, Variant::QUAT) +MAKE_TYPE_INFO(Rect3, Variant::RECT3) +MAKE_TYPE_INFO(Basis, Variant::BASIS) +MAKE_TYPE_INFO(Transform, Variant::TRANSFORM) +MAKE_TYPE_INFO(Color, Variant::COLOR) +MAKE_TYPE_INFO(NodePath, Variant::NODE_PATH) +MAKE_TYPE_INFO(RID, Variant::_RID) +MAKE_TYPE_INFO(Dictionary, Variant::DICTIONARY) +MAKE_TYPE_INFO(Array, Variant::ARRAY) +MAKE_TYPE_INFO(PoolByteArray, Variant::POOL_BYTE_ARRAY) +MAKE_TYPE_INFO(PoolIntArray, Variant::POOL_INT_ARRAY) +MAKE_TYPE_INFO(PoolRealArray, Variant::POOL_REAL_ARRAY) +MAKE_TYPE_INFO(PoolStringArray, Variant::POOL_STRING_ARRAY) +MAKE_TYPE_INFO(PoolVector2Array, Variant::POOL_VECTOR2_ARRAY) +MAKE_TYPE_INFO(PoolVector3Array, Variant::POOL_VECTOR3_ARRAY) +MAKE_TYPE_INFO(PoolColorArray, Variant::POOL_COLOR_ARRAY) + +MAKE_TYPE_INFO(StringName, Variant::STRING) +MAKE_TYPE_INFO(IP_Address, Variant::STRING) + +class BSP_Tree; +MAKE_TYPE_INFO(BSP_Tree, Variant::DICTIONARY) + +#define MAKE_TYPE_INFO_WITH_NAME(m_type, m_var_type, m_class_name) \ + template <> \ + struct GetTypeInfo<m_type> { \ + enum { VARIANT_TYPE = m_var_type }; \ + static inline StringName get_class_name() { \ + return m_class_name; \ + } \ + }; \ + template <> \ + struct GetTypeInfo<const m_type &> { \ + enum { VARIANT_TYPE = m_var_type }; \ + static inline StringName get_class_name() { \ + return m_class_name; \ + } \ + }; + +MAKE_TYPE_INFO_WITH_NAME(RefPtr, Variant::OBJECT, "Reference") +MAKE_TYPE_INFO_WITH_NAME(Variant, Variant::NIL, "Variant") + +#define MAKE_TEMPLATE_TYPE_INFO(m_template, m_type, m_var_type) \ + template <> \ + struct GetTypeInfo<m_template<m_type> > { \ + enum { VARIANT_TYPE = m_var_type }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; \ + template <> \ + struct GetTypeInfo<const m_template<m_type> &> { \ + enum { VARIANT_TYPE = m_var_type }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; + +MAKE_TEMPLATE_TYPE_INFO(Vector, uint8_t, Variant::POOL_BYTE_ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, int, Variant::POOL_INT_ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, float, Variant::POOL_REAL_ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, String, Variant::POOL_STRING_ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, Vector2, Variant::POOL_VECTOR2_ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, Vector3, Variant::POOL_VECTOR3_ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, Color, Variant::POOL_COLOR_ARRAY) + +MAKE_TEMPLATE_TYPE_INFO(Vector, Variant, Variant::ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, RID, Variant::ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, Plane, Variant::ARRAY) + +MAKE_TEMPLATE_TYPE_INFO(PoolVector, Plane, Variant::ARRAY) +MAKE_TEMPLATE_TYPE_INFO(PoolVector, Face3, Variant::POOL_VECTOR3_ARRAY) + +#define MAKE_ENUM_TYPE_INFO(m_enum) \ + template <> \ + struct GetTypeInfo<m_enum> { \ + enum { VARIANT_TYPE = Variant::INT }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; \ + template <> \ + struct GetTypeInfo<m_enum const> { \ + enum { VARIANT_TYPE = Variant::INT }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; \ + template <> \ + struct GetTypeInfo<m_enum &> { \ + enum { VARIANT_TYPE = Variant::INT }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; \ + template <> \ + struct GetTypeInfo<const m_enum &> { \ + enum { VARIANT_TYPE = Variant::INT }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; + +template <typename T> +struct GetTypeInfo<T *, typename EnableIf<TypeInherits<Object, T>::value>::type> { + enum { VARIANT_TYPE = Variant::OBJECT }; + + static inline StringName get_class_name() { + return T::get_class_static(); + } +}; + +template <typename T> +struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>::type> { + enum { VARIANT_TYPE = Variant::OBJECT }; + + static inline StringName get_class_name() { + return T::get_class_static(); + } +}; + +#endif // GET_TYPE_INFO_H diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index 637fcd91d4..19b9f161b7 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -496,8 +496,8 @@ void UndoRedo::_bind_methods() { ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "add_undo_method", &UndoRedo::_add_undo_method, mi); } - ClassDB::bind_method(D_METHOD("add_do_property", "object", "property", "value:Variant"), &UndoRedo::add_do_property); - ClassDB::bind_method(D_METHOD("add_undo_property", "object", "property", "value:Variant"), &UndoRedo::add_undo_property); + ClassDB::bind_method(D_METHOD("add_do_property", "object", "property", "value"), &UndoRedo::add_do_property); + ClassDB::bind_method(D_METHOD("add_undo_property", "object", "property", "value"), &UndoRedo::add_undo_property); ClassDB::bind_method(D_METHOD("add_do_reference", "object"), &UndoRedo::add_do_reference); ClassDB::bind_method(D_METHOD("add_undo_reference", "object"), &UndoRedo::add_undo_reference); ClassDB::bind_method(D_METHOD("clear_history"), &UndoRedo::clear_history); diff --git a/core/variant.h b/core/variant.h index 95782d9619..40de1a9bce 100644 --- a/core/variant.h +++ b/core/variant.h @@ -49,7 +49,6 @@ #include "rect3.h" #include "ref_ptr.h" #include "rid.h" -#include "simple_type.h" #include "transform.h" #include "ustring.h" #include "vector3.h" @@ -154,15 +153,6 @@ public: static bool can_convert(Type p_type_from, Type p_type_to); static bool can_convert_strict(Type p_type_from, Type p_type_to); - template <class T> - static Type get_type_for() { - - GetSimpleType<T> t; - Variant v(t.type); - Type r = v.get_type(); - return r; - } - bool is_ref() const; _FORCE_INLINE_ bool is_num() const { return type == INT || type == REAL; }; _FORCE_INLINE_ bool is_array() const { return type >= ARRAY; }; |