Godot Version
Godot4.4
Question
I have written a persistent signal class called SignalEx, and the code is as follows:
class_name SignalEx
extends Nodevar persistent_signal_agvar: Dictionary = {}
signal click_btnfunc emitex(signname, agvs):
persistent_signal_agvar[signname] = agvs
emit_signal(signname, agvs)func connectex(signname, callable):
connect(signname, callable)
if persistent_signal_agvar.has(signname):
callable.callv(persistent_signal_agvar[signname])
However, I am currently facing an issue: Error emit_signal(signal: StringName, …) vararg. The parameters for emit_signal are of vararg type, and I am wondering how I can pass a similar parameter agvs into it.
For example, the current usage is as follows:
extends Control
func _ready() → void:
g_signalex.connectex(“click_btn”, foo)func _on_button_pressed() → void:
g_signalex.emitex(“click_btn”, [“abc”, “456”])func foo(s1, s2):
prints(“========foo”, s1, s2)
My current approach has another issue: if the callback function has no parameters, emit_ex cannot distinguish it
I would prefer the call to be written in the same way as the native signal: g_signalex.emitex(“click_btn”, “abc”, “456”) instead of the current way g_signalex.emitex(“click_btn”, [“abc”, “456”]).
I have seen some issues requesting support for vararg, but there hasn’t been any follow-up, such as: Add support for variadic functions (varargs) to GDScript · Issue #1034 · godotengine/godot-proposals · GitHub.
Do you have any good suggestions? Thank you very much!