mirror of
https://github.com/etlegacy/wolfadmin.git
synced 2024-11-12 23:54:36 +00:00
Improved error handling of events
This commit is contained in:
parent
6d3197413a
commit
cd701f187b
1 changed files with 31 additions and 26 deletions
|
@ -15,9 +15,6 @@
|
|||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
local constants = wolfa_requireModule("util.constants")
|
||||
local util = wolfa_requireModule("util.util")
|
||||
|
||||
local events = {}
|
||||
|
||||
local data = {}
|
||||
|
@ -28,15 +25,23 @@ end
|
|||
|
||||
function events.add(name)
|
||||
if events.get(name) then
|
||||
error("event is already added: "..name)
|
||||
error("event is already added: "..name, 2)
|
||||
end
|
||||
|
||||
data[name] = {}
|
||||
end
|
||||
|
||||
function events.ishandled(name, func)
|
||||
function events.getHandlers(name)
|
||||
if not events.get(name) then
|
||||
error("event not added: "..name)
|
||||
error("event not added: "..name, 2)
|
||||
end
|
||||
|
||||
return events.get(name)
|
||||
end
|
||||
|
||||
function events.isHandled(name, func)
|
||||
if not events.get(name) then
|
||||
error("event not added: "..name, 2)
|
||||
end
|
||||
|
||||
local handlers = events.get(name)
|
||||
|
@ -52,11 +57,11 @@ end
|
|||
|
||||
function events.handle(name, func)
|
||||
if not events.get(name) then
|
||||
error("event not added: "..name)
|
||||
error("event not added: "..name, 2)
|
||||
end
|
||||
|
||||
if events.ishandled(name, func) then
|
||||
error("event "..name.." is already handled by this function")
|
||||
if events.isHandled(name, func) then
|
||||
error("event "..name.." is already handled by this function", 2)
|
||||
end
|
||||
|
||||
table.insert(data[name], func)
|
||||
|
@ -64,11 +69,11 @@ end
|
|||
|
||||
function events.unhandle(name, func)
|
||||
if not events.get(name) then
|
||||
error("event not added: "..name)
|
||||
error("event not added: "..name, 2)
|
||||
end
|
||||
|
||||
if not events.ishandled(name, func) then
|
||||
error("event "..name.." is not handled by this function")
|
||||
if not events.isHandled(name, func) then
|
||||
error("event "..name.." is not handled by this function", 2)
|
||||
end
|
||||
|
||||
local handlers = events.get(name)
|
||||
|
@ -84,7 +89,7 @@ function events.trigger(name, ...)
|
|||
local handlers = events.get(name)
|
||||
|
||||
if not handlers then
|
||||
error("event not added: "..name)
|
||||
error("event not added: "..name, 2)
|
||||
end
|
||||
|
||||
local returnValue
|
||||
|
|
Loading…
Reference in a new issue