use endbasic_core::*;
use std::borrow::Cow;
use std::rc::Rc;
pub(super) struct IsPositiveFunction {
metadata: Rc<CallableMetadata>,
}
impl IsPositiveFunction {
pub(super) fn new() -> Rc<Self> {
Rc::from(Self {
metadata: CallableMetadataBuilder::new("IS_POSITIVE")
.with_return_type(ExprType::Boolean)
.with_syntax(&[(
&[SingularArgSyntax::RequiredValue(
RequiredValueSyntax { name: Cow::Borrowed("n"), vtype: ExprType::Integer },
ArgSepSyntax::End,
)],
None,
)])
.test_build(),
})
}
}
impl Callable for IsPositiveFunction {
fn metadata(&self) -> Rc<CallableMetadata> {
self.metadata.clone()
}
fn exec(&self, scope: Scope<'_>) -> CallResult<()> {
let n = scope.get_integer(0);
scope.return_boolean(n > 0)
}
}