types.Table.rawget
tableReturns the value stored under key, without going through a metamethod.
... 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's own _get metamethod can only come from a delegate, and a delegate can only be attached from C++ (see getfuncinfos). The distinction between raw and plain access matters far more for class/ 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)
}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, without calling a metamethod. |
hasindex | Reports whether key is a slot in the table. |
| table | class index |