Created
June 7, 2019 17:48
-
-
Save howmanysmall/a419221ff06916ea2513a1bc6297a506 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local running = coroutine.running | |
local yield = coroutine.yield | |
local function BindableEvent() | |
local self = { } | |
local Length = 0 | |
local function Methods(Call, ...) | |
if Call == 0 then | |
for Index = 1, Length do | |
local Thread = coroutine.create(self[Index]) | |
coroutine.resume(Thread, ...) | |
end | |
elseif Call == 1 then | |
local Thread = running() | |
local function Yield(...) | |
Methods(3, Yield) | |
coroutine.resume(Thread, ...) | |
end | |
Length = Length + 1 | |
self[Length] = Yield | |
return yield() | |
elseif Call == 2 then | |
Length = Length + 1 | |
self[Length] = (...) | |
elseif Call == 3 then | |
for Index = 1, Length do | |
if (...) == self[Index] then | |
self[Index] = self[Length] | |
self[Length] = nil | |
Length = Length - 1 | |
break | |
end | |
end | |
else | |
for Index = 1, Length do | |
self[Index] = nil | |
end | |
Length = 0 | |
end | |
end | |
return Methods | |
end | |
return BindableEvent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local BindableEvent = { } | |
BindableEvent.__index = BindableEvent | |
BindableEvent.ClassName = "BindableEvent" | |
local setmetatable = setmetatable | |
local running = coroutine.running | |
function BindableEvent.new() | |
return setmetatable({ }, BindableEvent) | |
end | |
function BindableEvent:Fire(...) | |
for Index = 1, #self do | |
local Thread = coroutine.create(self[Index]) | |
coroutine.resume(Thread, ...) | |
end | |
end | |
function BindableEvent:Wait() | |
local Thread = running() | |
local function Yield(...) | |
self:Disconnect(Yield) | |
coroutine.resume(Thread, ...) | |
end | |
self[#self + 1] = Yield | |
return coroutine.yield() | |
end | |
function BindableEvent:Connect(Function) | |
self[#self + 1] = Function | |
end | |
function BindableEvent:Disconnect(Function) | |
local Size = #self | |
for Index = 1, Size do | |
if Function == self[Index] then | |
self[Index] = self[Size] | |
self[Size] = nil | |
break | |
end | |
end | |
end | |
function BindableEvent:Destroy() | |
for Index = 1, #self do | |
self[Index] = nil | |
end | |
end | |
return BindableEvent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment