Example #1
0
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;
			result = E->get().method.method((godot_object *)owner,
					E->get().method.method_data,
					userdata,
					p_argcount,
					(godot_variant **)p_args);
			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();
}
Example #2
0
Variant GDNative::call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments) {

	Map<StringName, native_call_cb>::Element *E = GDNativeCallRegistry::singleton->native_calls.find(p_native_call_type);
	if (!E) {
		ERR_PRINT((String("No handler for native call type \"" + p_native_call_type) + "\" found").utf8().get_data());
		return Variant();
	}

	void *procedure_handle;

	Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
			native_handle,
			p_procedure_name,
			procedure_handle);

	if (err != OK || procedure_handle == NULL) {
		return Variant();
	}

	godot_variant result = E->get()(procedure_handle, (godot_array *)&p_arguments);

	Variant res = *(Variant *)&result;
	godot_variant_destroy(&result);
	return res;
}
Example #3
0
bool NativeScriptInstance::set(const StringName &p_name, const Variant &p_value) {
	NativeScriptDesc *script_data = GET_SCRIPT_DESC();

	while (script_data) {
		OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = script_data->properties.find(p_name);
		if (P) {
			P.get().setter.set_func((godot_object *)owner,
					P.get().setter.method_data,
					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 };

			godot_variant result;
			result = E->get().method.method((godot_object *)owner,
					E->get().method.method_data,
					userdata,
					2,
					(godot_variant **)args);
			bool handled = *(Variant *)&result;
			godot_variant_destroy(&result);
			if (handled) {
				return true;
			}
		}

		script_data = script_data->base_data;
	}
	return false;
}
Example #4
0
void NativeScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
	script->get_script_property_list(p_properties);

	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,
					NULL);
			Variant res = *(Variant *)&result;
			godot_variant_destroy(&result);

			if (res.get_type() != Variant::ARRAY) {
				ERR_EXPLAIN("_get_property_list must return an array of dictionaries");
				ERR_FAIL();
			}

			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;
}
Example #5
0
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);
	}
}
Example #6
0
bool NativeScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
	NativeScriptDesc *script_data = GET_SCRIPT_DESC();

	while (script_data) {
		OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = script_data->properties.find(p_name);
		if (P) {
			godot_variant value;
			value = P.get().getter.get_func((godot_object *)owner,
					P.get().getter.method_data,
					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);
			if (r_ret.get_type() == Variant::NIL) {
				return false;
			}
			return true;
		}

		script_data = script_data->base_data;
	}
	return false;
}
Example #7
0
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;
	}
}