Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to perform initializations of GAP objects in Julia packages? #296

Closed
ThomasBreuer opened this issue Oct 17, 2019 · 1 comment
Closed

Comments

@ThomasBreuer
Copy link
Member

Consider the following file MyPackage.jl.

module MyPackage

using GAP

GAP.Globals.LoadPackage( GAP.julia_to_gap( "ctbllib" ) ) # or any other package

g = GAP.Globals.SymmetricGroup( 3 ) # pointer to a global variable that will be needed

function deal_with_g()
    return GAP.Globals.Size( g )
end

end # module

If one creates a proper Julia package from this (with dependency on GAP.jl listed in Project.toml) then the first using MyPackage will create a .ji file for MyPackage.
Leave Julia, start Julia anew, and call using MyPackage.
Now GAP is running, the Julia variable MyPackage.g exists, but the GAP object to which it shall point has not been created.
Analogously, GAP claims that the GAP package in question has not been loaded.
This is because the statements in MyPackage.jl are not executed w.r.t. the GAP that has been started now but w.r.t. the GAP that was used at compile time.

What is an elegant workaround for this situation?
I think it is quite common to have initializations of this kind.

@ThomasBreuer
Copy link
Member Author

The answer is to use a __init__ function in the module,
see the documentation on Module initialization and precompilation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant