Quirrel4.41.0

types.Class.__update

Method on every class
(table|class).__update(other: table|instance|class, ...): any

Copies every own member of each argument into the class it is called on, and returns that same class. Unlike __merge, nothing new is allocated.

The binding carries no declaration string, so the VM cannot report parameter names. The names above are from this page; the types and attributes still come from the VM. The VM also cannot tell an optional parameter from a variadic tail here, so read the brackets and any trailing ... from the prose below, not from the signature.

Parameters

othertable|instance|classa table, class, or instance to copy members from
...anymore tables, classes, or instances, copied in order repeats

Return value

The receiver itself, after the copy.

Errors

Throws a parameter type error naming the argument position when a source is not a table, class, or instance. Takes at least one argument beyond the receiver; calling it with none throws wrong number of parameters passed to native closure '__update' (1 passed, at least 2 required). Since it mutates the receiver in place, every rule for newmember/rawset on a class applies: a locked class rejects a new member, and a frozen reference rejects any change.

Notes

Class.__update and table.__update are the same native function; only the receiver's type differs. A same-named member from a later argument overwrites one from an earlier argument or from the receiver itself.

Example

examples/types/class/__update.nut
class A { a = 1 }
class B { b = 2 }
let same = A.__update(B)
println("same == A =", same == A)
println("A.a =", A.a, "A.b =", A.b)
Output:
same == A = true
A.a = 1 A.b = 2

See also

__mergeBuilds a new class out of the class it is called on plus every argument given, and returns it. The class it is called on is not changed.
newmemberAdds a member to the class, optionally as a static one.
__updateCopies every slot from each argument into the table, in place, later arguments overriding earlier ones.
classclass index