aboutsummaryrefslogtreecommitdiffhomepage
path: root/core
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2020-02-24 09:04:39 -0500
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2020-02-24 09:04:39 -0500
commite0316d39489aa02c547fdf747aeca4c07735afba (patch)
tree13c8115aa493925173d2f9aff7ea5158153c90dd /core
parentc26b98733225c36ef21d0d3818979dcaa6197acd (diff)
Fixed skipping of next event handler after disconnecting the current one.
Also removed localization for undefined event name. It was confusing, and anyone connecting to or emitting events should be comfortable with the error message, as it's consistent with Lua's type error messages.
Diffstat (limited to 'core')
-rw-r--r--core/events.lua24
-rw-r--r--core/locale.conf5
-rw-r--r--core/locales/locale.ar.conf5
-rw-r--r--core/locales/locale.de.conf5
-rw-r--r--core/locales/locale.es.conf5
-rw-r--r--core/locales/locale.fr.conf5
-rw-r--r--core/locales/locale.it.conf5
-rw-r--r--core/locales/locale.pl.conf5
-rw-r--r--core/locales/locale.ru.conf5
-rw-r--r--core/locales/locale.sv.conf5
-rw-r--r--core/locales/locale.zh.conf5
11 files changed, 12 insertions, 62 deletions
diff --git a/core/events.lua b/core/events.lua
index 6857b7e7..34f90bf7 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -294,7 +294,10 @@ local M = {}
-- Emitted by [`buffer.zoom_in()`]() and [`buffer.zoom_out()`]().
module('events')]]
-local handlers = {}
+local handlers = setmetatable({}, {__index = function(t, k)
+ t[k] = {}
+ return t[k]
+end})
---
-- Adds function *f* to the set of event handlers for event *event* at position
@@ -308,9 +311,7 @@ local handlers = {}
-- @see disconnect
-- @name connect
function M.connect(event, f, index)
- -- Note: cannot assert() here since _L is undefined early in init process.
- if not event then error(_L['Undefined event name']) end
- if not handlers[event] then handlers[event] = {} end
+ assert(type(event) == 'string', 'string expected')
M.disconnect(event, f) -- in case it already exists
table.insert(handlers[event], index or #handlers[event] + 1, f)
end
@@ -322,7 +323,6 @@ end
-- @see connect
-- @name disconnect
function M.disconnect(event, f)
- if not handlers[event] then return end
for i = 1, #handlers[event] do
if handlers[event][i] == f then table.remove(handlers[event], i) break end
end
@@ -344,22 +344,22 @@ local error_emitted = false
-- @usage events.emit('my_event', 'my message')
-- @name emit
function M.emit(event, ...)
- assert(event, _L['Undefined event name'])
- local h = handlers[event]
- if not h then return end
- for i = 1, #h do
- if not h[i] then break end -- M.disconnect() for this event was called
- local ok, result = pcall(h[i], ...)
+ assert(type(event) == 'string', 'string expectd')
+ local i = 1
+ while i <= #handlers[event] do
+ local handler = handlers[event][i]
+ local ok, result = pcall(handler, ...)
if not ok then
if not error_emitted then
error_emitted = true
M.emit(events.ERROR, result)
error_emitted = false
else
- io.stderr:write(result)
+ io.stderr:write(result) -- prevent infinite loop
end
end
if type(result) == 'boolean' then return result end
+ if handlers[event][i] == handler then i = i + 1 end -- unless M.disconnect()
end
end
diff --git a/core/locale.conf b/core/locale.conf
index c38daf68..665915da 100644
--- a/core/locale.conf
+++ b/core/locale.conf
@@ -10,11 +10,6 @@
# along with that letter will activate (click) the button or menu item. You are
# free to use or omit these "_" mnemonics from your translations as you see fit.
-# [core/events.lua]
-# This error message is displayed if the user accidentally emits an event with
-# no name (e.g. mistypes the name of an existing event).
-Undefined event name = Undefined event name
-
# [core/file_io.lua]
# The title of dialogs prompting the user to open a file.
Open File = Open File
diff --git a/core/locales/locale.ar.conf b/core/locales/locale.ar.conf
index adf00156..e8a1b9fa 100644
--- a/core/locales/locale.ar.conf
+++ b/core/locales/locale.ar.conf
@@ -10,11 +10,6 @@
# along with that letter will activate (click) the button or menu item. You are
# free to use or omit these "_" mnemonics from your translations as you see fit.
-# [core/events.lua]
-# This error message is displayed if the user accidentally emits an event with
-# no name (e.g. mistypes the name of an existing event).
-Undefined event name = اسم حدث غير معرّف
-
# [core/file_io.lua]
# The title of dialogs prompting the user to open a file.
Open File = افتح
diff --git a/core/locales/locale.de.conf b/core/locales/locale.de.conf
index 8a08d6e8..050924a3 100644
--- a/core/locales/locale.de.conf
+++ b/core/locales/locale.de.conf
@@ -10,11 +10,6 @@
# along with that letter will activate (click) the button or menu item. You are
# free to use or omit these "_" mnemonics from your translations as you see fit.
-# [core/events.lua]
-# This error message is displayed if the user accidentally emits an event with
-# no name (e.g. mistypes the name of an existing event).
-Undefined event name = Undefinierter Eventname
-
# [core/file_io.lua]
# The title of dialogs prompting the user to open a file.
Open File = Öffnen
diff --git a/core/locales/locale.es.conf b/core/locales/locale.es.conf
index 33610d39..895a99c1 100644
--- a/core/locales/locale.es.conf
+++ b/core/locales/locale.es.conf
@@ -10,11 +10,6 @@
# along with that letter will activate (click) the button or menu item. You are
# free to use or omit these "_" mnemonics from your translations as you see fit.
-# [core/events.lua]
-# This error message is displayed if the user accidentally emits an event with
-# no name (e.g. mistypes the name of an existing event).
-Undefined event name = Nombre de evento sin definir
-
# [core/file_io.lua]
# The title of dialogs prompting the user to open a file.
Open File = Abrir
diff --git a/core/locales/locale.fr.conf b/core/locales/locale.fr.conf
index 1d3ace45..ae8e826b 100644
--- a/core/locales/locale.fr.conf
+++ b/core/locales/locale.fr.conf
@@ -11,11 +11,6 @@
# along with that letter will activate (click) the button or menu item. You are
# free to use or omit these "_" mnemonics from your translations as you see fit.
-# [core/events.lua]
-# This error message is displayed if the user accidentally emits an event with
-# no name (e.g. mistypes the name of an existing event).
-Undefined event name = Nom d’évènement inconnu
-
# [core/file_io.lua]
# The title of dialogs prompting the user to open a file.
Open File = Ouvrir
diff --git a/core/locales/locale.it.conf b/core/locales/locale.it.conf
index 0b10762c..dc14be61 100644
--- a/core/locales/locale.it.conf
+++ b/core/locales/locale.it.conf
@@ -10,11 +10,6 @@
# along with that letter will activate (click) the button or menu item. You are
# free to use or omit these "_" mnemonics from your translations as you see fit.
-# [core/events.lua]
-# This error message is displayed if the user accidentally emits an event with
-# no name (e.g. mistypes the name of an existing event).
-Undefined event name = Nome di evento indefinito
-
# [core/file_io.lua]
# The title of dialogs prompting the user to open a file.
Open File = Apri
diff --git a/core/locales/locale.pl.conf b/core/locales/locale.pl.conf
index 36155f99..f48bd677 100644
--- a/core/locales/locale.pl.conf
+++ b/core/locales/locale.pl.conf
@@ -11,11 +11,6 @@
# along with that letter will activate (click) the button or menu item. You are
# free to use or omit these "_" mnemonics from your translations as you see fit.
-# [core/events.lua]
-# This error message is displayed if the user accidentally emits an event with
-# no name (e.g. mistypes the name of an existing event).
-Undefined event name = Brak nazwy zdarzenia
-
# [core/file_io.lua]
# The title of dialogs prompting the user to open a file.
Open File = Otwórz
diff --git a/core/locales/locale.ru.conf b/core/locales/locale.ru.conf
index eff9878d..20218cee 100644
--- a/core/locales/locale.ru.conf
+++ b/core/locales/locale.ru.conf
@@ -10,11 +10,6 @@
# along with that letter will activate (click) the button or menu item. You are
# free to use or omit these "_" mnemonics from your translations as you see fit.
-# [core/events.lua]
-# This error message is displayed if the user accidentally emits an event with
-# no name (e.g. mistypes the name of an existing event).
-Undefined event name = Неизвестное название события
-
# [core/file_io.lua]
# The title of dialogs prompting the user to open a file.
Open File = Открыть
diff --git a/core/locales/locale.sv.conf b/core/locales/locale.sv.conf
index f8c93fa0..0d4b5d89 100644
--- a/core/locales/locale.sv.conf
+++ b/core/locales/locale.sv.conf
@@ -10,11 +10,6 @@
# along with that letter will activate (click) the button or menu item. You are
# free to use or omit these "_" mnemonics from your translations as you see fit.
-# [core/events.lua]
-# This error message is displayed if the user accidentally emits an event with
-# no name (e.g. mistypes the name of an existing event).
-Undefined event name = Odefinierat event-namn
-
# [core/file_io.lua]
# The title of dialogs prompting the user to open a file.
Open File = Öppna
diff --git a/core/locales/locale.zh.conf b/core/locales/locale.zh.conf
index 79215913..cd1f7ed0 100644
--- a/core/locales/locale.zh.conf
+++ b/core/locales/locale.zh.conf
@@ -10,11 +10,6 @@
# along with that letter will activate (click) the button or menu item. You are
# free to use or omit these "_" mnemonics from your translations as you see fit.
-# [core/events.lua]
-# This error message is displayed if the user accidentally emits an event with
-# no name (e.g. mistypes the name of an existing event).
-Undefined event name = 未定义的事件名称
-
# [core/file_io.lua]
# The title of dialogs prompting the user to open a file.
Open File = Open File