types.Instance.hasindex
Method on every
instanceTests whether key names a field or method reachable on this instance.
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 member name to test for |
Return value
true if key is one of the instance's own fields or one of its class's methods, false otherwise.
Notes
Marked pure. Unlike a table, an instance's methods live on its class rather than in a separate delegate, and hasindex/rawget/rawin all see them directly: they are not something "raw" access skips here.
Example
class Foo {
x = 1
function bar() { return 2 }
}
let f = Foo()
println("f.hasindex(\"x\") =", f.hasindex("x"))
println("f.hasindex(\"bar\") =", f.hasindex("bar"))
println("f.hasindex(\"z\") =", f.hasindex("z"))Output:
f.hasindex("x") = true
f.hasindex("bar") = true
f.hasindex("z") = falseSee also
rawin | Tests whether key names a field or method reachable on this instance. |
rawget | Reads the value stored at key on this instance, without consulting a _get metamethod. |
hasindex | Tests whether key names a member of the class. |
| instance | class index |