Skip to content

Latest commit

 

History

History
46 lines (32 loc) · 1.9 KB

12.md

File metadata and controls

46 lines (32 loc) · 1.9 KB

LERN/LS/12

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.

Atomicity in LavishScript

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 functions in LavishScript called members, methods, and atoms 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.

Defining an atom

An atom is defined exactly like a function, but with the atom keyword, like so:

atom tight()
{
    echo "Tight, bro"
}

Using an atom as a command

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
}

The atexit atom

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.

Exercises

  1. Create your own command using an atom. Try adding a parameter to the atom, and pass a value to the command.