Values - Method that checks that a value is a reference to a class

This commit is contained in:
Emmanuel BENOîT 2023-01-15 18:08:55 +01:00
parent 453d243b91
commit 3c062df202

View file

@ -39,6 +39,14 @@ impl Value {
} }
} }
/// Check whether a value carries a class reference.
pub fn is_class(&self) -> bool {
match self {
Value::Object(obj_ref) => matches!(*obj_ref.borrow(), Object::Class(_)),
_ => false,
}
}
/// Run some code using the callable object wrapped inside a value. /// Run some code using the callable object wrapped inside a value.
/// If the value is not callable, an error function will be called /// If the value is not callable, an error function will be called
/// instead. /// instead.