From bigfug
Jump to: navigation, search

Lua is a lightweight, cross-platform scripting language that is widely used in the commercial gaming industry because of its speed and portability.

Fugio supports creating custom nodes using Lua within the editor itself.

https://en.wikipedia.org/wiki/Lua_(programming_language)

Video Tutorial

Fugio Tutorial 5 introduces Lua scripting

Installing Lua on Linux

Fugio Lua hasn't been tested on Linux yet, but should compile fine with changes to the Lua.pro file

Using Lua

Fugio's Lua plugin supplies one node, that begins with a single input called Source: the Lua source code that it will run.

You can use the Nodes:Text Editor node to edit the source code with error reporting and syntax highlighting.

Script Structure

The structure of a Lua script in Fugio follows this form:

-- Include the Fugio Lua library, which is built-in
 
fugio = require "fugio"

-- Code here will get called once, during initialisation

Message = "Hello, World!"

-- The main function is optional, but gets called whenever an input pin is updated
  
function main()
    -- Write the message to Fugio's Logger window

    fugio.log( Message )
end

Inputs and Outputs

You can add any number of input and output pins to a Lua node to pass data to and from your Lua script.

Adding an input pin

  1. Right-click or Ctrl-click on the node and choose "Add Input Pin..."
  2. Enter a name for the pin.

The pin name must be unique and only contain letters and numbers (it can't start with a number or use spaces, or any punctuation characters)

Accessing an input pin

fugio = require "fugio"

-- We have added an input pin called "Message" which takes a string.
-- PinMessage points to the pin itself - NOT the actual message

PinMessage = fugio.input( "Message" )

-- The main function is optional, but gets called whenever an input pin is updated
  
function main()
    -- Get the actual message from the message pin

    local Message = PinMessage:get()

    -- Write the message to Fugio's Logger window

    fugio.log( Message )
end

Adding an output pin

  1. Right-click or Ctrl-click on the node and choose "Add Output Pin..."
  2. Enter a name for the pin.
  3. Choose the type of pin you want to add

The pin name must be unique and only contain letters and numbers (it can't start with a number or use spaces, or any punctuation characters)

Unlike input pins, output pins hold the data inside them, which is why you need to choose what kind of pin you're adding

Accessing an output pin

fugio = require "fugio"

-- We have added an output pin that is a float - a floating point number
-- PinFloat points to the pin itself - NOT the actual float

PinFloat = fugio.output( "Float" )

function main()
    -- Just set the output value to PI

    PinFloat:set( math.pi )
end

Lua Reference

Learn more about coding in Lua at https://www.lua.org/start.html