aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2010-06-14 18:14:25 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2010-06-14 18:14:25 -0400
commit2873c1499b1a88847b30ce93e8da3a8891754e3d (patch)
treec748c749857f4a660d32fd2b3592c3c323edf494 /core
parentffbbad57c26c69f3eb9ea4f698f7a2a8873afe4a (diff)
downloadtextadept-2873c1499b1a88847b30ce93e8da3a8891754e3d.tar.gz
textadept-2873c1499b1a88847b30ce93e8da3a8891754e3d.zip
Added events.disconnect() function; core/events.lua
Diffstat (limited to 'core')
-rw-r--r--core/events.lua15
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
---