Skip to content

Commit c2b2127

Browse files
authored
Merge pull request #84 from JuliaIO/teh/stackoverflow2
An alternative solution to the "missing method" problem
2 parents 3cf464e + 2125090 commit c2b2127

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/loadsave.jl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function load{F}(q::Formatted{F}, args...; options...)
7979
for library in libraries
8080
try
8181
Library = checked_import(library)
82-
if !isdefined(Library, :load) || Library.load == FileIO.load
82+
if !has_method_from(methods(Library.load), Library)
8383
throw(LoaderError(string(library), "load not defined"))
8484
end
8585
return Library.load(q, args...; options...)
@@ -96,7 +96,7 @@ function save{F}(q::Formatted{F}, data...; options...)
9696
for library in libraries
9797
try
9898
Library = checked_import(library)
99-
if !isdefined(Library, :save) || Library.save == FileIO.save
99+
if !has_method_from(methods(Library.save), Library)
100100
throw(WriterError(string(library), "save not defined"))
101101
end
102102
return Library.save(q, data...; options...)
@@ -106,3 +106,18 @@ function save{F}(q::Formatted{F}, data...; options...)
106106
end
107107
handle_exceptions(failures, "saving \"$(filename(q))\"")
108108
end
109+
110+
function has_method_from(mt, Library)
111+
for m in mt
112+
if getmodule(m) == Library
113+
return true
114+
end
115+
end
116+
false
117+
end
118+
119+
if VERSION < v"0.5.0-dev+3543"
120+
getmodule(m) = m.func.code.module
121+
else
122+
getmodule(m) = m.module
123+
end

0 commit comments

Comments
 (0)