You may know the include statement from “C” or similar statements in almost all other programming languages. Well, ChaosPro also has such a statement: It’s called
import. It allows you to include content from another location. So code written by another one can be (re)used.
Due to performance reasons ChaosPro cannot allow such a general include statement as in C: There you can include huge files containing much functionality without having to worry about how long it takes to compile that huge file. Either your compiler can make use of precompiled header files to speed up compilation times or you don’t care about how long it actually takes to compile (one second more or less does not matter).
But in ChaosPro, where there’s real need for real time compiling this (unfortunately) does matter!
Due to this you need to write special library classes which then provide additional functionality. And you can include only those library classes.
The import statement is more similar to the technique of statically linked libraries in programming languages rather than an include statement: By importing a class ChaosPro will only “import” the functions from the class which are referenced. Exactly the same applies when you link your programs with static libraries: The linker in modern programming environments will only link the required routines to your program.
The general syntax for an import statement is as follows:
import <filename>.<classname> as <aliasname>;
Library classes cannot have own class local variables (due to the danger that they interfer with class local variables of the class in which they are to be included), they only can have functions (and function local variables) inside the class. These functions can be included without any further variables. Of course, the functions can have any number of parameters.
After having imported a class you can use a function by using <aliasname>.<function>(<param 1>,…,<param n>)