From 5a86fd2c31ce0ede9825657c969ccaa1ef423d5c Mon Sep 17 00:00:00 2001
From: Tedd Hansen
Date: Wed, 22 Aug 2007 18:09:38 +0000
Subject: (Untested) Scripts are individually loaded into objects (on rez), and
event fired likewise. Bugfixes coming in next commit.
---
.../DotNetEngine/Compiler/LSL/Compiler.cs | 44 ++++++++++++++--------
1 file changed, 28 insertions(+), 16 deletions(-)
(limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler')
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
index ad2717c..9dd274e 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
@@ -13,39 +13,51 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
{
private LSL2CSConverter LSL_Converter = new LSL2CSConverter();
private CSharpCodeProvider codeProvider = new CSharpCodeProvider();
+ private int ScriptCompileCounter = 0;
//private ICodeCompiler icc = codeProvider.CreateCompiler();
- public string Compile(string LSOFileName)
+ public string CompileFromFile(string LSOFileName)
{
-
-
- // Output assembly name
- string OutFile = Path.Combine("ScriptEngines", Path.GetFileNameWithoutExtension(LSOFileName) + ".dll");
- //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll");
-
- Common.SendToDebug("Reading source code into memory");
- // TODO: Add error handling
string CS_Code;
switch (System.IO.Path.GetExtension(LSOFileName).ToLower())
{
case ".txt":
case ".lsl":
Common.SendToDebug("Source code is LSL, converting to CS");
- CS_Code = LSL_Converter.Convert(File.ReadAllText(LSOFileName));
- break;
+ return CompileFromLSLText(File.ReadAllText(LSOFileName));
case ".cs":
Common.SendToDebug("Source code is CS");
- CS_Code = File.ReadAllText(LSOFileName);
- break;
+ return CompileFromCSText(File.ReadAllText(LSOFileName));
default:
throw new Exception("Unknown script type.");
}
+ }
+ ///
+ /// Converts script from LSL to CS and calls CompileFromCSText
+ ///
+ /// LSL script
+ /// Filename to .dll assembly
+ public string CompileFromLSLText(string Script)
+ {
+ return CompileFromCSText(LSL_Converter.Convert(Script));
+ }
+ ///
+ /// Compile CS script to .Net assembly (.dll)
+ ///
+ /// CS script
+ /// Filename to .dll assembly
+ public string CompileFromCSText(string Script)
+ {
- Common.SendToDebug("Compiling");
+
+ // Output assembly name
+ ScriptCompileCounter++;
+ string OutFile = Path.Combine("ScriptEngines", "Script_" + ScriptCompileCounter + ".dll");
+ //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll");
// DEBUG - write source to disk
try
{
- File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(LSOFileName) + ".cs"), CS_Code);
+ File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(OutFile) + ".cs"), Script);
}
catch { }
@@ -68,7 +80,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
//parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment");
parameters.GenerateExecutable = false;
parameters.OutputAssembly = OutFile;
- CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, CS_Code);
+ CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, Script);
// Go through errors
// TODO: Return errors to user somehow
--
cgit v1.1