types.Class.__update
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.
... from the prose below, not from the signature.Parameters
other | table|instance|class | a table, class, or instance to copy members from |
... | any | more 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
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)same == A = true
A.a = 1 A.b = 2See also
__merge | Builds 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. |
newmember | Adds a member to the class, optionally as a static one. |
__update | Copies every slot from each argument into the table, in place, later arguments overriding earlier ones. |
| class | class index |