Program.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. .SetValue("log", new Action<object>(Console.WriteLine))
  12. ;
  13. while (true)
  14. {
  15. Console.ForegroundColor = ConsoleColor.Green;
  16. Console.Write(" > ");
  17. var input = Console.ReadLine();
  18. if (input == "exit")
  19. {
  20. return;
  21. }
  22. try
  23. {
  24. var result = engine.GetValue(engine.Execute(input));
  25. var str = TypeConverter.ToString(engine.Json.Stringify(engine.Json, Arguments.From(result, Undefined.Instance, " ")));
  26. Console.ForegroundColor = ConsoleColor.Magenta;
  27. Console.WriteLine("=> {0}", str);
  28. }
  29. catch (JavaScriptException je)
  30. {
  31. Console.ForegroundColor = ConsoleColor.Red;
  32. Console.WriteLine(je.ToString());
  33. }
  34. }
  35. }
  36. }
  37. }