Primitives

Behind any semantic meaning lies what a value truly is at its core... a primitive built into the language.

This list of primitives includes all 8 from Lua 5.1, the 3 new primitives Luau added, and the ones Luwu's added so far.

To find or refine upon the primitive type of a value, use the global function type.

Summary

Simple values

nilLua
A value that represents the absence of a value
noneLuwuflagged
A falsy value that means intentionally empty and can be stored in tables
booleanLua
True or false
numberLua
A 64-bit floating-point number
integerLuauexperimentaldeprecated
A 64-bit signed integer
vectorLuau
A stack value holding three 32-bit floats: x, y and z

Text and bytes

stringLua
An immutable sequence of bytes
bufferLuauLuwu
A mutable fixed-size block of bytes for binary data

Functions and coroutines

functionLua
Code you can call, store and pass around
threadLua
A coroutine is a function that be paused, resumed, and used to interleave operations

Data structures

tableLua
Arrays, maps and records in one structure
classLuauLuwu
A class: the blueprint its objects are built from
objectLuauLuwu
An instance of a class
traitLuwuflagged
Behavior that many classes share

Embedder-defined structs

userdataLua
A value the host defines

Simple values

These simple copy-by-values live directly on the stack and fit into a single TValue in the VM. Creating one of these does not allocate additional memory on the heap and the garbage collector doesn't need to worry about collecting them.

nilLua

A value that represents the absence of a useful value. Since nil means emptiness, it cannot be stored within tables.

Setting a table value to nil removes it from the table.

Example
Input
const elements: { [string]: number? } = {
    cats = 1,
    dogs = 2,
    seals = 3,
}
print(elements)
elements.dogs = nil
print(elements)
Output
{
    cats = 1,
    dogs = 2,
    seals = 3,
}
{
    cats = 1,
    seals = 3,
}

noneLuwuflagged

A falsy value that represents presence but emptiness of a value. Unlike nil, none can be stored in without causing a table's key to disappear or an array to become holey.

Note that type(none) currently returns "symbol" and typeof(none) returns "none". The RFC says both should return "none", but there's an ongoing discussion about symbols and whether none should count as one again, so we're working on it.

See The none Primitive

Example
Input
const scores = { 120, none, 75 }
print(scores)
print(#scores)
Output
{
    [1] = 120,
    [2] = none,
    [3] = 75,
}
3

booleanLua

true and false. Conditions treat false, nil and none as false and every other value as true, 0 and empty strings included.

Example
Input
print(if 0 then "0 is truthy" else "0 is falsy")
Output
0 is truthy

numberLua

A double-precision float. It holds every whole number up to 2^53 exactly, and the math library works on it.

Example
Input
print(0.1 + 0.2 == 0.3)
Output
false

integerLuauexperimentaldeprecated

Deprecated

Luau is removing their version of integers by Luau 0.747.

Meanwhile, Luwu has been working on our own version of integers that will replace this library and the integer primitive.

This means code written using this integer library will no longer work in either language's VMs in the near future.

A whole number that stays exact across its whole 64-bit range unlike a number, which loses precision past 2^53. This implementation makes no distinction between signed and unsigned numbers. Use the integer library to create, add, subtract, etc., and otherwise manipulate integers.

vectorLuau

A primitive copy-by-value type that holds coordinates <x, y, z>. While seeming at first glance only useful for gameplay programming, vectors can be used to represent other kinds of values such as rgb colors, positions, offsets, scaling, directions, and more.

Since vectors are 3 f32s packed into one TValue, they're remarkably cheaper than storing 3 numbers in a table. Vectors are also very cheap to clone.

Use the vector library to create and manipulate vectors.

If you feel limited by only 3 (number) values, try using a collections.pair or collections.triple instead.

Example
Input
const position = vector.create(1, 2, 3)
print(position * 2)
Output
2, 4, 6

Text and bytes

stringLua

An immutable sequence of bytes that usually represents text.

Please note that unlike many high-level programming languages, Luwu strings are not UTF-8 encoded to maintain Lua 5.1 and Luau compatibility. Pre-buffer code often treats strings as the vehicle for representing arbitary bytes.

bufferLuauLuwu

A fixed-size but mutable bag of arbitrary bytes that you create and manipulate with the buffer library.

Luwu extends Luau's buffer type by adding support for external buffers (with memory managed by the host) and immutable buffers (passed as a frontend to memory shared between threads) for performance and safety reasons.

See External Buffers and Strings

Functions and coroutines

functionLua

Functions are values that capture the local variables around them.

See Functions

threadLua

A thread is a coroutine, not an operating system thread

Coroutines are interleaving (async) primitives and aren't for true parallelism (os multithreading). Coroutines can't use more than one CPU core.

Hosts that want real OS multithreading should expose an API that runs separate Luwu VMs per OS thread and facilitate communication via shared memory or message passing.

Because a coroutine has a separate stack, it can stop partway with coroutine.yield and pick up where it left off. The coroutine library works with coroutines. Lua 5.1 named them thread instead of coroutines, which may be confusing if you're working in an environment that exposes actual multithreading.

Data structures

Tables, classes, objects and traits are heap values. Assigning one to a variable or passing it to a function passes a reference to the same value, not a copy. A change made through one reference shows through every other.

tableLua

Keys of any type but nil map to values.

See Tables

classLuauLuwu

The class library inspects classes at runtime.

See Classes and Traits

objectLuauLuwu

Each object stores the values of its class's fields. typeof also gives "object". class.of returns the class it came from.

traitLuwuflagged

A trait is written once and implemented by many classes.

See Classes and Traits

Embedder-defined structs

userdataLua

Objects that the program embedding Luwu hands to scripts. typeof gives the name the host chose for them.

See Userdata