public void Execute(ShellContext context, string p)
		{
			string targetFileName = p + "-compiled";

			Script S = new Script(CoreModules.None);

			DynValue chunk = S.LoadFile(p);

			using (Stream stream = new FileStream(targetFileName, FileMode.Create, FileAccess.Write))
				S.Dump(chunk, stream);
		}
Example #2
0
		private static void ParseCommand(Script S, string p)
		{
			if (p == "help")
			{
				Console.WriteLine("Type Lua code to execute Lua code, multilines are accepted, ");
				Console.WriteLine("or type one of the following commands to execute them.");
				Console.WriteLine("");
				Console.WriteLine("Commands:");
				Console.WriteLine("");
				Console.WriteLine("	!exit - Exits the interpreter");
				Console.WriteLine("	!debug - Starts the debugger");
				Console.WriteLine("	!run <filename> - Executes the specified Lua script");
				Console.WriteLine("	!compile <filename> - Compiles the file in a binary format");
				Console.WriteLine("");
			}
			else if (p == "exit")
			{
				Environment.Exit(0);
			}
			else if (p == "debug" && m_Debugger == null)
			{
				m_Debugger = new RemoteDebuggerService();
				m_Debugger.Attach(S, "MoonSharp REPL interpreter", false);
				Process.Start(m_Debugger.HttpUrlStringLocalHost);
			}
			else if (p.StartsWith("run"))
			{
				p = p.Substring(3).Trim();
				S.DoFile(p);
			}
			else if (p == "!")
			{
				ParseCommand(S, "debug");
				ParseCommand(S, @"run c:\temp\test.lua");
			}
			else if (p.StartsWith("compile"))
			{
				p = p.Substring("compile".Length).Trim();

				string targetFileName = p + "-compiled";

				DynValue chunk = S.LoadFile(p);

				using (Stream stream = new FileStream(targetFileName, FileMode.Create, FileAccess.Write))
					S.Dump(chunk, stream);
			}
		}
Example #3
0
 /// <summary>
 /// Asynchronously dumps a function on the specified stream.
 /// This method is supported only on .NET 4.x and .NET 4.x PCL targets.
 /// </summary>
 /// <param name="script">The script.</param>
 /// <param name="function">The function.</param>
 /// <param name="stream">The stream.</param>
 /// <returns></returns>
 /// <exception cref="System.ArgumentException">function arg is not a function!
 /// or
 /// stream is readonly!
 /// or
 /// function arg has upvalues other than _ENV</exception>
 public static Task DumpAsync(this Script script, DynValue function, Stream stream)
 {
     return(ExecAsyncVoid(() => script.Dump(function, stream)));
 }