I was trying out IRC and found out that it still uses the old Bind event API:
base.Bind(SqIrcEvent.Connect, this, this.OnConnected);
I would've expected something like this:
base.On.Connected.Connect(this.OnConnected, this);
The signals and slots event system is bound to the main plugin. However, you can easily convert it to the new implementation via script:
class MyIRC extends SqIRC.Session
{
On = null; // DO NOT MAKE THE TABLE HERE BECAUSE IT'LL BE SHARED AMONG ALL INSTANCES OF THIS CLASS!
function constructor()
{
// Our table of signals
this.On = {
Connected = SqSignal();
}
// Construct the actual IRC session instance
base.constructor();
// Setup event forwarding so that the signal instance receives the event and forwards it to the connected functions/slots
// Use the signal instance as the environment and call the emit function with it
base.Bind(SqIrcEvent.Connect, this.On.Connected, SqSignal.Emit);
// Now use the signals as you would normally use them
this.On.Connected.Connect(function(event, origin, params) {
print("some guy connected");
});
}
}
IRC <- MyIRC();
/*
IRC.On.Connected.Connect(function(event, origin, params) {
print("some guy connected");
});
*/
It's just a matter of receiving from one end and forwarding to another.