diff --git a/valuescript_vm/src/string_methods.rs b/valuescript_vm/src/string_methods.rs index bbdbdcd..ec545cb 100644 --- a/valuescript_vm/src/string_methods.rs +++ b/valuescript_vm/src/string_methods.rs @@ -47,6 +47,7 @@ pub fn get_string_method(method: &str) -> Val { // "charCodeAt" => Val::Static(&CHAR_CODE_AT), // "codePointAt" => Val::Static(&CODE_POINT_AT), + "concat" => Val::Static(&CONCAT), _ => Val::Undefined, } } @@ -96,6 +97,23 @@ static CODE_POINT_AT: NativeFunction = NativeFunction { }, }; +static CONCAT: NativeFunction = NativeFunction { + fn_: |this: &mut Val, params: Vec| -> Val { + match this { + Val::String(string_data) => { + let mut result = string_data.as_str().to_string(); + + for param in params { + result.push_str(param.val_to_string().as_str()); + } + + Val::String(Rc::new(result)) + } + _ => std::panic!("Not implemented: exceptions/string indirection"), + } + }, +}; + fn unicode_at(bytes: &[u8], index: usize) -> Option { match code_point_at(bytes, index) { Some(code_point) => Some(