Program.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using Jint.Native;
  3. using Jint.Runtime;
  4. namespace Jint.Repl
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. var engine = new Engine();
  11. while (true)
  12. {
  13. Console.ForegroundColor = ConsoleColor.Green;
  14. Console.Write(" > ");
  15. var input = Console.ReadLine();
  16. if (input == "exit")
  17. {
  18. return;
  19. }
  20. try
  21. {
  22. var result = engine.GetValue(engine.Execute(input));
  23. var str = engine.Json.Stringify(engine.Json, Arguments.From(result, Undefined.Instance, " "));
  24. Console.ForegroundColor = ConsoleColor.Magenta;
  25. Console.WriteLine("=> {0}", str);
  26. }
  27. catch (JavaScriptException je)
  28. {
  29. Console.ForegroundColor = ConsoleColor.Red;
  30. Console.WriteLine("Error => {0}", engine.Json.Stringify(engine.Json, Arguments.From(je.Error, Undefined.Instance, " ")));
  31. }
  32. }
  33. }
  34. }
  35. }