diff options
author | 2010-06-14 18:14:25 -0400 | |
---|---|---|
committer | 2010-06-14 18:14:25 -0400 | |
commit | 2873c1499b1a88847b30ce93e8da3a8891754e3d (patch) | |
tree | c748c749857f4a660d32fd2b3592c3c323edf494 /core/events.lua | |
parent | ffbbad57c26c69f3eb9ea4f698f7a2a8873afe4a (diff) | |
download | textadept-2873c1499b1a88847b30ce93e8da3a8891754e3d.tar.gz textadept-2873c1499b1a88847b30ce93e8da3a8891754e3d.zip |
Added events.disconnect() function; core/events.lua
Diffstat (limited to 'core/events.lua')
-rw-r--r-- | core/events.lua | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/core/events.lua b/core/events.lua index d80857f6..3313d919 100644 --- a/core/events.lua +++ b/core/events.lua @@ -151,6 +151,8 @@ local events = events -- anywhere. -- @param f The Lua function to add. -- @param index Optional index to insert the handler into. +-- @return Index of handler. +-- @see disconnect function connect(event, f, index) local plural = event..'s' if not events[plural] then events[plural] = {} end @@ -160,6 +162,19 @@ function connect(event, f, index) else handlers[#handlers + 1] = f end + return index or #handlers +end + +--- +-- Disconnects a handler function from an event. +-- @param event The string event name. +-- @param index Index of the handler (returned by events.connect). +-- @see connect +function disconnect(event, index) + local plural = event..'s' + if not events[plural] then return end + local handlers = events[plural] + table.remove(handlers, index) end --- |