types.Instance.getmetamethod
Looks up one of this instance's class's metamethods by name, without triggering it.
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
name | string | a metamethod name, underscore included ("_add", "_tostring", ...) |
Return value
The closure installed for that metamethod on the instance's class, or null if the class does not define it. Equivalent to getclass().getmetamethod(name).
Errors
Throws Unknown metamethod if name is not one of the metamethod names the VM recognizes: _add, _sub, _mul, _div, _unm, _modulo, _set, _get, _typeof, _nexti, _cmp, _call, _cloned, _newslot, _delslot, _tostring, _lock.
Example
class Vec {
function _add(o) { return 1 }
}
let v = Vec()
println("v.getmetamethod(\"_add\") != null =", v.getmetamethod("_add") != null)
println("v.getmetamethod(\"_sub\") == null =", v.getmetamethod("_sub") == null)Output:
v.getmetamethod("_add") != null = true
v.getmetamethod("_sub") == null = trueSee also
getmetamethod | Looks up one of the class's metamethods by name, without triggering it. |
getclass | Returns the class this instance was constructed from. |
| instance | class index |