Change the scirpt engine loading mechanism. Script engines are now

ordinary region modules and are able to coexist in one instance.
See http://opensimulator.org/wiki/ScriptEngines for details. There were
changes to OpenSim.ini.example, please note DefaultScriptEngine.
Also see the User docs and FAQ on the Wiki. Default is DotNetEngine.
This commit is contained in:
Melanie Thielker
2008-09-21 21:47:00 +00:00
parent 451bd5a0ca
commit 94aaf67dfa
19 changed files with 142 additions and 514 deletions

View File

@@ -65,32 +65,37 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
myScriptEngine = _ScriptEngine;
ReadConfig();
// Hook up to events from OpenSim
// We may not want to do it because someone is controlling us and will deliver events to us
if (performHookUp)
{
myScriptEngine.Log.Info("[" + myScriptEngine.ScriptEngineName + "]: Hooking up to server events");
myScriptEngine.World.EventManager.OnObjectGrab += touch_start;
myScriptEngine.World.EventManager.OnObjectDeGrab += touch_end;
myScriptEngine.World.EventManager.OnRezScript += OnRezScript;
myScriptEngine.World.EventManager.OnRemoveScript += OnRemoveScript;
myScriptEngine.World.EventManager.OnScriptChangedEvent += changed;
myScriptEngine.World.EventManager.OnScriptAtTargetEvent += at_target;
myScriptEngine.World.EventManager.OnScriptNotAtTargetEvent += not_at_target;
myScriptEngine.World.EventManager.OnScriptControlEvent += control;
myScriptEngine.World.EventManager.OnScriptColliderStart += collision_start;
myScriptEngine.World.EventManager.OnScriptColliding += collision;
myScriptEngine.World.EventManager.OnScriptCollidingEnd += collision_end;
// TODO: HOOK ALL EVENTS UP TO SERVER!
IMoneyModule money=myScriptEngine.World.RequestModuleInterface<IMoneyModule>();
if (money != null)
{
money.OnObjectPaid+=HandleObjectPaid;
}
}
}
public void HookUpEvents()
{
// Hook up to events from OpenSim
// We may not want to do it because someone is controlling us and will deliver events to us
myScriptEngine.Log.Info("[" + myScriptEngine.ScriptEngineName + "]: Hooking up to server events");
myScriptEngine.World.EventManager.OnObjectGrab += touch_start;
myScriptEngine.World.EventManager.OnObjectDeGrab += touch_end;
myScriptEngine.World.EventManager.OnRemoveScript += OnRemoveScript;
myScriptEngine.World.EventManager.OnScriptChangedEvent += changed;
myScriptEngine.World.EventManager.OnScriptAtTargetEvent += at_target;
myScriptEngine.World.EventManager.OnScriptNotAtTargetEvent += not_at_target;
myScriptEngine.World.EventManager.OnScriptControlEvent += control;
myScriptEngine.World.EventManager.OnScriptColliderStart += collision_start;
myScriptEngine.World.EventManager.OnScriptColliding += collision;
myScriptEngine.World.EventManager.OnScriptCollidingEnd += collision_end;
// TODO: HOOK ALL EVENTS UP TO SERVER!
IMoneyModule money=myScriptEngine.World.RequestModuleInterface<IMoneyModule>();
if (money != null)
{
money.OnObjectPaid+=HandleObjectPaid;
}
}
public void ReadConfig()
{
@@ -187,8 +192,11 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "touch_end", detstruct, new object[] { new LSL_Types.LSLInteger(1) });
}
public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez)
public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine)
{
if (engine != "DotNetEngine")
return;
myScriptEngine.Log.Debug("OnRezScript localID: " + localID + " LLUID: " + itemID.ToString() + " Size: " +
script.Length);
myScriptEngine.m_ScriptManager.StartScript(localID, itemID, script, startParam, postOnRez);

View File

@@ -353,6 +353,11 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
/// <param name="param">Array of parameters to match event mask</param>
public void AddToScriptQueue(uint localID, UUID itemID, string FunctionName, Queue_llDetectParams_Struct qParams, params object[] param)
{
List<UUID> keylist = new List<UUID>(m_ScriptEngine.m_ScriptManager.GetScriptKeys(localID));
if (!keylist.Contains(itemID)) // We don't manage that script
return;
lock (eventQueue)
{
if (eventQueue.Count >= EventExecutionMaxQueueSize)

View File

@@ -56,6 +56,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public IConfigSource ConfigSource;
public IConfig ScriptConfigSource;
public abstract string ScriptEngineName { get; }
private bool m_enabled = true;
private bool m_hookUpToServer = false;
/// <summary>
/// How many seconds between re-reading config-file. 0 = never. ScriptEngine will try to adjust to new config changes.
@@ -91,6 +93,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
{
World = Sceneworld;
ConfigSource = config;
m_hookUpToServer = HookUpToServer;
m_log.Info("[" + ScriptEngineName + "]: ScriptEngine initializing");
// Make sure we have config
@@ -98,13 +102,16 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
ConfigSource.AddConfig(ScriptEngineName);
ScriptConfigSource = ConfigSource.Configs[ScriptEngineName];
m_enabled = ScriptConfigSource.GetBoolean("Enabled", true);
if (!m_enabled)
return;
//m_log.Info("[" + ScriptEngineName + "]: InitializeEngine");
// Create all objects we'll be using
m_EventQueueManager = new EventQueueManager(this);
m_EventManager = new EventManager(this, HookUpToServer);
// We need to start it
newScriptManager.Start();
m_ScriptManager = newScriptManager;
m_AppDomainManager = new AppDomainManager(this);
m_ASYNCLSLCommandManager = new AsyncCommandManager(this);
@@ -118,6 +125,17 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
// Or can we assume we are loaded before anything else so we can use proper events?
}
public void PostInitialise()
{
if (!m_enabled)
return;
if (m_hookUpToServer)
m_EventManager.HookUpEvents();
m_ScriptManager.Start();
}
public void Shutdown()
{
// We are shutting down
@@ -155,10 +173,6 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public abstract void Initialise(Scene scene, IConfigSource config);
public void PostInitialise()
{
}
public void Close()
{
}

View File

@@ -64,6 +64,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
private static bool PrivateThread;
private int LoadUnloadMaxQueueSize;
private Object scriptLock = new Object();
private bool m_started = false;
// Load/Unload structure
private struct LUStruct
@@ -119,6 +120,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public abstract void Initialize();
public void Start()
{
m_started = true;
ReadConfig();
Initialize();
@@ -213,6 +216,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public void DoScriptLoadUnload()
{
if (!m_started)
return;
lock (LUQueue)
{
if (LUQueue.Count > 0)
@@ -258,7 +264,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
{
lock (LUQueue)
{
if (LUQueue.Count >= LoadUnloadMaxQueueSize)
if ((LUQueue.Count >= LoadUnloadMaxQueueSize) && m_started)
{
m_scriptEngine.Log.Error("[" + m_scriptEngine.ScriptEngineName + "]: ERROR: Load/unload queue item count is at " + LUQueue.Count + ". Config variable \"LoadUnloadMaxQueueSize\" is set to " + LoadUnloadMaxQueueSize + ", so ignoring new script.");
return;

View File

@@ -39,7 +39,7 @@ namespace OpenSim.Region.ScriptEngine.Common
public interface RemoteEvents
{
void touch_start(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient);
void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez);
void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine);
void OnRemoveScript(uint localID, UUID itemID);
void state_exit(uint localID);
void touch(uint localID, uint originalID, UUID itemID);

View File

@@ -82,7 +82,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
// private static int instanceID = new Random().Next(0, int.MaxValue); // Unique number to use on our compiled files
private static UInt64 scriptCompileCounter = 0; // And a counter
private bool m_UseCompiler = true;
public IScriptEngine m_scriptEngine;
public Compiler(IScriptEngine scriptEngine)
@@ -93,8 +92,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
public bool in_startup = true;
public void ReadConfig()
{
m_UseCompiler = m_scriptEngine.Config.GetBoolean("UseNewCompiler", true);
// Get some config
WriteScriptSourceToDebugFile = m_scriptEngine.Config.GetBoolean("WriteScriptSourceToDebugFile", true);
CompileWithDebugInformation = m_scriptEngine.Config.GetBoolean("CompileWithDebugInformation", true);
@@ -327,14 +324,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
{
// Its LSL, convert it to C#
//compileScript = LSL_Converter.Convert(Script);
if (m_UseCompiler)
LSL_Converter = (ICodeConverter)new CSCodeGenerator();
else
LSL_Converter = (ICodeConverter)new LSL2CSConverter();
LSL_Converter = (ICodeConverter)new CSCodeGenerator();
compileScript = LSL_Converter.Convert(Script);
if (m_UseCompiler)
m_positionMap = ((CSCodeGenerator) LSL_Converter).PositionMap;
m_positionMap = ((CSCodeGenerator) LSL_Converter).PositionMap;
l = enumCompileType.cs;
}
@@ -549,31 +542,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
severity = "Warning";
}
if (m_UseCompiler)
KeyValuePair<int, int> lslPos;
try
{
KeyValuePair<int, int> lslPos;
try
{
lslPos = m_positionMap[new KeyValuePair<int, int>(CompErr.Line, CompErr.Column)];
}
catch (KeyNotFoundException) // we don't have this line/column mapped
{
m_scriptEngine.Log.Debug(String.Format("[Compiler]: Lookup of C# line {0}, column {1} failed.", CompErr.Line, CompErr.Column));
lslPos = new KeyValuePair<int, int>(-CompErr.Line, -CompErr.Column);
}
// The Second Life viewer's script editor begins
// countingn lines and columns at 0, so we subtract 1.
errtext += String.Format("Line {0}, column {1}, {4} Number: {2}, '{3}'\r\n", lslPos.Key - 1, lslPos.Value - 1, CompErr.ErrorNumber, CompErr.ErrorText, severity);
lslPos = m_positionMap[new KeyValuePair<int, int>(CompErr.Line, CompErr.Column)];
}
else
catch (KeyNotFoundException) // we don't have this line/column mapped
{
errtext += "Line number " + (CompErr.Line - LinesToRemoveOnError) +
", " + severity + " Number: " + CompErr.ErrorNumber +
", '" + CompErr.ErrorText + "'\r\n";
m_scriptEngine.Log.Debug(String.Format("[Compiler]: Lookup of C# line {0}, column {1} failed.", CompErr.Line, CompErr.Column));
lslPos = new KeyValuePair<int, int>(-CompErr.Line, -CompErr.Column);
}
// The Second Life viewer's script editor begins
// countingn lines and columns at 0, so we subtract 1.
errtext += String.Format("Line {0}, column {1}, {4} Number: {2}, '{3}'\r\n", lslPos.Key - 1, lslPos.Value - 1, CompErr.ErrorNumber, CompErr.ErrorText, severity);
}
Console.WriteLine("[COMPILER MESSAGES]: " + errtext);

View File

@@ -1,374 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
{
public class LSL2CSConverter : ICodeConverter
{
// Uses regex to convert LSL code to C# code.
//private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled);
private Dictionary<string, string> dataTypes = new Dictionary<string, string>();
private Dictionary<string, string> quotes = new Dictionary<string, string>();
// c Style
private Regex cstylecomments = new Regex(@"/\*(.|[\r\n])*?\*/", RegexOptions.Compiled | RegexOptions.Multiline);
// c# one liners
private Regex nonCommentFwsl = new Regex("\"[a-zA-Z0-9.,:/\\n ]+//[^\"+]+([\\\\\\\"+]+)?(\\s+)?[\"+](\\s+)?(;)?", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
private Regex conelinecomments = new Regex(@"[^:].?([\/]{2}[^\n]*)|([\n]{1,}[\/]{2}[^\n]*)", RegexOptions.Compiled | RegexOptions.Multiline);
// ([^\"])((?:[a-zA-Z])\.[a-zA-Z].?)([^\"])
// value we're looking for: (?:[a-zA-Z])\.[a-zA-Z]
public LSL2CSConverter()
{
// Only the types we need to convert
dataTypes.Add("void", "void");
dataTypes.Add("integer", "LSL_Types.LSLInteger");
dataTypes.Add("float", "LSL_Types.LSLFloat");
dataTypes.Add("string", "LSL_Types.LSLString");
dataTypes.Add("key", "LSL_Types.LSLString");
dataTypes.Add("vector", "LSL_Types.Vector3");
dataTypes.Add("rotation", "LSL_Types.Quaternion");
dataTypes.Add("list", "LSL_Types.list");
dataTypes.Add("null", "null");
}
public string Convert(string Script)
{
quotes.Clear();
string Return = String.Empty;
Script = " \r\n" + Script;
//
// Prepare script for processing
//
// Clean up linebreaks
Script = Regex.Replace(Script, @"\r\n", "\n");
Script = Regex.Replace(Script, @"\n", "\r\n");
// QUOTE REPLACEMENT
// temporarily replace quotes so we can work our magic on the script without
// always considering if we are inside our outside quotes's
// TODO: Does this work on half-quotes in strings? ;)
string _Script = String.Empty;
string C;
bool in_quote = false;
bool quote_replaced = false;
string quote_replacement_string = "Q_U_O_T_E_REPLACEMENT_";
string quote = String.Empty;
bool last_was_escape = false;
int quote_replaced_count = 0;
string removefwnoncomments = nonCommentFwsl.Replace(Script, "\"\";");
string removecomments = conelinecomments.Replace(removefwnoncomments, "");
removecomments = cstylecomments.Replace(removecomments, "");
string[] localscript = removecomments.Split('"');
string checkscript = String.Empty;
bool flip = true;
for (int p = 0; p < localscript.Length; p++)
{
//if (localscript[p].Length >= 1)
//{
if (!localscript[p].EndsWith(@"\"))
{
flip = !flip;
//System.Console.WriteLine("Flip:" + flip.ToString() + " - " + localscript[p] + " ! " + localscript[p].EndsWith(@"\").ToString());
}
//}
//else
//{
// flip = !flip;
// System.Console.WriteLine("Flip:" + flip.ToString() + " - " + localscript[p]);
//}
if (!flip)
checkscript += localscript[p];
}
//System.Console.WriteLine("SCRIPT:" + checkscript);
// checks for alpha.alpha way of referring to objects in C#
// ignores alpha.X alpha.Y, alpha.Z for refering to vector components
Match SecurityM;
// BROKEN: this check is very wrong. It block's any url in strings.
SecurityM = Regex.Match(checkscript, @"(?:[a-zA-Z])\.(?:[a-rt-wA-Z]|[a-zA-Z][a-zA-Z])", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
if (SecurityM.Success)
throw new Exception("CS0103: 'The . symbol cannot be used in LSL except in float values or vector components'. Detected around: " + SecurityM.Captures[0].Value);
SecurityM = Regex.Match(checkscript, @"typeof\s", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
if (SecurityM.Success)
throw new Exception("CS0103: 'The object.typeof method isn't allowed in LSL'");
SecurityM = Regex.Match(checkscript, @"GetType\(", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
if (SecurityM.Success)
throw new Exception("CS0103: 'The object.GetType method isn't allowed in LSL'");
for (int p = 0; p < Script.Length; p++)
{
C = Script.Substring(p, 1);
while (true)
{
// found " and last was not \ so this is not an escaped \"
if (C == "\"" && last_was_escape == false)
{
// Toggle inside/outside quote
in_quote = !in_quote;
if (in_quote)
{
quote_replaced_count++;
}
else
{
if (quote == String.Empty)
{
// We didn't replace quote, probably because of empty string?
_Script += quote_replacement_string +
quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]);
}
// We just left a quote
quotes.Add(
quote_replacement_string +
quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]), quote);
quote = String.Empty;
}
break;
}
if (!in_quote)
{
// We are not inside a quote
quote_replaced = false;
}
else
{
// We are inside a quote
if (!quote_replaced)
{
// Replace quote
_Script += quote_replacement_string +
quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]);
quote_replaced = true;
}
quote += C;
break;
}
_Script += C;
break;
}
last_was_escape = false;
if (C == @"\")
{
last_was_escape = true;
}
}
Script = _Script;
//
// END OF QUOTE REPLACEMENT
//
//
// PROCESS STATES
// Remove state definitions and add state names to start of each event within state
//
int ilevel = 0;
int lastlevel = 0;
string ret = String.Empty;
string cache = String.Empty;
bool in_state = false;
string current_statename = String.Empty;
for (int p = 0; p < Script.Length; p++)
{
C = Script.Substring(p, 1);
while (true)
{
// inc / dec level
if (C == @"{")
ilevel++;
if (C == @"}")
ilevel--;
if (ilevel < 0)
ilevel = 0;
cache += C;
// if level == 0, add to return
if (ilevel == 1 && lastlevel == 0)
{
// 0 => 1: Get last
Match m =
//Regex.Match(cache, @"(?![a-zA-Z_]+)\s*([a-zA-Z_]+)[^a-zA-Z_\(\)]*{",
Regex.Match(cache, @"(?![a-zA-Z_]+)\s*(state\s+)?(?<statename>[a-zA-Z_][a-zA-Z_0-9]*)[^a-zA-Z_0-9\(\)]*{",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
in_state = false;
if (m.Success)
{
// Go back to level 0, this is not a state
in_state = true;
current_statename = m.Groups["statename"].Captures[0].Value;
//Console.WriteLine("Current statename: " + current_statename);
cache =
//@"(?<s1>(?![a-zA-Z_]+)\s*)" + @"([a-zA-Z_]+)(?<s2>[^a-zA-Z_\(\)]*){",
Regex.Replace(cache,
@"(?<s1>(?![a-zA-Z_]+)\s*)" + @"(state\s+)?([a-zA-Z_][a-zA-Z_0-9]*)(?<s2>[^a-zA-Z_0-9\(\)]*){",
"${s1}${s2}",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
}
ret += cache;
cache = String.Empty;
}
if (ilevel == 0 && lastlevel == 1)
{
// 1 => 0: Remove last }
if (in_state == true)
{
cache = cache.Remove(cache.Length - 1, 1);
//cache = Regex.Replace(cache, "}$", String.Empty, RegexOptions.Multiline | RegexOptions.Singleline);
//Replace function names
// void dataserver(key query_id, string data) {
//cache = Regex.Replace(cache, @"([^a-zA-Z_]\s*)((?!if|switch|for)[a-zA-Z_]+\s*\([^\)]*\)[^{]*{)", "$1" + "<STATE>" + "$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
//Console.WriteLine("Replacing using statename: " + current_statename);
cache =
Regex.Replace(cache,
@"^(\s*)((?!(if|switch|for|while)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)",
@"$1public " + current_statename + "_event_$2",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
}
ret += cache;
cache = String.Empty;
in_state = true;
current_statename = String.Empty;
}
break;
}
lastlevel = ilevel;
}
ret += cache;
cache = String.Empty;
Script = ret;
ret = String.Empty;
foreach (string key in dataTypes.Keys)
{
string val;
dataTypes.TryGetValue(key, out val);
// Replace CAST - (integer) with (int)
Script =
Regex.Replace(Script, @"\(" + key + @"\)", @"(" + val + ")",
RegexOptions.Compiled | RegexOptions.Multiline);
// Replace return types and function variables - integer a() and f(integer a, integer a)
Script =
Regex.Replace(Script, @"(^|;|}|[\(,])(\s*)" + key + @"(\s+)", @"$1$2" + val + "$3",
RegexOptions.Compiled | RegexOptions.Multiline);
Script =
Regex.Replace(Script, @"(^|;|}|[\(,])(\s*)" + key + @"(\s*)[,]", @"$1$2" + val + "$3,",
RegexOptions.Compiled | RegexOptions.Multiline);
}
// Change jumps into goto's and prefix its label
Script =
Regex.Replace(Script,
@"(\W)jump\s+([a-zA-Z_][a-zA-Z_0-9]*)\s*;",
@"$1goto label_$2;", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
// and prefix labels so the do not clash with C#'s reserved words
Script =
Regex.Replace(Script,
@"@([a-zA-Z_][a-zA-Z_0-9]*)\s*;",
@"label_$1: ;", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
// Add "void" in front of functions that needs it
Script =
Regex.Replace(Script,
@"^(\s*public\s+)?((?!(if|switch|for)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)",
@"$1void $2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
// Replace <x,y,z> and <x,y,z,r>
Script =
Regex.Replace(Script, @"<([^,>;]*,[^,>;]*,[^,>;]*,[^,>;]*)>", @"new LSL_Types.Quaternion($1)",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
Script =
Regex.Replace(Script, @"<([^,>;)]*,[^,>;]*,[^,>;]*)>", @"new LSL_Types.Vector3($1)",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
// Replace List []'s
Script =
Regex.Replace(Script, @"\[([^\]]*)\]", @"new LSL_Types.list($1)",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
// Replace (string) to .ToString() //
Script =
Regex.Replace(Script, @"\(string\)\s*([a-zA-Z0-9_.]+(\s*\([^\)]*\))?)", @"$1.ToString()",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
Script =
Regex.Replace(Script, @"\((float|int)\)\s*([a-zA-Z0-9_.]+(\s*\([^\)]*\))?)", @"$1.Parse($2)",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
// Replace "state STATENAME" with "state("statename")"
Script =
Regex.Replace(Script, @"(state)\s+([^;\n\r]+)(;[\r\n\s])", "$1(\"$2\")$3",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
// REPLACE BACK QUOTES
foreach (string key in quotes.Keys)
{
string val;
quotes.TryGetValue(key, out val);
Script = Script.Replace(key, "\"" + val + "\"");
}
//System.Console.WriteLine(Script);
Return = String.Empty;// +
//"using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;";
//Return += String.Empty +
// "namespace SecondLife { ";
//Return += String.Empty +
// //"[Serializable] " +
// "public class Script : OpenSim.Region.ScriptEngine.Shared.LSL_BaseClass { ";
//Return += @"public Script() { } ";
Return += Script;
//Return += "} }\r\n";
quotes.Clear();
return Return;
}
}
}

View File

@@ -67,6 +67,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
private int m_SleepTime;
private int m_SaveTime;
private ThreadPriority m_Prio;
private bool m_Enabled = true;
// disable warning: need to keep a reference to XEngine.EventManager
// alive to avoid it being garbage collected
@@ -151,6 +152,19 @@ namespace OpenSim.Region.ScriptEngine.XEngine
//
public void Initialise(Scene scene, IConfigSource configSource)
{
m_ScriptConfig = configSource.Configs["XEngine"];
if (m_ScriptConfig == null)
{
// m_log.ErrorFormat("[XEngine] No script configuration found. Scripts disabled");
return;
}
m_Enabled = m_ScriptConfig.GetBoolean("Enabled", true);
if (!m_Enabled)
return;
AppDomain.CurrentDomain.AssemblyResolve +=
OnAssemblyResolve;
@@ -158,14 +172,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
scene.RegionInfo.RegionName);
m_Scene = scene;
m_ScriptConfig = configSource.Configs["XEngine"];
if (m_ScriptConfig == null)
{
m_log.ErrorFormat("[XEngine] No script configuration found. Scripts disabled");
return;
}
m_MinThreads = m_ScriptConfig.GetInt("MinThreads", 2);
m_MaxThreads = m_ScriptConfig.GetInt("MaxThreads", 100);
m_IdleTimeout = m_ScriptConfig.GetInt("IdleTimeout", 60);
@@ -220,6 +226,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
public void PostInitialise()
{
if (!m_Enabled)
return;
m_EventManager = new EventManager(this);
m_Compiler = new Compiler(this);
@@ -330,8 +339,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
get { return false; }
}
public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez)
public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine)
{
if (engine != "XEngine")
return;
Object[] parms = new Object[]{localID, itemID, script, startParam, postOnRez};
lock (m_CompileQueue)