aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/Scripting/Engines/LSLEngine/LSLHandler/Engine.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/Scripting/Engines/LSLEngine/LSLHandler/Engine.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/Scripting/Engines/LSLEngine/LSLHandler/Engine.cs228
1 files changed, 0 insertions, 228 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
deleted file mode 100644
index 5cd1f71..0000000
--- a/OpenSim/Region/Environment/Scenes/Scripting/Engines/LSLEngine/LSLHandler/Engine.cs
+++ /dev/null
@@ -1,228 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28/* Original code: Tedd Hansen */
29using System;
30 using System.Reflection;
31 using System.Reflection.Emit;
32 using System.Threading;
33
34 namespace OpenSim.Region.Scripting.LSL
35 {
36
37
38 public class Engine
39 {
40 //private string LSO_FileName = @"LSO\AdditionTest.lso";
41 private string LSO_FileName;// = @"LSO\CloseToDefault.lso";
42 AppDomain appDomain;
43
44 public void Start(string FileName)
45 {
46 LSO_FileName = FileName;
47
48
49 //appDomain = AppDomain.CreateDomain("AlternateAppDomain");
50 appDomain = Thread.GetDomain();
51
52 // Create Assembly Name
53 AssemblyName asmName = new AssemblyName();
54 asmName.Name = System.IO.Path.GetFileNameWithoutExtension(LSO_FileName);
55 //asmName.Name = "TestAssembly";
56
57 string DLL_FileName = asmName.Name + ".dll";
58 string DLL_FileName_WithPath = System.IO.Path.GetDirectoryName(FileName) + @"\" + DLL_FileName;
59
60 Common.SendToLog("LSO File Name: " + System.IO.Path.GetFileName(FileName));
61 Common.SendToLog("Assembly name: " + asmName.Name);
62 Common.SendToLog("Assembly File Name: " + asmName.Name + ".dll");
63 Common.SendToLog("Starting processing of LSL ByteCode...");
64 Common.SendToLog("");
65
66
67
68 // Create Assembly
69 AssemblyBuilder asmBuilder = appDomain.DefineDynamicAssembly(
70 asmName,
71 AssemblyBuilderAccess.RunAndSave
72 );
73 //// Create Assembly
74 //AssemblyBuilder asmBuilder =
75 // Thread.GetDomain().DefineDynamicAssembly
76 //(asmName, AssemblyBuilderAccess.RunAndSave);
77
78 // Create a module (and save to disk)
79 ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule
80 (asmName.Name,
81 DLL_FileName);
82
83 //Common.SendToDebug("asmName.Name is still \"" + asmName.Name + "\"");
84 // Create a Class (/Type)
85 TypeBuilder typeBuilder = modBuilder.DefineType(
86 "LSL_ScriptObject",
87 TypeAttributes.Public | TypeAttributes.BeforeFieldInit);
88 //,
89 // typeof());
90 //, typeof(LSL_BuiltIn_Commands_Interface));
91 //,
92 // typeof(object),
93 // new Type[] { typeof(LSL_CLRInterface.LSLScript) });
94
95
96 if (Common.IL_CreateConstructor)
97 IL_CREATE_CONSTRUCTOR(typeBuilder);
98
99
100 /*
101 * Generate the IL itself
102 */
103
104 LSO_Parser LSOP = new LSO_Parser();
105 LSOP.ParseFile(LSO_FileName, typeBuilder);
106
107 /*
108 * Done generating. Create a type and run it.
109 */
110
111
112
113 Common.SendToLog("Attempting to compile assembly...");
114 // Compile it
115 Type type = typeBuilder.CreateType();
116 Common.SendToLog("Compilation successful!");
117
118 Common.SendToLog("Saving assembly: " + DLL_FileName);
119 asmBuilder.Save(DLL_FileName);
120
121
122 Common.SendToLog("Creating an instance of new assembly...");
123 // Create an instance we can play with
124 //LSLScript hello = (LSLScript)Activator.CreateInstance(type);
125 //LSL_CLRInterface.LSLScript MyScript = (LSL_CLRInterface.LSLScript)Activator.CreateInstance(type);
126 object MyScript = (object)Activator.CreateInstance(type);
127
128
129 Common.SendToLog("");
130
131 System.Reflection.MemberInfo[] Members = type.GetMembers();
132
133 Common.SendToLog("Members of assembly " + type.ToString () + ":");
134 foreach (MemberInfo member in Members )
135 Common.SendToLog(member.ToString());
136
137
138 // Play with it
139 //MyScript.event_state_entry("Test");
140 object[] args = { null } ;
141 //System.Collections.Generic.List<string> Functions = (System.Collections.Generic.List<string>)type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, MyScript, null);
142
143 string[] ret = { };
144 if (Common.IL_CreateFunctionList)
145 ret = (string[])type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, MyScript, null);
146
147 foreach (string s in ret)
148 {
149 Common.SendToLog("");
150 Common.SendToLog("*** Executing LSL Server Event: " + s);
151 //object test = type.GetMember(s);
152 //object runner = type.InvokeMember(s, BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, MyScript, args);
153 //runner();
154 //objBooks_Late = type.InvokeMember(s, BindingFlags.CreateInstance, null, objApp_Late, null);
155 type.InvokeMember(s, BindingFlags.InvokeMethod, null, MyScript, new object[] { "Test" });
156
157 }
158
159 }
160
161
162 private static void IL_CREATE_CONSTRUCTOR(TypeBuilder typeBuilder)
163 {
164
165
166 Common.SendToDebug("IL_CREATE_CONSTRUCTOR()");
167 //ConstructorBuilder constructor = typeBuilder.DefineConstructor(
168 // MethodAttributes.Public,
169 // CallingConventions.Standard,
170 // new Type[0]);
171 ConstructorBuilder constructor = typeBuilder.DefineConstructor(
172 MethodAttributes.Public |
173 MethodAttributes.SpecialName |
174 MethodAttributes.RTSpecialName,
175 CallingConventions.Standard,
176 new Type[0]);
177
178 //Define the reflection ConstructorInfor for System.Object
179 ConstructorInfo conObj = typeof(object).GetConstructor(new Type[0]);
180
181 //call constructor of base object
182 ILGenerator il = constructor.GetILGenerator();
183
184 Common.SendToDebug("IL_CREATE_CONSTRUCTOR: Creating global: UInt32 State = 0;");
185 string FieldName;
186 // Create state object
187 FieldName = "State";
188 FieldBuilder State_fb = typeBuilder.DefineField(
189 FieldName,
190 typeof(UInt32),
191 FieldAttributes.Public);
192 il.Emit(OpCodes.Ldarg_0);
193 il.Emit(OpCodes.Ldc_I4, 0);
194 il.Emit(OpCodes.Stfld, State_fb);
195
196
197 Common.SendToDebug("IL_CREATE_CONSTRUCTOR: Creating global: LSL_BuiltIn_Commands_TestImplementation LSL_BuiltIns = New LSL_BuiltIn_Commands_TestImplementation();");
198 //Type objType1 = typeof(object);
199 Type objType1 = typeof(LSL_BuiltIn_Commands_TestImplementation);
200
201 FieldName = "LSL_BuiltIns";
202 FieldBuilder LSL_BuiltIns_fb = typeBuilder.DefineField(
203 FieldName,
204 objType1,
205 FieldAttributes.Public);
206
207 //LSL_BuiltIn_Commands_TestImplementation _ti = new LSL_BuiltIn_Commands_TestImplementation();
208 il.Emit(OpCodes.Ldarg_0);
209 //il.Emit(OpCodes.Ldstr, "Test 123");
210 il.Emit(OpCodes.Newobj, objType1.GetConstructor(new Type[] { }));
211 il.Emit(OpCodes.Stfld, LSL_BuiltIns_fb);
212
213 il.Emit(OpCodes.Ldarg_0);
214 il.Emit(OpCodes.Call, conObj);
215
216
217
218 ////il.Emit(OpCodes.Newobj, typeof(UInt32));
219 //il.Emit(OpCodes.Starg_0);
220 //// Create LSL function library
221 //FieldBuilder LSL_BuiltIns_fb = typeBuilder.DefineField("LSL_BuiltIns", typeof(LSL_BuiltIn_Commands_Interface), FieldAttributes.Public);
222 //il.Emit(OpCodes.Newobj, typeof(LSL_BuiltIn_Commands_Interface));
223 //il.Emit(OpCodes.Stloc_1);
224
225 il.Emit(OpCodes.Ret);
226 }
227 }
228 }