diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | 200 |
1 files changed, 199 insertions, 1 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs index 9f753df..8d85b69 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | |||
@@ -32,6 +32,7 @@ using System; | |||
32 | 32 | ||
33 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | 33 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL |
34 | { | 34 | { |
35 | |||
35 | public class LSL2CSConverter | 36 | public class LSL2CSConverter |
36 | { | 37 | { |
37 | 38 | ||
@@ -41,6 +42,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
41 | //private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled); | 42 | //private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled); |
42 | private Dictionary<string, string> dataTypes = new Dictionary<string, string>(); | 43 | private Dictionary<string, string> dataTypes = new Dictionary<string, string>(); |
43 | private Dictionary<string, string> quotes = new Dictionary<string, string>(); | 44 | private Dictionary<string, string> quotes = new Dictionary<string, string>(); |
45 | private Dictionary<string, scriptEvents> state_events = new Dictionary<string, scriptEvents>(); | ||
44 | 46 | ||
45 | public LSL2CSConverter() | 47 | public LSL2CSConverter() |
46 | { | 48 | { |
@@ -294,8 +296,63 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
294 | } | 296 | } |
295 | 297 | ||
296 | 298 | ||
299 | // Finds out which events are in the script and writes a method call with the events in each state_entry event | ||
300 | |||
301 | // Note the (?:)? block optional, and not returning a group. Less greedy then .* | ||
302 | |||
303 | string[] eventmatches = new string[0]; | ||
304 | //Regex stateevents = new Regex(@"(public void )([^_]+)(_event_)([^\(]+)[\(\)]+\s+[^\{]\{"); | ||
305 | eventmatches = Regex.Split(Script, @"public void\s([^_]+)_event_([^\(]+)\((?:[a-zA-Z0-9\s_,\.\-]+)?\)+\s+[^\{]\{", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); | ||
306 | for (int pos = 0; pos<eventmatches.GetUpperBound(0);pos++) | ||
307 | { | ||
308 | pos++; // garbage | ||
309 | |||
310 | string statea = eventmatches[pos]; pos++; | ||
311 | string eventa = eventmatches[pos]; | ||
312 | scriptEvents storedEventsForState = scriptEvents.None; | ||
313 | if (state_events.ContainsKey(statea)) | ||
314 | { | ||
315 | storedEventsForState = state_events[statea]; | ||
316 | state_events[statea] |= convertnametoFlag(eventa); | ||
317 | } | ||
318 | else | ||
319 | { | ||
320 | state_events.Add(statea, convertnametoFlag(eventa)); | ||
321 | } | ||
322 | System.Console.WriteLine("State:" + statea + ", event: " + eventa); | ||
323 | } | ||
324 | System.Console.WriteLine("Matches:" + eventmatches.GetUpperBound(0)); | ||
297 | // Add namespace, class name and inheritance | 325 | // Add namespace, class name and inheritance |
298 | 326 | ||
327 | // Looking *ONLY* for state entry events | ||
328 | string scriptCopy = ""; | ||
329 | |||
330 | //Only match State_Entry events now | ||
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[\(\)]+\s+[^\{]\{)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); | ||
333 | int endloop = eventmatches.GetUpperBound(0); | ||
334 | for (int pos = 0; pos < endloop; pos++) | ||
335 | { | ||
336 | // Returns text before state entry match, | ||
337 | scriptCopy += eventmatches[pos]; pos++; | ||
338 | |||
339 | // Returns text of state entry match, | ||
340 | scriptCopy += eventmatches[pos]; pos++; | ||
341 | |||
342 | // 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++; | ||
344 | |||
345 | // adds the remainder of the script. | ||
346 | if ((pos + 1) == endloop) | ||
347 | { | ||
348 | pos++; | ||
349 | scriptCopy += eventmatches[pos++]; | ||
350 | } | ||
351 | |||
352 | } | ||
353 | // save modified script. | ||
354 | Script = scriptCopy; | ||
355 | //System.Console.WriteLine(Script); | ||
299 | Return = String.Empty;// + | 356 | Return = String.Empty;// + |
300 | //"using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;"; | 357 | //"using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;"; |
301 | 358 | ||
@@ -309,10 +366,151 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
309 | Return += Script; | 366 | Return += Script; |
310 | //Return += "} }\r\n"; | 367 | //Return += "} }\r\n"; |
311 | 368 | ||
312 | 369 | state_events.Clear(); | |
313 | quotes.Clear(); | 370 | quotes.Clear(); |
314 | 371 | ||
315 | return Return; | 372 | return Return; |
316 | } | 373 | } |
374 | public scriptEvents convertnametoFlag(string eventname) | ||
375 | { | ||
376 | switch (eventname) | ||
377 | { | ||
378 | case "attach": | ||
379 | return scriptEvents.attach; | ||
380 | //break; | ||
381 | // case "at_rot_target": | ||
382 | //return (long)scriptEvents.at_rot_target; | ||
383 | //break; | ||
384 | //case "at_target": | ||
385 | //return (long)scriptEvents.at_target; | ||
386 | //break; | ||
387 | //case "changed": | ||
388 | //return (long)scriptEvents.changed; | ||
389 | //break; | ||
390 | case "collision": | ||
391 | return scriptEvents.collision; | ||
392 | // break; | ||
393 | case "collision_end": | ||
394 | return scriptEvents.collision_end; | ||
395 | //break; | ||
396 | case "collision_start": | ||
397 | return scriptEvents.collision_start; | ||
398 | // break; | ||
399 | case "control": | ||
400 | return scriptEvents.control; | ||
401 | //break; | ||
402 | case "dataserver": | ||
403 | return scriptEvents.dataserver; | ||
404 | // break; | ||
405 | case "email": | ||
406 | return scriptEvents.email; | ||
407 | // break; | ||
408 | case "http_response": | ||
409 | return scriptEvents.http_response; | ||
410 | // break; | ||
411 | case "land_collision": | ||
412 | return scriptEvents.land_collision; | ||
413 | // break; | ||
414 | case "land_collision_end": | ||
415 | return scriptEvents.land_collision_end; | ||
416 | // break; | ||
417 | case "land_collision_start": | ||
418 | return scriptEvents.land_collision_start; | ||
419 | // break; | ||
420 | case "link_message": | ||
421 | return scriptEvents.link_message; | ||
422 | // break; | ||
423 | case "listen": | ||
424 | return scriptEvents.listen; | ||
425 | // break; | ||
426 | case "money": | ||
427 | return scriptEvents.money; | ||
428 | // break; | ||
429 | case "moving_end": | ||
430 | return scriptEvents.moving_end; | ||
431 | // break; | ||
432 | case "moving_start": | ||
433 | return scriptEvents.moving_start; | ||
434 | // break; | ||
435 | case "not_at_rot_target": | ||
436 | return scriptEvents.not_at_rot_target; | ||
437 | // break; | ||
438 | case "not_at_target": | ||
439 | return scriptEvents.not_at_target; | ||
440 | // break; | ||
441 | // case "no_sensor": | ||
442 | //return (long)scriptEvents.no_sensor; | ||
443 | //break; | ||
444 | //case "on_rez": | ||
445 | //return (long)scriptEvents.on_rez; | ||
446 | // break; | ||
447 | case "remote_data": | ||
448 | return scriptEvents.remote_data; | ||
449 | // break; | ||
450 | case "run_time_permissions": | ||
451 | return scriptEvents.run_time_permissions; | ||
452 | // break; | ||
453 | //case "sensor": | ||
454 | //return (long)scriptEvents.sensor; | ||
455 | // break; | ||
456 | case "state_entry": | ||
457 | return scriptEvents.state_entry; | ||
458 | // break; | ||
459 | case "state_exit": | ||
460 | return scriptEvents.state_exit; | ||
461 | // break; | ||
462 | case "timer": | ||
463 | return scriptEvents.timer; | ||
464 | // break; | ||
465 | case "touch": | ||
466 | return scriptEvents.touch; | ||
467 | // break; | ||
468 | case "touch_end": | ||
469 | return scriptEvents.touch_end; | ||
470 | // break; | ||
471 | case "touch_start": | ||
472 | return scriptEvents.touch_start; | ||
473 | // break; | ||
474 | case "object_rez": | ||
475 | return scriptEvents.object_rez; | ||
476 | default: | ||
477 | return 0; | ||
478 | //break; | ||
479 | } | ||
480 | //return 0; | ||
481 | } | ||
482 | } | ||
483 | |||
484 | [Flags] | ||
485 | public enum scriptEvents : int | ||
486 | { | ||
487 | None = 0, | ||
488 | attach = 1, | ||
489 | collision = 15, | ||
490 | collision_end = 32, | ||
491 | collision_start = 64, | ||
492 | control = 128, | ||
493 | dataserver = 256, | ||
494 | email = 512, | ||
495 | http_response = 1024, | ||
496 | land_collision = 2048, | ||
497 | land_collision_end = 4096, | ||
498 | land_collision_start = 8192, | ||
499 | link_message = 16384, | ||
500 | listen = 32768, | ||
501 | money = 65536, | ||
502 | moving_end = 131072, | ||
503 | moving_start = 262144, | ||
504 | not_at_rot_target = 524288, | ||
505 | not_at_target = 1048576, | ||
506 | remote_data = 8388608, | ||
507 | run_time_permissions = 268435456, | ||
508 | state_entry = 1073741824, | ||
509 | state_exit = 2, | ||
510 | timer = 4, | ||
511 | touch = 8, | ||
512 | touch_end = 536870912, | ||
513 | touch_start = 2097152, | ||
514 | object_rez = 4194304 | ||
317 | } | 515 | } |
318 | } \ No newline at end of file | 516 | } \ No newline at end of file |