Пример #1
0
        static public CompileResult Evaluate(string code, bool autoCompleteComma = true)
        {
            if (autoCompleteComma && !code.EndsWith(";"))
            {
                code += ";";
            }

            var result = new CompileResult();

            result.code = code;

            // find commands and expand it if found.
            if (RuntimeCommands.ConvertIntoCodeIfCommand(ref code) ||
                Commands.ConvertIntoCodeIfCommand(ref code))
            {
                // the give code is a command and converted into an actual code.
            }

            // eval the code using Mono.
            object ret            = null;
            bool   hasReturnValue = false;

            var  originalOutput = Mono.MessageOutput;
            var  errorWriter    = new System.IO.StringWriter();
            bool isPartial      = false;

            Mono.MessageOutput = errorWriter;
            try {
                isPartial = Mono.Evaluate(code, out ret, out hasReturnValue) != null;
            } catch (System.Exception e) {
                errorWriter.Write(e.Message);
            }
            Mono.MessageOutput = originalOutput;

            var error = errorWriter.ToString();

            if (!string.IsNullOrEmpty(error))
            {
                error = error.Replace("{interactive}", "");
                var lastLineBreakPos = error.LastIndexOf('\n');
                if (lastLineBreakPos != -1)
                {
                    error = error.Remove(lastLineBreakPos);
                }
                result.type  = CompileResult.Type.Error;
                result.error = error;
                return(result);
            }
            errorWriter.Dispose();

            if (isPartial)
            {
                result.type = CompileResult.Type.Partial;
                return(result);
            }

            result.type  = CompileResult.Type.Success;
            result.value = (hasReturnValue && ret != null) ? ret : "null";
            return(result);
        }
Пример #2
0
 static private void SetUsings()
 {
     Mono.Run("using uREPL;");
     Mono.Run("using System;");
     Mono.Run("using UnityEngine;");
     // #if UNITY_EDITOR
     // Mono.Run("using UnityEditor;");
     // #endif
 }
Пример #3
0
        static public void Initialize()
        {
            if (isInitialized)
            {
                return;
            }
            isInitialized = true;

            Mono.Initialize();
            ReferenceAllAssemblies();
            SetUsings();

            Log.Initialize();
            Inspector.Initialize();
        }
Пример #4
0
        static public void Initialize()
        {
            if (isInitialized)
            {
                return;
            }
            isInitialized = true;

            Mono.Initialize();
            SetUsings();

            Log.Initialize();
            Inspector.Initialize();

            Evaluate("null;");
        }
Пример #5
0
 static private void ReferenceAllAssemblies()
 {
     // See the detailed information about this hack at:
     //   http://forum.unity3d.com/threads/mono-csharp-evaluator.102162/
     for (int n = 0; n < 2;)
     {
         foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
         {
             if (assembly == null)
             {
                 continue;
             }
             Mono.ReferenceAssembly(assembly);
         }
         Mono.Evaluate("null;");
         n++;
     }
 }
Пример #6
0
 static public string GetUsing() => Mono.GetUsing();
Пример #7
0
 static public string GetVars() => Mono.GetVars();
Пример #8
0
 static public string[] GetCompletions(string input, out string prefix) =>
 Mono.GetCompletions(input, out prefix);
Пример #9
0
 static public string GetUsing()
 {
     return(Mono.GetUsing());
 }
Пример #10
0
 static public string GetVars()
 {
     return(Mono.GetVars());
 }
Пример #11
0
 static public string[] GetCompletions(string input, out string prefix)
 {
     return(Mono.GetCompletions(input, out prefix));
 }