types.Class.getmetamethod
Looks up one of the 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, or null if the class does not define it.
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. A recognized name that the class has not implemented is not an error; it returns null instead.
Notes
Calling Instance.getmetamethod(name) on an instance reads from that instance's own class, so it agrees with calling the same method on the class directly.
Example
class Vec {
function _add(o) { return 1 }
}
println("Vec.getmetamethod(\"_add\") != null =", Vec.getmetamethod("_add") != null)
println("Vec.getmetamethod(\"_sub\") == null =", Vec.getmetamethod("_sub") == null)
try {
Vec.getmetamethod("_bogus")
} catch (e) {
println("Vec.getmetamethod(\"_bogus\") throws:", e)
}Output:
Vec.getmetamethod("_add") != null = true
Vec.getmetamethod("_sub") == null = true
Vec.getmetamethod("_bogus") throws: Unknown metamethodSee also
getmetamethod | Looks up one of this instance's class's metamethods by name, without triggering it. |
newmember | Adds a member to the class, optionally as a static one. |
| class | class index |