public string Stringify(object obj, bool printError = false)
{
if (obj == null)
throw ErrorFactory.CreateTypeError( "Invalid operand type: 'null'");
if (obj is BikeObject)
{
var sb = new StringBuilder();
var bo = (BikeObject) obj;
if (bo.Exist("to_string") || bo.Exist (InterpreterHelper.MemberMissing))
{
var ts = bo.Resolve("to_string");
if (ts is BikeFunction)
{
var value = CallBikeFunction((BikeFunction) ts, bo, new object[0]);
sb.Append(((BikeString) value).Value);
}
else
{
throw ErrorFactory.CreateTypeError("to_string is not a function");
}
}
else
{
throw ErrorFactory.CreateNotDefinedError("to_string");
}
if (printError && !bo.Exist(InterpreterHelper.SpecialSuffix + "is_error") && bo.Exist("stack_trace"))
{
var st = ((BikeString)bo.Resolve("stack_trace")).Value;
sb.AppendLine().Append("Stack Trace:").AppendLine().Append(st).AppendLine();
}
return sb.ToString();
}
return obj.ToString();
}