From 200a448fef9c0df5e19f764ad3ba8e053f29a184 Mon Sep 17 00:00:00 2001 From: Moelf Date: Sun, 5 May 2019 14:17:48 -0700 Subject: [PATCH 1/3] REPL docs for __init__ --- base/docs/basedocs.jl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/base/docs/basedocs.jl b/base/docs/basedocs.jl index fdac8e5715590..893fb9964c2ce 100644 --- a/base/docs/basedocs.jl +++ b/base/docs/basedocs.jl @@ -100,6 +100,30 @@ 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 From a3b80dbea5f6555056265fddb2628b351699ad68 Mon Sep 17 00:00:00 2001 From: Moelf Date: Sun, 5 May 2019 19:14:16 -0700 Subject: [PATCH 2/3] REPL docs for __init__ --- base/docs/basedocs.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/docs/basedocs.jl b/base/docs/basedocs.jl index 893fb9964c2ce..4fde8c3c9ce85 100644 --- a/base/docs/basedocs.jl +++ b/base/docs/basedocs.jl @@ -104,7 +104,7 @@ kw"module" """ __init__ -`__init_()` function in your module would executes immediately *after* the module is loaded at +`__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 From 5d64f71068ffd7661d7756daad2b992997e314a5 Mon Sep 17 00:00:00 2001 From: Moelf Date: Mon, 13 May 2019 15:51:11 -0700 Subject: [PATCH 3/3] Reformat --- base/docs/basedocs.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/base/docs/basedocs.jl b/base/docs/basedocs.jl index 4fde8c3c9ce85..58b901903fbbb 100644 --- a/base/docs/basedocs.jl +++ b/base/docs/basedocs.jl @@ -100,8 +100,7 @@ end """ kw"module" - - """ +""" __init__ `__init__()` function in your module would executes immediately *after* the module is loaded at