Skip to content

Commit 72ef922

Browse files
__precompile__ works now
1 parent a1cacb8 commit 72ef922

File tree

1 file changed

+50
-26
lines changed

1 file changed

+50
-26
lines changed

src/DocumentFunction.jl

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# __precompile__()
1+
__precompile__()
22

33
"""
44
MADS: Model Analysis & Decision Support in Julia (Mads.jl v1.0) 2017
@@ -34,15 +34,30 @@ function stdoutcaptureoff()
3434
return output
3535
end
3636

37+
"""
38+
Get function methods
39+
40+
Arguments:
41+
42+
- `f`: function to be documented
43+
44+
Return:
45+
46+
- array with function methods
47+
"""
48+
function getfunctionmethods(f::Function)
49+
m = methods(f)
50+
return convert(Array{String, 1}, strip.(split(string(m.mt), "\n"))[2:end])
51+
end
52+
3753
function documentfunction(f::Function; location::Bool=true, maintext::String="", argtext::Dict=Dict(), keytext::Dict=Dict())
3854
modulename = Base.function_module(f)
3955
stdoutcaptureon()
4056
if maintext != ""
4157
println("**$(f)**\n")
4258
println("$(maintext)\n")
4359
end
44-
m = methods(f)
45-
ms = convert(Array{String, 1}, strip.(split(string(m.mt), "\n"))[2:end])
60+
ms = getfunctionmethods(f)
4661
nm = length(ms)
4762
if nm == 0
4863
println("No methods\n")
@@ -91,9 +106,24 @@ function documentfunction(f::Function; location::Bool=true, maintext::String="",
91106
stdoutcaptureoff()
92107
end
93108

109+
@doc """
110+
Create function documentation
111+
112+
Arguments:
113+
114+
- `f`: function to be documented"
115+
116+
Keywords:
117+
118+
- `maintext`: function description
119+
- `argtext`: dictionary with text for each argument
120+
- `keytext`: dictionary with text for each keyword
121+
- `location`: show/hide function location on the disk
122+
""" documentfunction
123+
94124
function getfunctionarguments(f::Function)
95-
m = methods(f)
96-
getfunctionarguments(f, string.(collect(m.ms)))
125+
ms = getfunctionmethods(f)
126+
getfunctionarguments(f, ms)
97127
end
98128
function getfunctionarguments(f::Function, m::Vector{String})
99129
l = length(m)
@@ -115,9 +145,18 @@ function getfunctionarguments(f::Function, m::Vector{String})
115145
return sort(unique(mp))
116146
end
117147

148+
@doc """
149+
Get function arguments
150+
151+
Arguments:
152+
153+
- `f`: function to be documented"
154+
- `m`: function methods
155+
""" getfunctionarguments
156+
118157
function getfunctionkeywords(f::Function)
119-
m = methods(f)
120-
getfunctionkeywords(f, string.(collect(m.ms)))
158+
ms = getfunctionmethods(f)
159+
getfunctionkeywords(f, ms)
121160
end
122161
function getfunctionkeywords(f::Function, m::Vector{String})
123162
# getfunctionkeywords(f::Function) = methods(methods(f).mt.kwsorter).mt.defs.func.lambda_template.slotnames[4:end-4]
@@ -138,27 +177,12 @@ function getfunctionkeywords(f::Function, m::Vector{String})
138177
end
139178

140179
@doc """
141-
$(DocumentFunction.documentfunction(documentfunction;
142-
maintext="Create function documentation",
143-
argtext=Dict("f"=>"Function to be documented"),
144-
keytext=Dict("maintext"=>"Function description",
145-
"argtext"=>"Dictionary with text for each argument",
146-
"keytext"=>"Dictionary with text for each keyword",
147-
"location"=>"Boolean to show/hide function location on the disk")))
148-
""" documentfunction
180+
Get function keywords
149181
150-
@doc """
151-
$(DocumentFunction.documentfunction(getfunctionarguments;
152-
maintext="Get function arguments",
153-
argtext=Dict("f"=>"Function to be documented",
154-
"m"=>"Function methods")))
155-
""" getfunctionarguments
182+
Arguments:
156183
157-
@doc """
158-
$(DocumentFunction.documentfunction(getfunctionkeywords;
159-
maintext="Get function keywords",
160-
argtext=Dict("f"=>"Function to be documented",
161-
"m"=>"Function methods")))
184+
- `f`: function to be documented
185+
- `m`: function methods
162186
""" getfunctionkeywords
163187

164188
end

0 commit comments

Comments
 (0)