[Bug] The IRC module still uses the old event API

EK.IceFlake

  • Hero Member
  • "We are the champions my fellahs" - Sufyan/VK.SuFy
  • Posts: 1,761
[Bug] The IRC module still uses the old event API
« on June 13th, 2017, 09:33 AM »
I was trying out IRC and found out that it still uses the old Bind event API:
Code: [Select]
base.Bind(SqIrcEvent.Connect, this, this.OnConnected);
I would've expected something like this:
Code: [Select]
base.On.Connected.Connect(this.OnConnected, this);

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,804
[Bug] Re: The IRC module still uses the old event API
« Reply #1, on June 13th, 2017, 01:05 PM »Last edited on June 13th, 2017, 05:10 PM
The signals and slots event system is bound to the main plugin. However, you can easily convert it to the new implementation via script:
Code: [Select]
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.
.