diff options
author | onefang | 2019-09-11 16:36:50 +1000 |
---|---|---|
committer | onefang | 2019-09-11 16:36:50 +1000 |
commit | 50cd1ffd32f69228e566f2b0b89f86ea0d9fe489 (patch) | |
tree | 52f2ab0c04f1a5d7d6ac5dc872981b4b156447e7 /OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs | |
parent | Renamed branch to SledjChisl. (diff) | |
parent | Bump to release flavour, build 0. (diff) | |
download | opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.zip opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.gz opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.bz2 opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.xz |
Merge branch 'SledjChisl'
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs | 84 |
1 files changed, 46 insertions, 38 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index 1458c95..692bec0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs | |||
@@ -107,14 +107,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
107 | /// Dumps an error message on the debug console. | 107 | /// Dumps an error message on the debug console. |
108 | /// </summary> | 108 | /// </summary> |
109 | /// <param name='message'></param> | 109 | /// <param name='message'></param> |
110 | internal void MODShoutError(string message) | 110 | internal void MODShoutError(string message) |
111 | { | 111 | { |
112 | if (message.Length > 1023) | 112 | if (message.Length > 1023) |
113 | message = message.Substring(0, 1023); | 113 | message = message.Substring(0, 1023); |
114 | 114 | ||
115 | World.SimChat( | 115 | World.SimChat( |
116 | Utils.StringToBytes(message), | 116 | Utils.StringToBytes(message), |
117 | ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, | 117 | ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, |
118 | m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false); | 118 | m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false); |
119 | 119 | ||
120 | IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); | 120 | IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); |
@@ -122,7 +122,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
122 | } | 122 | } |
123 | 123 | ||
124 | /// <summary> | 124 | /// <summary> |
125 | /// | 125 | /// |
126 | /// </summary> | 126 | /// </summary> |
127 | /// <param name="fname">The name of the function to invoke</param> | 127 | /// <param name="fname">The name of the function to invoke</param> |
128 | /// <param name="parms">List of parameters</param> | 128 | /// <param name="parms">List of parameters</param> |
@@ -130,13 +130,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
130 | public void modInvokeN(string fname, params object[] parms) | 130 | public void modInvokeN(string fname, params object[] parms) |
131 | { | 131 | { |
132 | // m_log.DebugFormat( | 132 | // m_log.DebugFormat( |
133 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | 133 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", |
134 | // fname, | 134 | // fname, |
135 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | 135 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), |
136 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | 136 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); |
137 | 137 | ||
138 | Type returntype = m_comms.LookupReturnType(fname); | 138 | Type returntype = m_comms.LookupReturnType(fname); |
139 | if (returntype != typeof(string)) | 139 | if (returntype != typeof(void)) |
140 | MODError(String.Format("return type mismatch for {0}",fname)); | 140 | MODError(String.Format("return type mismatch for {0}",fname)); |
141 | 141 | ||
142 | modInvoke(fname,parms); | 142 | modInvoke(fname,parms); |
@@ -145,9 +145,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
145 | public LSL_String modInvokeS(string fname, params object[] parms) | 145 | public LSL_String modInvokeS(string fname, params object[] parms) |
146 | { | 146 | { |
147 | // m_log.DebugFormat( | 147 | // m_log.DebugFormat( |
148 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | 148 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", |
149 | // fname, | 149 | // fname, |
150 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | 150 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), |
151 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | 151 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); |
152 | 152 | ||
153 | Type returntype = m_comms.LookupReturnType(fname); | 153 | Type returntype = m_comms.LookupReturnType(fname); |
@@ -161,9 +161,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
161 | public LSL_Integer modInvokeI(string fname, params object[] parms) | 161 | public LSL_Integer modInvokeI(string fname, params object[] parms) |
162 | { | 162 | { |
163 | // m_log.DebugFormat( | 163 | // m_log.DebugFormat( |
164 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | 164 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", |
165 | // fname, | 165 | // fname, |
166 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | 166 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), |
167 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | 167 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); |
168 | 168 | ||
169 | Type returntype = m_comms.LookupReturnType(fname); | 169 | Type returntype = m_comms.LookupReturnType(fname); |
@@ -173,13 +173,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
173 | int result = (int)modInvoke(fname,parms); | 173 | int result = (int)modInvoke(fname,parms); |
174 | return new LSL_Integer(result); | 174 | return new LSL_Integer(result); |
175 | } | 175 | } |
176 | 176 | ||
177 | public LSL_Float modInvokeF(string fname, params object[] parms) | 177 | public LSL_Float modInvokeF(string fname, params object[] parms) |
178 | { | 178 | { |
179 | // m_log.DebugFormat( | 179 | // m_log.DebugFormat( |
180 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | 180 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", |
181 | // fname, | 181 | // fname, |
182 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | 182 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), |
183 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | 183 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); |
184 | 184 | ||
185 | Type returntype = m_comms.LookupReturnType(fname); | 185 | Type returntype = m_comms.LookupReturnType(fname); |
@@ -193,9 +193,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
193 | public LSL_Key modInvokeK(string fname, params object[] parms) | 193 | public LSL_Key modInvokeK(string fname, params object[] parms) |
194 | { | 194 | { |
195 | // m_log.DebugFormat( | 195 | // m_log.DebugFormat( |
196 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | 196 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", |
197 | // fname, | 197 | // fname, |
198 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | 198 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), |
199 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | 199 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); |
200 | 200 | ||
201 | Type returntype = m_comms.LookupReturnType(fname); | 201 | Type returntype = m_comms.LookupReturnType(fname); |
@@ -209,9 +209,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
209 | public LSL_Vector modInvokeV(string fname, params object[] parms) | 209 | public LSL_Vector modInvokeV(string fname, params object[] parms) |
210 | { | 210 | { |
211 | // m_log.DebugFormat( | 211 | // m_log.DebugFormat( |
212 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | 212 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", |
213 | // fname, | 213 | // fname, |
214 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | 214 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), |
215 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | 215 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); |
216 | 216 | ||
217 | Type returntype = m_comms.LookupReturnType(fname); | 217 | Type returntype = m_comms.LookupReturnType(fname); |
@@ -225,9 +225,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
225 | public LSL_Rotation modInvokeR(string fname, params object[] parms) | 225 | public LSL_Rotation modInvokeR(string fname, params object[] parms) |
226 | { | 226 | { |
227 | // m_log.DebugFormat( | 227 | // m_log.DebugFormat( |
228 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | 228 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", |
229 | // fname, | 229 | // fname, |
230 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | 230 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), |
231 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | 231 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); |
232 | 232 | ||
233 | Type returntype = m_comms.LookupReturnType(fname); | 233 | Type returntype = m_comms.LookupReturnType(fname); |
@@ -241,9 +241,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
241 | public LSL_List modInvokeL(string fname, params object[] parms) | 241 | public LSL_List modInvokeL(string fname, params object[] parms) |
242 | { | 242 | { |
243 | // m_log.DebugFormat( | 243 | // m_log.DebugFormat( |
244 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | 244 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", |
245 | // fname, | 245 | // fname, |
246 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | 246 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), |
247 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | 247 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); |
248 | 248 | ||
249 | Type returntype = m_comms.LookupReturnType(fname); | 249 | Type returntype = m_comms.LookupReturnType(fname); |
@@ -308,27 +308,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
308 | } | 308 | } |
309 | 309 | ||
310 | // m_log.DebugFormat( | 310 | // m_log.DebugFormat( |
311 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | 311 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", |
312 | // fname, | 312 | // fname, |
313 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | 313 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), |
314 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | 314 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); |
315 | 315 | ||
316 | Type[] signature = m_comms.LookupTypeSignature(fname); | 316 | Type[] signature = m_comms.LookupTypeSignature(fname); |
317 | if (signature.Length != parms.Length) | 317 | if (signature.Length != parms.Length) |
318 | MODError(String.Format("wrong number of parameters to function {0}",fname)); | 318 | MODError(String.Format("wrong number of parameters to function {0}",fname)); |
319 | 319 | ||
320 | object[] convertedParms = new object[parms.Length]; | 320 | object[] convertedParms = new object[parms.Length]; |
321 | for (int i = 0; i < parms.Length; i++) | 321 | for (int i = 0; i < parms.Length; i++) |
322 | convertedParms[i] = ConvertFromLSL(parms[i], signature[i], fname); | 322 | convertedParms[i] = ConvertFromLSL(parms[i], signature[i], fname); |
323 | 323 | ||
324 | // now call the function, the contract with the function is that it will always return | 324 | // now call the function, the contract with the function is that it will always return |
325 | // non-null but don't trust it completely | 325 | // non-null but don't trust it completely |
326 | try | 326 | try |
327 | { | 327 | { |
328 | object result = m_comms.InvokeOperation(m_host.UUID, m_item.ItemID, fname, convertedParms); | 328 | object result = m_comms.InvokeOperation(m_host.UUID, m_item.ItemID, fname, convertedParms); |
329 | if (result != null) | 329 | if (result != null) |
330 | return result; | 330 | return result; |
331 | 331 | ||
332 | Type returntype = m_comms.LookupReturnType(fname); | ||
333 | if (returntype == typeof(void)) | ||
334 | return null; | ||
335 | |||
332 | MODError(String.Format("Invocation of {0} failed; null return value",fname)); | 336 | MODError(String.Format("Invocation of {0} failed; null return value",fname)); |
333 | } | 337 | } |
334 | catch (Exception e) | 338 | catch (Exception e) |
@@ -338,7 +342,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
338 | 342 | ||
339 | return null; | 343 | return null; |
340 | } | 344 | } |
341 | 345 | ||
342 | /// <summary> | 346 | /// <summary> |
343 | /// Send a command to functions registered on an event | 347 | /// Send a command to functions registered on an event |
344 | /// </summary> | 348 | /// </summary> |
@@ -361,8 +365,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
361 | /// </summary> | 365 | /// </summary> |
362 | protected object ConvertFromLSL(object lslparm, Type type, string fname) | 366 | protected object ConvertFromLSL(object lslparm, Type type, string fname) |
363 | { | 367 | { |
368 | |||
369 | if(lslparm.GetType() == type) | ||
370 | return lslparm; | ||
371 | |||
364 | // ---------- String ---------- | 372 | // ---------- String ---------- |
365 | if (lslparm is LSL_String) | 373 | else if (lslparm is LSL_String) |
366 | { | 374 | { |
367 | if (type == typeof(string)) | 375 | if (type == typeof(string)) |
368 | return (string)(LSL_String)lslparm; | 376 | return (string)(LSL_String)lslparm; |
@@ -421,7 +429,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
421 | for (int i = 0; i < plist.Length; i++) | 429 | for (int i = 0; i < plist.Length; i++) |
422 | { | 430 | { |
423 | if (plist[i] is LSL_String) | 431 | if (plist[i] is LSL_String) |
424 | result[i] = (string)(LSL_String)plist[i]; | 432 | result[i] = (string)(LSL_String)plist[i]; |
425 | else if (plist[i] is LSL_Integer) | 433 | else if (plist[i] is LSL_Integer) |
426 | result[i] = (int)(LSL_Integer)plist[i]; | 434 | result[i] = (int)(LSL_Integer)plist[i]; |
427 | // The int check exists because of the many plain old int script constants in ScriptBase which | 435 | // The int check exists because of the many plain old int script constants in ScriptBase which |
@@ -443,7 +451,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
443 | return result; | 451 | return result; |
444 | } | 452 | } |
445 | } | 453 | } |
446 | 454 | ||
447 | MODError(String.Format("{0}: parameter type mismatch; expecting {1}, type(parm)={2}", fname, type.Name, lslparm.GetType())); | 455 | MODError(String.Format("{0}: parameter type mismatch; expecting {1}, type(parm)={2}", fname, type.Name, lslparm.GetType())); |
448 | return null; | 456 | return null; |
449 | } | 457 | } |