public TextLib() { RegisterMethod("split", 2, args => FObject.NewArray(new FArray( args[0].IsString().Split(args[1].IsString()) .Select(FObject.NewString).ToArray()))); RegisterMethod("replace", 3, GetMethod((x, y, z) => x.Replace(y, z))); RegisterMethod("join", 2, (x) => { var arr = x[0]; if (arr.Type != FObjectType.Array) { throw new Exception(); } var glue = x[1].IsString(); return(FObject.NewString(string.Join(glue, arr.Array().Get().Select(y => y.ToString())))); }); }
internal Method GetMethod(TripleString str) { return(x => FObject.NewString(str.Invoke(x[0].IsString(), x[1].IsString(), x[2].IsString()))); }
internal Method GetMethod(SingleString str) { return(x => FObject.NewString(str.Invoke(x[0].IsString()))); }