This example consists of a single file, LS/12.iss
This example demonstrates specialized atom
functions, and their use as commands.
Enter the command run lern/ls/12
to run the example.
When we refer to something as "atomic" in programming, it means that it is to be taken unbroken, as a whole.
For LavishScript in particular, atomic functions must complete immediately, without possibly waiting for the host game (or application) to prepare another frame for rendering. In fact, atomic functions in LavishScript are considered to be "blocking", and will prevent the host game from advancing until finished.
Specialized function
s in LavishScript called member
s, method
s, and atom
s are atomic.
The property of being atomic is what enables LavishScript to use these specialized functions for those specialized purposes.
That is in contrast to a regular function
, which may persist for any length of time, as the game continues normally.
An atom
is defined exactly like a function
, but with the atom
keyword, like so:
atom tight()
{
echo "Tight, bro"
}
The properties of an atom
make them ideal for use as commands in LavishScript.
The atom tight
defined in this example can be executed as if it were a command called tight
, like this:
function main()
{
tight
}
When a LavishScript script is ending, an atom called atexit
is executed, if provided.
This serves as an event handler, allowing the developer to destroy objects (such as GUI) and initiate other behaviors on behalf of the script before it completes shutting down.
- Create your own command using an
atom
. Try adding a parameter to theatom
, and pass a value to the command.