using Gee;
[CCode (has_target = false)]
delegate void MyDelegate();
int main() {
var map = new HashMap<string, MyDelegate>();
map["one"] = () => { stdout.printf("1\n"); };
map["two"] = () => { stdout.printf("2\n"); };
MyDelegate d = map["two"];
d();
return 0;
}
If you need a target in your delegate you have to write a wrapper, see this question:
Gee HashMap containing methods as values
As you can see, you don't need self invokation. Self invokation would look something like this:
int main() {
(() => { stdout.printf("Hello world!\n"); })();
return 0;
}
This is not supported by Vala (I tested this with valac-0.22).
Invoking a delegate var works as expected:
delegate void MyDelegate();
int main() {
MyDelegate d = () => { stdout.printf("Hello world!\n"); };
d();
return 0;
}