mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-01-13 15:38:06 -05:00
Add is_truthy
This commit is contained in:
@@ -51,4 +51,8 @@ impl VsValue for VsFunction {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
fn is_truthy(&self) -> bool {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,4 +35,8 @@ impl VsValue for VsNumber {
|
||||
fn push_frame(&self, vm: &mut VirtualMachine) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
fn is_truthy(&self) -> bool {
|
||||
return self.value != 0_f64;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,4 +93,8 @@ impl VsValue for VsPointer {
|
||||
fn push_frame(&self, vm: &mut VirtualMachine) -> bool {
|
||||
return self.decode().push_frame(vm);
|
||||
}
|
||||
|
||||
fn is_truthy(&self) -> bool {
|
||||
return self.decode().is_truthy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,4 +39,8 @@ impl VsValue for VsString {
|
||||
fn push_frame(&self, vm: &mut VirtualMachine) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
fn is_truthy(&self) -> bool {
|
||||
return self.value != "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,4 +33,8 @@ impl VsValue for VsUndefined {
|
||||
fn push_frame(&self, vm: &mut VirtualMachine) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
fn is_truthy(&self) -> bool {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ pub trait VsValue {
|
||||
fn to_string(&self) -> String;
|
||||
fn to_number(&self) -> f64;
|
||||
fn is_primitive(&self) -> bool;
|
||||
fn is_truthy(&self) -> bool;
|
||||
|
||||
fn push_frame(&self, vm: &mut VirtualMachine) -> bool;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user