Values and types

Lua is a dynamically typed language. This means that variables do not have types; only values do. There are no type definitions in the language. All values carry their own type.

All values in Lua are first-class values. This means that all values can be stored in variables, passed as arguments to other functions, and returned as results.

There are six basic types in nzLua: null, boolean, number, string, function, and table.

Null is the type of the value null, whose main property is to be different from any other value; it usually represents the absence of a useful value. The Lua parser has been extended for nzLua so that the keyword null is equivalent to the standard Lua keyword nil. Unlike a NULL value in SQL, null (and nil) does equal itself, therefore null == null returns true.

Boolean is the type of the values false and true. Both null and false make a condition false; any other value makes it true.

Number represents real (double-precision floating-point) numbers.

String represents arrays of characters. Lua is 8-bit clean: strings can contain any 8-bit character,including embedded zeros ('\0').

The type table implements associative arrays, that is, arrays that can be indexed not only with numbers, but with any value (except null). Tables can be heterogeneous; that is, they can contain values of all types (except null). Tables are the sole data structuring mechanism in Lua; they can be used to represent ordinary arrays, symbol tables, sets, records, graphs, trees, etc. To represent

records, Lua uses the field name as an index. The language supports this representation by providing as syntactic sugar fora["name"]. There are several convenient ways to create tables in Lua.

Like indices, the value of a table field can be of any type (except null). In particular, because functions are first-class values, table fields can contain functions. Thus tables can also carry methods.

Tables and functions values are objects: variables do not actually contain these values, only references to them. Assignment, parameter passing, and function returns always manipulate references to such values; these operations do not imply any kind of copy.