Modules
Modules are precompiled libraries of functions, globals, consts and user defined types for use by applications and other modules.
Creating modules
Modules live in the 'mod' directory within the main BlitzMax directory. To create your own module, you must add a new subdirectory to 'mod' with the following format:
mod/ModuleScope.mod/ModuleName.mod
ModuleScope should be a unique name (for example, the name of your organization or company) and is used to group together modules provided by a common source.
You will also need to create a main module source file inside the module directory. This file must have the same name as ModuleName:
mod/ModuleScope.mod/ModuleName.mod/ModuleName.bmx
Finally, your source file must include a Module statement at the top:
Module ModuleScope.ModuleName
Once your module is setup, BMK can be used to build it:
bmk makemods ModuleScope.ModuleName
Or, to build all of your own modules:
bmk makemods ModuleScope
Using modules within modules
To use a module within another module, you must import it with the Import command:
Import ModuleScope.ModuleName
Import is recursive - it will automatically import any modules imported by the module your are importing. Cyclic imports are illegal.
Using modules within applications
By default, BlitzMax imports every module it finds in the 'mod' directory when compiling applications. However, this can result in bulky executables. You can override this default behaviour by using the Framework command:
Framework ModuleScope.ModuleName
Framework should appear at the top of your main application source file.
Specifying an application framework prevents BlitzMax from importing every module under the sun. Only the framework module and any explicit Import modules are imported into your application.
For example, to create a 'stripped down' BASIC application, you can use the BRL.Basic framework. For example:
Framework BRL.Basic 'create a stripped down app
Print "Hello World!"
When a building a multifile application, the framework (if any) found in the main source file is automatically passed to all 'child' files in the application.