diff --git a/src/obj/str.rs b/src/obj/str.rs index d9ef33a..359944d 100644 --- a/src/obj/str.rs +++ b/src/obj/str.rs @@ -24,6 +24,7 @@ impl Str { attrs: Default::default(), }, vtable: |obj_ref: ObjRef| vtable! { + BOOL_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), STR_BOOL_METH.clone()), STR_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), STR_STR_METH.clone()), REPR_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), STR_REPR_METH.clone()), INT_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), STR_INT_METH.clone()), @@ -48,6 +49,18 @@ impl Debug for Str { // Builtin Str functions //////////////////////////////////////////////////////////////////////////////// +/// Str.__bool__(self) impl +static STR_BOOL_METH: Lazy = Lazy::new(|| { + NativeFun::new_obj(1, |_callee, vm, args| { + read_obj_downcast!(let str_obj: Option<&Str> = &args[0]); + let str_obj = str_obj.ok_or_else(|| Error::ValueError { + error: "expected Str value".to_string(), + })?; + vm.push(BoolRef::from(!str_obj.value.is_empty())); + Ok(crate::vm::signal::Signal::Return) + }) +}); + /// Str.__str__(self) impl static STR_STR_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(1, |_callee, vm, args| {