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
nilInherited from Lua 5.1's standard library.
Lua- A value that represents the absence of a value
noneAdded by Luwu.
LuwuAvailable in luwu/integration and gated by an FFlag. We anticipate this feature to be released and enabled by default in 0.1.0.
Needs the
flaggedLuwuNonePrimitiveFFlag.- A falsy value that means intentionally empty and can be stored in tables
booleanInherited from Lua 5.1's standard library.
Lua- True or false
numberInherited from Lua 5.1's standard library.
Lua- A 64-bit floating-point number
integerAdded by Luau 0.715.
LuauAvailable in luwu/integration; this feature is unstable and may change without a semver bump.
experimentalDeprecated by Luau and Luwu.
Luau is removing integers and Luwu is replacing them with a new integer implementation
deprecated- A 64-bit signed integer
vectorAdded by Luau 0.501 or earlier.
Luau- A stack value holding three 32-bit floats: x, y and z
Text and bytes
stringInherited from Lua 5.1's standard library.
Lua- An immutable sequence of bytes
bufferAdded by Luau 0.600.
LuauChanged by Luwu: Adds buffers the host manages outside the VM and frozen buffers scripts can't write to.
Luwu- A mutable fixed-size block of bytes for binary data
Functions and coroutines
functionInherited from Lua 5.1's standard library.
Lua- Code you can call, store and pass around
threadInherited from Lua 5.1's standard library.
Lua- A coroutine is a function that be paused, resumed, and used to interleave operations
Data structures
tableInherited from Lua 5.1's standard library.
Lua- Arrays, maps and records in one structure
classAdded by Luau 0.722.
LuauChanged by Luwu: Rebuilds classes from the ground up and optimizes them.
Luwu- A class: the blueprint its objects are built from
objectAdded by Luau 0.722.
LuauChanged by Luwu: Rebuilds objects from the ground up and optimizes them.
Luwu- An instance of a class
traitAdded by Luwu.
LuwuAvailable in luwu/integration and gated by an FFlag. We anticipate this feature to be released and enabled by default in 0.1.0.
Needs the
flaggedLuwuTraitsFFlag.- Behavior that many classes share
Embedder-defined structs
userdataInherited from Lua 5.1's standard library.
Lua- 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.
nilInherited from Lua 5.1's standard library.
Lua
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
const elements: { [string]: number? } = {
cats = 1,
dogs = 2,
seals = 3,
}
print(elements)
elements.dogs = nil
print(elements){
cats = 1,
dogs = 2,
seals = 3,
}
{
cats = 1,
seals = 3,
}noneAdded by Luwu.
LuwuAvailable in luwu/integration and gated by an FFlag. We anticipate this feature to be released and enabled by default in 0.1.0.
Needs the LuwuNonePrimitive FFlag.
flagged
LuwuNonePrimitive FFlag.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.
Example
const scores = { 120, none, 75 }
print(scores)
print(#scores){
[1] = 120,
[2] = none,
[3] = 75,
}
3booleanInherited from Lua 5.1's standard library.
Lua
true and false. Conditions treat false, nil and none as false and every other value as true, 0 and empty strings included.
Example
print(if 0 then "0 is truthy" else "0 is falsy")0 is truthy
numberInherited from Lua 5.1's standard library.
Lua
A double-precision float. It holds every whole number up to 2^53 exactly, and the math library works on it.
Example
print(0.1 + 0.2 == 0.3)false
integerAdded by Luau 0.715.
LuauAvailable in luwu/integration; this feature is unstable and may change without a semver bump.
experimentalDeprecated by Luau and Luwu.
Luau is removing integers and Luwu is replacing them with a new integer implementation
deprecated
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.
vectorAdded by Luau 0.501 or earlier.
Luau
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
const position = vector.create(1, 2, 3)
print(position * 2)2, 4, 6
Text and bytes
stringInherited from Lua 5.1's standard library.
Lua
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.
bufferAdded by Luau 0.600.
LuauChanged by Luwu: Adds buffers the host manages outside the VM and frozen buffers scripts can't write to.
Luwu
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.
Functions and coroutines
functionInherited from Lua 5.1's standard library.
Lua
Functions are values that capture the local variables around them.
See Functions
threadInherited from Lua 5.1's standard library.
Lua
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.
tableInherited from Lua 5.1's standard library.
Lua
Keys of any type but nil map to values.
See Tables
classAdded by Luau 0.722.
LuauChanged by Luwu: Rebuilds classes from the ground up and optimizes them.
Luwu
The class library inspects classes at runtime.
objectAdded by Luau 0.722.
LuauChanged by Luwu: Rebuilds objects from the ground up and optimizes them.
Luwu
Each object stores the values of its class's fields. typeof also gives "object". class.of returns the class it came from.
traitAdded by Luwu.
LuwuAvailable in luwu/integration and gated by an FFlag. We anticipate this feature to be released and enabled by default in 0.1.0.
Needs the LuwuTraits FFlag.
flagged
LuwuTraits FFlag.A trait is written once and implemented by many classes.
Embedder-defined structs
userdataInherited from Lua 5.1's standard library.
Lua
Objects that the program embedding Luwu hands to scripts. typeof gives the name the host chose for them.
See Userdata