Lua Datatypes

From Data Realms Wiki

(Redirected from Vector)
Jump to: navigation, search
Lua Syntax Syntax
If you have no idea how to use Lua, start here.


Lua Datatypes Datatypes
Descriptions of the data types Lua uses.


List of all Lua functions Functions
Listing of known functions.


LuaDocs/Index 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:

Contents


Number

A Number in Lua is any variable of type Interger, Float, or Fixed.

Vector

A Vector in Cortex Command is an array with values X and Y, used to specify a position.

String

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:

  1. print("She said "Hello," to me.");

...would probably not function correctly, whereas...

  1. print('She said "Hello," to me.');

...would.

Note that, alternately, one could simply escape the quotes, like this:

  1. print("She said \"Hello,\" to me.");

Some consider this a better habit than going out of one's way to use single quotes.

Boolean

A boolean can have two values: true or false.

Table

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.

Function

In Lua, functions are assigned to variables, just like numbers and strings. Functions are created using the function keyword, as follows:

  1. function greet(name)
  2.         if (not name) then name = "world"; end
  3.  
  4.         print("Hello, "..name.."!");
  5. end

"nil"

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

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.

Personal tools