DLang Notes and Examples
← prev | next →     Top-level ToC     /modules-and-packages.html     (printable version)

1 General Notes

One file == one module. File scope == module scope.

In foo.bar.baz, baz is the module name. baz is in the bar package, which is in the foo package. Packages group modules.

import foo.bar.baz; <–> foo/bar/baz.d

Module names are usually named all lowercase.

The module name is the filename, unless you make it otherwise.

2 Using Modules

import foo.bar;            // You get all public symbols in bar.d.
import foo.bar : baz;      // You only get bar.d's `baz`.
import baz = foo.bar.baz;  // `baz` is an alias for `foo.bar.baz`.

3 Your own modules

cd ~/dev
mkdir my-proj
cd my-proj
dub init
mkdir source/mypkg
edit source/mypkg/foo.d
# In source/mypkg/foo.d, add `module mypkg.foo` to the top
geany source/app.d
# add `import mypkg.foo` and use functions from it.
dub # run your app