(
_state: &mut State<'gc>,
args: Vec<Value<'gc>>,
)
| 147 | } |
| 148 | |
| 149 | pub(super) fn ord<'gc>( |
| 150 | _state: &mut State<'gc>, |
| 151 | args: Vec<Value<'gc>>, |
| 152 | ) -> Result<Value<'gc>, VmError> { |
| 153 | if args.len() != 1 { |
| 154 | return Err(VmError::RuntimeError( |
| 155 | "ord() takes exactly one argument.".into(), |
| 156 | )); |
| 157 | } |
| 158 | |
| 159 | let s = match &args[0] { |
| 160 | Value::String(s) /*| Value::IoString(s)*/ => s.to_string(), |
| 161 | _ => { |
| 162 | return Err(VmError::RuntimeError( |
| 163 | "ord() argument must be a string.".into(), |
| 164 | )) |
| 165 | } |
| 166 | }; |
| 167 | |
| 168 | let mut chars = s.chars(); |
| 169 | match (chars.next(), chars.next()) { |
| 170 | (Some(c), None) => Ok(Value::Number(c as u32 as f64)), |
| 171 | (None, _) => Err(VmError::RuntimeError( |
| 172 | "ord() argument must be a string of length 1.".into(), |
| 173 | )), |
| 174 | (Some(_), Some(_)) => Err(VmError::RuntimeError( |
| 175 | "ord() argument must be a string of length 1.".into(), |
| 176 | )), |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | pub(super) fn str<'gc>( |
| 181 | state: &mut State<'gc>, |
nothing calls this directly
no test coverage detected