Compiling now includes source filenames at end in success message (thanks Venk)

This commit is contained in:
UnknownShadow200 2022-02-08 21:01:57 +11:00
parent ca8f6eba59
commit f82ea2cb51
5 changed files with 22 additions and 19 deletions

View File

@ -32,7 +32,7 @@ namespace MCGalaxy.Commands.Scripting {
if (!Formatter.ValidFilename(p, args[0])) return;
string language = args.Length > 1 ? args[1] : "";
ICompiler engine = ICompiler.Lookup(language, p);
ICompiler engine = ScriptingOperations.GetCompiler(p, language);
if (engine == null) return;
string path = engine.CommandPath(args[0]);

View File

@ -32,7 +32,7 @@ namespace MCGalaxy.Commands.Scripting {
if (!Formatter.ValidFilename(p, args[0])) return;
string language = args.Length > 1 ? args[1] : "";
ICompiler compiler = ICompiler.Lookup(language, p);
ICompiler compiler = ScriptingOperations.GetCompiler(p, language);
if (compiler == null) return;
// either "source" or "source1,source2,source3"

View File

@ -61,7 +61,7 @@ namespace MCGalaxy.Commands.Scripting {
}
static void CompilePlugin(Player p, string name, string language) {
ICompiler compiler = ICompiler.Lookup(language, p);
ICompiler compiler = ScriptingOperations.GetCompiler(p, language);
if (compiler == null) return;
// either "source" or "source1,source2,source3"
@ -110,7 +110,7 @@ namespace MCGalaxy.Commands.Scripting {
}
static void CreatePlugin(Player p, string name, string language) {
ICompiler engine = ICompiler.Lookup(language, p);
ICompiler engine = ScriptingOperations.GetCompiler(p, language);
if (engine == null) return;
string path = engine.PluginPath(name);

View File

@ -202,19 +202,6 @@ namespace MCGalaxy.Scripting
public static List<ICompiler> Compilers = new List<ICompiler>() { CS, VB };
public static ICompiler Lookup(string name, Player p) {
if (name.Length == 0) return Compilers[0];
foreach (ICompiler comp in Compilers) {
if (comp.ShortName.CaselessEq(name)) return comp;
}
p.Message("&WUnknown language \"{0}\"", name);
p.Message("&HAvailable languages: &f{0}",
Compilers.Join(c => c.ShortName + " (" + c.FullName + ")"));
return null;
}
static string FormatSource(string source, params string[] args) {
// Always use \r\n line endings so it looks correct in Notepad
source = source.Replace(@"\t", "\t");

View File

@ -28,6 +28,21 @@ namespace MCGalaxy.Scripting
{
public static class ScriptingOperations
{
public static ICompiler GetCompiler(Player p, string name) {
if (name.Length == 0) return ICompiler.Compilers[0];
foreach (ICompiler comp in ICompiler.Compilers)
{
if (comp.ShortName.CaselessEq(name)) return comp;
}
p.Message("&WUnknown language \"{0}\"", name);
p.Message("&HAvailable languages: &f{0}",
ICompiler.Compilers.Join(c => c.ShortName + " (" + c.FullName + ")"));
return null;
}
const int MAX_LOG = 2;
/// <summary> Attempts to compile the given source code files into a .dll </summary>
@ -48,7 +63,8 @@ namespace MCGalaxy.Scripting
CompilerResults results = compiler.Compile(srcs, dst);
if (!results.Errors.HasErrors) {
p.Message("{0} compiled successfully.", type);
p.Message("{0} compiled successfully from {1}",
type, srcs.Join(file => Path.GetFileName(file)));
return results;
}