How to update a precompiled Module's data from a second module?

33 views
Skip to first unread message

Philip Tellis

unread,
Sep 25, 2016, 12:18:32 AM9/25/16
to julia-users
I have two modules that are included by a julia program.  Let's call them Primary and External.

Primary contains a list of names in an array that's global to the module and a method to register new names:

module Primary

global names = AbstractString[]

function registerName(name::AbstractString)
    push!(names, name)
end

end

External needs to register a name into Primary, and does that in its initialization code:

module External

using Primary

Primary.registerName("external")

end

This works.  If I load both modules into my program or the REPL, Primary.names contains "external"

However, if I add __precompile__(true) to the top of Primary, this no longer works.  Primary.names is now always an empty array.  However, I can still call Primary.registerName from the REPL or my program and it works.

Is there any way for me to get Primary.registerName to work when called from a second module?

Philip Tellis

unread,
Sep 25, 2016, 12:31:40 AM9/25/16
to julia-users
Ok, just discovered that I should put my code from External into `__init__()` to get it to run at compile time
Reply all
Reply to author
Forward
0 new messages