types.Table.hasindex
Method on every
tableReports whether key is a slot in the 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
key | any | the key to test |
Return value
true if key names a slot in the table, false otherwise.
Notes
Takes exactly one argument; t.hasindex() throws a wrong-number-of-parameters error.
Implemented the same way as rawin: both call sq_rawget directly, so neither ever consults a _get metamethod. The two exist as separate methods because the shared C++ function also backs class and instance, where hasindex additionally accepts those types; on a table the two methods behave identically.
Example
let t = {a=1, b=null}
println("t.hasindex(\"a\") =", t.hasindex("a"))
println("t.hasindex(\"missing\") =", t.hasindex("missing"))
println("t.hasindex(\"b\") =", t.hasindex("b")) // present with a null value: still true
println("t.hasindex(\"a\") == t.rawin(\"a\"):", t.hasindex("a") == t.rawin("a")) // identical on a tableOutput:
t.hasindex("a") = true
t.hasindex("missing") = false
t.hasindex("b") = true
t.hasindex("a") == t.rawin("a"): trueSee also
hasvalue | Reports whether value is stored under any key in the table. |
rawin | Reports whether key is a slot in the table, without calling a metamethod. |
rawget | Returns the value stored under key, without going through a metamethod. |
| table | class index |