aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs85
1 files changed, 75 insertions, 10 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
index a90362e..0605590 100644
--- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
@@ -35,6 +35,8 @@ using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Region.Framework.Scenes; 35using OpenSim.Region.Framework.Scenes;
36using Mono.Addins; 36using Mono.Addins;
37using OpenMetaverse; 37using OpenMetaverse;
38using System.Linq;
39using System.Linq.Expressions;
38 40
39namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms 41namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
40{ 42{
@@ -47,15 +49,15 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
47#region ScriptInvocation 49#region ScriptInvocation
48 protected class ScriptInvocationData 50 protected class ScriptInvocationData
49 { 51 {
50 public ScriptInvocation ScriptInvocationFn { get; private set; } 52 public Delegate ScriptInvocationDelegate { get; private set; }
51 public string FunctionName { get; private set; } 53 public string FunctionName { get; private set; }
52 public Type[] TypeSignature { get; private set; } 54 public Type[] TypeSignature { get; private set; }
53 public Type ReturnType { get; private set; } 55 public Type ReturnType { get; private set; }
54 56
55 public ScriptInvocationData(string fname, ScriptInvocation fn, Type[] callsig, Type returnsig) 57 public ScriptInvocationData(string fname, Delegate fn, Type[] callsig, Type returnsig)
56 { 58 {
57 FunctionName = fname; 59 FunctionName = fname;
58 ScriptInvocationFn = fn; 60 ScriptInvocationDelegate = fn;
59 TypeSignature = callsig; 61 TypeSignature = callsig;
60 ReturnType = returnsig; 62 ReturnType = returnsig;
61 } 63 }
@@ -126,14 +128,62 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
126 m_scriptModule.PostScriptEvent(script, "link_message", args); 128 m_scriptModule.PostScriptEvent(script, "link_message", args);
127 } 129 }
128 130
129 public void RegisterScriptInvocation(string fname, ScriptInvocation fcall, Type[] csig, Type rsig) 131 public void RegisterScriptInvocation(object target, string meth)
130 { 132 {
133 m_log.DebugFormat("[MODULE COMMANDS] Register method {0} from type {1}",meth,target.GetType().Name);
134
135
136 MethodInfo mi = target.GetType().GetMethod(meth,
137 BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
138 if (mi == null)
139 {
140 m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}",meth);
141 return;
142 }
143
144 Type delegateType;
145 var typeArgs = mi.GetParameters()
146 .Select(p => p.ParameterType)
147 .ToList();
148
149 if (mi.ReturnType == typeof(void))
150 {
151 delegateType = Expression.GetActionType(typeArgs.ToArray());
152 }
153 else
154 {
155 typeArgs.Add(mi.ReturnType);
156 delegateType = Expression.GetFuncType(typeArgs.ToArray());
157 }
158
159 Delegate fcall = Delegate.CreateDelegate(delegateType, target, mi);
160
131 lock (m_scriptInvocation) 161 lock (m_scriptInvocation)
132 { 162 {
133 m_scriptInvocation[fname] = new ScriptInvocationData(fname,fcall,csig,rsig); 163 ParameterInfo[] parameters = fcall.Method.GetParameters ();
164 if (parameters.Length < 2) // Must have two UUID params
165 return;
166
167 // Hide the first two parameters
168 Type[] parmTypes = new Type[parameters.Length - 2];
169 for (int i = 2 ; i < parameters.Length ; i++)
170 parmTypes[i - 2] = parameters[i].ParameterType;
171 m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType);
134 } 172 }
135 } 173 }
136 174
175 public Delegate[] GetScriptInvocationList()
176 {
177 List<Delegate> ret = new List<Delegate>();
178
179 lock (m_scriptInvocation)
180 {
181 foreach (ScriptInvocationData d in m_scriptInvocation.Values)
182 ret.Add(d.ScriptInvocationDelegate);
183 }
184 return ret.ToArray();
185 }
186
137 public string LookupModInvocation(string fname) 187 public string LookupModInvocation(string fname)
138 { 188 {
139 lock (m_scriptInvocation) 189 lock (m_scriptInvocation)
@@ -147,19 +197,29 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
147 return "modInvokeI"; 197 return "modInvokeI";
148 else if (sid.ReturnType == typeof(float)) 198 else if (sid.ReturnType == typeof(float))
149 return "modInvokeF"; 199 return "modInvokeF";
200 else if (sid.ReturnType == typeof(UUID))
201 return "modInvokeK";
202 else if (sid.ReturnType == typeof(OpenMetaverse.Vector3))
203 return "modInvokeV";
204 else if (sid.ReturnType == typeof(OpenMetaverse.Quaternion))
205 return "modInvokeR";
206 else if (sid.ReturnType == typeof(object[]))
207 return "modInvokeL";
208
209 m_log.WarnFormat("[MODULE COMMANDS] failed to find match for {0} with return type {1}",fname,sid.ReturnType.Name);
150 } 210 }
151 } 211 }
152 212
153 return null; 213 return null;
154 } 214 }
155 215
156 public ScriptInvocation LookupScriptInvocation(string fname) 216 public Delegate LookupScriptInvocation(string fname)
157 { 217 {
158 lock (m_scriptInvocation) 218 lock (m_scriptInvocation)
159 { 219 {
160 ScriptInvocationData sid; 220 ScriptInvocationData sid;
161 if (m_scriptInvocation.TryGetValue(fname,out sid)) 221 if (m_scriptInvocation.TryGetValue(fname,out sid))
162 return sid.ScriptInvocationFn; 222 return sid.ScriptInvocationDelegate;
163 } 223 }
164 224
165 return null; 225 return null;
@@ -189,10 +249,15 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
189 return null; 249 return null;
190 } 250 }
191 251
192 public object InvokeOperation(UUID scriptid, string fname, params object[] parms) 252 public object InvokeOperation(UUID hostid, UUID scriptid, string fname, params object[] parms)
193 { 253 {
194 ScriptInvocation fn = LookupScriptInvocation(fname); 254 List<object> olist = new List<object>();
195 return fn(scriptid,parms); 255 olist.Add(hostid);
256 olist.Add(scriptid);
257 foreach (object o in parms)
258 olist.Add(o);
259 Delegate fn = LookupScriptInvocation(fname);
260 return fn.DynamicInvoke(olist.ToArray());
196 } 261 }
197#endregion 262#endregion
198 263