Added header/footer of scripts to make C# and VB scripts much easier to write.

Added some logging on what is happening during compile.
ThreadPoolClientBranch
Tedd Hansen 2008-02-02 03:42:35 +00:00
parent 5c8abed450
commit 8dc5153ad7
2 changed files with 49 additions and 8 deletions

View File

@ -81,6 +81,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
public bool in_startup = true; public bool in_startup = true;
public void ReadConfig() public void ReadConfig()
{ {
// Get some config
WriteScriptSourceToDebugFile = m_scriptEngine.ScriptConfigSource.GetBoolean("WriteScriptSourceToDebugFile", true); WriteScriptSourceToDebugFile = m_scriptEngine.ScriptConfigSource.GetBoolean("WriteScriptSourceToDebugFile", true);
CompileWithDebugInformation = m_scriptEngine.ScriptConfigSource.GetBoolean("CompileWithDebugInformation", true); CompileWithDebugInformation = m_scriptEngine.ScriptConfigSource.GetBoolean("CompileWithDebugInformation", true);
CleanUpOldScriptsOnStartup = m_scriptEngine.ScriptConfigSource.GetBoolean("CleanUpOldScriptsOnStartup", true); CleanUpOldScriptsOnStartup = m_scriptEngine.ScriptConfigSource.GetBoolean("CleanUpOldScriptsOnStartup", true);
@ -91,16 +93,18 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
{ {
FilePrefix = FilePrefix.Replace(c, '_'); FilePrefix = FilePrefix.Replace(c, '_');
} }
// First time we start?
// First time we start? Delete old files
if (in_startup) if (in_startup)
{ {
in_startup = false; in_startup = false;
DeleteOldFiles(); DeleteOldFiles();
} }
LanguageMapping.Add("cs", enumCompileType.cs); // Map name and enum type of our supported languages
LanguageMapping.Add("vb", enumCompileType.vb); LanguageMapping.Add(enumCompileType.cs.ToString(), enumCompileType.cs);
LanguageMapping.Add("lsl", enumCompileType.lsl); LanguageMapping.Add(enumCompileType.vb.ToString(), enumCompileType.vb);
LanguageMapping.Add(enumCompileType.lsl.ToString(), enumCompileType.lsl);
// Allowed compilers // Allowed compilers
string allowedCompilers = m_scriptEngine.ScriptConfigSource.GetString("AllowedCompilers", "lsl;cs;vb"); string allowedCompilers = m_scriptEngine.ScriptConfigSource.GetString("AllowedCompilers", "lsl;cs;vb");
@ -112,6 +116,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
{ {
m_scriptEngine.Log.Error(m_scriptEngine.ScriptEngineName, "Config error. Compiler is unable to recongnize language type \"" + strl + "\" specified in \"AllowedCompilers\"."); m_scriptEngine.Log.Error(m_scriptEngine.ScriptEngineName, "Config error. Compiler is unable to recongnize language type \"" + strl + "\" specified in \"AllowedCompilers\".");
} }
else
{
#if DEBUG
m_scriptEngine.Log.Debug(m_scriptEngine.ScriptEngineName, "Config OK. Compiler recongnized language type \"" + strl + "\" specified in \"AllowedCompilers\".");
#endif
}
AllowedCompilers.Add(strlan, true); AllowedCompilers.Add(strlan, true);
} }
if (AllowedCompilers.Count == 0) if (AllowedCompilers.Count == 0)
@ -122,7 +132,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
// Is this language recognized at all? // Is this language recognized at all?
if (!LanguageMapping.ContainsKey(defaultCompileLanguage)) if (!LanguageMapping.ContainsKey(defaultCompileLanguage))
m_scriptEngine.Log.Error(m_scriptEngine.ScriptEngineName, "Config error. Default language specified in \"DefaultCompileLanguage\" is not recognized as a valid language. Scripts may not be executed!"); {
m_scriptEngine.Log.Error(m_scriptEngine.ScriptEngineName,
"Config error. Default language \"" + defaultCompileLanguage + "\" specified in \"DefaultCompileLanguage\" is not recognized as a valid language. Changing default to: \"lsl\".");
defaultCompileLanguage = "lsl";
}
// Is this language in allow-list? // Is this language in allow-list?
if (!AllowedCompilers.ContainsKey(defaultCompileLanguage)) if (!AllowedCompilers.ContainsKey(defaultCompileLanguage))
@ -132,6 +146,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
} }
else else
{ {
#if DEBUG
m_scriptEngine.Log.Debug(m_scriptEngine.ScriptEngineName,
"Config OK. Default language \"" + defaultCompileLanguage + "\" specified in \"DefaultCompileLanguage\" is recognized as a valid language.");
#endif
// LANGUAGE IS IN ALLOW-LIST // LANGUAGE IS IN ALLOW-LIST
DefaultCompileLanguage = LanguageMapping[defaultCompileLanguage]; DefaultCompileLanguage = LanguageMapping[defaultCompileLanguage];
} }
@ -140,6 +158,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
} }
/// <summary>
/// Delete old script files
/// </summary>
private void DeleteOldFiles() private void DeleteOldFiles()
{ {
@ -227,10 +248,27 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
compileScript = LSL_Converter.Convert(Script); compileScript = LSL_Converter.Convert(Script);
l = enumCompileType.cs; l = enumCompileType.cs;
} }
else
switch (l)
{ {
// We don't need to convert case enumCompileType.cs:
compileScript = Script; compileScript = String.Empty +
"using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;" +
String.Empty + "namespace SecondLife { " +
String.Empty + "public class Script : OpenSim.Region.ScriptEngine.Common.LSL_BaseClass { " +
@"public Script() { } " +
Script +
"} }\r\n";
break;
case enumCompileType.vb:
compileScript = String.Empty +
"Imports OpenSim.Region.ScriptEngine.Common: Imports System.Collections.Generic: " +
String.Empty + "NameSpace SecondLife { " +
String.Empty + "Public Class Script: Inherits OpenSim.Region.ScriptEngine.Common.LSL_BaseClass: " +
@"Public Sub New(): End Sub: " +
Script +
":End Class :End Namespace\r\n";
break;
} }
return CompileFromCSorVBText(Script, l); return CompileFromCSorVBText(Script, l);
} }

View File

@ -41,6 +41,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
: base(scriptEngine) : base(scriptEngine)
{ {
base.m_scriptEngine = scriptEngine; base.m_scriptEngine = scriptEngine;
} }
// KEEP TRACK OF SCRIPTS <int id, whatever script> // KEEP TRACK OF SCRIPTS <int id, whatever script>
@ -57,7 +58,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
// First time start? Lets fire up our compiler... // First time start? Lets fire up our compiler...
if (LSLCompiler == null) if (LSLCompiler == null)
{
LSLCompiler = new Compiler.LSL.Compiler(m_scriptEngine); LSLCompiler = new Compiler.LSL.Compiler(m_scriptEngine);
}
//IScriptHost root = host.GetRoot(); //IScriptHost root = host.GetRoot();