Directives are written using the @
syntax.
External documentation
Perhaps the most common directives are those associated with external documentation.
External documentation is appended to the functions at compile time when exporting to a library file. This means after the code is compiled, using the -h doc command on the compiled file and requesting the documentation by name will return the text that was allocated to that documentation:
@doc "MyFunction : This function returns true" @author "Jamie Balfour" @date "July 2020" function MyFunction () return true end function
The description must be quoted after the @doc
directive. This is available only as of version 1.4.1. Previous
versions use a different system.
This kind of documentation can be very useful if you are distributing your compiled code or planning to add it as a library.
Accessing it again is done with the -h ZAC applied on a compiled script.
zpe -h doc -f file.zex -s $function_name
Prior to version 1.4.1
In older versions of ZPE, internal documentation can be exported using @ commands within multiline comments.
/*@doc My function:This function returns true*/
The colon in the middle splits the documentation into two halves, one for the name (on the left) and one for the description (on the right).
When using the @ commands, the comment must use the multiline comment symbols /* and */.
The standard library (stdLib) contains examples of these directives.
@directive
The @directive
is a special compiler directive that tells
the YASS compiler to do something. It could be a simple thing such as telling it to do
something differently, or it could be to ignore something during compilation.
prevent_auto_include
The prevent_auto_include
directive is used to prevent a compiled program
having to include a file at the start which can potentially overwrite code within it.
@directive prevent_auto_include : true
requires_explicit_declaration
The requires_explicit_declaration
directive was added in ZPE 1.12.9 (Piper Pine Marten,
September 2024) and tells the compiler to throw an error
when it comes across a variable that has been defined previously. To define a variable
before use, you can use the string $x = ""
syntax and then from there on you may just refer to $x
.
@directive requires_explicit_declaration : true string $x = "" $x = "Hello world" //This will work print($x) $y = "Hello world" //This will not work print($y)