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); } }
public CommandResult Execute(string[] inputCommands) { //REPLをセットアップする SetUpREPL(); _isActive = true; Console.WriteLine("Start REPL."); while (_isActive) { Console.Write(_luaInterpreter.ClassicPrompt); var input = Console.ReadLine(); var inputByte = Encoding.UTF8.GetBytes(input); try { _luaInterpreter.Evaluate(input); } catch (Exception e) { Console.WriteLine("[ERROR] " + e.Message); } } Console.WriteLine("End REPL."); return(CommandResult.Executed); }
public override ExecutionResult ExecuteMundane(string input, IChannel channel) { var oldAction = printFn; printFn = channel.Stdout; try { var result = interp.Evaluate(input); if (result == null) { channel.Stderr("Interpreter returned null, this is typically due to incomplete input."); return(ExecuteStatus.Error.ToExecutionResult()); } else if (result.ToObject() != null) { return(result.ToExecutionResult()); } else { return(ExecuteStatus.Ok.ToExecutionResult()); } } catch (Exception ex) { channel.Stderr(ex.ToString()); return(ExecuteStatus.Error.ToExecutionResult()); } finally { printFn = oldAction; } }
static void Main(string[] args) { var programPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var pobDirectory = Path.Combine(programPath, "PathOfBuilding"); EnsurePobExists(pobDirectory).GetAwaiter().GetResult(); var wrapper = new PobWrapper(pobDirectory); wrapper.LoadBuildFromFile(Path.Combine(programPath, "Builds", "Test-Character.xml")); Console.WriteLine("REPL Ready"); var repl = new ReplInterpreter(wrapper.Script); var line = ""; while (line != "quit") { Console.Write(repl.ClassicPrompt); line = Console.ReadLine(); try { var result = repl.Evaluate(line); if (result.IsNotNil()) { Console.WriteLine(result); } } catch (Exception e) { Console.WriteLine($"Exception: {e.Message}"); } } /* * wrapper.RunLua(@" * local build = mainObject.main.modes[""BUILD""] * * local f = io.open(""Player.txt"", ""w"") * f:write(inspect(build.calcsTab.mainEnv.player)) * f:close() * "); */ if (Debugger.IsAttached) { Console.ReadLine(); } }
/// <summary> /// REPLのセットアップ /// </summary> public void SetUpREPL() { var lua = new Script(); UserData.RegisterType <LuaREPLExtension>(); lua.Globals.Set(ExtensionObjectName, UserData.Create(new LuaREPLExtension(this))); _luaInterpreter = new ReplInterpreter(lua); //拡張用のスクリプトを読み込み using (var sr = new StreamReader(ExtensionFilePath, Encoding.GetEncoding("UTF-8"))) { //テキストをインタプリタ用に変換 var text = sr.ReadToEnd() .Split(new string[] { Environment.NewLine, "\t" }, StringSplitOptions.RemoveEmptyEntries) .Aggregate((s1, s2) => s1 + " " + s2); //拡張用スクリプトをあらかじめ実行 _luaInterpreter.Evaluate(text); } }
public static DynValue debug(ScriptExecutionContext executionContext, CallbackArguments args) { Script script = executionContext.GetScript(); if (script.Options.DebugInput == null) { throw new ScriptRuntimeException("debug.debug not supported on this platform/configuration"); } ReplInterpreter interpreter = new ReplInterpreter(script) { HandleDynamicExprs = false, HandleClassicExprsSyntax = true }; while (true) { string s = script.Options.DebugInput(interpreter.ClassicPrompt + " "); try { DynValue 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)); } } }
public void Run <T>(T startup, string exit, string[] args) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine("用法:"); Console.WriteLine($" >> module = Startup.ModuleManager.GetModule(\"LoginModule\")"); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.White; var script = new Script(CoreModules.Preset_Complete); var interpreter = new ReplInterpreter(script) { HandleDynamicExprs = true, HandleClassicExprsSyntax = true }; script.Globals["Startup"] = startup; while (true) { Console.Write("$Ssf-lua " + interpreter.ClassicPrompt + " "); var s = Console.ReadLine(); try { var 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); } } }
private static void InterpreterLoop(ReplInterpreter interpreter, ShellContext shellContext) { Console.Write(interpreter.ClassicPrompt + " "); string s = Console.ReadLine(); 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); } }
/// <summary> /// Asynchronously evaluates a REPL command. /// This method returns the result of the computation, or null if more input is needed for having valid code. /// In case of errors, exceptions are propagated to the caller. /// /// This method is supported only on .NET 4.x and .NET 4.x PCL targets. /// </summary> /// <param name="interpreter">The interpreter.</param> /// <param name="input">The input.</param> /// <returns> /// This method returns the result of the computation, or null if more input is needed for a computation. /// </returns> public static Task <DynValue> EvaluateAsync(this ReplInterpreter interpreter, string input) { return(ExecAsync(() => interpreter.Evaluate(input))); }
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); } } } }