Skip to content

Commit

Permalink
Small refactoring using varargs
Browse files Browse the repository at this point in the history
  • Loading branch information
tisztamo committed Jun 14, 2020
1 parent c2b1f3f commit 64f5c49
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.jl.cov
*.jl.mem
.DS_Store
.vscode/
/Manifest.toml
/dev/
/docs/build/
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
28 changes: 5 additions & 23 deletions src/Plugins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

2 comments on commit 64f5c49

@tisztamo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/16375

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.1 -m "<description of version>" 64f5c49cf25c27f153c1b6186e4692ad358e1224
git push origin v0.1.1

Please sign in to comment.