示例#1
0
bool NativeScript::is_tool() const {
	NativeScriptDesc *script_data = get_script_desc();

	if (script_data)
		return script_data->is_tool;

	return false;
}
示例#2
0
StringName NativeScript::get_instance_base_type() const {
	NativeScriptDesc *script_data = get_script_desc();

	if (!script_data)
		return "";

	return script_data->base_native_type;
}
示例#3
0
bool NativeScript::has_script_signal(const StringName &p_signal) const {
	NativeScriptDesc *script_data = get_script_desc();

	while (script_data) {
		if (script_data->signals_.has(p_signal))
			return true;
		script_data = script_data->base_data;
	}
	return false;
}
示例#4
0
String NativeScript::get_class_documentation() const {
	NativeScriptDesc *script_data = get_script_desc();

	if (!script_data) {
		ERR_EXPLAIN("Attempt to get class documentation on invalid NativeScript");
		ERR_FAIL_V("");
	}

	return script_data->documentation;
}
示例#5
0
Ref<Script> NativeScript::get_base_script() const {
	NativeScriptDesc *script_data = get_script_desc();

	if (!script_data)
		return Ref<Script>();

	Ref<NativeScript> ns = Ref<NativeScript>(NSL->create_script());
	ns->set_class_name(script_data->base);
	ns->set_library(get_library());
	return ns;
}
示例#6
0
bool NativeScript::can_instance() const {

	NativeScriptDesc *script_data = get_script_desc();

#ifdef TOOLS_ENABLED

	return script_data || (!is_tool() && !ScriptServer::is_scripting_enabled());
#else
	return script_data;
#endif
}
示例#7
0
bool NativeScript::has_method(const StringName &p_method) const {
	NativeScriptDesc *script_data = get_script_desc();

	while (script_data) {
		if (script_data->methods.has(p_method))
			return true;

		script_data = script_data->base_data;
	}
	return false;
}
示例#8
0
ScriptInstance *NativeScript::instance_create(Object *p_this) {

	NativeScriptDesc *script_data = get_script_desc();

	if (!script_data) {
		return NULL;
	}

#ifdef TOOLS_ENABLED
	if (!ScriptServer::is_scripting_enabled() && !is_tool()) {
		// placeholder for nodes. For tools we want the rool thing.

		PlaceHolderScriptInstance *sins = memnew(PlaceHolderScriptInstance(NSL, Ref<Script>(this), p_this));
		placeholders.insert(sins);

		if (script_data->create_func.create_func) {
			script_data->create_func.create_func(
					(godot_object *)p_this,
					script_data->create_func.method_data);
		}

		_update_placeholder(sins);

		return sins;
	}
#endif

	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

#ifndef NO_THREADS
	owners_lock->lock();
#endif

	instance_owners.insert(p_this);

#ifndef NO_THREADS
	owners_lock->unlock();
#endif

	return nsi;
}
示例#9
0
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;
	Object *owner = NULL;

	if (!(script_data->base_native_type == "")) {
		owner = ClassDB::instance(script_data->base_native_type);
	} else {
		owner = memnew(Reference);
	}

	if (!owner) {
		r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL;
		return Variant();
	}

	Reference *r = Object::cast_to<Reference>(owner);
	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;
	}
}
示例#10
0
Ref<Script> NativeScript::get_base_script() const {
	NativeScriptDesc *script_data = get_script_desc();

	if (!script_data)
		return Ref<Script>();

	NativeScript *script = (NativeScript *)NSL->create_script();
	Ref<NativeScript> ns = Ref<NativeScript>(script);
	ERR_FAIL_COND_V(!ns.is_valid(), Ref<Script>());

	ns->set_class_name(script_data->base);
	ns->set_library(get_library());
	return ns;
}
示例#11
0
bool NativeScript::get_property_default_value(const StringName &p_property, Variant &r_value) const {
	NativeScriptDesc *script_data = get_script_desc();

	OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P;
	while (!P && script_data) {
		P = script_data->properties.find(p_property);
		script_data = script_data->base_data;
	}
	if (!P)
		return false;

	r_value = P.get().default_value;
	return true;
}
示例#12
0
void NativeScript::_update_placeholder(PlaceHolderScriptInstance *p_placeholder) {
	NativeScriptDesc *script_data = get_script_desc();

	ERR_FAIL_COND(!script_data);

	List<PropertyInfo> info;
	get_script_property_list(&info);
	Map<StringName, Variant> values;
	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;
	}

	p_placeholder->update(info, values);
}
示例#13
0
MethodInfo NativeScript::get_method_info(const StringName &p_method) const {
	NativeScriptDesc *script_data = get_script_desc();

	if (!script_data)
		return MethodInfo();

	while (script_data) {
		Map<StringName, NativeScriptDesc::Method>::Element *M = script_data->methods.find(p_method);

		if (M)
			return M->get().info;

		script_data = script_data->base_data;
	}
	return MethodInfo();
}
示例#14
0
void NativeScript::get_script_property_list(List<PropertyInfo> *p_list) const {
	NativeScriptDesc *script_data = get_script_desc();

	Set<StringName> existing_properties;
	List<PropertyInfo>::Element *original_back = p_list->back();
	while (script_data) {
		List<PropertyInfo>::Element *insert_position = original_back;

		for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) {
			if (!existing_properties.has(E.key())) {
				insert_position = p_list->insert_after(insert_position, E.get().info);
				existing_properties.insert(E.key());
			}
		}
		script_data = script_data->base_data;
	}
}
示例#15
0
void NativeScript::get_script_method_list(List<MethodInfo> *p_list) const {
	NativeScriptDesc *script_data = get_script_desc();

	if (!script_data)
		return;

	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());
	}
}
示例#16
0
void NativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
	NativeScriptDesc *script_data = get_script_desc();

	if (!script_data)
		return;

	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());
	}
}
示例#17
0
String NativeScript::get_method_documentation(const StringName &p_method) const {
	NativeScriptDesc *script_data = get_script_desc();

	if (!script_data) {
		ERR_EXPLAIN("Attempt to get method documentation on invalid NativeScript");
		ERR_FAIL_V("");
	}

	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;
	}

	ERR_EXPLAIN("Attempt to get method documentation for non-existent method");
	ERR_FAIL_V("");
}
示例#18
0
String NativeScript::get_signal_documentation(const StringName &p_signal_name) const {
	NativeScriptDesc *script_data = get_script_desc();

	if (!script_data) {
		ERR_EXPLAIN("Attempt to get signal documentation on invalid NativeScript");
		ERR_FAIL_V("");
	}

	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;
	}

	ERR_EXPLAIN("Attempt to get signal documentation for non-existent signal");
	ERR_FAIL_V("");
}
示例#19
0
String NativeScript::get_property_documentation(const StringName &p_path) const {
	NativeScriptDesc *script_data = get_script_desc();

	if (!script_data) {
		ERR_EXPLAIN("Attempt to get property documentation on invalid NativeScript");
		ERR_FAIL_V("");
	}

	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;
	}

	ERR_EXPLAIN("Attempt to get property documentation for non-existent signal");
	ERR_FAIL_V("");
}