diff --git a/base/docs/basedocs.jl b/base/docs/basedocs.jl index fdac8e5715590..58b901903fbbb 100644 --- a/base/docs/basedocs.jl +++ b/base/docs/basedocs.jl @@ -100,6 +100,29 @@ end """ kw"module" +""" + __init__ + +`__init__()` function in your module would executes immediately *after* the module is loaded at +runtime for the first time (i.e., it is only called once and only after all statements in the +module have been executed). Because it is called *after* fully importing the module, `__init__` +functions of submodules will be executed *first*. Two typical uses of __init__ are calling +runtime initialization functions of external C libraries and initializing global constants +that involve pointers returned by external libraries. +See the [manual section about modules](@ref modules) for more details. + +# Examples +```julia +const foo_data_ptr = Ref{Ptr{Cvoid}}(0) +function __init__() + ccall((:foo_init, :libfoo), Cvoid, ()) + foo_data_ptr[] = ccall((:foo_data, :libfoo), Ptr{Cvoid}, ()) + nothing +end +``` +""" +kw"__init__" + """ baremodule