Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/trixi_include.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ function trixi_include(elixir::AbstractString; kwargs...)
trixi_include(Main, elixir; kwargs...)
end

"""
@trixi_include(elixir::AbstractString; kwargs...)

This is a convenience macro for [`trixi_include`](@ref) that evaluates the
`trixi_include` function in the global scope of the current module.
It is equivalent to calling `trixi_include` with the current module as the first argument.
"""
macro trixi_include(elixir, kwargs...)
foreach(kwargs) do kwarg
if !(kwarg isa Expr && kwarg.head === :(=))
throw(ArgumentError("`@trixi_include` only accepts keyword arguments, got: $kwarg"))
end
kwarg.head = :kw
end
esc(quote
$trixi_include($__module__, $(elixir); $(kwargs...))
end)
end

"""
trixi_include_changeprecision(T, [mod::Module=Main,] elixir::AbstractString; kwargs...)

Expand Down
4 changes: 4 additions & 0 deletions test/trixi_include.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
@trixi_test_nowarn trixi_include(path, x = 11)
@test Main.x == 11

# Verify that the macro version uses the right module
@trixi_include(path, x = 3)
@test x == 3

@test_throws "assignment `y` not found in expression" trixi_include(@__MODULE__,
path,
y = 3)
Expand Down
Loading