spawn — Luau Binding
require("spawn"): pre-allocated pools of targets, borrowed and returned without allocation churn. The programmatic surface of the spawn system. Every function is[antos].
Status: design. Not built yet.
local spawn = require("spawn")
| Call | Returns | Does |
|---|---|---|
spawn.pool(kind, size, init?) |
pool |
pre-allocate a pool of size targets of kind; init seeds each one's defaults |
spawn.get(pool, opts?) |
target |
borrow a live target from the pool (position, etc. in opts); nil if exhausted and the policy is refuse |
spawn.despawn(target) |
ok |
reset the target and return it to its pool — removes it from every sibling at once |
spawn.alive(pool) |
number |
how many of the pool are currently live |
spawn.policy(pool, how) |
ok |
over-capacity behaviour — "recycle-oldest" or "refuse" |
local spawn = require("spawn")
local bullets = spawn.pool("bullet", 128)
local b = spawn.get(bullets, { x = gun.x, y = gun.y })
motion.play(b, "FD 2000")
collision.on("enter", function(a, hit) if a == b then spawn.despawn(b) end end)