Example #1
0
		private static void InterpreterLoop(ReplInterpreter interpreter, ShellContext shellContext)
		{
			Console.Write(interpreter.ClassicPrompt + " ");

			string s = Console.ReadLine();

			if (!interpreter.HasPendingCommand && s.StartsWith("!"))
			{
				ExecuteCommand(shellContext, s.Substring(1));
				return;
			}

			try
			{
				DynValue result = interpreter.Evaluate(s);

				if (result != null && result.Type != DataType.Void)
					Console.WriteLine("{0}", result);
			}
			catch (InterpreterException ex)
			{
				Console.WriteLine("{0}", ex.DecoratedMessage ?? ex.Message);
			}
			catch (Exception ex)
			{
				Console.WriteLine("{0}", ex.Message);
			}
		}
Example #2
0
        public static DynValue debug(ScriptExecutionContext executionContext, CallbackArguments args)
        {
            var script = executionContext.GetScript();

            if (script.Options.DebugInput == null)
                throw new ScriptRuntimeException("debug.debug not supported on this platform/configuration");

            var interpreter = new ReplInterpreter(script)
            {
                HandleDynamicExprs = false,
                HandleClassicExprsSyntax = true
            };

            while (true)
            {
                var s = script.Options.DebugInput(interpreter.ClassicPrompt + " ");

                try
                {
                    var result = interpreter.Evaluate(s);

                    if (result != null && result.Type != DataType.Void)
                        script.Options.DebugPrint(string.Format("{0}", result));
                }
                catch (InterpreterException ex)
                {
                    script.Options.DebugPrint(string.Format("{0}", ex.DecoratedMessage ?? ex.Message));
                }
                catch (Exception ex)
                {
                    script.Options.DebugPrint(string.Format("{0}", ex.Message));
                }
            }
        }
Example #3
0
		static void Main(string[] args)
		{
			CommandManager.Initialize();

			Script.DefaultOptions.ScriptLoader = new ReplInterpreterScriptLoader();

			Script script = new Script(CoreModules.Preset_Complete);

			script.Globals["makestatic"] = (Func<string, DynValue>)(MakeStatic);

			if (CheckArgs(args, new ShellContext(script)))
				return;

			Banner();

			ReplInterpreter interpreter = new ReplInterpreter(script)
			{
				HandleDynamicExprs = true,
				HandleClassicExprsSyntax = true
			};


			while (true)
			{
				InterpreterLoop(interpreter, new ShellContext(script));
			}
		}
Example #4
0
		static void Main(string[] args)
		{
			Script.DefaultOptions.ScriptLoader = new ReplInterpreterScriptLoader();

			Console.WriteLine("MoonSharp REPL {0} [{1}]", Script.VERSION, Script.GlobalOptions.Platform.GetPlatformName());
			Console.WriteLine("Copyright (C) 2014-2015 Marco Mastropaolo");
			Console.WriteLine("http://www.moonsharp.org");
			Console.WriteLine();

			if (args.Length == 1)
			{
				Script script = new Script();

				script.DoFile(args[0]);

				Console.WriteLine("Done.");

				if (System.Diagnostics.Debugger.IsAttached)
					Console.ReadKey();
			}
			else
			{
				Console.WriteLine("Type Lua code to execute it or type !help to see help on commands.\n");
				Console.WriteLine("Welcome.\n");

				Script script = new Script(CoreModules.Preset_Complete);

				ReplInterpreter interpreter = new ReplInterpreter(script)
				{
					HandleDynamicExprs = true,
					HandleClassicExprsSyntax = true
				};

				while (true)
				{
					Console.Write(interpreter.ClassicPrompt + " ");

					string s = Console.ReadLine();

					if (!interpreter.HasPendingCommand && s.StartsWith("!"))
					{
						ParseCommand(script, s.Substring(1));
						continue;
					}

					try
					{
						DynValue result = interpreter.Evaluate(s);

						if (result != null && result.Type != DataType.Void)
							Console.WriteLine("{0}", result);
					}
					catch (InterpreterException ex)
					{
						Console.WriteLine("{0}", ex.DecoratedMessage ?? ex.Message);
					}
					catch (Exception ex)
					{
						Console.WriteLine("{0}", ex.Message);
					}
				}
			}
		}