Import/Export
This page describes a new experimental feature added in CLEO 5. In order to use it, CLEO 5 must be installed.
For technical details and specification refer to Modules RFC.
CLEO 5 allows to share reusable code across multiple scripts and projects in a form of modules.
Modules are pre-compiled files that export functions. Scripts can import them by name and call as regular SCM functions. Modules act as libraries that can be developed independently from scripts consuming them.
Export
To create a module with an exported function, create a new CLEO script with one or multiple functions. To make the function visible outside of the module, add an export
keyword before function definition:
This is an example module with one exported function. Save it as my.txt
and compile to get a my.mod
file.
A module can export multiple functions
Some functions can remain private (not exported)
Modules should not have any code outside of functions.
Import
To use a module in a script, add an import
statement in your code:
Compile this script and run in game to see the result.
Syntax
function name should match the exported function name. Name is case insensitive.
module path should point to the module file relative to the current script.
To import multiple functions from the same module, list them on separate lines:
Imported functions are opaque, which means the compiler currently does not validate if it is called with the correct number of arguments. It is user responsibility to provide a correct number of arguments and also make sure there are enough variables to store the result, if the imported function returns any.
Loading functions code from a module occurs in runtime. A module file has to be distributed along with script that uses it. Modules can be updated independently from scripts; scripts recompilation is not required as long as the exported function retains its name.
Last updated