Skip to content

Commit

Permalink
LoadpackageAndExposeGlobals
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasguts committed May 5, 2019
1 parent 5a5f478 commit 55f9556
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pkg/GAPJulia/JuliaInterface/julia/gap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,46 @@ macro gap(str)
end

export @gap

function LoadPackageAndExposeGlobals(package::String, mod::String; all_globals::Bool = false)
mod_sym = Symbol(mod)
Base.MainInclude.eval(:(
module $(mod_sym)
import GAP
end
))
mod_mod = Base.MainInclude.eval(:(Main.$(mod_sym)))
Base.invokelatest(LoadPackageAndExposeGlobals,package,mod_mod; all_globals=all_globals)
end

function LoadPackageAndExposeGlobals(package::String, mod::Module = Main; all_globals::Bool = false )
if mod == Main
eval_func = Base.MainInclude.eval
else
eval_func = mod.eval
end
current_gvar_list = EvalString("ShallowCopy(NamesGVars())")
load_package = EvalString("LoadPackage(\"$package\")")
if load_package == Globals.fail
error("cannot load package $package")
end
new_gvar_list = nothing
if all_globals
new_gvar_list = Globals.NamesGVars()
else
new_gvar_list = Globals.Difference(Globals.NamesGVars(),current_gvar_list)
end
new_gvar_list_translated = gap_to_julia(Array{String,1},new_gvar_list)
for i_string in new_gvar_list_translated
try
i = Symbol(i_string)
eval_func(:(
$(i)=GAP.Globals.$(i)
))
catch
end
end
end

export LoadPackageAndExposeGlobals

0 comments on commit 55f9556

Please sign in to comment.