diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs | 254 |
1 files changed, 197 insertions, 57 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 | } |