aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs254
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs25
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs39
3 files changed, 244 insertions, 74 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
index 2942104..7c07e15 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
@@ -120,33 +120,110 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
120 /// 120 ///
121 /// </summary> 121 /// </summary>
122 /// <param name="fname">The name of the function to invoke</param> 122 /// <param name="fname">The name of the function to invoke</param>
123 /// <param name="fname">List of parameters</param> 123 /// <param name="parms">List of parameters</param>
124 /// <returns>string result of the invocation</returns> 124 /// <returns>string result of the invocation</returns>
125 public string modInvokeS(string fname, params object[] parms) 125 public void modInvokeN(string fname, params object[] parms)
126 { 126 {
127 Type returntype = m_comms.LookupReturnType(fname); 127 Type returntype = m_comms.LookupReturnType(fname);
128 if (returntype != typeof(string)) 128 if (returntype != typeof(string))
129 MODError(String.Format("return type mismatch for {0}",fname)); 129 MODError(String.Format("return type mismatch for {0}",fname));
130 130
131 return (string)modInvoke(fname,parms); 131 modInvoke(fname,parms);
132 } 132 }
133 133
134 public int modInvokeI(string fname, params object[] parms) 134 public LSL_String modInvokeS(string fname, params object[] parms)
135 {
136 Type returntype = m_comms.LookupReturnType(fname);
137 if (returntype != typeof(string))
138 MODError(String.Format("return type mismatch for {0}",fname));
139
140 string result = (string)modInvoke(fname,parms);
141 return new LSL_String(result);
142 }
143
144 public LSL_Integer modInvokeI(string fname, params object[] parms)
135 { 145 {
136 Type returntype = m_comms.LookupReturnType(fname); 146 Type returntype = m_comms.LookupReturnType(fname);
137 if (returntype != typeof(int)) 147 if (returntype != typeof(int))
138 MODError(String.Format("return type mismatch for {0}",fname)); 148 MODError(String.Format("return type mismatch for {0}",fname));
139 149
140 return (int)modInvoke(fname,parms); 150 int result = (int)modInvoke(fname,parms);
151 return new LSL_Integer(result);
141 } 152 }
142 153
143 public float modInvokeF(string fname, params object[] parms) 154 public LSL_Float modInvokeF(string fname, params object[] parms)
144 { 155 {
145 Type returntype = m_comms.LookupReturnType(fname); 156 Type returntype = m_comms.LookupReturnType(fname);
146 if (returntype != typeof(float)) 157 if (returntype != typeof(float))
147 MODError(String.Format("return type mismatch for {0}",fname)); 158 MODError(String.Format("return type mismatch for {0}",fname));
148 159
149 return (float)modInvoke(fname,parms); 160 float result = (float)modInvoke(fname,parms);
161 return new LSL_Float(result);
162 }
163
164 public LSL_Key modInvokeK(string fname, params object[] parms)
165 {
166 Type returntype = m_comms.LookupReturnType(fname);
167 if (returntype != typeof(UUID))
168 MODError(String.Format("return type mismatch for {0}",fname));
169
170 UUID result = (UUID)modInvoke(fname,parms);
171 return new LSL_Key(result.ToString());
172 }
173
174 public LSL_Vector modInvokeV(string fname, params object[] parms)
175 {
176 Type returntype = m_comms.LookupReturnType(fname);
177 if (returntype != typeof(OpenMetaverse.Vector3))
178 MODError(String.Format("return type mismatch for {0}",fname));
179
180 OpenMetaverse.Vector3 result = (OpenMetaverse.Vector3)modInvoke(fname,parms);
181 return new LSL_Vector(result.X,result.Y,result.Z);
182 }
183
184 public LSL_Rotation modInvokeR(string fname, params object[] parms)
185 {
186 Type returntype = m_comms.LookupReturnType(fname);
187 if (returntype != typeof(OpenMetaverse.Quaternion))
188 MODError(String.Format("return type mismatch for {0}",fname));
189
190 OpenMetaverse.Quaternion result = (OpenMetaverse.Quaternion)modInvoke(fname,parms);
191 return new LSL_Rotation(result.X,result.Y,result.Z,result.W);
192 }
193
194 public LSL_List modInvokeL(string fname, params object[] parms)
195 {
196 Type returntype = m_comms.LookupReturnType(fname);
197 if (returntype != typeof(object[]))
198 MODError(String.Format("return type mismatch for {0}",fname));
199
200 object[] result = (object[])modInvoke(fname,parms);
201 object[] llist = new object[result.Length];
202 for (int i = 0; i < result.Length; i++)
203 {
204 if (result[i] is string)
205 llist[i] = new LSL_String((string)result[i]);
206 else if (result[i] is int)
207 llist[i] = new LSL_Integer((int)result[i]);
208 else if (result[i] is float)
209 llist[i] = new LSL_Float((float)result[i]);
210 else if (result[i] is OpenMetaverse.Vector3)
211 {
212 OpenMetaverse.Vector3 vresult = (OpenMetaverse.Vector3)result[i];
213 llist[i] = new LSL_Vector(vresult.X,vresult.Y,vresult.Z);
214 }
215 else if (result[i] is OpenMetaverse.Quaternion)
216 {
217 OpenMetaverse.Quaternion qresult = (OpenMetaverse.Quaternion)result[i];
218 llist[i] = new LSL_Rotation(qresult.X,qresult.Y,qresult.Z,qresult.W);
219 }
220 else
221 {
222 MODError(String.Format("unknown list element returned by {0}",fname));
223 }
224 }
225
226 return new LSL_List(llist);
150 } 227 }
151 228
152 /// <summary> 229 /// <summary>
@@ -168,63 +245,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
168 MODError(String.Format("wrong number of parameters to function {0}",fname)); 245 MODError(String.Format("wrong number of parameters to function {0}",fname));
169 246
170 object[] convertedParms = new object[parms.Length]; 247 object[] convertedParms = new object[parms.Length];
171
172 for (int i = 0; i < parms.Length; i++) 248 for (int i = 0; i < parms.Length; i++)
173 { 249 convertedParms[i] = ConvertFromLSL(parms[i],signature[i]);
174 if (parms[i] is LSL_String)
175 {
176 if (signature[i] != typeof(string))
177 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
178 250
179 convertedParms[i] = (string)(LSL_String)parms[i]; 251 // now call the function, the contract with the function is that it will always return
180 } 252 // non-null but don't trust it completely
181 else if (parms[i] is LSL_Integer) 253 try
182 { 254 {
183 if (signature[i] != typeof(int)) 255 object result = m_comms.InvokeOperation(m_host.UUID, m_itemID, fname, convertedParms);
184 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); 256 if (result != null)
185 257 return result;
186 convertedParms[i] = (int)(LSL_Integer)parms[i];
187 }
188 else if (parms[i] is LSL_Float)
189 {
190 if (signature[i] != typeof(float))
191 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
192
193 convertedParms[i] = (float)(LSL_Float)parms[i];
194 }
195 else if (parms[i] is LSL_Key)
196 {
197 if (signature[i] != typeof(string))
198 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
199
200 convertedParms[i] = (string)(LSL_Key)parms[i];
201 }
202 else if (parms[i] is LSL_Rotation)
203 {
204 if (signature[i] != typeof(string))
205 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
206
207 convertedParms[i] = (string)(LSL_Rotation)parms[i];
208 }
209 else if (parms[i] is LSL_Vector)
210 {
211 if (signature[i] != typeof(string))
212 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
213
214 convertedParms[i] = (string)(LSL_Vector)parms[i];
215 }
216 else
217 {
218 if (signature[i] != parms[i].GetType())
219 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
220 258
221 convertedParms[i] = parms[i]; 259 MODError(String.Format("Invocation of {0} failed; null return value",fname));
222 } 260 }
261 catch (Exception e)
262 {
263 MODError(String.Format("Invocation of {0} failed; {1}",fname,e.Message));
223 } 264 }
224 265
225 return m_comms.InvokeOperation(m_itemID,fname,convertedParms); 266 return null;
226 } 267 }
227 268
269 /// <summary>
270 /// Send a command to functions registered on an event
271 /// </summary>
228 public string modSendCommand(string module, string command, string k) 272 public string modSendCommand(string module, string command, string k)
229 { 273 {
230 if (!m_MODFunctionsEnabled) 274 if (!m_MODFunctionsEnabled)
@@ -239,5 +283,101 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
239 283
240 return req.ToString(); 284 return req.ToString();
241 } 285 }
286
287 /// <summary>
288 /// </summary>
289 protected object ConvertFromLSL(object lslparm, Type type)
290 {
291 // ---------- String ----------
292 if (lslparm is LSL_String)
293 {
294 if (type == typeof(string))
295 return (string)(LSL_String)lslparm;
296
297 // Need to check for UUID since keys are often treated as strings
298 if (type == typeof(UUID))
299 return new UUID((string)(LSL_String)lslparm);
300 }
301
302 // ---------- Integer ----------
303 else if (lslparm is LSL_Integer)
304 {
305 if (type == typeof(int))
306 return (int)(LSL_Integer)lslparm;
307 }
308
309 // ---------- Float ----------
310 else if (lslparm is LSL_Float)
311 {
312 if (type == typeof(float))
313 return (float)(LSL_Float)lslparm;
314 }
315
316 // ---------- Key ----------
317 else if (lslparm is LSL_Key)
318 {
319 if (type == typeof(UUID))
320 return new UUID((LSL_Key)lslparm);
321 }
322
323 // ---------- Rotation ----------
324 else if (lslparm is LSL_Rotation)
325 {
326 if (type == typeof(OpenMetaverse.Quaternion))
327 {
328 LSL_Rotation rot = (LSL_Rotation)lslparm;
329 return new OpenMetaverse.Quaternion((float)rot.x,(float)rot.y,(float)rot.z,(float)rot.s);
330 }
331 }
332
333 // ---------- Vector ----------
334 else if (lslparm is LSL_Vector)
335 {
336 if (type == typeof(OpenMetaverse.Vector3))
337 {
338 LSL_Vector vect = (LSL_Vector)lslparm;
339 return new OpenMetaverse.Vector3((float)vect.x,(float)vect.y,(float)vect.z);
340 }
341 }
342
343 // ---------- List ----------
344 else if (lslparm is LSL_List)
345 {
346 if (type == typeof(object[]))
347 {
348 object[] plist = (lslparm as LSL_List).Data;
349 object[] result = new object[plist.Length];
350 for (int i = 0; i < plist.Length; i++)
351 {
352 if (plist[i] is LSL_String)
353 result[i] = (string)(LSL_String)plist[i];
354 else if (plist[i] is LSL_Integer)
355 result[i] = (int)(LSL_Integer)plist[i];
356 else if (plist[i] is LSL_Float)
357 result[i] = (float)(LSL_Float)plist[i];
358 else if (plist[i] is LSL_Key)
359 result[i] = new UUID((LSL_Key)plist[i]);
360 else if (plist[i] is LSL_Rotation)
361 {
362 LSL_Rotation rot = (LSL_Rotation)plist[i];
363 result[i] = new OpenMetaverse.Quaternion((float)rot.x,(float)rot.y,(float)rot.z,(float)rot.s);
364 }
365 else if (plist[i] is LSL_Vector)
366 {
367 LSL_Vector vect = (LSL_Vector)plist[i];
368 result[i] = new OpenMetaverse.Vector3((float)vect.x,(float)vect.y,(float)vect.z);
369 }
370 else
371 MODError("unknown LSL list element type");
372 }
373
374 return result;
375 }
376 }
377
378 MODError(String.Format("parameter type mismatch; expecting {0}",type.Name));
379 return null;
380 }
381
242 } 382 }
243} 383}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
index 756a59f..aa78aaa 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
@@ -28,26 +28,27 @@
28using System.Collections; 28using System.Collections;
29using OpenSim.Region.ScriptEngine.Interfaces; 29using OpenSim.Region.ScriptEngine.Interfaces;
30 30
31using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; 31using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
32using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; 32using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
33using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; 33using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
34using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; 34using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
35using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
35using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; 36using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
36using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; 37using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
37using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
38 38
39namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces 39namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
40{ 40{
41 public interface IMOD_Api 41 public interface IMOD_Api
42 { 42 {
43 // Invocation functions 43 // Invocation functions
44 string modInvokeS(string fname, params object[] parms); 44 void modInvokeN(string fname, params object[] parms);
45 int modInvokeI(string fname, params object[] parms); 45 LSL_String modInvokeS(string fname, params object[] parms);
46 float modInvokeF(string fname, params object[] parms); 46 LSL_Integer modInvokeI(string fname, params object[] parms);
47 // vector modInvokeV(string fname, params object[] parms); 47 LSL_Float modInvokeF(string fname, params object[] parms);
48 // rotation modInvokeV(string fname, params object[] parms); 48 LSL_Key modInvokeK(string fname, params object[] parms);
49 // key modInvokeK(string fname, params object[] parms); 49 LSL_Vector modInvokeV(string fname, params object[] parms);
50 // list modInvokeL(string fname, params object[] parms); 50 LSL_Rotation modInvokeR(string fname, params object[] parms);
51 LSL_List modInvokeL(string fname, params object[] parms);
51 52
52 //Module functions 53 //Module functions
53 string modSendCommand(string modules, string command, string k); 54 string modSendCommand(string modules, string command, string k);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs
index 04b7f14..1c47138 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs
@@ -39,10 +39,14 @@ using integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
39using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; 39using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
40using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; 40using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
41using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; 41using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
42using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; 42
43using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
44using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; 43using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
45using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; 44using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
45using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
46using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
47using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
48using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
49using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
46 50
47namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase 51namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
48{ 52{
@@ -58,21 +62,46 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
58 m_MOD_Functions = (IMOD_Api)api; 62 m_MOD_Functions = (IMOD_Api)api;
59 } 63 }
60 64
61 public string modInvokeS(string fname, params object[] parms) 65 public void modInvokeN(string fname, params object[] parms)
66 {
67 m_MOD_Functions.modInvokeN(fname, parms);
68 }
69
70 public LSL_String modInvokeS(string fname, params object[] parms)
62 { 71 {
63 return m_MOD_Functions.modInvokeS(fname, parms); 72 return m_MOD_Functions.modInvokeS(fname, parms);
64 } 73 }
65 74
66 public int modInvokeI(string fname, params object[] parms) 75 public LSL_Integer modInvokeI(string fname, params object[] parms)
67 { 76 {
68 return m_MOD_Functions.modInvokeI(fname, parms); 77 return m_MOD_Functions.modInvokeI(fname, parms);
69 } 78 }
70 79
71 public float modInvokeF(string fname, params object[] parms) 80 public LSL_Float modInvokeF(string fname, params object[] parms)
72 { 81 {
73 return m_MOD_Functions.modInvokeF(fname, parms); 82 return m_MOD_Functions.modInvokeF(fname, parms);
74 } 83 }
75 84
85 public LSL_Key modInvokeK(string fname, params object[] parms)
86 {
87 return m_MOD_Functions.modInvokeK(fname, parms);
88 }
89
90 public LSL_Vector modInvokeV(string fname, params object[] parms)
91 {
92 return m_MOD_Functions.modInvokeV(fname, parms);
93 }
94
95 public LSL_Rotation modInvokeR(string fname, params object[] parms)
96 {
97 return m_MOD_Functions.modInvokeR(fname, parms);
98 }
99
100 public LSL_List modInvokeL(string fname, params object[] parms)
101 {
102 return m_MOD_Functions.modInvokeL(fname, parms);
103 }
104
76 public string modSendCommand(string module, string command, string k) 105 public string modSendCommand(string module, string command, string k)
77 { 106 {
78 return m_MOD_Functions.modSendCommand(module, command, k); 107 return m_MOD_Functions.modSendCommand(module, command, k);