Roblox Wiki
Advertisement
Roblox Wiki

A data type is a set of possible values which an expression such as a function or a variable can take. Primitive types provide these set of values while composite types derive from primitive types.

There are two sets of data types used by the engine's Lua API: types provided by Lua and types provided by the engine. There are a few C++ types such as void which are sometimes referenced by the engine's API reference. The Lua built-in type function determines a Lua type while the Roblox built-in function typeof also includes Roblox types. There are internal types, which themselves are not exposed in Lua and cannot be accessed.

In the context of variables, data types can be either value types or reference types. Also, variables do not have types, the values do. Luau allows gradual typing where variables can be given types.

Certain data types, such as a table, can be converted to a JSON string through HttpService light iconHttpService dark iconHttpService:JSONEncode. However, data types that are not table, string, number or boolean are converted into the JSON "null" type, while nil is ignored. In the case of composite types, composite values may be serialized (converted into discrete values of primitive types like numbers) first. For example, a CFrame object can be converted into 12 individual components represented as numbers. Tables that can be treated as arrays will be converted into JSON arrays (ordered list), otherwise JSON objects (key-value pairs) where number keys are converted into strings.

Types by category[]

Value/reference type[]

Values of most data types can be stored via variables. Depending on the data type the value of which is being stored, it may be either a value type (set of values, one of which the variable directly contains) or a reference type (where a value, usually of a composite data type, is referenced by the variable rather than being contained, and the reference is the value being contained). Value types include nil, boolean, number, string and vector. Reference types include function, table, thread and userdata.

Internal types[]

Because the engine is built in C++, there are internal types which include C++ types and some Roblox types (e.g. Tuple and Variant). Internal types themselves are not exposed in Lua and cannot be accessed. In members, the API converts these types into the usable Lua types and vice versa. For example, a value of any C++ number type is converted into a Lua number, and a Content/ProtectedString value is converted into a Lua string.

Types by source[]

Lua[]

The eight types provided by Lua are nil, boolean, number, string, function, userdata, thread, and table. The engine also considers Vector3 as the "vector" Lua type as well as being a value type.[1][2]

Lua has a built-in function type which, if called, returns a string that indicates the type of the argument passed.

Roblox engine[]

The Roblox engine has its own types, including instances and enums. Roblox types are represented by the "userdata" Lua type.

The engine has a built-in function typeof, which is similar to the Lua function type but also determines the type (e.g. typeof returns "Instance" while type returns "userdata").

C++[]

The Roblox engine runs in C++. There are a few C++ types that are used internally by the API:

  • void often represents zero arguments returned by a function.
  • Numbers, all of which are represented by the Lua type number:
    • double, known as number in most places, represents a 64 bit (double) floating-point number.
    • float represents a 32 bit floating-point number.
    • int represents a 32-bit integer.
    • int64 represents a 64-bit integer.

These types were referenced on the Roblox Developer Hub. The website was replaced by Roblox Creator Documentation, which no longer references C++ types except for void and instead references Lua types.

References[]


Advertisement