public DyObject Print(ExecutionContext ctx, [VarArg] DyObject values, [Default(",")] DyObject separator, [Default("\n")] DyObject terminator) { var fst = true; foreach (var a in (DyTuple)values) { if (!fst) { Console.Write(separator.TypeId == DyType.String ? separator.GetString() : separator.ToString(ctx).ToString()); } if (a.TypeId == DyType.String) { Console.Write(a.GetString()); } else { Console.Write(a.ToString(ctx)); } fst = false; if (ctx.Error != null) { break; } } Console.Write(terminator.TypeId == DyType.String ? terminator.GetString() : terminator.ToString(ctx).ToString()); return(DyNil.Instance); }
public DyObject Parse(ExecutionContext ctx, DyObject expression) { if (expression.TypeId != DyType.String) { return(ctx.InvalidType(expression)); } try { var p = new DyParser(); var res = p.Parse(SourceBuffer.FromString(expression.GetString())); if (!res.Success) { return(ctx.FailedReadLiteral(res.Messages.First().ToString())); } if (res.Value.Root == null || res.Value.Root.Nodes.Count == 0) { return(ctx.FailedReadLiteral("Empty expression.")); } else if (res.Value.Root.Nodes.Count > 1) { return(ctx.FailedReadLiteral("Only single expressions allowed.")); } return(LiteralEvaluator.Eval(res.Value.Root.Nodes[0])); } catch (Exception ex) { return(ctx.FailedReadLiteral(ex.Message)); } }