create()
Use 'create' to choose a storage representation. A collection descriptor gives you an empty collection; a packed descriptor or layout creates zero-initialized storage.
Collections
Use 'create(array)', 'create(dict)', or 'create(table)' for empty mutable collections.
Packed storage
Pass an element descriptor or record layout and a nonnegative count to allocate a packed array. Omit the count for a single scalar or record value.
pixels = create(u8, 3)
pixels[0] = 255
print(pixels[0])
Output
255
Coroutines
Use 'create(coroutine, entry, ...arguments)' to prepare a coroutine. Its entry starts when you resume it.
See Packed data and Coroutines.
Creates zero-initialized packed data, a mutable collection, or a coroutine.
Signature
create(descriptor[, count]) or create(coroutine, entry, ...arguments)
Parameters
Use array, dict or table alone, a packable scalar or layout with optional nonnegative signed count, or coroutine plus a script function and positional arguments.
Returns
An empty collection, zero scalar, record/fixed value, packed array, or ready coroutine.
Behavior
Each storage creation owns its allocation. A supplied layout dictionary is resolved at creation. Coroutine code starts on resume.
Errors
Unsupported descriptor, invalid size/layout, or unsupported coroutine entry.
Example
p = create({x = f32}, 2)
assert(p[1].x == 0 and count(create(array)) == 0)