diff options
author | Teravus Ovares | 2008-04-23 22:04:45 +0000 |
---|---|---|
committer | Teravus Ovares | 2008-04-23 22:04:45 +0000 |
commit | e108133d91099a8c3667a8a7999681872a752331 (patch) | |
tree | f5e8355956df1ed02f3db20b58c98895db45e8d1 /OpenSim/Region/ScriptEngine/DotNetEngine | |
parent | fix for mantis 1036 (diff) | |
download | opensim-SC-e108133d91099a8c3667a8a7999681872a752331.zip opensim-SC-e108133d91099a8c3667a8a7999681872a752331.tar.gz opensim-SC-e108133d91099a8c3667a8a7999681872a752331.tar.bz2 opensim-SC-e108133d91099a8c3667a8a7999681872a752331.tar.xz |
* Fixes lsl scripts with no state_entry event at all
* Fixes event reporting on states with no state_entry in lsl scripts.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine')
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs index 0025b26..05838cc 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | |||
@@ -331,6 +331,30 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
331 | // Note the whole regex is a group, then we have the state this entry belongs to. | 331 | // Note the whole regex is a group, then we have the state this entry belongs to. |
332 | eventmatches = Regex.Split(Script, @"(public void\s([^_]+)_event_state_entry[\(\)](?:[^\{]+)?\{)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); | 332 | eventmatches = Regex.Split(Script, @"(public void\s([^_]+)_event_state_entry[\(\)](?:[^\{]+)?\{)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); |
333 | int endloop = eventmatches.GetUpperBound(0); | 333 | int endloop = eventmatches.GetUpperBound(0); |
334 | |||
335 | // Add all the states to a list of | ||
336 | List<string> unUsedStates = new List<string>(); | ||
337 | foreach (string state in state_events.Keys) | ||
338 | { | ||
339 | unUsedStates.Add(state); | ||
340 | } | ||
341 | |||
342 | // If endloop is 0, then there are no state entry events in the entire script. | ||
343 | // Stick a default state entry in there. | ||
344 | if (endloop == 0) | ||
345 | { | ||
346 | if (state_events.ContainsKey("default")) | ||
347 | { | ||
348 | scriptCopy = "\r\n// programmatically added this state entry event.\r\n\r\npublic void default_event_state_entry() {\r\n\tosSetStateEvents((int)" + (int)state_events["default"] + ");\r\n }\r\n\r\n " + Script; | ||
349 | unUsedStates.Remove("default"); | ||
350 | } | ||
351 | else | ||
352 | { | ||
353 | throw new Exception("You must define a default state. Compile failed. See LSL documentation for more details."); | ||
354 | } | ||
355 | } | ||
356 | |||
357 | // Loop over state entry events and rewrite the first line to define the events the state listens for. | ||
334 | for (int pos = 0; pos < endloop; pos++) | 358 | for (int pos = 0; pos < endloop; pos++) |
335 | { | 359 | { |
336 | // Returns text before state entry match, | 360 | // Returns text before state entry match, |
@@ -342,6 +366,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
342 | // Returns which state we're matching and writes a method call to the end of the above state_entry | 366 | // Returns which state we're matching and writes a method call to the end of the above state_entry |
343 | scriptCopy += "\r\n\t\tosSetStateEvents((int)" + (int)state_events[eventmatches[pos]] + ");"; //pos++; | 367 | scriptCopy += "\r\n\t\tosSetStateEvents((int)" + (int)state_events[eventmatches[pos]] + ");"; //pos++; |
344 | 368 | ||
369 | // Remove the state from the unused list. There might be more states matched then defined, so we | ||
370 | // check if the state was defined first | ||
371 | if (unUsedStates.Contains(eventmatches[pos])) | ||
372 | unUsedStates.Remove(eventmatches[pos]); | ||
373 | |||
345 | // adds the remainder of the script. | 374 | // adds the remainder of the script. |
346 | if ((pos + 1) == endloop) | 375 | if ((pos + 1) == endloop) |
347 | { | 376 | { |
@@ -350,6 +379,15 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
350 | } | 379 | } |
351 | 380 | ||
352 | } | 381 | } |
382 | |||
383 | // states with missing state_entry blocks won't publish their events, | ||
384 | // so, to fix that we write a state entry with only the event publishing method for states missing a state_entry event | ||
385 | foreach (string state in unUsedStates) | ||
386 | { | ||
387 | // Write the remainder states out into a blank state entry with the event setting routine | ||
388 | scriptCopy = "\r\n// programmatically added this state entry event.\r\n\r\npublic void " + state + "_event_state_entry() {\r\n\tosSetStateEvents((int)" + (int)state_events[state] + ");\r\n}\r\n\r\n " + scriptCopy; | ||
389 | } | ||
390 | |||
353 | // save modified script. | 391 | // save modified script. |
354 | Script = scriptCopy; | 392 | Script = scriptCopy; |
355 | //System.Console.WriteLine(Script); | 393 | //System.Console.WriteLine(Script); |
@@ -365,7 +403,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
365 | //Return += @"public Script() { } "; | 403 | //Return += @"public Script() { } "; |
366 | Return += Script; | 404 | Return += Script; |
367 | //Return += "} }\r\n"; | 405 | //Return += "} }\r\n"; |
368 | 406 | unUsedStates.Clear(); | |
369 | state_events.Clear(); | 407 | state_events.Clear(); |
370 | quotes.Clear(); | 408 | quotes.Clear(); |
371 | 409 | ||