| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  nativescript.cpp                                                     */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2022-01-13 09:45:09 +01:00
										 |  |  | /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | #include "nativescript.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 12:40:41 +02:00
										 |  |  | #include "gdnative/gdnative.h"
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-09 22:07:40 -07:00
										 |  |  | #include "core/core_string_names.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-08 23:47:38 +02:00
										 |  |  | #include "core/global_constants.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/io/file_access_encrypted.h"
 | 
					
						
							|  |  |  | #include "core/os/file_access.h"
 | 
					
						
							|  |  |  | #include "core/os/os.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-08 23:47:38 +02:00
										 |  |  | #include "core/project_settings.h"
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-22 10:24:04 +03:00
										 |  |  | #include "main/main.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | #include "scene/main/scene_tree.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-12 17:18:13 +01:00
										 |  |  | #include "scene/resources/resource_format_text.h"
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-02 19:01:30 +01:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | #ifndef NO_THREADS
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/os/thread.h"
 | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | #if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED)
 | 
					
						
							|  |  |  | #include "api_generator.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef TOOLS_ENABLED
 | 
					
						
							|  |  |  | #include "editor/editor_node.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScript::_bind_methods() { | 
					
						
							| 
									
										
										
										
											2017-08-09 13:19:41 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_class_name", "class_name"), &NativeScript::set_class_name); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_class_name"), &NativeScript::get_class_name); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 13:19:41 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_library", "library"), &NativeScript::set_library); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_library"), &NativeScript::get_library); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-04 21:48:45 -05:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_script_class_name", "class_name"), &NativeScript::set_script_class_name); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_script_class_name"), &NativeScript::get_script_class_name); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_script_class_icon_path", "icon_path"), &NativeScript::set_script_class_icon_path); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_script_class_icon_path"), &NativeScript::get_script_class_icon_path); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_class_documentation"), &NativeScript::get_class_documentation); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_method_documentation", "method"), &NativeScript::get_method_documentation); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_signal_documentation", "signal_name"), &NativeScript::get_signal_documentation); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_property_documentation", "path"), &NativeScript::get_property_documentation); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 11:30:02 -03:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "class_name"), "set_class_name", "get_class_name"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library"); | 
					
						
							| 
									
										
										
										
											2018-08-04 21:48:45 -05:00
										 |  |  | 	ADD_GROUP("Script Class", "script_class_"); | 
					
						
							| 
									
										
										
										
											2018-11-08 11:30:02 -03:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "script_class_name"), "set_script_class_name", "get_script_class_name"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "script_class_icon_path", PROPERTY_HINT_FILE), "set_script_class_icon_path", "get_script_class_icon_path"); | 
					
						
							| 
									
										
										
										
											2017-07-25 00:22:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-26 16:36:51 +00:00
										 |  |  | 	ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &NativeScript::_new, MethodInfo("new")); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define NSL NativeScriptLanguage::get_singleton()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef TOOLS_ENABLED
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScript::_update_placeholder(PlaceHolderScriptInstance *p_placeholder) { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!script_data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	List<PropertyInfo> info; | 
					
						
							| 
									
										
										
										
											2017-08-09 20:51:38 +07:00
										 |  |  | 	get_script_property_list(&info); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	Map<StringName, Variant> values; | 
					
						
							| 
									
										
										
										
											2017-08-09 20:51:38 +07:00
										 |  |  | 	for (List<PropertyInfo>::Element *E = info.front(); E; E = E->next()) { | 
					
						
							|  |  |  | 		Variant value; | 
					
						
							|  |  |  | 		get_property_default_value(E->get().name, value); | 
					
						
							|  |  |  | 		values[E->get().name] = value; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	p_placeholder->update(info, values); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { | 
					
						
							|  |  |  | 	placeholders.erase(p_placeholder); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-02 04:48:17 +02:00
										 |  |  | bool NativeScript::inherits_script(const Ref<Script> &p_script) const { | 
					
						
							| 
									
										
										
										
											2021-08-02 14:34:43 +02:00
										 |  |  | 	Ref<NativeScript> ns = p_script; | 
					
						
							|  |  |  | 	if (ns.is_null()) { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const NativeScriptDesc *other_s = ns->get_script_desc(); | 
					
						
							|  |  |  | 	if (!other_s) { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const NativeScriptDesc *s = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (s) { | 
					
						
							|  |  |  | 		if (s == other_s) { | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		s = s->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-02 04:48:17 +02:00
										 |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | void NativeScript::set_class_name(String p_class_name) { | 
					
						
							|  |  |  | 	class_name = p_class_name; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String NativeScript::get_class_name() const { | 
					
						
							|  |  |  | 	return class_name; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScript::set_library(Ref<GDNativeLibrary> p_library) { | 
					
						
							|  |  |  | 	if (!library.is_null()) { | 
					
						
							| 
									
										
										
										
											2019-11-29 21:10:20 +01:00
										 |  |  | 		WARN_PRINT("Library in NativeScript already set. Do nothing."); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (p_library.is_null()) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	library = p_library; | 
					
						
							| 
									
										
										
										
											2017-11-02 17:14:37 +01:00
										 |  |  | 	lib_path = library->get_current_library_path(); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | #ifndef NO_THREADS
 | 
					
						
							| 
									
										
										
										
											2017-08-07 17:17:31 +07:00
										 |  |  | 	if (Thread::get_caller_id() != Thread::get_main_id()) { | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 		NSL->defer_init_library(p_library, this); | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		NSL->init_library(p_library); | 
					
						
							|  |  |  | 		NSL->register_script(this); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Ref<GDNativeLibrary> NativeScript::get_library() const { | 
					
						
							|  |  |  | 	return library; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-04 21:48:45 -05:00
										 |  |  | void NativeScript::set_script_class_name(String p_type) { | 
					
						
							|  |  |  | 	script_class_name = p_type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String NativeScript::get_script_class_name() const { | 
					
						
							|  |  |  | 	return script_class_name; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScript::set_script_class_icon_path(String p_icon_path) { | 
					
						
							|  |  |  | 	script_class_icon_path = p_icon_path; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String NativeScript::get_script_class_icon_path() const { | 
					
						
							|  |  |  | 	return script_class_icon_path; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | bool NativeScript::can_instance() const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef TOOLS_ENABLED
 | 
					
						
							| 
									
										
										
										
											2019-03-22 12:54:19 +01:00
										 |  |  | 	// Only valid if this is either a tool script or a "regular" script.
 | 
					
						
							| 
									
										
										
										
											2022-12-15 12:26:59 +01:00
										 |  |  | 	// (so an environment where scripting is disabled (and not the editor) would not
 | 
					
						
							| 
									
										
										
										
											2019-03-22 12:54:19 +01:00
										 |  |  | 	// create objects).
 | 
					
						
							|  |  |  | 	return script_data && (is_tool() || ScriptServer::is_scripting_enabled()); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	return script_data; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Ref<Script> NativeScript::get_base_script() const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (!script_data) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		return Ref<Script>(); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-22 17:41:50 -03:00
										 |  |  | 	NativeScript *script = (NativeScript *)NSL->create_script(); | 
					
						
							|  |  |  | 	Ref<NativeScript> ns = Ref<NativeScript>(script); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!ns.is_valid(), Ref<Script>()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	ns->set_class_name(script_data->base); | 
					
						
							|  |  |  | 	ns->set_library(get_library()); | 
					
						
							|  |  |  | 	return ns; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | StringName NativeScript::get_instance_base_type() const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (!script_data) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		return ""; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return script_data->base_native_type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ScriptInstance *NativeScript::instance_create(Object *p_this) { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!script_data) { | 
					
						
							| 
									
										
										
										
											2021-05-04 16:00:45 +02:00
										 |  |  | 		return nullptr; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	NativeScriptInstance *nsi = memnew(NativeScriptInstance); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	nsi->owner = p_this; | 
					
						
							|  |  |  | 	nsi->script = Ref<NativeScript>(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef TOOLS_ENABLED
 | 
					
						
							|  |  |  | 	if (!ScriptServer::is_scripting_enabled()) { | 
					
						
							|  |  |  | 		nsi->userdata = NULL; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		nsi->userdata = script_data->create_func.create_func((godot_object *)p_this, script_data->create_func.method_data); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 	nsi->userdata = script_data->create_func.create_func((godot_object *)p_this, script_data->create_func.method_data); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-27 10:43:02 +01:00
										 |  |  | 	owners_lock.lock(); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	instance_owners.insert(p_this); | 
					
						
							| 
									
										
										
										
											2021-01-27 10:43:02 +01:00
										 |  |  | 	owners_lock.unlock(); | 
					
						
							| 
									
										
										
										
											2017-07-27 15:30:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	return nsi; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-22 12:54:19 +01:00
										 |  |  | PlaceHolderScriptInstance *NativeScript::placeholder_instance_create(Object *p_this) { | 
					
						
							|  |  |  | #ifdef TOOLS_ENABLED
 | 
					
						
							|  |  |  | 	PlaceHolderScriptInstance *sins = memnew(PlaceHolderScriptInstance(NSL, Ref<Script>(this), p_this)); | 
					
						
							|  |  |  | 	placeholders.insert(sins); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_update_placeholder(sins); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return sins; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | bool NativeScript::instance_has(const Object *p_this) const { | 
					
						
							|  |  |  | 	return instance_owners.has((Object *)p_this); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeScript::has_source_code() const { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String NativeScript::get_source_code() const { | 
					
						
							|  |  |  | 	return ""; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScript::set_source_code(const String &p_code) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Error NativeScript::reload(bool p_keep_state) { | 
					
						
							|  |  |  | 	return FAILED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeScript::has_method(const StringName &p_method) const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		if (script_data->methods.has(p_method)) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			return true; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MethodInfo NativeScript::get_method_info(const StringName &p_method) const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (!script_data) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		return MethodInfo(); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							|  |  |  | 		Map<StringName, NativeScriptDesc::Method>::Element *M = script_data->methods.find(p_method); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		if (M) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			return M->get().info; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return MethodInfo(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-27 19:55:37 -03:00
										 |  |  | bool NativeScript::is_valid() const { | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | bool NativeScript::is_tool() const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (script_data) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		return script_data->is_tool; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ScriptLanguage *NativeScript::get_language() const { | 
					
						
							|  |  |  | 	return NativeScriptLanguage::get_singleton(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeScript::has_script_signal(const StringName &p_signal) const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							| 
									
										
										
										
											2017-07-30 14:51:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		if (script_data->signals_.has(p_signal)) { | 
					
						
							| 
									
										
										
										
											2017-07-30 14:51:34 +02:00
										 |  |  | 			return true; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-30 14:51:34 +02:00
										 |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (!script_data) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Set<MethodInfo> signals_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							|  |  |  | 		for (Map<StringName, NativeScriptDesc::Signal>::Element *S = script_data->signals_.front(); S; S = S->next()) { | 
					
						
							|  |  |  | 			signals_.insert(S->get().signal); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (Set<MethodInfo>::Element *E = signals_.front(); E; E = E->next()) { | 
					
						
							|  |  |  | 		r_signals->push_back(E->get()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeScript::get_property_default_value(const StringName &p_property, Variant &r_value) const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 	OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P; | 
					
						
							| 
									
										
										
										
											2017-08-09 20:37:37 +07:00
										 |  |  | 	while (!P && script_data) { | 
					
						
							|  |  |  | 		P = script_data->properties.find(p_property); | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (!P) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 	r_value = P.get().default_value; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScript::update_exports() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScript::get_script_method_list(List<MethodInfo> *p_list) const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (!script_data) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Set<MethodInfo> methods; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							|  |  |  | 		for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) { | 
					
						
							|  |  |  | 			methods.insert(E->get().info); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (Set<MethodInfo>::Element *E = methods.front(); E; E = E->next()) { | 
					
						
							|  |  |  | 		p_list->push_back(E->get()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScript::get_script_property_list(List<PropertyInfo> *p_list) const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 	Set<StringName> existing_properties; | 
					
						
							| 
									
										
										
										
											2018-04-10 16:01:13 +02:00
										 |  |  | 	List<PropertyInfo>::Element *original_back = p_list->back(); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	while (script_data) { | 
					
						
							| 
									
										
										
										
											2018-04-10 16:01:13 +02:00
										 |  |  | 		List<PropertyInfo>::Element *insert_position = original_back; | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) { | 
					
						
							|  |  |  | 			if (!existing_properties.has(E.key())) { | 
					
						
							| 
									
										
										
										
											2018-04-10 16:01:13 +02:00
										 |  |  | 				insert_position = p_list->insert_after(insert_position, E.get().info); | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 				existing_properties.insert(E.key()); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | String NativeScript::get_class_documentation() const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 06:49:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get class documentation on invalid NativeScript."); | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return script_data->documentation; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String NativeScript::get_method_documentation(const StringName &p_method) const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 06:49:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get method documentation on invalid NativeScript."); | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							|  |  |  | 		Map<StringName, NativeScriptDesc::Method>::Element *method = script_data->methods.find(p_method); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (method) { | 
					
						
							|  |  |  | 			return method->get().documentation; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 06:49:33 +02:00
										 |  |  | 	ERR_FAIL_V_MSG("", "Attempt to get method documentation for non-existent method."); | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String NativeScript::get_signal_documentation(const StringName &p_signal_name) const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 06:49:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get signal documentation on invalid NativeScript."); | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							|  |  |  | 		Map<StringName, NativeScriptDesc::Signal>::Element *signal = script_data->signals_.find(p_signal_name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (signal) { | 
					
						
							|  |  |  | 			return signal->get().documentation; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 06:49:33 +02:00
										 |  |  | 	ERR_FAIL_V_MSG("", "Attempt to get signal documentation for non-existent signal."); | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String NativeScript::get_property_documentation(const StringName &p_path) const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 06:49:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get property documentation on invalid NativeScript."); | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							|  |  |  | 		OrderedHashMap<StringName, NativeScriptDesc::Property>::Element property = script_data->properties.find(p_path); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (property) { | 
					
						
							|  |  |  | 			return property.get().documentation; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 06:49:33 +02:00
										 |  |  | 	ERR_FAIL_V_MSG("", "Attempt to get property documentation for non-existent signal."); | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | Variant NativeScript::_new(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { | 
					
						
							|  |  |  | 	if (lib_path.empty() || class_name.empty() || library.is_null()) { | 
					
						
							|  |  |  | 		r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL; | 
					
						
							|  |  |  | 		return Variant(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = get_script_desc(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!script_data) { | 
					
						
							|  |  |  | 		r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL; | 
					
						
							|  |  |  | 		return Variant(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	r_error.error = Variant::CallError::CALL_OK; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	REF ref; | 
					
						
							| 
									
										
										
										
											2021-05-04 16:00:45 +02:00
										 |  |  | 	Object *owner = nullptr; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!(script_data->base_native_type == "")) { | 
					
						
							|  |  |  | 		owner = ClassDB::instance(script_data->base_native_type); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		owner = memnew(Reference); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-14 23:39:10 +01:00
										 |  |  | 	if (!owner) { | 
					
						
							|  |  |  | 		r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL; | 
					
						
							|  |  |  | 		return Variant(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 	Reference *r = Object::cast_to<Reference>(owner); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	if (r) { | 
					
						
							|  |  |  | 		ref = REF(r); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	NativeScriptInstance *instance = (NativeScriptInstance *)instance_create(owner); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	owner->set_script_instance(instance); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!instance) { | 
					
						
							|  |  |  | 		if (ref.is_null()) { | 
					
						
							|  |  |  | 			memdelete(owner); //no owner, sorry
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return Variant(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ref.is_valid()) { | 
					
						
							|  |  |  | 		return ref; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return owner; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NativeScript::NativeScript() { | 
					
						
							|  |  |  | 	library = Ref<GDNative>(); | 
					
						
							|  |  |  | 	lib_path = ""; | 
					
						
							|  |  |  | 	class_name = ""; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NativeScript::~NativeScript() { | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 	NSL->unregister_script(this); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GET_SCRIPT_DESC() script->get_script_desc()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptInstance::_ml_call_reversed(NativeScriptDesc *script_data, const StringName &p_method, const Variant **p_args, int p_argcount) { | 
					
						
							|  |  |  | 	if (script_data->base_data) { | 
					
						
							|  |  |  | 		_ml_call_reversed(script_data->base_data, p_method, p_args, p_argcount); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); | 
					
						
							|  |  |  | 	if (E) { | 
					
						
							|  |  |  | 		godot_variant res = E->get().method.method((godot_object *)owner, E->get().method.method_data, userdata, p_argcount, (godot_variant **)p_args); | 
					
						
							|  |  |  | 		godot_variant_destroy(&res); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeScriptInstance::set(const StringName &p_name, const Variant &p_value) { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = GET_SCRIPT_DESC(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 		OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = script_data->properties.find(p_name); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		if (P) { | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 			P.get().setter.set_func((godot_object *)owner, | 
					
						
							|  |  |  | 					P.get().setter.method_data, | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 					userdata, | 
					
						
							|  |  |  | 					(godot_variant *)&p_value); | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find("_set"); | 
					
						
							|  |  |  | 		if (E) { | 
					
						
							|  |  |  | 			Variant name = p_name; | 
					
						
							|  |  |  | 			const Variant *args[2] = { &name, &p_value }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-27 23:45:29 +10:00
										 |  |  | 			godot_variant result; | 
					
						
							|  |  |  | 			result = E->get().method.method((godot_object *)owner, | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 					E->get().method.method_data, | 
					
						
							|  |  |  | 					userdata, | 
					
						
							|  |  |  | 					2, | 
					
						
							|  |  |  | 					(godot_variant **)args); | 
					
						
							| 
									
										
										
										
											2018-07-27 23:45:29 +10:00
										 |  |  | 			bool handled = *(Variant *)&result; | 
					
						
							|  |  |  | 			godot_variant_destroy(&result); | 
					
						
							|  |  |  | 			if (handled) { | 
					
						
							|  |  |  | 				return true; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | bool NativeScriptInstance::get(const StringName &p_name, Variant &r_ret) const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = GET_SCRIPT_DESC(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 		OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = script_data->properties.find(p_name); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		if (P) { | 
					
						
							|  |  |  | 			godot_variant value; | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 			value = P.get().getter.get_func((godot_object *)owner, | 
					
						
							|  |  |  | 					P.get().getter.method_data, | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 					userdata); | 
					
						
							|  |  |  | 			r_ret = *(Variant *)&value; | 
					
						
							|  |  |  | 			godot_variant_destroy(&value); | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find("_get"); | 
					
						
							|  |  |  | 		if (E) { | 
					
						
							|  |  |  | 			Variant name = p_name; | 
					
						
							|  |  |  | 			const Variant *args[1] = { &name }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			godot_variant result; | 
					
						
							|  |  |  | 			result = E->get().method.method((godot_object *)owner, | 
					
						
							|  |  |  | 					E->get().method.method_data, | 
					
						
							|  |  |  | 					userdata, | 
					
						
							|  |  |  | 					1, | 
					
						
							|  |  |  | 					(godot_variant **)args); | 
					
						
							|  |  |  | 			r_ret = *(Variant *)&result; | 
					
						
							|  |  |  | 			godot_variant_destroy(&result); | 
					
						
							| 
									
										
										
										
											2018-07-27 23:45:29 +10:00
										 |  |  | 			if (r_ret.get_type() != Variant::NIL) { | 
					
						
							|  |  |  | 				return true; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const { | 
					
						
							| 
									
										
										
										
											2017-07-24 22:00:14 +05:30
										 |  |  | 	script->get_script_property_list(p_properties); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = GET_SCRIPT_DESC(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							|  |  |  | 		Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find("_get_property_list"); | 
					
						
							|  |  |  | 		if (E) { | 
					
						
							|  |  |  | 			godot_variant result; | 
					
						
							|  |  |  | 			result = E->get().method.method((godot_object *)owner, | 
					
						
							|  |  |  | 					E->get().method.method_data, | 
					
						
							|  |  |  | 					userdata, | 
					
						
							|  |  |  | 					0, | 
					
						
							| 
									
										
										
										
											2021-05-04 16:00:45 +02:00
										 |  |  | 					nullptr); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			Variant res = *(Variant *)&result; | 
					
						
							|  |  |  | 			godot_variant_destroy(&result); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 06:49:33 +02:00
										 |  |  | 			ERR_FAIL_COND_MSG(res.get_type() != Variant::ARRAY, "_get_property_list must return an array of dictionaries."); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			Array arr = res; | 
					
						
							|  |  |  | 			for (int i = 0; i < arr.size(); i++) { | 
					
						
							|  |  |  | 				Dictionary d = arr[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				ERR_CONTINUE(!d.has("name")); | 
					
						
							|  |  |  | 				ERR_CONTINUE(!d.has("type")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				PropertyInfo info; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				info.type = Variant::Type(d["type"].operator int64_t()); | 
					
						
							|  |  |  | 				ERR_CONTINUE(info.type < 0 || info.type >= Variant::VARIANT_MAX); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				info.name = d["name"]; | 
					
						
							|  |  |  | 				ERR_CONTINUE(info.name == ""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (d.has("hint")) { | 
					
						
							|  |  |  | 					info.hint = PropertyHint(d["hint"].operator int64_t()); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (d.has("hint_string")) { | 
					
						
							|  |  |  | 					info.hint_string = d["hint_string"]; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (d.has("usage")) { | 
					
						
							|  |  |  | 					info.usage = d["usage"]; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				p_properties->push_back(info); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Variant::Type NativeScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = GET_SCRIPT_DESC(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 		OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = script_data->properties.find(p_name); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		if (P) { | 
					
						
							|  |  |  | 			*r_is_valid = true; | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 			return P.get().info.type; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return Variant::NIL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptInstance::get_method_list(List<MethodInfo> *p_list) const { | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 	script->get_script_method_list(p_list); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeScriptInstance::has_method(const StringName &p_method) const { | 
					
						
							|  |  |  | 	return script->has_method(p_method); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Variant NativeScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = GET_SCRIPT_DESC(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							|  |  |  | 		Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); | 
					
						
							|  |  |  | 		if (E) { | 
					
						
							|  |  |  | 			godot_variant result; | 
					
						
							| 
									
										
										
										
											2018-07-02 16:18:58 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | 			current_method_call = p_method; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			result = E->get().method.method((godot_object *)owner, | 
					
						
							|  |  |  | 					E->get().method.method_data, | 
					
						
							|  |  |  | 					userdata, | 
					
						
							|  |  |  | 					p_argcount, | 
					
						
							|  |  |  | 					(godot_variant **)p_args); | 
					
						
							| 
									
										
										
										
											2018-07-02 16:18:58 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | 			current_method_call = ""; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			Variant res = *(Variant *)&result; | 
					
						
							|  |  |  | 			godot_variant_destroy(&result); | 
					
						
							|  |  |  | 			r_error.error = Variant::CallError::CALL_OK; | 
					
						
							|  |  |  | 			return res; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; | 
					
						
							|  |  |  | 	return Variant(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptInstance::notification(int p_notification) { | 
					
						
							| 
									
										
										
										
											2018-07-02 16:18:58 -03:00
										 |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | 	if (p_notification == MainLoop::NOTIFICATION_CRASH) { | 
					
						
							|  |  |  | 		if (current_method_call != StringName("")) { | 
					
						
							| 
									
										
										
										
											2021-06-16 11:56:25 +01:00
										 |  |  | 			ERR_PRINT("NativeScriptInstance detected crash on method: " + current_method_call); | 
					
						
							| 
									
										
										
										
											2018-07-02 16:18:58 -03:00
										 |  |  | 			current_method_call = ""; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	Variant value = p_notification; | 
					
						
							|  |  |  | 	const Variant *args[1] = { &value }; | 
					
						
							|  |  |  | 	call_multilevel("_notification", args, 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-09 22:07:40 -07:00
										 |  |  | String NativeScriptInstance::to_string(bool *r_valid) { | 
					
						
							|  |  |  | 	if (has_method(CoreStringNames::get_singleton()->_to_string)) { | 
					
						
							|  |  |  | 		Variant::CallError ce; | 
					
						
							| 
									
										
										
										
											2021-05-04 16:00:45 +02:00
										 |  |  | 		Variant ret = call(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce); | 
					
						
							| 
									
										
										
										
											2019-04-09 22:07:40 -07:00
										 |  |  | 		if (ce.error == Variant::CallError::CALL_OK) { | 
					
						
							|  |  |  | 			if (ret.get_type() != Variant::STRING) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 				if (r_valid) { | 
					
						
							| 
									
										
										
										
											2019-04-09 22:07:40 -07:00
										 |  |  | 					*r_valid = false; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-08-09 06:49:33 +02:00
										 |  |  | 				ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); | 
					
						
							| 
									
										
										
										
											2019-04-09 22:07:40 -07:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			if (r_valid) { | 
					
						
							| 
									
										
										
										
											2019-04-09 22:07:40 -07:00
										 |  |  | 				*r_valid = true; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-04-09 22:07:40 -07:00
										 |  |  | 			return ret.operator String(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (r_valid) { | 
					
						
							| 
									
										
										
										
											2019-04-09 22:07:40 -07:00
										 |  |  | 		*r_valid = false; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-09 22:07:40 -07:00
										 |  |  | 	return String(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 20:24:15 +07:00
										 |  |  | void NativeScriptInstance::refcount_incremented() { | 
					
						
							|  |  |  | 	Variant::CallError err; | 
					
						
							| 
									
										
										
										
											2021-05-04 16:00:45 +02:00
										 |  |  | 	call("_refcount_incremented", nullptr, 0, err); | 
					
						
							| 
									
										
										
										
											2017-07-26 20:24:15 +07:00
										 |  |  | 	if (err.error != Variant::CallError::CALL_OK && err.error != Variant::CallError::CALL_ERROR_INVALID_METHOD) { | 
					
						
							|  |  |  | 		ERR_PRINT("Failed to invoke _refcount_incremented - should not happen"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeScriptInstance::refcount_decremented() { | 
					
						
							|  |  |  | 	Variant::CallError err; | 
					
						
							| 
									
										
										
										
											2021-05-04 16:00:45 +02:00
										 |  |  | 	Variant ret = call("_refcount_decremented", nullptr, 0, err); | 
					
						
							| 
									
										
										
										
											2017-07-26 20:24:15 +07:00
										 |  |  | 	if (err.error != Variant::CallError::CALL_OK && err.error != Variant::CallError::CALL_ERROR_INVALID_METHOD) { | 
					
						
							|  |  |  | 		ERR_PRINT("Failed to invoke _refcount_decremented - should not happen"); | 
					
						
							|  |  |  | 		return true; // assume we can destroy the object
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (err.error == Variant::CallError::CALL_ERROR_INVALID_METHOD) { | 
					
						
							|  |  |  | 		// the method does not exist, default is true
 | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | Ref<Script> NativeScriptInstance::get_script() const { | 
					
						
							|  |  |  | 	return script; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | MultiplayerAPI::RPCMode NativeScriptInstance::get_rpc_mode(const StringName &p_method) const { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	NativeScriptDesc *script_data = GET_SCRIPT_DESC(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							|  |  |  | 		Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); | 
					
						
							|  |  |  | 		if (E) { | 
					
						
							|  |  |  | 			switch (E->get().rpc_mode) { | 
					
						
							|  |  |  | 				case GODOT_METHOD_RPC_MODE_DISABLED: | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 					return MultiplayerAPI::RPC_MODE_DISABLED; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 				case GODOT_METHOD_RPC_MODE_REMOTE: | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 					return MultiplayerAPI::RPC_MODE_REMOTE; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 				case GODOT_METHOD_RPC_MODE_MASTER: | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 					return MultiplayerAPI::RPC_MODE_MASTER; | 
					
						
							| 
									
										
										
										
											2018-09-14 21:59:47 +02:00
										 |  |  | 				case GODOT_METHOD_RPC_MODE_PUPPET: | 
					
						
							|  |  |  | 					return MultiplayerAPI::RPC_MODE_PUPPET; | 
					
						
							| 
									
										
										
										
											2018-05-26 10:30:36 +02:00
										 |  |  | 				case GODOT_METHOD_RPC_MODE_REMOTESYNC: | 
					
						
							|  |  |  | 					return MultiplayerAPI::RPC_MODE_REMOTESYNC; | 
					
						
							|  |  |  | 				case GODOT_METHOD_RPC_MODE_MASTERSYNC: | 
					
						
							|  |  |  | 					return MultiplayerAPI::RPC_MODE_MASTERSYNC; | 
					
						
							| 
									
										
										
										
											2018-09-14 21:59:47 +02:00
										 |  |  | 				case GODOT_METHOD_RPC_MODE_PUPPETSYNC: | 
					
						
							|  |  |  | 					return MultiplayerAPI::RPC_MODE_PUPPETSYNC; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 				default: | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 					return MultiplayerAPI::RPC_MODE_DISABLED; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 	return MultiplayerAPI::RPC_MODE_DISABLED; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | MultiplayerAPI::RPCMode NativeScriptInstance::get_rset_mode(const StringName &p_variable) const { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	NativeScriptDesc *script_data = GET_SCRIPT_DESC(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 		OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.find(p_variable); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		if (E) { | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 			switch (E.get().rset_mode) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 				case GODOT_METHOD_RPC_MODE_DISABLED: | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 					return MultiplayerAPI::RPC_MODE_DISABLED; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 				case GODOT_METHOD_RPC_MODE_REMOTE: | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 					return MultiplayerAPI::RPC_MODE_REMOTE; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 				case GODOT_METHOD_RPC_MODE_MASTER: | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 					return MultiplayerAPI::RPC_MODE_MASTER; | 
					
						
							| 
									
										
										
										
											2018-09-14 21:59:47 +02:00
										 |  |  | 				case GODOT_METHOD_RPC_MODE_PUPPET: | 
					
						
							|  |  |  | 					return MultiplayerAPI::RPC_MODE_PUPPET; | 
					
						
							| 
									
										
										
										
											2018-09-14 23:10:12 +02:00
										 |  |  | 				case GODOT_METHOD_RPC_MODE_REMOTESYNC: | 
					
						
							|  |  |  | 					return MultiplayerAPI::RPC_MODE_REMOTESYNC; | 
					
						
							|  |  |  | 				case GODOT_METHOD_RPC_MODE_MASTERSYNC: | 
					
						
							|  |  |  | 					return MultiplayerAPI::RPC_MODE_MASTERSYNC; | 
					
						
							|  |  |  | 				case GODOT_METHOD_RPC_MODE_PUPPETSYNC: | 
					
						
							|  |  |  | 					return MultiplayerAPI::RPC_MODE_PUPPETSYNC; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 				default: | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 					return MultiplayerAPI::RPC_MODE_DISABLED; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 	return MultiplayerAPI::RPC_MODE_DISABLED; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ScriptLanguage *NativeScriptInstance::get_language() { | 
					
						
							|  |  |  | 	return NativeScriptLanguage::get_singleton(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptInstance::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = GET_SCRIPT_DESC(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (script_data) { | 
					
						
							|  |  |  | 		Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); | 
					
						
							|  |  |  | 		if (E) { | 
					
						
							|  |  |  | 			godot_variant res = E->get().method.method((godot_object *)owner, | 
					
						
							|  |  |  | 					E->get().method.method_data, | 
					
						
							|  |  |  | 					userdata, | 
					
						
							|  |  |  | 					p_argcount, | 
					
						
							|  |  |  | 					(godot_variant **)p_args); | 
					
						
							|  |  |  | 			godot_variant_destroy(&res); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		script_data = script_data->base_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptInstance::call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = GET_SCRIPT_DESC(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (script_data) { | 
					
						
							|  |  |  | 		_ml_call_reversed(script_data, p_method, p_args, p_argcount); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NativeScriptInstance::~NativeScriptInstance() { | 
					
						
							|  |  |  | 	NativeScriptDesc *script_data = GET_SCRIPT_DESC(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (!script_data) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	script_data->destroy_func.destroy_func((godot_object *)owner, script_data->destroy_func.method_data, userdata); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (owner) { | 
					
						
							| 
									
										
										
										
											2021-01-27 10:43:02 +01:00
										 |  |  | 		script->owners_lock.lock(); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		script->instance_owners.erase(owner); | 
					
						
							| 
									
										
										
										
											2021-01-27 10:43:02 +01:00
										 |  |  | 		script->owners_lock.unlock(); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NativeScriptLanguage *NativeScriptLanguage::singleton; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-06 21:10:01 +01:00
										 |  |  | void NativeScriptLanguage::_unload_stuff(bool p_reload) { | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 	Map<String, Ref<GDNative>> erase_and_unload; | 
					
						
							| 
									
										
										
										
											2018-03-31 01:45:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 	for (Map<String, Map<StringName, NativeScriptDesc>>::Element *L = library_classes.front(); L; L = L->next()) { | 
					
						
							| 
									
										
										
										
											2018-01-18 12:04:34 +01:00
										 |  |  | 		String lib_path = L->key(); | 
					
						
							|  |  |  | 		Map<StringName, NativeScriptDesc> classes = L->get(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (p_reload) { | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 			Map<String, Ref<GDNative>>::Element *E = library_gdnatives.find(lib_path); | 
					
						
							| 
									
										
										
										
											2018-01-18 12:04:34 +01:00
										 |  |  | 			Ref<GDNative> gdn; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (E) { | 
					
						
							|  |  |  | 				gdn = E->get(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			bool should_reload = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (gdn.is_valid()) { | 
					
						
							|  |  |  | 				Ref<GDNativeLibrary> lib = gdn->get_library(); | 
					
						
							|  |  |  | 				if (lib.is_valid()) { | 
					
						
							|  |  |  | 					should_reload = lib->is_reloadable(); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!should_reload) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-06 21:10:01 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 		Map<String, Ref<GDNative>>::Element *E = library_gdnatives.find(lib_path); | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 		Ref<GDNative> gdn; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (E) { | 
					
						
							|  |  |  | 			gdn = E->get(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-18 12:04:34 +01:00
										 |  |  | 		for (Map<StringName, NativeScriptDesc>::Element *C = classes.front(); C; C = C->next()) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			// free property stuff first
 | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 			for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = C->get().properties.front(); P; P = P.next()) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 				if (P.get().getter.free_func) { | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 					P.get().getter.free_func(P.get().getter.method_data); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 				if (P.get().setter.free_func) { | 
					
						
							| 
									
										
										
										
											2017-08-13 15:37:56 +07:00
										 |  |  | 					P.get().setter.free_func(P.get().setter.method_data); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// free method stuff
 | 
					
						
							|  |  |  | 			for (Map<StringName, NativeScriptDesc::Method>::Element *M = C->get().methods.front(); M; M = M->next()) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 				if (M->get().method.free_func) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 					M->get().method.free_func(M->get().method.method_data); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// free constructor/destructor
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			if (C->get().create_func.free_func) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 				C->get().create_func.free_func(C->get().create_func.method_data); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			if (C->get().destroy_func.free_func) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 				C->get().destroy_func.free_func(C->get().destroy_func.method_data); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-03-31 01:45:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		erase_and_unload.insert(lib_path, gdn); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 	for (Map<String, Ref<GDNative>>::Element *E = erase_and_unload.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2018-03-31 01:45:18 +02:00
										 |  |  | 		String lib_path = E->key(); | 
					
						
							|  |  |  | 		Ref<GDNative> gdn = E->get(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		library_classes.erase(lib_path); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (gdn.is_valid() && gdn->get_library().is_valid()) { | 
					
						
							|  |  |  | 			Ref<GDNativeLibrary> lib = gdn->get_library(); | 
					
						
							|  |  |  | 			void *terminate_fn; | 
					
						
							|  |  |  | 			Error err = gdn->get_symbol(lib->get_symbol_prefix() + _terminate_call_name, terminate_fn, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (err == OK) { | 
					
						
							|  |  |  | 				void (*terminate)(void *) = (void (*)(void *))terminate_fn; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				terminate((void *)&lib_path); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NativeScriptLanguage::NativeScriptLanguage() { | 
					
						
							|  |  |  | 	NativeScriptLanguage::singleton = this; | 
					
						
							| 
									
										
										
										
											2018-08-20 12:14:52 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-04 09:49:46 +02:00
										 |  |  | 	_init_call_type = "nativescript_init"; | 
					
						
							|  |  |  | 	_init_call_name = "nativescript_init"; | 
					
						
							|  |  |  | 	_terminate_call_name = "nativescript_terminate"; | 
					
						
							|  |  |  | 	_noarg_call_type = "nativescript_no_arg"; | 
					
						
							|  |  |  | 	_frame_call_name = "nativescript_frame"; | 
					
						
							|  |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 	_thread_enter_call_name = "nativescript_thread_enter"; | 
					
						
							|  |  |  | 	_thread_exit_call_name = "nativescript_thread_exit"; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NativeScriptLanguage::~NativeScriptLanguage() { | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 	for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { | 
					
						
							| 
									
										
										
										
											2019-03-09 18:01:08 +01:00
										 |  |  | 		Ref<GDNative> lib = L->get(); | 
					
						
							|  |  |  | 		// only shut down valid libs, duh!
 | 
					
						
							|  |  |  | 		if (lib.is_valid()) { | 
					
						
							|  |  |  | 			// If it's a singleton-library then the gdnative module
 | 
					
						
							|  |  |  | 			// manages the destruction at engine shutdown, not NativeScript.
 | 
					
						
							|  |  |  | 			if (!lib->get_library()->is_singleton()) { | 
					
						
							|  |  |  | 				lib->terminate(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-14 01:01:35 +01:00
										 |  |  | 	NSL->library_classes.clear(); | 
					
						
							|  |  |  | 	NSL->library_gdnatives.clear(); | 
					
						
							|  |  |  | 	NSL->library_script_users.clear(); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String NativeScriptLanguage::get_name() const { | 
					
						
							|  |  |  | 	return "NativeScript"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void _add_reload_node() { | 
					
						
							|  |  |  | #ifdef TOOLS_ENABLED
 | 
					
						
							|  |  |  | 	NativeReloadNode *rn = memnew(NativeReloadNode); | 
					
						
							|  |  |  | 	EditorNode::get_singleton()->add_child(rn); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::init() { | 
					
						
							|  |  |  | #if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	List<String> args = OS::get_singleton()->get_cmdline_args(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	List<String>::Element *E = args.find("--gdnative-generate-json-api"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (E && E->next()) { | 
					
						
							|  |  |  | 		if (generate_c_api(E->next()->get()) != OK) { | 
					
						
							|  |  |  | 			ERR_PRINT("Failed to generate C API\n"); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-04-22 10:24:04 +03:00
										 |  |  | 		Main::cleanup(true); | 
					
						
							| 
									
										
										
										
											2017-11-02 19:01:30 +01:00
										 |  |  | 		exit(0); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef TOOLS_ENABLED
 | 
					
						
							|  |  |  | 	EditorNode::add_init_callback(&_add_reload_node); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | String NativeScriptLanguage::get_type() const { | 
					
						
							|  |  |  | 	return "NativeScript"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | String NativeScriptLanguage::get_extension() const { | 
					
						
							|  |  |  | 	return "gdns"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | Error NativeScriptLanguage::execute_file(const String &p_path) { | 
					
						
							|  |  |  | 	return OK; // Qué?
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void NativeScriptLanguage::finish() { | 
					
						
							|  |  |  | 	_unload_stuff(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void NativeScriptLanguage::get_reserved_words(List<String> *p_words) const { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-11-12 17:08:07 +01:00
										 |  |  | bool NativeScriptLanguage::is_control_flow_keyword(String p_keyword) const { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | void NativeScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void NativeScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Ref<Script> NativeScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { | 
					
						
							|  |  |  | 	NativeScript *s = memnew(NativeScript); | 
					
						
							|  |  |  | 	s->set_class_name(p_class_name); | 
					
						
							|  |  |  | 	return Ref<NativeScript>(s); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | bool NativeScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { | 
					
						
							| 
									
										
										
										
											2018-01-18 16:00:38 +01:00
										 |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Script *NativeScriptLanguage::create_script() const { | 
					
						
							|  |  |  | 	NativeScript *script = memnew(NativeScript); | 
					
						
							|  |  |  | 	return script; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | bool NativeScriptLanguage::has_named_classes() const { | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-10-24 01:54:47 +02:00
										 |  |  | bool NativeScriptLanguage::supports_builtin_mode() const { | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | int NativeScriptLanguage::find_function(const String &p_function, const String &p_code) const { | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | String NativeScriptLanguage::make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const { | 
					
						
							|  |  |  | 	return ""; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void NativeScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void NativeScriptLanguage::add_global_constant(const StringName &p_variable, const Variant &p_value) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Debugging stuff here. Not used for now.
 | 
					
						
							|  |  |  | String NativeScriptLanguage::debug_get_error() const { | 
					
						
							|  |  |  | 	return ""; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | int NativeScriptLanguage::debug_get_stack_level_count() const { | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | int NativeScriptLanguage::debug_get_stack_level_line(int p_level) const { | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | String NativeScriptLanguage::debug_get_stack_level_function(int p_level) const { | 
					
						
							|  |  |  | 	return ""; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | String NativeScriptLanguage::debug_get_stack_level_source(int p_level) const { | 
					
						
							|  |  |  | 	return ""; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void NativeScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void NativeScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void NativeScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | String NativeScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { | 
					
						
							|  |  |  | 	return ""; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | // Debugging stuff end.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::reload_all_scripts() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void NativeScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const { | 
					
						
							|  |  |  | 	p_extensions->push_back("gdns"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | void NativeScriptLanguage::get_public_constants(List<Pair<String, Variant>> *p_constants) const { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::profiling_start() { | 
					
						
							| 
									
										
										
										
											2018-08-20 12:14:52 -03:00
										 |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 	MutexLock lock(mutex); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	profile_data.clear(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::profiling_stop() { | 
					
						
							| 
									
										
										
										
											2018-08-20 12:14:52 -03:00
										 |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 	MutexLock lock(mutex); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int NativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) { | 
					
						
							| 
									
										
										
										
											2018-08-20 12:14:52 -03:00
										 |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 	MutexLock lock(mutex); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	int current = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		if (current >= p_info_max) { | 
					
						
							| 
									
										
										
										
											2018-08-20 12:14:52 -03:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-20 12:14:52 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		p_info_arr[current].call_count = d->get().call_count; | 
					
						
							|  |  |  | 		p_info_arr[current].self_time = d->get().self_time; | 
					
						
							|  |  |  | 		p_info_arr[current].total_time = d->get().total_time; | 
					
						
							|  |  |  | 		p_info_arr[current].signature = d->get().signature; | 
					
						
							|  |  |  | 		current++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return current; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2017-08-08 18:02:45 -03:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2018-08-20 12:14:52 -03:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) { | 
					
						
							| 
									
										
										
										
											2018-08-20 12:14:52 -03:00
										 |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 	MutexLock lock(mutex); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	int current = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		if (current >= p_info_max) { | 
					
						
							| 
									
										
										
										
											2018-08-20 12:14:52 -03:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-20 12:14:52 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (d->get().last_frame_call_count) { | 
					
						
							|  |  |  | 			p_info_arr[current].call_count = d->get().last_frame_call_count; | 
					
						
							|  |  |  | 			p_info_arr[current].self_time = d->get().last_frame_self_time; | 
					
						
							|  |  |  | 			p_info_arr[current].total_time = d->get().last_frame_total_time; | 
					
						
							|  |  |  | 			p_info_arr[current].signature = d->get().signature; | 
					
						
							|  |  |  | 			current++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return current; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2017-08-08 18:02:45 -03:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2018-08-20 12:14:52 -03:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::profiling_add_data(StringName p_signature, uint64_t p_time) { | 
					
						
							|  |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 	MutexLock lock(mutex); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Map<StringName, ProfileData>::Element *d = profile_data.find(p_signature); | 
					
						
							|  |  |  | 	if (d) { | 
					
						
							|  |  |  | 		d->get().call_count += 1; | 
					
						
							|  |  |  | 		d->get().total_time += p_time; | 
					
						
							|  |  |  | 		d->get().frame_call_count += 1; | 
					
						
							|  |  |  | 		d->get().frame_total_time += p_time; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		ProfileData data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		data.signature = p_signature; | 
					
						
							|  |  |  | 		data.call_count = 1; | 
					
						
							|  |  |  | 		data.self_time = 0; | 
					
						
							|  |  |  | 		data.total_time = p_time; | 
					
						
							|  |  |  | 		data.frame_call_count = 1; | 
					
						
							|  |  |  | 		data.frame_self_time = 0; | 
					
						
							|  |  |  | 		data.frame_total_time = p_time; | 
					
						
							|  |  |  | 		data.last_frame_call_count = 0; | 
					
						
							|  |  |  | 		data.last_frame_self_time = 0; | 
					
						
							|  |  |  | 		data.last_frame_total_time = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		profile_data.insert(p_signature, data); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | int NativeScriptLanguage::register_binding_functions(godot_instance_binding_functions p_binding_functions) { | 
					
						
							|  |  |  | 	// find index
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int idx = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < binding_functions.size(); i++) { | 
					
						
							|  |  |  | 		if (!binding_functions[i].first) { | 
					
						
							|  |  |  | 			// free, we'll take it
 | 
					
						
							|  |  |  | 			idx = i; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (idx == -1) { | 
					
						
							|  |  |  | 		idx = binding_functions.size(); | 
					
						
							|  |  |  | 		binding_functions.resize(idx + 1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// set the functions
 | 
					
						
							| 
									
										
										
										
											2018-07-25 03:11:03 +02:00
										 |  |  | 	binding_functions.write[idx].first = true; | 
					
						
							|  |  |  | 	binding_functions.write[idx].second = p_binding_functions; | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return idx; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::unregister_binding_functions(int p_idx) { | 
					
						
							|  |  |  | 	ERR_FAIL_INDEX(p_idx, binding_functions.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (Set<Vector<void *> *>::Element *E = binding_instances.front(); E; E = E->next()) { | 
					
						
							|  |  |  | 		Vector<void *> &binding_data = *E->get(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		if (p_idx < binding_data.size() && binding_data[p_idx] && binding_functions[p_idx].second.free_instance_binding_data) { | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 			binding_functions[p_idx].second.free_instance_binding_data(binding_functions[p_idx].second.data, binding_data[p_idx]); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 03:11:03 +02:00
										 |  |  | 	binding_functions.write[p_idx].first = false; | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (binding_functions[p_idx].second.free_func) { | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 		binding_functions[p_idx].second.free_func(binding_functions[p_idx].second.data); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_object) { | 
					
						
							| 
									
										
										
										
											2021-05-04 16:00:45 +02:00
										 |  |  | 	ERR_FAIL_INDEX_V(p_idx, binding_functions.size(), nullptr); | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-04 16:00:45 +02:00
										 |  |  | 	ERR_FAIL_COND_V_MSG(!binding_functions[p_idx].first, nullptr, "Tried to get binding data for a nativescript binding that does not exist."); | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Vector<void *> *binding_data = (Vector<void *> *)p_object->get_script_instance_binding(lang_idx); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (!binding_data) { | 
					
						
							| 
									
										
										
										
											2021-05-04 16:00:45 +02:00
										 |  |  | 		return nullptr; // should never happen.
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (binding_data->size() <= p_idx) { | 
					
						
							|  |  |  | 		// okay, add new elements here.
 | 
					
						
							|  |  |  | 		int old_size = binding_data->size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		binding_data->resize(p_idx + 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int i = old_size; i <= p_idx; i++) { | 
					
						
							| 
									
										
										
										
											2018-07-25 03:11:03 +02:00
										 |  |  | 			(*binding_data).write[i] = NULL; | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(*binding_data)[p_idx]) { | 
					
						
							| 
									
										
										
										
											2019-05-18 07:54:16 +05:30
										 |  |  | 		const void *global_type_tag = get_global_type_tag(p_idx, p_object->get_class_name()); | 
					
						
							| 
									
										
										
										
											2018-04-04 21:32:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 		// no binding data yet, soooooo alloc new one \o/
 | 
					
						
							| 
									
										
										
										
											2018-07-25 03:11:03 +02:00
										 |  |  | 		(*binding_data).write[p_idx] = binding_functions[p_idx].second.alloc_instance_binding_data(binding_functions[p_idx].second.data, global_type_tag, (godot_object *)p_object); | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (*binding_data)[p_idx]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) { | 
					
						
							|  |  |  | 	Vector<void *> *binding_data = new Vector<void *>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	binding_data->resize(binding_functions.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < binding_functions.size(); i++) { | 
					
						
							| 
									
										
										
										
											2018-07-25 03:11:03 +02:00
										 |  |  | 		(*binding_data).write[i] = NULL; | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	binding_instances.insert(binding_data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (void *)binding_data; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::free_instance_binding_data(void *p_data) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (!p_data) { | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Vector<void *> &binding_data = *(Vector<void *> *)p_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < binding_data.size(); i++) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		if (!binding_data[i]) { | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-09 15:04:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (binding_functions[i].first && binding_functions[i].second.free_instance_binding_data) { | 
					
						
							|  |  |  | 			binding_functions[i].second.free_instance_binding_data(binding_functions[i].second.data, binding_data[i]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	binding_instances.erase(&binding_data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	delete &binding_data; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-30 19:55:04 +02:00
										 |  |  | void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_object) { | 
					
						
							|  |  |  | 	void *data = p_object->get_script_instance_binding(lang_idx); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (!data) { | 
					
						
							| 
									
										
										
										
											2018-08-30 19:55:04 +02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-30 19:55:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Vector<void *> &binding_data = *(Vector<void *> *)data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < binding_data.size(); i++) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		if (!binding_data[i]) { | 
					
						
							| 
									
										
										
										
											2018-08-30 19:55:04 +02:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-30 19:55:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		if (!binding_functions[i].first) { | 
					
						
							| 
									
										
										
										
											2018-08-30 19:55:04 +02:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-30 19:55:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (binding_functions[i].second.refcount_incremented_instance_binding) { | 
					
						
							|  |  |  | 			binding_functions[i].second.refcount_incremented_instance_binding(binding_data[i], p_object); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeScriptLanguage::refcount_decremented_instance_binding(Object *p_object) { | 
					
						
							|  |  |  | 	void *data = p_object->get_script_instance_binding(lang_idx); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (!data) { | 
					
						
							| 
									
										
										
										
											2018-08-30 19:55:04 +02:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-30 19:55:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Vector<void *> &binding_data = *(Vector<void *> *)data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool can_die = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < binding_data.size(); i++) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		if (!binding_data[i]) { | 
					
						
							| 
									
										
										
										
											2018-08-30 19:55:04 +02:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-30 19:55:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		if (!binding_functions[i].first) { | 
					
						
							| 
									
										
										
										
											2018-08-30 19:55:04 +02:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-30 19:55:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (binding_functions[i].second.refcount_decremented_instance_binding) { | 
					
						
							|  |  |  | 			can_die = can_die && binding_functions[i].second.refcount_decremented_instance_binding(binding_data[i], p_object); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return can_die; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 21:32:49 +02:00
										 |  |  | void NativeScriptLanguage::set_global_type_tag(int p_idx, StringName p_class_name, const void *p_type_tag) { | 
					
						
							|  |  |  | 	if (!global_type_tags.has(p_idx)) { | 
					
						
							|  |  |  | 		global_type_tags.insert(p_idx, HashMap<StringName, const void *>()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	HashMap<StringName, const void *> &tags = global_type_tags[p_idx]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tags.set(p_class_name, p_type_tag); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const void *NativeScriptLanguage::get_global_type_tag(int p_idx, StringName p_class_name) const { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (!global_type_tags.has(p_idx)) { | 
					
						
							| 
									
										
										
										
											2021-05-04 16:00:45 +02:00
										 |  |  | 		return nullptr; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-04 21:32:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	const HashMap<StringName, const void *> &tags = global_type_tags[p_idx]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (!tags.has(p_class_name)) { | 
					
						
							| 
									
										
										
										
											2021-05-04 16:00:45 +02:00
										 |  |  | 		return nullptr; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-05-18 07:54:16 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 21:32:49 +02:00
										 |  |  | 	const void *tag = tags.get(p_class_name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return tag; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | void NativeScriptLanguage::defer_init_library(Ref<GDNativeLibrary> lib, NativeScript *script) { | 
					
						
							|  |  |  | 	MutexLock lock(mutex); | 
					
						
							|  |  |  | 	libs_to_init.insert(lib); | 
					
						
							|  |  |  | 	scripts_to_register.insert(script); | 
					
						
							| 
									
										
										
										
											2021-01-31 13:34:42 +01:00
										 |  |  | 	has_objects_to_register.set(); | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { | 
					
						
							|  |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 	MutexLock lock(mutex); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	// See if this library was "registered" already.
 | 
					
						
							| 
									
										
										
										
											2017-11-02 17:14:37 +01:00
										 |  |  | 	const String &lib_path = lib->get_current_library_path(); | 
					
						
							| 
									
										
										
										
											2019-08-09 06:49:33 +02:00
										 |  |  | 	ERR_FAIL_COND_MSG(lib_path.length() == 0, lib->get_name() + " does not have a library for the current platform."); | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 	Map<String, Ref<GDNative>>::Element *E = library_gdnatives.find(lib_path); | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!E) { | 
					
						
							|  |  |  | 		Ref<GDNative> gdn; | 
					
						
							|  |  |  | 		gdn.instance(); | 
					
						
							|  |  |  | 		gdn->set_library(lib); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-02 19:01:30 +01:00
										 |  |  | 		// TODO check the return value?
 | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 		gdn->initialize(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		library_gdnatives.insert(lib_path, gdn); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		library_classes.insert(lib_path, Map<StringName, NativeScriptDesc>()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		if (!library_script_users.has(lib_path)) { | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 			library_script_users.insert(lib_path, Set<NativeScript *>()); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 15:42:10 +02:00
										 |  |  | 		void *proc_ptr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-02 17:14:37 +01:00
										 |  |  | 		Error err = gdn->get_symbol(lib->get_symbol_prefix() + _init_call_name, proc_ptr); | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-16 00:19:31 +02:00
										 |  |  | 		if (err != OK) { | 
					
						
							|  |  |  | 			ERR_PRINT(String("No " + _init_call_name + " in \"" + lib_path + "\" found").utf8().get_data()); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			((void (*)(godot_string *))proc_ptr)((godot_string *)&lib_path); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		// already initialized. Nice.
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::register_script(NativeScript *script) { | 
					
						
							|  |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 	MutexLock lock(mutex); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	library_script_users[script->lib_path].insert(script); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::unregister_script(NativeScript *script) { | 
					
						
							|  |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 	MutexLock lock(mutex); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 	Map<String, Set<NativeScript *>>::Element *S = library_script_users.find(script->lib_path); | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 	if (S) { | 
					
						
							|  |  |  | 		S->get().erase(script); | 
					
						
							|  |  |  | 		if (S->get().size() == 0) { | 
					
						
							|  |  |  | 			library_script_users.erase(S); | 
					
						
							| 
									
										
										
										
											2020-12-23 06:23:41 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 			Map<String, Ref<GDNative>>::Element *G = library_gdnatives.find(script->lib_path); | 
					
						
							| 
									
										
										
										
											2021-04-06 11:55:15 +10:00
										 |  |  | 			if (G && G->get()->get_library()->is_reloadable()) { | 
					
						
							|  |  |  | 				// ONLY if the library is marked as reloadable, and no more instances of its scripts exist do we unload the library
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// First remove meta data related to the library
 | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 				Map<String, Map<StringName, NativeScriptDesc>>::Element *L = library_classes.find(script->lib_path); | 
					
						
							| 
									
										
										
										
											2021-04-06 11:55:15 +10:00
										 |  |  | 				if (L) { | 
					
						
							|  |  |  | 					Map<StringName, NativeScriptDesc> classes = L->get(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					for (Map<StringName, NativeScriptDesc>::Element *C = classes.front(); C; C = C->next()) { | 
					
						
							|  |  |  | 						// free property stuff first
 | 
					
						
							|  |  |  | 						for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = C->get().properties.front(); P; P = P.next()) { | 
					
						
							|  |  |  | 							if (P.get().getter.free_func) { | 
					
						
							|  |  |  | 								P.get().getter.free_func(P.get().getter.method_data); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							if (P.get().setter.free_func) { | 
					
						
							|  |  |  | 								P.get().setter.free_func(P.get().setter.method_data); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2021-03-09 14:28:52 -08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 11:55:15 +10:00
										 |  |  | 						// free method stuff
 | 
					
						
							|  |  |  | 						for (Map<StringName, NativeScriptDesc::Method>::Element *M = C->get().methods.front(); M; M = M->next()) { | 
					
						
							|  |  |  | 							if (M->get().method.free_func) { | 
					
						
							|  |  |  | 								M->get().method.free_func(M->get().method.method_data); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2021-03-09 14:28:52 -08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 11:55:15 +10:00
										 |  |  | 						// free constructor/destructor
 | 
					
						
							|  |  |  | 						if (C->get().create_func.free_func) { | 
					
						
							|  |  |  | 							C->get().create_func.free_func(C->get().create_func.method_data); | 
					
						
							| 
									
										
										
										
											2021-03-09 14:28:52 -08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 11:55:15 +10:00
										 |  |  | 						if (C->get().destroy_func.free_func) { | 
					
						
							|  |  |  | 							C->get().destroy_func.free_func(C->get().destroy_func.method_data); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2021-03-09 14:28:52 -08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 11:55:15 +10:00
										 |  |  | 					library_classes.erase(script->lib_path); | 
					
						
							| 
									
										
										
										
											2021-03-09 14:28:52 -08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2021-04-04 15:53:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 11:55:15 +10:00
										 |  |  | 				// now unload the library
 | 
					
						
							| 
									
										
										
										
											2020-12-23 06:23:41 -08:00
										 |  |  | 				G->get()->terminate(); | 
					
						
							|  |  |  | 				library_gdnatives.erase(G); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 	scripts_to_register.erase(script); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-03 14:04:04 +07:00
										 |  |  | void NativeScriptLanguage::call_libraries_cb(const StringName &name) { | 
					
						
							|  |  |  | 	// library_gdnatives is modified only from the main thread, so it's safe not to use mutex here
 | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 	for (Map<String, Ref<GDNative>>::Element *L = library_gdnatives.front(); L; L = L->next()) { | 
					
						
							| 
									
										
										
										
											2018-01-18 12:04:34 +01:00
										 |  |  | 		if (L->get().is_null()) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 21:17:33 +07:00
										 |  |  | 		if (L->get()->is_initialized()) { | 
					
						
							| 
									
										
										
										
											2017-10-14 15:42:10 +02:00
										 |  |  | 			void *proc_ptr; | 
					
						
							| 
									
										
										
										
											2017-11-02 17:14:37 +01:00
										 |  |  | 			Error err = L->get()->get_symbol(L->get()->get_library()->get_symbol_prefix() + name, proc_ptr); | 
					
						
							| 
									
										
										
										
											2017-10-14 15:42:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 03:38:18 +02:00
										 |  |  | 			if (!err) { | 
					
						
							| 
									
										
										
										
											2017-10-14 15:42:10 +02:00
										 |  |  | 				((void (*)())proc_ptr)(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-08-04 21:17:33 +07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-08-03 14:04:04 +07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::frame() { | 
					
						
							| 
									
										
										
										
											2017-08-03 14:04:04 +07:00
										 |  |  | #ifndef NO_THREADS
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:34:42 +01:00
										 |  |  | 	if (has_objects_to_register.is_set()) { | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 		MutexLock lock(mutex); | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 		for (Set<Ref<GDNativeLibrary>>::Element *L = libs_to_init.front(); L; L = L->next()) { | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 			init_library(L->get()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		libs_to_init.clear(); | 
					
						
							|  |  |  | 		for (Set<NativeScript *>::Element *S = scripts_to_register.front(); S; S = S->next()) { | 
					
						
							|  |  |  | 			register_script(S->get()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		scripts_to_register.clear(); | 
					
						
							| 
									
										
										
										
											2021-01-31 13:34:42 +01:00
										 |  |  | 		has_objects_to_register.clear(); | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-03 14:04:04 +07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-08-20 12:14:52 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 		MutexLock lock(mutex); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) { | 
					
						
							|  |  |  | 			d->get().last_frame_call_count = d->get().frame_call_count; | 
					
						
							|  |  |  | 			d->get().last_frame_self_time = d->get().frame_self_time; | 
					
						
							|  |  |  | 			d->get().last_frame_total_time = d->get().frame_total_time; | 
					
						
							|  |  |  | 			d->get().frame_call_count = 0; | 
					
						
							|  |  |  | 			d->get().frame_self_time = 0; | 
					
						
							|  |  |  | 			d->get().frame_total_time = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-03 14:04:04 +07:00
										 |  |  | 	call_libraries_cb(_frame_call_name); | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-03 14:04:04 +07:00
										 |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | void NativeScriptLanguage::thread_enter() { | 
					
						
							| 
									
										
										
										
											2017-08-03 14:04:04 +07:00
										 |  |  | 	call_libraries_cb(_thread_enter_call_name); | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeScriptLanguage::thread_exit() { | 
					
						
							| 
									
										
										
										
											2017-08-03 14:04:04 +07:00
										 |  |  | 	call_libraries_cb(_thread_exit_call_name); | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // NO_THREADS
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-04 21:48:45 -05:00
										 |  |  | bool NativeScriptLanguage::handles_global_class_type(const String &p_type) const { | 
					
						
							|  |  |  | 	return p_type == "NativeScript"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String NativeScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const { | 
					
						
							| 
									
										
										
										
											2019-02-26 15:17:39 +01:00
										 |  |  | 	if (!p_path.empty()) { | 
					
						
							|  |  |  | 		Ref<NativeScript> script = ResourceLoader::load(p_path, "NativeScript"); | 
					
						
							|  |  |  | 		if (script.is_valid()) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			if (r_base_type) { | 
					
						
							| 
									
										
										
										
											2019-02-26 15:17:39 +01:00
										 |  |  | 				*r_base_type = script->get_instance_base_type(); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (r_icon_path) { | 
					
						
							| 
									
										
										
										
											2019-02-26 15:17:39 +01:00
										 |  |  | 				*r_icon_path = script->get_script_class_icon_path(); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-02-26 15:17:39 +01:00
										 |  |  | 			return script->get_script_class_name(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		if (r_base_type) { | 
					
						
							| 
									
										
										
										
											2019-02-26 15:17:39 +01:00
										 |  |  | 			*r_base_type = String(); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (r_icon_path) { | 
					
						
							| 
									
										
										
										
											2019-02-26 15:17:39 +01:00
										 |  |  | 			*r_icon_path = String(); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-04 21:48:45 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return String(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | void NativeReloadNode::_bind_methods() { | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_notification"), &NativeReloadNode::_notification); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeReloadNode::_notification(int p_what) { | 
					
						
							|  |  |  | #ifdef TOOLS_ENABLED
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (p_what) { | 
					
						
							|  |  |  | 		case MainLoop::NOTIFICATION_WM_FOCUS_OUT: { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			if (unloaded) { | 
					
						
							| 
									
										
										
										
											2017-07-25 18:18:36 +02:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 			MutexLock lock(NSL->mutex); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-01-06 21:10:01 +01:00
										 |  |  | 			NSL->_unload_stuff(true); | 
					
						
							| 
									
										
										
										
											2018-03-31 01:45:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 			for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { | 
					
						
							| 
									
										
										
										
											2018-01-06 12:31:30 +01:00
										 |  |  | 				Ref<GDNative> gdn = L->get(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-18 12:04:34 +01:00
										 |  |  | 				if (gdn.is_null()) { | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-09 18:01:08 +01:00
										 |  |  | 				// Don't unload what should not be reloaded!
 | 
					
						
							| 
									
										
										
										
											2018-01-06 12:31:30 +01:00
										 |  |  | 				if (!gdn->get_library()->is_reloadable()) { | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-09 18:01:08 +01:00
										 |  |  | 				// singleton libraries might have alive pointers living inside the
 | 
					
						
							|  |  |  | 				// editor. Also reloading a singleton library would mean that
 | 
					
						
							|  |  |  | 				// the singleton entry will not be called again, as this only
 | 
					
						
							|  |  |  | 				// happens at engine startup.
 | 
					
						
							|  |  |  | 				if (gdn->get_library()->is_singleton()) { | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-06 12:31:30 +01:00
										 |  |  | 				gdn->terminate(); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 18:18:36 +02:00
										 |  |  | 			unloaded = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case MainLoop::NOTIFICATION_WM_FOCUS_IN: { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			if (!unloaded) { | 
					
						
							| 
									
										
										
										
											2017-07-25 18:18:36 +02:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-07-26 15:58:12 +07:00
										 |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 			MutexLock lock(NSL->mutex); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			Set<StringName> libs_to_remove; | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 			for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { | 
					
						
							| 
									
										
										
										
											2018-01-06 12:31:30 +01:00
										 |  |  | 				Ref<GDNative> gdn = L->get(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-18 12:04:34 +01:00
										 |  |  | 				if (gdn.is_null()) { | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-06 12:31:30 +01:00
										 |  |  | 				if (!gdn->get_library()->is_reloadable()) { | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-09 18:01:08 +01:00
										 |  |  | 				// since singleton libraries are not unloaded there is no point
 | 
					
						
							|  |  |  | 				// in loading them again.
 | 
					
						
							| 
									
										
										
										
											2019-03-22 11:46:34 +01:00
										 |  |  | 				if (gdn->get_library()->is_singleton()) { | 
					
						
							| 
									
										
										
										
											2019-03-09 18:01:08 +01:00
										 |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-06 12:31:30 +01:00
										 |  |  | 				if (!gdn->initialize()) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 					libs_to_remove.insert(L->key()); | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				NSL->library_classes.insert(L->key(), Map<StringName, NativeScriptDesc>()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// here the library registers all the classes and stuff.
 | 
					
						
							| 
									
										
										
										
											2017-10-14 15:42:10 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				void *proc_ptr; | 
					
						
							| 
									
										
										
										
											2018-01-06 12:31:30 +01:00
										 |  |  | 				Error err = gdn->get_symbol(gdn->get_library()->get_symbol_prefix() + "nativescript_init", proc_ptr); | 
					
						
							| 
									
										
										
										
											2017-10-16 00:19:31 +02:00
										 |  |  | 				if (err != OK) { | 
					
						
							|  |  |  | 					ERR_PRINT(String("No godot_nativescript_init in \"" + L->key() + "\" found").utf8().get_data()); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					((void (*)(void *))proc_ptr)((void *)&L->key()); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-04 14:20:36 +02:00
										 |  |  | 				for (Map<String, Set<NativeScript *>>::Element *U = NSL->library_script_users.front(); U; U = U->next()) { | 
					
						
							| 
									
										
										
										
											2022-09-22 13:52:05 +03:00
										 |  |  | 					// Multiple GDNative libraries may be reloaded. The library and script
 | 
					
						
							|  |  |  | 					// path should match to prevent failing `NSL->library_classes` lookup
 | 
					
						
							|  |  |  | 					// from `get_script_desc()` in `script->_update_placeholder` below.
 | 
					
						
							| 
									
										
										
										
											2022-12-15 12:26:59 +01:00
										 |  |  | 					// This check also prevents "!script_data is true" error from occurring
 | 
					
						
							| 
									
										
										
										
											2022-09-22 13:52:05 +03:00
										 |  |  | 					// when e. g. re-focusing editor window.
 | 
					
						
							|  |  |  | 					if (L->key() != U->key()) { | 
					
						
							|  |  |  | 						continue; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 					for (Set<NativeScript *>::Element *S = U->get().front(); S; S = S->next()) { | 
					
						
							|  |  |  | 						NativeScript *script = S->get(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 						if (script->placeholders.size() == 0) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 							continue; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						for (Set<PlaceHolderScriptInstance *>::Element *P = script->placeholders.front(); P; P = P->next()) { | 
					
						
							|  |  |  | 							script->_update_placeholder(P->get()); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 18:18:36 +02:00
										 |  |  | 			unloaded = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 			for (Set<StringName>::Element *R = libs_to_remove.front(); R; R = R->next()) { | 
					
						
							|  |  |  | 				NSL->library_gdnatives.erase(R->get()); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		default: { | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-25 15:51:37 -04:00
										 |  |  | RES ResourceFormatLoaderNativeScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) { | 
					
						
							|  |  |  | 	return ResourceFormatLoaderText::singleton->load(p_path, p_original_path, r_error, p_no_subresource_cache); | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourceFormatLoaderNativeScript::get_recognized_extensions(List<String> *p_extensions) const { | 
					
						
							|  |  |  | 	p_extensions->push_back("gdns"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ResourceFormatLoaderNativeScript::handles_type(const String &p_type) const { | 
					
						
							|  |  |  | 	return (p_type == "Script" || p_type == "NativeScript"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String ResourceFormatLoaderNativeScript::get_resource_type(const String &p_path) const { | 
					
						
							|  |  |  | 	String el = p_path.get_extension().to_lower(); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	if (el == "gdns") { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		return "NativeScript"; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 	return ""; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Error ResourceFormatSaverNativeScript::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { | 
					
						
							|  |  |  | 	ResourceFormatSaverText rfst; | 
					
						
							|  |  |  | 	return rfst.save(p_path, p_resource, p_flags); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ResourceFormatSaverNativeScript::recognize(const RES &p_resource) const { | 
					
						
							| 
									
										
										
										
											2021-05-04 16:00:45 +02:00
										 |  |  | 	return Object::cast_to<NativeScript>(*p_resource) != nullptr; | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourceFormatSaverNativeScript::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 	if (Object::cast_to<NativeScript>(*p_resource)) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:44:14 +02:00
										 |  |  | 		p_extensions->push_back("gdns"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |