From 64f5c49cf25c27f153c1b6186e4692ad358e1224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scha=CC=88ffer=20Krisztia=CC=81n?= Date: Sun, 14 Jun 2020 20:56:19 +0200 Subject: [PATCH] Small refactoring using varargs --- .gitignore | 1 + Project.toml | 2 +- src/Plugins.jl | 28 +++++----------------------- 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 99e2cea..2a02107 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.jl.cov *.jl.mem .DS_Store +.vscode/ /Manifest.toml /dev/ /docs/build/ diff --git a/Project.toml b/Project.toml index 4416b2e..f318a6f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Plugins" uuid = "231a7ae5-8495-40ed-9891-ff920a14b9bd" authors = ["KrisztiƔn Schaffer"] -version = "0.1.0" +version = "0.1.1" [compat] julia = "1.3" diff --git a/src/Plugins.jl b/src/Plugins.jl index 7728f44..aa3382c 100644 --- a/src/Plugins.jl +++ b/src/Plugins.jl @@ -27,30 +27,14 @@ struct HookList{TNext, THandler, TPlugin, TFramework} framework::TFramework end -@inline function (hook::HookList)()::Bool - if hook.handler(hook.plugin, hook.framework) !== false - return hook.next() +@inline function (hook::HookList)(params...)::Bool + if hook.handler(hook.plugin, hook.framework, params...) !== false + return hook.next(params...) end return false end -@inline function (hook::HookList)(event)::Bool - if hook.handler(hook.plugin, hook.framework, event) !== false - return hook.next(event) - end - return false -end - -@inline function (hook::HookList)(p1, p2)::Bool - if hook.handler(hook.plugin, hook.framework, p1, p2) !== false - return hook.next(p1, p2) - end - return false -end - -(hook::HookList{Nothing, T, Nothing, Nothing})() where T = true -(hook::HookList{Nothing, T, Nothing, Nothing})(a) where T = true -(hook::HookList{Nothing, T, Nothing, Nothing})(p1, p2) where T = true +(hook::HookList{Nothing, T, Nothing, Nothing})(::Vararg{Any}) where T = true length(l::HookList{Nothing, T, Nothing, Nothing}) where T = 0 length(l::HookList) = 1 + length(l.next) @@ -64,9 +48,7 @@ function hooks(plugins::Array{TPlugins}, handler::THandler, framework::TFramewor return HookList(nothing, nothing, nothing, nothing) end plugin = plugins[1] - if length(methods(handler, (typeof(plugin), TFramework))) > 0 || - length(methods(handler, (typeof(plugin), TFramework, Any))) > 0 || - length(methods(handler, (typeof(plugin), TFramework, Any, Any))) > 0 + if length(methods(handler, (typeof(plugin), TFramework, Vararg{Any}))) > 0 return HookList(hooks(plugins[2:end], handler, framework), handler, plugin, framework) end return hooks(plugins[2:end], handler, framework)