Quirrel4.41.0

types.Class.rawget

Method on every class
pure class.rawget(key): any

Reads the value stored at key in the class's own member table.

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

keyanythe member name to look up

Return value

The value stored at key: a field's current default value, or the closure stored for a method or static member.

Errors

Throws the index doesn't exist when key is not a member of the class; check with rawin first to avoid the throw.

Notes

A class has no delegate of its own to bypass - only instances and tables do - so rawget behaves like plain indexing here. Inherited members are visible too: a derived class copies every member of its base into its own table when it is declared, so rawget on the derived class reads them directly, with no lookup chain involved.

Example

examples/types/class/rawget.nut
class Animal { legs = 4 }
class Dog(Animal) { tail = true }
println("Dog.rawget(\"legs\") =", Dog.rawget("legs"))
println("Dog.rawget(\"tail\") =", Dog.rawget("tail"))
try {
  Dog.rawget("missing")
} catch (e) {
  println("Dog.rawget(\"missing\") throws:", e)
}
Output:
Dog.rawget("legs") = 4
Dog.rawget("tail") = true
Dog.rawget("missing") throws: the index doesn't exist

See also

rawinTests whether key names a member of the class.
rawsetCreates or replaces a member of the class, and unlike newmember, wires key and value to the roles their names suggest.
hasindexTests whether key names a member of the class.
rawgetReads the value stored at key on this instance, without consulting a _get metamethod.
classclass index