< Previous | Contents | Next >
Lua
The Lua programming language is known for its efficiency, speed, and small memory footprint. Therefore it has been used widely in science and video games.
Fusion ships with Lua 5.1, with some additional libraries build in:
> IUP - for Graphical user interfaces (compare the chapter Graphical User Interfaces)
> bmd.scriptlib - A library with common Fusion related helper functions
Lua is a first class citizen in Fusion as it ships with the install. All preferences and compositions are stored in a Lua table. Fuses are written in Lua and Simple Expressions also consist of a subset of Lua. Additionally, Fusion uses the LuaJIT (JustInTime) flavour of Lua, which outperforms CPython. While in regular scripts this may not matter, it is one reason why Fuses can only be written in Lua.
For a complete reference of the language, see the Lua documentation at: http://www.lua.org/ manual/5.1/
Here is the difference of Lua and Python in a nutshell:
> Member properties are accessed with a dot . Methods are invoked with a colon:
print(comp:GetToolList(true))
print(comp.ActiveTool)
For example:
> Boolean types are lowercase in Lua (true, false)
> functions, loops and conditions etc. are closed with an end statement.
> Lua only knows one collection type called tuple. It can be used like a Python tuple, list, or dictionary.
> Fusion has a function buildin called dump() which can be seen as an extension to print(). It formats the output of tables to be more readable. In the console you may also start the line with == as short from for dump, e.g., ==comp:GetAttrs()