Re-export variable define in __init__ of submodule with precompilation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re-export variable define in __init__ of submodule with precompilation

Simon Byrne
How can I reexport a variable defined in the  __init__ method of a submodule, to play nice with precompilation.

The following gives me a "WARNING: could not import Foo.bar into TestExport":

__precompile__()
module TestExport
    export bar

    module Foo
        export bar

        function __init__()
            global const bar = 1
        end
    end

    import .Foo.bar
end # module

it works if I replace "import .Foo.bar" with "using .Foo", but I don't want to import all the submodules exported symbols into the module.

Any ideas?

-Simon

Reply | Threaded
Open this post in threaded view
|

Re: Re-export variable define in __init__ of submodule with precompilation

Yichao Yu
On Fri, Nov 4, 2016 at 12:30 PM, Simon Byrne <[hidden email]> wrote:

> How can I reexport a variable defined in the  __init__ method of a
> submodule, to play nice with precompilation.
>
> The following gives me a "WARNING: could not import Foo.bar into
> TestExport":
>
> __precompile__()
> module TestExport
>     export bar
>
>     module Foo
>         export bar
>
>         function __init__()
>             global const bar = 1

Don't do this. This isn't really precompile compatible.
If it is a runtime value,use something like a global const `Ref{Int}`
and mutate that in the `__init__` function instead.

>         end
>     end
>
>     import .Foo.bar
> end # module
>
> it works if I replace "import .Foo.bar" with "using .Foo", but I don't want
> to import all the submodules exported symbols into the module.
>
> Any ideas?
>
> -Simon
>