Luawe All pages

maid

Cleaning up: a maid holds what has to go together (the connections a part of a script made, its things, its tasks) and cleans it all up in one call, so nothing is left listening by mistake.

maid.newfunction

maid.new(): maid

A new maid: give it what has to be cleaned up together (connections, functions, things, tasks...), and clean cleans it all at once: local events = maid.new(), events:give(scored:connect(f)), then events:clean().

Gives: maid.

maid:givefunction

m:give(what: connection or function or thing or shader or task or maid or sound or table, name: string or nil): any

Gives the maid something to clean up later: a connection (stopped), a function (called), a thing (destroyed), a shader (destroyed), a task (stopped), a looped sound (stopped), another maid (cleaned) or a table with a destroy function (called). Gives it back: local c = m:give(door.touched:connect(f)). Given under a name that is taken, what had the name is cleaned first.

ValueType
whatconnection or function or thing or shader or task or maid or sound or table
namestring or nilMay be left out.

Gives: any.

maid:giveForfunction

m:giveFor(what: connection or function or thing or shader or task or maid or sound or table, seconds: number, name: string or nil): any

Gives the maid something as give does, and it is cleaned up by itself after that many seconds, while the script carries on. Gives it back: m:giveFor(things.new(cat.Kind.decoration), 5). If it is cleaned or taken out before then, nothing more happens to it.

ValueType
whatconnection or function or thing or shader or task or maid or sound or table
secondsnumber
namestring or nilMay be left out.

Gives: any.

maid:cleanfunction

m:clean(...: string)

Cleans up everything the maid holds, the last given first, and empties it: it can be given more after. With names, only what was given under them: m:clean("music").

ValueType
...string

maid:keepfunction

m:keep(...: string)

Cleans up everything the maid holds except what was given under these names, the last given first: m:keep("music"). What is kept stays in the maid. With no names, nothing is kept.

ValueType
...string

maid:cleanAfterfunction

m:cleanAfter(seconds: number): task

Cleans the maid after that many seconds, as clean does, while the script carries on. It is not destroyed: it can be given more after. Gives the task: task.cancel stops it.

ValueType
secondsnumber

Gives: task.

maid:takefunction

m:take(...: string): any

Takes what was given under a name out of the maid without cleaning it, and gives it back. With no name: everything, as a list.

ValueType
...string

Gives: any.

maid:getfunction

m:get(name: string): any

What was given under a name (nil: nothing). It stays in the maid.

ValueType
namestring

Gives: any.

maid:allfunction

m:all(): table

A list of everything the maid holds, in the order it was given.

Gives: table.

maid:cleanWhenGonefunction

m:cleanWhenGone(thing: thing): connection

Cleans the maid up when the thing goes for good (destroyed, or its time up). Tied to several things, it is cleaned when the first one goes. Cleaning unties it.

ValueType
thingthing

Gives: connection.

maid:destroyfunction

m:destroy()

Cleans everything up, and the maid is done: giving it more is a mistake (as for a thing after thing:destroy).

maid:destroyAfterfunction

m:destroyAfter(seconds: number): task

Destroys the maid after that many seconds, as destroy does, while the script carries on. Gives the task: task.cancel stops it.

ValueType
secondsnumber

Gives: task.

maid.cleanedfunction

m.cleaned: event

An event that happens each time the maid has cleaned something up: once for each clean, keep, cleanAfter or cleanWhenGone, for a give that takes a name from something, when giveFor times come, and in destroy. Not when there was nothing to clean.

maid.destroyedfunction

m.destroyed: event

An event that happens once, when the maid is destroyed (destroy or destroyAfter), after its last cleaned. Then both events are over: what was connected to them is disconnected.