LavishScript:Atoms
Contents
Background
LavishScript is an iterative, single-entry language (as opposed to event-based). This means that script functions cannot be executed from outside of a script, and that scripts are designed such that all commands are executed in a very specific order. Execution of commands that were not a part of the original script must therefore be done at a designated point in the script, via a command queue.
The LavishScript Engine allowing multiple scripts to run at once adds the additional problem of context switching. A context switch occurs when the engine determines that a script's execution time is up for a given frame, and allows the next script to perform its duties. Between this and "wait" commands, no two consecutive lines of a script are guaranteed to execute in the same frame. This means that scripts and script functions can only be executed asynchronously.
Enter the Atom
An atom in LavishScript is a complete function that is guaranteed to execute to completion immediately. This makes them atomic, meaning they are not broken down, whereas a function is not atomic and is broken down. Commands that could be completed on a successive frame (such as call, wait, waitframe, executequeued, and so on) are not allowed within an atom, and no context switching will occur during atom execution. An atom is not required to be associated with a script, but may be.
Because atoms are effectively synchronous, they can fill many gaps:
- Callback functions
- Embedded scripts (LavishGUI)
- Function hooks implemented completely within scripts (Inner Space)
- Smarter hotkeys or key "binds" (Inner Space)
- Synchronous Text "Triggers"
Creating Atoms
Atoms can be defined as part of script syntax, or through the AddAtom command.
Executing Atoms
Atoms can be executed via the ExecuteAtom command or by using the atom as a command.
Deleting Atoms
Atoms can be removed via DeleteAtom.