aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/Engine.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/Engine.cs280
1 files changed, 140 insertions, 140 deletions
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/Engine.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/Engine.cs
index 8b957d3..012a00e 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/Engine.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/Engine.cs
@@ -1,140 +1,140 @@
1using System; 1using System;
2using System.Reflection; 2using System.Reflection;
3using System.Reflection.Emit; 3using System.Reflection.Emit;
4using System.Threading; 4using System.Threading;
5 5
6using OpenSim.Region.Scripting; 6using OpenSim.Region.Scripting;
7 7
8namespace OpenSim.ScriptEngines.LSL 8namespace OpenSim.ScriptEngines.LSL
9{ 9{
10 10
11 11
12 public class Engine 12 public class Engine
13 { 13 {
14 public void Start(ScriptInfo WorldAPI) 14 public void Start(ScriptInfo WorldAPI)
15 { 15 {
16 16
17 17
18 18
19 // Create Assembly Name 19 // Create Assembly Name
20 AssemblyName asmName = new AssemblyName(); 20 AssemblyName asmName = new AssemblyName();
21 asmName.Name = "TestAssembly"; 21 asmName.Name = "TestAssembly";
22 22
23 // Create Assembly 23 // Create Assembly
24 AssemblyBuilder asmBuilder = 24 AssemblyBuilder asmBuilder =
25 Thread.GetDomain().DefineDynamicAssembly 25 Thread.GetDomain().DefineDynamicAssembly
26 (asmName, AssemblyBuilderAccess.RunAndSave); 26 (asmName, AssemblyBuilderAccess.RunAndSave);
27 27
28 // Create a module (and save to disk) 28 // Create a module (and save to disk)
29 ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule 29 ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule
30 (asmName.Name, asmName.Name + ".dll"); 30 (asmName.Name, asmName.Name + ".dll");
31 31
32 // Create a Class (/Type) 32 // Create a Class (/Type)
33 TypeBuilder typeBuilder = modBuilder.DefineType( 33 TypeBuilder typeBuilder = modBuilder.DefineType(
34 "MyClass", 34 "MyClass",
35 TypeAttributes.Public, 35 TypeAttributes.Public,
36 typeof(object), 36 typeof(object),
37 new Type[] { typeof(LSL_CLRInterface.LSLScript) }); 37 new Type[] { typeof(LSL_CLRInterface.LSLScript) });
38 38
39 39
40 40
41 /* 41 /*
42 * Generate the IL itself 42 * Generate the IL itself
43 */ 43 */
44 44
45 GenerateIL(WorldAPI, typeBuilder); 45 GenerateIL(WorldAPI, typeBuilder);
46 46
47 47
48 /* 48 /*
49 * Done generating, create a type and run it. 49 * Done generating, create a type and run it.
50 */ 50 */
51 51
52 // Create type object for the class (after defining fields and methods) 52 // Create type object for the class (after defining fields and methods)
53 Type type = typeBuilder.CreateType(); 53 Type type = typeBuilder.CreateType();
54 54
55 asmBuilder.Save("TestAssembly.dll"); 55 asmBuilder.Save("TestAssembly.dll");
56 56
57 // Create an instance we can play with 57 // Create an instance we can play with
58 //LSLScript hello = (LSLScript)Activator.CreateInstance(type); 58 //LSLScript hello = (LSLScript)Activator.CreateInstance(type);
59 LSL_CLRInterface.LSLScript MyScript = (LSL_CLRInterface.LSLScript)Activator.CreateInstance(type); 59 LSL_CLRInterface.LSLScript MyScript = (LSL_CLRInterface.LSLScript)Activator.CreateInstance(type);
60 60
61 // Play with it 61 // Play with it
62 MyScript.event_state_entry("Test"); 62 MyScript.event_state_entry("Test");
63 } 63 }
64 64
65 private void GenerateIL(ScriptInfo WorldAPI, TypeBuilder typeBuilder) 65 private void GenerateIL(ScriptInfo WorldAPI, TypeBuilder typeBuilder)
66 { 66 {
67 67
68 68
69 // For debug 69 // For debug
70 LSO_Parser LSOP = new LSO_Parser(); 70 LSO_Parser LSOP = new LSO_Parser();
71 LSOP.ParseFile("LSO\\CloseToDefault.lso", WorldAPI, ref typeBuilder); 71 LSOP.ParseFile("LSO\\CloseToDefault.lso", WorldAPI, ref typeBuilder);
72 return; 72 return;
73 73
74 74
75 // Override a Method / Function 75 // Override a Method / Function
76 MethodBuilder methodBuilder = typeBuilder.DefineMethod("event_state_entry", 76 MethodBuilder methodBuilder = typeBuilder.DefineMethod("event_state_entry",
77 MethodAttributes.Private | MethodAttributes.Virtual, 77 MethodAttributes.Private | MethodAttributes.Virtual,
78 typeof(void), 78 typeof(void),
79 new Type[] { typeof(object) }); 79 new Type[] { typeof(object) });
80 80
81 typeBuilder.DefineMethodOverride(methodBuilder, 81 typeBuilder.DefineMethodOverride(methodBuilder,
82 typeof(LSL_CLRInterface.LSLScript).GetMethod("event_state_entry")); 82 typeof(LSL_CLRInterface.LSLScript).GetMethod("event_state_entry"));
83 83
84 // Create the IL generator 84 // Create the IL generator
85 ILGenerator il = methodBuilder.GetILGenerator(); 85 ILGenerator il = methodBuilder.GetILGenerator();
86 86
87 87
88 /* 88 /*
89 * TRY 89 * TRY
90 */ 90 */
91 il.BeginExceptionBlock(); 91 il.BeginExceptionBlock();
92 92
93 // Push "Hello World!" string to stack 93 // Push "Hello World!" string to stack
94 il.Emit(OpCodes.Ldstr, "Hello World!"); 94 il.Emit(OpCodes.Ldstr, "Hello World!");
95 95
96 // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!"); 96 // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!");
97 il.Emit(OpCodes.Call, typeof(Console).GetMethod 97 il.Emit(OpCodes.Call, typeof(Console).GetMethod
98 ("WriteLine", new Type[] { typeof(string) })); 98 ("WriteLine", new Type[] { typeof(string) }));
99 99
100 //il.EmitCall(OpCodes.Callvirt 100 //il.EmitCall(OpCodes.Callvirt
101 //il.Emit(OpCodes.Call, typeof(WorldAPI).GetMethod 101 //il.Emit(OpCodes.Call, typeof(WorldAPI).GetMethod
102 //("TestFunction")); 102 //("TestFunction"));
103 103
104 104
105 //il.ThrowException(typeof(NotSupportedException)); 105 //il.ThrowException(typeof(NotSupportedException));
106 106
107 107
108 /* 108 /*
109 * CATCH 109 * CATCH
110 */ 110 */
111 il.BeginCatchBlock(typeof(Exception)); 111 il.BeginCatchBlock(typeof(Exception));
112 112
113 // Push "Hello World!" string to stack 113 // Push "Hello World!" string to stack
114 il.Emit(OpCodes.Ldstr, "Something went wrong: "); 114 il.Emit(OpCodes.Ldstr, "Something went wrong: ");
115 115
116 //call void [mscorlib]System.Console::WriteLine(string) 116 //call void [mscorlib]System.Console::WriteLine(string)
117 il.Emit(OpCodes.Call, typeof(Console).GetMethod 117 il.Emit(OpCodes.Call, typeof(Console).GetMethod
118 ("Write", new Type[] { typeof(string) })); 118 ("Write", new Type[] { typeof(string) }));
119 119
120 //callvirt instance string [mscorlib]System.Exception::get_Message() 120 //callvirt instance string [mscorlib]System.Exception::get_Message()
121 il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod 121 il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod
122 ("get_Message")); 122 ("get_Message"));
123 123
124 //call void [mscorlib]System.Console::WriteLine(string) 124 //call void [mscorlib]System.Console::WriteLine(string)
125 il.Emit(OpCodes.Call, typeof(Console).GetMethod 125 il.Emit(OpCodes.Call, typeof(Console).GetMethod
126 ("WriteLine", new Type[] { typeof(string) })); 126 ("WriteLine", new Type[] { typeof(string) }));
127 127
128 /* 128 /*
129 * END TRY 129 * END TRY
130 */ 130 */
131 il.EndExceptionBlock(); 131 il.EndExceptionBlock();
132 132
133 133
134 // Push "Return from current method, with return value if present" to stack 134 // Push "Return from current method, with return value if present" to stack
135 il.Emit(OpCodes.Ret); 135 il.Emit(OpCodes.Ret);
136 136
137 137
138 } 138 }
139 } 139 }
140} 140}