types.Table.__update
Copies every slot from each argument into the table, in place, later arguments overriding earlier ones.
... from the prose below, not from the signature.Parameters
other | table|instance|class | a table, class or instance to copy slots from; repeatable, so more than one may be given |
... | any | repeats |
Return value
The table itself.
Errors
Throws Cannot modify immutable object when the table was frozen with freeze().
Throws a type error when an argument is not a table, class or instance, but the wording depends on which one: a bad first other throws parameter 1 of '__update' has an invalid type '...' ; expected: 'table|class|instance', while a bad second or later argument throws parameter N of '<unknown>' has an invalid type '...' ; expected: 'table|class|instance', with N counting the table itself as parameter 1. Only the first argument goes through the VM's own automatic type check, which knows the function's name; the rest are checked by hand inside __update, which does not pass a name along.
Notes
Takes 1 or more arguments - this method is variadic, unlike reduce or findvalue on this page, where a negative arity in the binding does not mean open-ended. t.__update() with no arguments throws a wrong-number-of-parameters error; t.__update(a, b, c) copies a, then b, then c, each overwriting slots the previous ones set.
Despite the name, this is an ordinary method - there is no operator or assignment syntax that calls it implicitly, script code always writes t.__update(other) out. See __merge for the non-mutating version that builds a new table instead of writing into t.
Example
let t = {fizz=1}
let r = t.__update({buzz=2}, {fizz=10}) // later arguments win
println("r == t:", r == t)
println("t.fizz =", t.fizz, "t.buzz =", t.buzz)
try {
t.__update() // at least one argument is required
} catch (e) {
println("t.__update() throws:", e)
}
try {
t.__update("not a table")
} catch (e) {
println("t.__update(\"not a table\") throws:", e)
}r == t: true
t.fizz = 10 t.buzz = 2
t.__update() throws: wrong number of parameters passed to native closure '__update' (1 passed, at least 2 required)
t.__update("not a table") throws: parameter 1 of '__update' has an invalid type 'string' ; expected: 'table|class|instance'See also
__merge | Returns a new table built from this table and every argument, later arguments overriding earlier ones. |
replace_with | Replaces the table's entire contents with a copy of other's slots, in place. |
rawset | Sets the slot at key to value, creating the slot if it does not exist yet. |
| table | class index |