PP() public static method

public static PP ( StringBuilder output, object result, bool expandTypes = false ) : void
output StringBuilder
result object
expandTypes bool
return void
Exemplo n.º 1
0
    private void ShowVars()
    {
        if (fields == null)
        {
            fields = EvaluatorProxy.fields;
        }

        scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, false, false);
        EditorGUI.indentLevel++;
        GUILayout.BeginHorizontal();
        GUILayout.Space(EditorGUI.indentLevel * 14);
        GUILayout.BeginVertical();
        // TODO: This is gonna be WAY inefficient *AND* ugly.  Need a better
        // TODO: way to handle tabular data, and need a way to track what
        // TODO: has/hasn't changed here.
        StringBuilder tmp = new StringBuilder();

        foreach (DictionaryEntry kvp in fields)
        {
            FieldInfo field = (FieldInfo)kvp.Value;
            GUILayout.BeginHorizontal();
            GUILayout.Label(TypeManagerProxy.CSharpName(field.FieldType));
            GUILayout.Space(10);
            GUILayout.Label((string)kvp.Key);
            GUILayout.FlexibleSpace();
            PrettyPrint.PP(tmp, field.GetValue(null));
            GUILayout.Label(tmp.ToString());
            tmp.Length = 0;
            GUILayout.EndHorizontal();
        }
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();
        EditorGUI.indentLevel--;
        EditorGUILayout.EndScrollView();
    }
Exemplo n.º 2
0
    public bool Eval(string code)
    {
        EditorApplication.LockReloadAssemblies();

        bool status    = false,
             hasOutput = false;
        object output  = null;
        string res     = null,
               tmpCode = code.Trim();

//    Debug.Log("Evaluating: " + tmpCode);

        try {
            if (tmpCode.StartsWith("="))
            {
                // Special case handling of calculator mode.  The problem is that
                // expressions involving multiplication are grammatically ambiguous
                // without a var declaration or some other grammatical construct.
                // TODO: Change the prompt in calculator mode.  Needs to be done from Shell.
                tmpCode = "(" + tmpCode.Substring(1, tmpCode.Length - 1) + ");";
            }
            res = Evaluate(tmpCode, out output, out hasOutput);
        } catch (EvaluationException) {
            Debug.LogError(@"Error compiling/executing code.  Please double-check syntax, method/variable names, etc.
You can find more information in Unity's `Editor.log` file (*not* the editor console!).");

            output    = new Evaluator.NoValueSet();
            hasOutput = false;
            res       = tmpCode; // Enable continued editing on syntax errors, etc.
        } catch (Exception e) {
            Debug.LogError(e);

            res = tmpCode; // Enable continued editing on unexpected errors.
        } finally {
            status = res == null;
        }

        if (hasOutput)
        {
            if (status)
            {
                try {
                    StringBuilder sb = new StringBuilder();
                    PrettyPrint.PP(sb, output, true);
                    Debug.Log(sb.ToString());
                } catch (Exception e) {
                    Debug.LogError(e.ToString().Trim());
                }
            }
        }

        EditorApplication.UnlockReloadAssemblies();
        return(status);
    }
Exemplo n.º 3
0
    public bool Eval(List <LogEntry> logEntries, string code)
    {
        EditorApplication.LockReloadAssemblies();

        bool     status    = false;
        bool     hasOutput = false;
        object   output    = null;
        LogEntry cmdEntry  = null;

        string tmpCode = code.Trim();

        cmdEntry = new LogEntry()
        {
            logEntryType = LogEntryType.Command,
            command      = tmpCode
        };

        bool isExpression = false;

        try {
            if (tmpCode.StartsWith("="))
            {
                tmpCode      = "(" + tmpCode.Substring(1, tmpCode.Length - 1) + ");";
                isExpression = true;
            }
            Application.RegisterLogCallback(delegate(string cond, string sTrace, LogType lType) {
                cmdEntry.Add(new LogEntry()
                {
                    logEntryType   = LogEntryType.ConsoleLog,
                    condition      = cond,
                    stackTrace     = sTrace,
                    consoleLogType = lType
                });
            });
            status = Evaluator.Evaluate(tmpCode, out output, out hasOutput) == null;
            if (status)
            {
                logEntries.Add(cmdEntry);
            }
        } catch (Exception e) {
            cmdEntry.Add(new LogEntry()
            {
                logEntryType = LogEntryType.EvaluationError,
                error        = e.ToString().Trim() // TODO: Produce a stack trace a la Debug, and put it in stackTrace so we can filter it.
            });

            output    = new Evaluator.NoValueSet();
            hasOutput = false;
            status    = true; // Need this to avoid 'stickiness' where we let user
                              // continue editing due to incomplete code.
            logEntries.Add(cmdEntry);
        } finally {
            Application.RegisterLogCallback(null);
        }

        // Catch compile errors that are not dismissed as a product of interactive
        // editing by Mono.CSharp.Evaluator...
        StringBuilder buffer = FluffReporter();
        string        tmp    = buffer.ToString().Trim();

        buffer.Length = 0;
        if (!String.IsNullOrEmpty(tmp))
        {
            cmdEntry.Add(new LogEntry()
            {
                logEntryType = LogEntryType.SystemConsole,
                error        = tmp
            });
            status = false;
        }

        if (hasOutput && (isExpression || output is REPLMessage))
        {
            if (status)
            {
                outputBuffer.Length = 0;
                PrettyPrint.PP(outputBuffer, output);
                cmdEntry.Add(new LogEntry()
                {
                    logEntryType = LogEntryType.Output,
                    output       = outputBuffer.ToString().Trim()
                });
            }
        }

        EditorApplication.UnlockReloadAssemblies();
        return(status);
    }