table.create
Creates a table preallocated for a number of entries, optionally filled with one value.
Syntax
table.create(count: number, value?: any) -> table
Parameters
| Parameter | Type | Description |
|---|---|---|
count | number | Number of entries to reserve. Must not be negative. |
value | any | Optional value assigned to indices 1..count. |
Returns
| Type | Description |
|---|---|
table | The new table. |
Description
When value is omitted the table is only preallocated and stays empty, matching Luau.
A negative count raises table.create: count must be non-negative.
Example
local zeros = table.create(5, 0)
print(#zeros, zeros[1]) -- 5 0
local rows = table.create(3)
print(#rows) -- 0
Notes
table.create(n, {})— Shares one table across all slots; build each row in a loop instead.