types.Table.rawget
Method on every
tableReturns the value stored under key.
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
key | any | the key to look up |
Return value
The value stored under key.
Errors
Throws the index doesn't exist when key is not in the table.
Notes
Takes exactly one argument - t.rawget() and t.rawget("a", "b") both throw a wrong-number-of-parameters error rather than reaching this code.
Plain indexing, t[key], and rawget both throw on a missing key for an ordinary table (with different wording - t[key] throws the index 'key' (type='...') does not exist), because a table has no _get metamethod. The distinction between raw and plain access matters far more for an instance, where _get is reachable from script and can turn a "missing" key into a computed value.
Example
let t = {a=1, b=2}
println("t.rawget(\"a\") =", t.rawget("a"))
println("t[\"a\"] =", t["a"]) // same result: a table has no reachable _get here
try {
t.rawget("missing")
} catch (e) {
println("t.rawget(\"missing\") throws:", e)
}
try {
t.missing // plain indexing also throws, with different wording
} catch (e) {
println("t.missing throws:", e)
}Output:
t.rawget("a") = 1
t["a"] = 1
t.rawget("missing") throws: the index doesn't exist
t.missing throws: the index 'missing' (type='string') does not existSee also
rawset | Sets the slot at key to value, creating the slot if it does not exist yet. |
rawin | Reports whether key is a slot in the table. |
hasindex | Reports whether key is a slot in the table. |
| table | class index |