From cc15dfacd6ee5a28d8a058ce5439645071836c0b Mon Sep 17 00:00:00 2001 From: Sebastian Gutsche Date: Mon, 17 Jun 2019 17:19:23 +0200 Subject: [PATCH] Enable ? help for `GAP.Globals.FOO` --- pkg/GAPJulia/JuliaInterface/julia/libgap.jl | 19 ++++++++++++++++ src/GAP.jl | 1 + src/gap2.jl | 5 ----- src/help.jl | 25 +++++++++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 pkg/GAPJulia/JuliaInterface/julia/libgap.jl create mode 100644 src/help.jl diff --git a/pkg/GAPJulia/JuliaInterface/julia/libgap.jl b/pkg/GAPJulia/JuliaInterface/julia/libgap.jl new file mode 100644 index 00000000..436316d9 --- /dev/null +++ b/pkg/GAPJulia/JuliaInterface/julia/libgap.jl @@ -0,0 +1,19 @@ +# +# This is a very hacky prototype calling libgap from julia +# +# It is intended to be a low level interface to the C functions +# the higher level API can be found in gap.jl +# + +using Libdl + +import Base: length, convert + +const MPtr = Main.ForeignGAP.MPtr + + +include( "ccalls.jl" ) +include( "gap.jl" ) +include( "gap_to_julia.jl" ) +include( "julia_to_gap.jl" ) +include( "help.jl" ) diff --git a/src/GAP.jl b/src/GAP.jl index beb668fa..55a99421 100644 --- a/src/GAP.jl +++ b/src/GAP.jl @@ -129,5 +129,6 @@ include( "gap2.jl" ) include( "macros.jl" ) include( "gap_to_julia.jl" ) include( "julia_to_gap.jl" ) +include( "help.jl" ) end diff --git a/src/gap2.jl b/src/gap2.jl index b13dd61c..e6caf9bc 100644 --- a/src/gap2.jl +++ b/src/gap2.jl @@ -144,8 +144,3 @@ function Display(x::GapObj) error("variable was not correctly evaluated") end end - -function show_GAP_help( topic::String, onlyexact::Bool=false ) - print( GAP.gap_to_julia( GAP.Globals.HelpString( - GAP.julia_to_gap( topic ), onlyexact ) ) ) -end diff --git a/src/help.jl b/src/help.jl new file mode 100644 index 00000000..6d109c06 --- /dev/null +++ b/src/help.jl @@ -0,0 +1,25 @@ +function GAP_help_string(topic::String, onlyexact::Bool = false) + return GAP.gap_to_julia(GAP.Globals.HelpString(GAP.julia_to_gap(topic), onlyexact)) +end + +function show_GAP_help(topic::String, onlyexact::Bool = false) + print(GAP_help_string(topic, onlyexact)) +end + +import Base.Docs: Binding, getdoc, docstr + +## Create a helper type that gets returned by Binding +struct GAPHelpType + name::Symbol +end + +Base.Docs.Binding(x::GlobalsType, name::Symbol) = GAPHelpType(name) + +function Base.Docs.doc(x::GAPHelpType, typesig::Type = Union{}) + return Text(GAP_help_string(string(x.name))) +end + +## Set getdoc for GlobalsType to nothing, +## so it dispatches on the Binding. +Base.Docs.getdoc(x::GlobalsType) = nothing +Base.Docs.getdoc(x::GapObj) = Text(GAP_help_string(gap_to_julia(Globals.NameFunction(x))))