Skip to content

Import#

Introduction#

Monkey2 includes a simple build system that converts monkey2 files to C++, compiles the C++ code, and links the resultant object files.

The build system allows you to import *.monkey2 files and several types of non-monkey2 files into a project for compilation and/or linking. This is done using a system import directive:

#Import "<system_file>"

...or a local import directive:

#Import "local_file"

Import directives can appear any where in a monkey2 source file, but it's generally tidiest if they are placed at the top of the file.

System Imports#

System files are files that are generally provided with the compiler toolset, and that the compiler and/or linker are configured to find automatically.
Monkey2 recognizes the following system file types:

System file type suffix System file type
.monkey2 Monkey2 module.
.o, .obj, .a, .lib Static library.
.so, .dll, .dylib Dynamic library.
.framework MacOS framework.
.h, .hh, .hpp C/C++/Objective C header.

Note that system file names are enclosed by < and > characters, while local file names are not.

An example of importing a system library:

#Import "<wsock32.a>"

If no extension is provided for a system import, Monkey2 will assume you are importing a monkey2 module, eg:

#Import "<std>"

This will import the monkey2 'std' module. This is effectively the same as:

#Import "<std.monkey2>"

Local Imports#

Local files are files that are located relative to the monkey2 file that imports them.

Monkey2 recognizes the following local file types:

Local file type suffix Local file type
.monkey2 Monkey2 source code.
.o, .obj Object file.
.a, .lib Static library.
.so, .dll, .dylib Dynamic library.
.framework MacOS framework.
.exe Windows executable.
.c, .cc, .cxx, .cpp, .m, .mm C/C++/Objective C source code.
.h, .hh, .hpp C/C++/Objective C header.

When importing *.monkey2 files, the file extension can be omited:

#Import "player" ' imports player.monkey2

Import include directories#

It is also possible to add local 'include directories', 'library directories' and 'framework directories' with import. This is done using syntax similar to a local import, but replacing the filename with a wildcard.

For example, to add an include directory:

#Import "include_directory/*.h"

This will allow you to import any header file inside 'include_directory' using...

#Import "<include_file>"

...without having to specify the full path of the file.

To add a library directory:

#Import "staticlib_directory/*.a"

To add a macOS framework directory:

#Import "framework_directory/*.framework"

Importing Assets#

#Import is also used for importing assets like images, sound files, etc.

See the topic about Assets for detailed informations.