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.
As in almost all programming languages, Lua has numerous types of data, each of which is used for different purposes. Integration with Cortex Command has also expanded the number somewhat. These are as follows:
A Number in Lua is any variable of type Interger, Float, or Fixed.
A Vector in Cortex Command is an array with values X and Y, used to specify a position.
A String is any number of typed characters, enclosed in double or single quotes (" or ', respectively). Double quotes require more escaping than single quotes, the latter of which treat everything inside as escaped. This means that typing the following:
- print("She said "Hello," to me.");
...would probably not function correctly, whereas...
- print('She said "Hello," to me.');
Note that, alternately, one could simply escape the quotes, like this:
- print("She said \"Hello,\" to me.");
Some consider this a better habit than going out of one's way to use single quotes.
A boolean can have two values: true or false.
Lua has a general-purpose aggregate datatype called a table. Aggregate data types are used for storing collections (such as lists, sets, arrays, and associative arrays) containing other objects (including numbers, strings, or even other aggregates). Lua is a unique language in that tables are used for representing most all other aggregate types. More information can be found here.
In Lua, functions are assigned to variables, just like numbers and strings. Functions are created using the function keyword, as follows:
- function greet(name)
- if (not name) then name = "world"; end
- print("Hello, "..name.."!");
Essentially the same as null in other programming languages, nil is a special value which indicates no value - nothing. If a variable has the value nil then it has no value assigned to it, and therefore will no longer exist (or doesn't exist yet). Assigning a variable the value nil is functionally equivalent to deleting it.
As a side note, nil is considered false for the purposes of evaluation.
Userdata values are objects foreign to Lua, such as objects implemented in C. These typically come about when an object in a C library is exposed to Lua. An example of a userdata in Cortex Command value is an Activity.
To guarantee that the game data is not 'broken' or changed in an otherwise unfitting manner by Lua, Lua is largely incapable of modifying or even utilizing userdata on its own. Cortex Command augments Lua and allows it to use userdata to certain extents, but it still remains almost completely unable to modify it without using something (usually Cortex Command) as an interface.