From Data Realms Wiki
| Syntax |
If you have no idea how to use Lua, start here.
| Datatypes |
Descriptions of the data types Lua uses.
| Functions |
Listing of known functions.
| Official Reference |
Raw output generated directly from Data's source.
Here's a little crash-course in Lua syntax, as it pertains to Cortex Command.
A variable stores a value. The value can be any of a few datatypes. Here are examples to assign variables x, y, and z number, boolean, and string values respectively:
- x = 21 --Integer
- y = true --Boolean
- z = "Cortex" --String
In programming, comments are parts of code that are completely ignored by the reading program. In Lua, this is accomplished with the use of two hyphens right next to each other: "--"
- --This is a proper comment.
- function() --Comments can also be placed after a statement.
- --[[Or this format can be used
- to make a block comment,
- which can span multiple lines.
Variables of any datatype can be manipulated in a variety of ways. We will explain the methods of computing, comparing, and assigning variable values.
The math operators are common math signs:
Assignment & Math
These operators are shorthand; they first add the inputs, and then assign the result to the first.
- x = 1 --x is 1
- x = x + 1 --x is 2
- x += 1 --shorthand form; x is 3
These operators are usually used with control structures and return a boolean value.
|==||is equal to|
|~=||is not equal to|
|>=||is greater or equal|
|<=||is less or equal|
|>||is greater than|
|<||is less than|
- x = 5 --assignment
- x == 5 --true
- x ~= 5 --false
One of the simplest logical constructions, the first statement is evaluated as a boolean. Equality operators are useful to this effect. If the first statement is true the statement after then is executed.
- x = 1
- if x == 1 then y = 1 end
- x = true
- if x then y = true end
A for loop is, simply put, a block of code that's executed multiple times.
- x = 0
- for i = 1, 10 do
- x = x + 1
A while loop runs indefinitely, or while a condition is met.
- x = 1
- while x < 5 do -- "while x is lesser than five, do"
- x = x + 1 -- once x is greater than five, the while loop will cease to execute until x is lesser than five again
A Lua function is a set of instructions invoked as a group by name with the syntax:
In Lua, the trailing parenthesis are not necessary for control structures such as if or for, but may be useful to maintain logical flow while reading code. If in doubt, parenthesize. Another important facet of functions is their return value. A function can be used in the stead of a datatype as long as its return value is of that datatype.
You may have wondered at the term "member function," but this is simply a function that is organized into a group of functions and variables which in Cortex Command are the Manager objects. Proper syntax for accessing member functions in Lua: