aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared
diff options
context:
space:
mode:
authorMic Bowman2012-03-24 22:43:42 -0700
committerMic Bowman2012-03-24 22:43:42 -0700
commita14437ad5abf4d4dc95897216224548515a599e7 (patch)
tree56f793d9461c722efddc2f70b8b6efb6cd11c86a /OpenSim/Region/ScriptEngine/Shared
parentHave the PhysicsParameters module output console command responses (diff)
downloadopensim-SC_OLD-a14437ad5abf4d4dc95897216224548515a599e7.zip
opensim-SC_OLD-a14437ad5abf4d4dc95897216224548515a599e7.tar.gz
opensim-SC_OLD-a14437ad5abf4d4dc95897216224548515a599e7.tar.bz2
opensim-SC_OLD-a14437ad5abf4d4dc95897216224548515a599e7.tar.xz
Add support for key, vector, rotation and list types for both
arguments and return values to the modInvoke family of functions. See http://opensimulator.org/wiki/OSSL_Script_Library/ModInvoke
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs245
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs24
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs34
3 files changed, 229 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..1bcbcd3 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
@@ -120,33 +120,101 @@ 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 LSL_String modInvokeS(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 string result = (string)modInvoke(fname,parms);
132 return new LSL_String(result);
132 } 133 }
133 134
134 public int modInvokeI(string fname, params object[] parms) 135 public LSL_Integer modInvokeI(string fname, params object[] parms)
135 { 136 {
136 Type returntype = m_comms.LookupReturnType(fname); 137 Type returntype = m_comms.LookupReturnType(fname);
137 if (returntype != typeof(int)) 138 if (returntype != typeof(int))
138 MODError(String.Format("return type mismatch for {0}",fname)); 139 MODError(String.Format("return type mismatch for {0}",fname));
139 140
140 return (int)modInvoke(fname,parms); 141 int result = (int)modInvoke(fname,parms);
142 return new LSL_Integer(result);
141 } 143 }
142 144
143 public float modInvokeF(string fname, params object[] parms) 145 public LSL_Float modInvokeF(string fname, params object[] parms)
144 { 146 {
145 Type returntype = m_comms.LookupReturnType(fname); 147 Type returntype = m_comms.LookupReturnType(fname);
146 if (returntype != typeof(float)) 148 if (returntype != typeof(float))
147 MODError(String.Format("return type mismatch for {0}",fname)); 149 MODError(String.Format("return type mismatch for {0}",fname));
148 150
149 return (float)modInvoke(fname,parms); 151 float result = (float)modInvoke(fname,parms);
152 return new LSL_Float(result);
153 }
154
155 public LSL_Key modInvokeK(string fname, params object[] parms)
156 {
157 Type returntype = m_comms.LookupReturnType(fname);
158 if (returntype != typeof(UUID))
159 MODError(String.Format("return type mismatch for {0}",fname));
160
161 UUID result = (UUID)modInvoke(fname,parms);
162 return new LSL_Key(result.ToString());
163 }
164
165 public LSL_Vector modInvokeV(string fname, params object[] parms)
166 {
167 Type returntype = m_comms.LookupReturnType(fname);
168 if (returntype != typeof(OpenMetaverse.Vector3))
169 MODError(String.Format("return type mismatch for {0}",fname));
170
171 OpenMetaverse.Vector3 result = (OpenMetaverse.Vector3)modInvoke(fname,parms);
172 return new LSL_Vector(result.X,result.Y,result.Z);
173 }
174
175 public LSL_Rotation modInvokeR(string fname, params object[] parms)
176 {
177 Type returntype = m_comms.LookupReturnType(fname);
178 if (returntype != typeof(OpenMetaverse.Quaternion))
179 MODError(String.Format("return type mismatch for {0}",fname));
180
181 OpenMetaverse.Quaternion result = (OpenMetaverse.Quaternion)modInvoke(fname,parms);
182 return new LSL_Rotation(result.X,result.Y,result.Z,result.W);
183 }
184
185 public LSL_List modInvokeL(string fname, params object[] parms)
186 {
187 Type returntype = m_comms.LookupReturnType(fname);
188 if (returntype != typeof(object[]))
189 MODError(String.Format("return type mismatch for {0}",fname));
190
191 object[] result = (object[])modInvoke(fname,parms);
192 object[] llist = new object[result.Length];
193 for (int i = 0; i < result.Length; i++)
194 {
195 if (result[i] is string)
196 llist[i] = new LSL_String((string)result[i]);
197 else if (result[i] is int)
198 llist[i] = new LSL_Integer((int)result[i]);
199 else if (result[i] is float)
200 llist[i] = new LSL_Float((float)result[i]);
201 else if (result[i] is OpenMetaverse.Vector3)
202 {
203 OpenMetaverse.Vector3 vresult = (OpenMetaverse.Vector3)result[i];
204 llist[i] = new LSL_Vector(vresult.X,vresult.Y,vresult.Z);
205 }
206 else if (result[i] is OpenMetaverse.Quaternion)
207 {
208 OpenMetaverse.Quaternion qresult = (OpenMetaverse.Quaternion)result[i];
209 llist[i] = new LSL_Rotation(qresult.X,qresult.Y,qresult.Z,qresult.W);
210 }
211 else
212 {
213 MODError(String.Format("unknown list element returned by {0}",fname));
214 }
215 }
216
217 return new LSL_List(llist);
150 } 218 }
151 219
152 /// <summary> 220 /// <summary>
@@ -168,63 +236,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
168 MODError(String.Format("wrong number of parameters to function {0}",fname)); 236 MODError(String.Format("wrong number of parameters to function {0}",fname));
169 237
170 object[] convertedParms = new object[parms.Length]; 238 object[] convertedParms = new object[parms.Length];
171
172 for (int i = 0; i < parms.Length; i++) 239 for (int i = 0; i < parms.Length; i++)
173 { 240 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
179 convertedParms[i] = (string)(LSL_String)parms[i];
180 }
181 else if (parms[i] is LSL_Integer)
182 {
183 if (signature[i] != typeof(int))
184 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
185
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 241
214 convertedParms[i] = (string)(LSL_Vector)parms[i]; 242 // now call the function, the contract with the function is that it will always return
215 } 243 // non-null but don't trust it completely
216 else 244 try
217 { 245 {
218 if (signature[i] != parms[i].GetType()) 246 object result = m_comms.InvokeOperation(m_itemID,fname,convertedParms);
219 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); 247 if (result != null)
248 return result;
220 249
221 convertedParms[i] = parms[i]; 250 MODError(String.Format("Invocation of {0} failed; null return value",fname));
222 } 251 }
252 catch (Exception e)
253 {
254 MODError(String.Format("Invocation of {0} failed; {1}",fname,e.Message));
223 } 255 }
224 256
225 return m_comms.InvokeOperation(m_itemID,fname,convertedParms); 257 return null;
226 } 258 }
227 259
260 /// <summary>
261 /// Send a command to functions registered on an event
262 /// </summary>
228 public string modSendCommand(string module, string command, string k) 263 public string modSendCommand(string module, string command, string k)
229 { 264 {
230 if (!m_MODFunctionsEnabled) 265 if (!m_MODFunctionsEnabled)
@@ -239,5 +274,101 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
239 274
240 return req.ToString(); 275 return req.ToString();
241 } 276 }
277
278 /// <summary>
279 /// </summary>
280 protected object ConvertFromLSL(object lslparm, Type type)
281 {
282 // ---------- String ----------
283 if (lslparm is LSL_String)
284 {
285 if (type == typeof(string))
286 return (string)(LSL_String)lslparm;
287
288 // Need to check for UUID since keys are often treated as strings
289 if (type == typeof(UUID))
290 return new UUID((string)(LSL_String)lslparm);
291 }
292
293 // ---------- Integer ----------
294 else if (lslparm is LSL_Integer)
295 {
296 if (type == typeof(int))
297 return (int)(LSL_Integer)lslparm;
298 }
299
300 // ---------- Float ----------
301 else if (lslparm is LSL_Float)
302 {
303 if (type == typeof(float))
304 return (float)(LSL_Float)lslparm;
305 }
306
307 // ---------- Key ----------
308 else if (lslparm is LSL_Key)
309 {
310 if (type == typeof(UUID))
311 return new UUID((LSL_Key)lslparm);
312 }
313
314 // ---------- Rotation ----------
315 else if (lslparm is LSL_Rotation)
316 {
317 if (type == typeof(OpenMetaverse.Quaternion))
318 {
319 LSL_Rotation rot = (LSL_Rotation)lslparm;
320 return new OpenMetaverse.Quaternion((float)rot.x,(float)rot.y,(float)rot.z,(float)rot.s);
321 }
322 }
323
324 // ---------- Vector ----------
325 else if (lslparm is LSL_Vector)
326 {
327 if (type == typeof(OpenMetaverse.Vector3))
328 {
329 LSL_Vector vect = (LSL_Vector)lslparm;
330 return new OpenMetaverse.Vector3((float)vect.x,(float)vect.y,(float)vect.z);
331 }
332 }
333
334 // ---------- List ----------
335 else if (lslparm is LSL_List)
336 {
337 if (type == typeof(object[]))
338 {
339 object[] plist = (lslparm as LSL_List).Data;
340 object[] result = new object[plist.Length];
341 for (int i = 0; i < plist.Length; i++)
342 {
343 if (plist[i] is LSL_String)
344 result[i] = (string)(LSL_String)plist[i];
345 else if (plist[i] is LSL_Integer)
346 result[i] = (int)(LSL_Integer)plist[i];
347 else if (plist[i] is LSL_Float)
348 result[i] = (float)(LSL_Float)plist[i];
349 else if (plist[i] is LSL_Key)
350 result[i] = new UUID((LSL_Key)plist[i]);
351 else if (plist[i] is LSL_Rotation)
352 {
353 LSL_Rotation rot = (LSL_Rotation)plist[i];
354 result[i] = new OpenMetaverse.Quaternion((float)rot.x,(float)rot.y,(float)rot.z,(float)rot.s);
355 }
356 else if (plist[i] is LSL_Vector)
357 {
358 LSL_Vector vect = (LSL_Vector)plist[i];
359 result[i] = new OpenMetaverse.Vector3((float)vect.x,(float)vect.y,(float)vect.z);
360 }
361 else
362 MODError("unknown LSL list element type");
363 }
364
365 return result;
366 }
367 }
368
369 MODError(String.Format("parameter type mismatch; expecting {0}",type.Name));
370 return null;
371 }
372
242 } 373 }
243} 374}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
index 756a59f..d258f76 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
@@ -28,26 +28,26 @@
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 LSL_String modInvokeS(string fname, params object[] parms);
45 int modInvokeI(string fname, params object[] parms); 45 LSL_Integer modInvokeI(string fname, params object[] parms);
46 float modInvokeF(string fname, params object[] parms); 46 LSL_Float modInvokeF(string fname, params object[] parms);
47 // vector modInvokeV(string fname, params object[] parms); 47 LSL_Key modInvokeK(string fname, params object[] parms);
48 // rotation modInvokeV(string fname, params object[] parms); 48 LSL_Vector modInvokeV(string fname, params object[] parms);
49 // key modInvokeK(string fname, params object[] parms); 49 LSL_Rotation modInvokeR(string fname, params object[] parms);
50 // list modInvokeL(string fname, params object[] parms); 50 LSL_List modInvokeL(string fname, params object[] parms);
51 51
52 //Module functions 52 //Module functions
53 string modSendCommand(string modules, string command, string k); 53 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..e7a4b2b 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,41 @@ 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 LSL_String modInvokeS(string fname, params object[] parms)
62 { 66 {
63 return m_MOD_Functions.modInvokeS(fname, parms); 67 return m_MOD_Functions.modInvokeS(fname, parms);
64 } 68 }
65 69
66 public int modInvokeI(string fname, params object[] parms) 70 public LSL_Integer modInvokeI(string fname, params object[] parms)
67 { 71 {
68 return m_MOD_Functions.modInvokeI(fname, parms); 72 return m_MOD_Functions.modInvokeI(fname, parms);
69 } 73 }
70 74
71 public float modInvokeF(string fname, params object[] parms) 75 public LSL_Float modInvokeF(string fname, params object[] parms)
72 { 76 {
73 return m_MOD_Functions.modInvokeF(fname, parms); 77 return m_MOD_Functions.modInvokeF(fname, parms);
74 } 78 }
75 79
80 public LSL_Key modInvokeK(string fname, params object[] parms)
81 {
82 return m_MOD_Functions.modInvokeK(fname, parms);
83 }
84
85 public LSL_Vector modInvokeV(string fname, params object[] parms)
86 {
87 return m_MOD_Functions.modInvokeV(fname, parms);
88 }
89
90 public LSL_Rotation modInvokeR(string fname, params object[] parms)
91 {
92 return m_MOD_Functions.modInvokeR(fname, parms);
93 }
94
95 public LSL_List modInvokeL(string fname, params object[] parms)
96 {
97 return m_MOD_Functions.modInvokeL(fname, parms);
98 }
99
76 public string modSendCommand(string module, string command, string k) 100 public string modSendCommand(string module, string command, string k)
77 { 101 {
78 return m_MOD_Functions.modSendCommand(module, command, k); 102 return m_MOD_Functions.modSendCommand(module, command, k);