Allow tracing booleans.
This requires implementing *some level* of coercions, even though this isn't the way to do it.
This commit is contained in:
parent
00186f7602
commit
c6265bb50c
|
@ -21,7 +21,7 @@ fn trace<'gc>(
|
||||||
args: &[Value<'gc>],
|
args: &[Value<'gc>],
|
||||||
) -> Result<ReturnValue<'gc>, Error> {
|
) -> Result<ReturnValue<'gc>, Error> {
|
||||||
if let Some(s) = args.get(0) {
|
if let Some(s) = args.get(0) {
|
||||||
log::info!(target: "avm_trace", "{}", s.as_string()?);
|
log::info!(target: "avm_trace", "{}", s.clone().coerce_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Value::Undefined.into())
|
Ok(Value::Undefined.into())
|
||||||
|
|
|
@ -245,6 +245,9 @@ impl<'gc> Value<'gc> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Demand a string value, erroring out if one is not found.
|
||||||
|
///
|
||||||
|
/// TODO: This should be replaced with `coerce_string` where possible.
|
||||||
pub fn as_string(&self) -> Result<&String, Error> {
|
pub fn as_string(&self) -> Result<&String, Error> {
|
||||||
match self {
|
match self {
|
||||||
Value::String(s) => Ok(s),
|
Value::String(s) => Ok(s),
|
||||||
|
@ -252,6 +255,16 @@ impl<'gc> Value<'gc> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Coerce a value into a string.
|
||||||
|
pub fn coerce_string(self) -> String {
|
||||||
|
match self {
|
||||||
|
Value::String(s) => s,
|
||||||
|
Value::Bool(true) => "true".to_string(),
|
||||||
|
Value::Bool(false) => "false".to_string(),
|
||||||
|
_ => "".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn as_number(&self) -> Result<f64, Error> {
|
pub fn as_number(&self) -> Result<f64, Error> {
|
||||||
match self {
|
match self {
|
||||||
Value::Number(f) => Ok(*f),
|
Value::Number(f) => Ok(*f),
|
||||||
|
|
Loading…
Reference in New Issue