Skip to content

Commit 20ff589

Browse files
committed
PROOF OF CONCEPT: a function to write extension functions with matching warning
1 parent fec0ec0 commit 20ff589

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

src/io.jl

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ WriteVTK.VTKCellType(::Type{<:Quadrilateral2D}) = VTKCellTypes.VTK_QUAD
77
WriteVTK.VTKCellType(::Type{<:Tetrahedron3D}) = VTKCellTypes.VTK_TETRA
88
WriteVTK.VTKCellType(::Type{<:Hexahedron3D}) = VTKCellTypes.VTK_HEXAHEDRON
99

10+
function prepare_extension_function(fname::Symbol,x)
11+
expr = quote
12+
function $fname($x;kwargs...)
13+
@info "single parameter function"
14+
end
15+
end
16+
eval(expr)
17+
end
18+
19+
function prepare_extension_function(fname::Symbol,weakdeps::Vector{Symbol},x::Symbol)
20+
expr = quote
21+
function $fname($x;kwargs...)
22+
if mapreduce(x->x in names(Main,imported=true),&,$weakdeps)
23+
@error "Extension was loaded but argument types are wrong"
24+
else
25+
@error "This specific function is part of an extension.\n"*
26+
"To use it install and load the following modules:"*
27+
mapreduce(x->"\n"*x,*,String.($weakdeps))
28+
end
29+
end
30+
end
31+
eval(expr)
32+
end
33+
1034
"""
1135
$(TYPEDSIGNATURES)
1236
@@ -162,19 +186,11 @@ function simplexgrid(file::String; format = "", kwargs...)
162186
end
163187

164188
function simplexgrid(file::String, ::Type{Val{:msh}}; kwargs...)
165-
return try
166-
simplexgrid_from_gmsh(file)
167-
catch e
168-
throw(ErrorException("Missing Gmsh extension. Add Gmsh.jl to your environment and import it to read msh files."))
169-
end
189+
return simplexgrid_from_gmsh(file)
170190
end
171191

172192
function simplexgrid(file::String, ::Type{Val{:geo}}; kwargs...)
173-
return try
174-
simplexgrid_from_gmsh(file)
175-
catch e
176-
throw(ErrorException("Missing Gmsh extension. Add Gmsh.jl to your environment and import it to read geo files."))
177-
end
193+
return simplexgrid_from_gmsh(file)
178194
end
179195

180196
function simplexgrid(file::String, ::Type{Val{:sg}}; kwargs...)
@@ -272,7 +288,10 @@ function simplexgrid(file::String, ::Type{Val{:sg}}; kwargs...)
272288
return g
273289
end
274290

275-
function simplexgrid_from_gmsh end
291+
prepare_extension_function(:simplexgrid_from_gmsh,[:Gmsh],:filename)
292+
# function simplexgrid_from_gmsh(filename; incomplete = false, Tc = Float32, Ti = Int32)
293+
# throw(ErrorException("Missing Gmsh extension. Add Gmsh.jl to your environment and import it to read msh or geo files."))
294+
# end
276295

277296
function simplexgrid_to_gmsh end
278297

0 commit comments

Comments
 (0)