LuaΒΆ
Guerilla uses the Lua 5.1 scripting language. You can find the documentation about the language and its basic libraries on the Lua Homepage. Here is a quick presentation of the language :
Types
-- *** nil
local a
-- Verify a is nil
assert (a == nil)
-- *** number
local a = 1
local b = math.floor (a + 0.5)
-- *** string
local a = "First "
-- Concatenation
local b = a .. "Name"
-- *** boolean
local a = true
local b = false
-- c is false, because is 12 is true
local c = not 12
-- *** table
local a = {}                -- Empty table
a[1] = "David"
a[2] = "Ben"
a[3] = "Antoine"
print (#a)                  -- Print the size (the last non-nil element) of the table, 3
table.insert (a, "Cyril")   -- Append a new element
local b = {}                -- Empty table
b["FirstName"] = "Cyril"
b.LastName = "Corvazier"    -- b.LastName is an alias for b["LastName"]
-- *** function
function sum (a, b)
    return a+b
end
Conditional
-- *** if
if a == b then
    print (a)
end
if a ~= b or not a < c then
    print (a)
elseif a == b then          -- Notice else and if are glued together!
    print (b)
end
-- nil and false are false, all other are true
if 0 then
    print ("Yes, O is true")     -- Beware of this one!
end
-- If object and object.Value are not nil, value gets object.Value else value gets ""
local value = object and object.Value or ""
Loop
-- *** for
-- Simple loop
for i=1,10 do
    print (i)
end
-- Iterate a table
for key,value in pairs (a_table) do
    assert (value == a_table[key])
end
-- While
while node do
    print (node.Name)
    node = node.Parent
end
Functions
-- Fun with functions
function compose (functionA, functionB)
    -- Craft a new function, the composition of functionA and functionB
    return function (x)
        return functionB (functionA (x))
    end
end
Methods
local a = { Value = 12 }
-- All these definition are equivalent: a:method () is syntaxical sugar for a.method (self)
a.method = function (self) print (self.Value) end
function a.method (self) print (self.Value) end
function a:method () print (self.Value) end
-- All these calls are equivalent: a:method () is syntaxical sugar for a.method (a)
a.method (a)
a:method ()