diff options
author | Melanie | 2012-08-31 14:40:30 +0100 |
---|---|---|
committer | Melanie | 2012-08-31 14:40:30 +0100 |
commit | c0feaf54deed8af6ee17706e85d98d59b0abc8e6 (patch) | |
tree | 98c5a9014a139d5b8bc658dea334b0817cdd9476 /OpenSim/Region/OptionalModules | |
parent | Merge branch 'master' into careminster (diff) | |
parent | Merge branch 'master' of melanie@opensimulator.org:/var/git/opensim (diff) | |
download | opensim-SC-c0feaf54deed8af6ee17706e85d98d59b0abc8e6.zip opensim-SC-c0feaf54deed8af6ee17706e85d98d59b0abc8e6.tar.gz opensim-SC-c0feaf54deed8af6ee17706e85d98d59b0abc8e6.tar.bz2 opensim-SC-c0feaf54deed8af6ee17706e85d98d59b0abc8e6.tar.xz |
Merge branch 'master' into careminster
Diffstat (limited to 'OpenSim/Region/OptionalModules')
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index 705a847..8d100e8 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | |||
@@ -130,13 +130,25 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms | |||
130 | m_scriptModule.PostScriptEvent(script, "link_message", args); | 130 | m_scriptModule.PostScriptEvent(script, "link_message", args); |
131 | } | 131 | } |
132 | 132 | ||
133 | private static MethodInfo GetMethodInfoFromType(Type target, string meth, bool searchInstanceMethods) | ||
134 | { | ||
135 | BindingFlags getMethodFlags = | ||
136 | BindingFlags.NonPublic | BindingFlags.Public; | ||
137 | |||
138 | if (searchInstanceMethods) | ||
139 | getMethodFlags |= BindingFlags.Instance; | ||
140 | else | ||
141 | getMethodFlags |= BindingFlags.Static; | ||
142 | |||
143 | return target.GetMethod(meth, getMethodFlags); | ||
144 | } | ||
145 | |||
133 | public void RegisterScriptInvocation(object target, string meth) | 146 | public void RegisterScriptInvocation(object target, string meth) |
134 | { | 147 | { |
135 | MethodInfo mi = target.GetType().GetMethod(meth, | 148 | MethodInfo mi = GetMethodInfoFromType(target.GetType(), meth, true); |
136 | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); | ||
137 | if (mi == null) | 149 | if (mi == null) |
138 | { | 150 | { |
139 | m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}",meth); | 151 | m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}", meth); |
140 | return; | 152 | return; |
141 | } | 153 | } |
142 | 154 | ||
@@ -154,35 +166,51 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms | |||
154 | m_log.DebugFormat("[MODULE COMMANDS] Register method {0} from type {1}", mi.Name, target.GetType().Name); | 166 | m_log.DebugFormat("[MODULE COMMANDS] Register method {0} from type {1}", mi.Name, target.GetType().Name); |
155 | 167 | ||
156 | Type delegateType; | 168 | Type delegateType; |
157 | var typeArgs = mi.GetParameters() | 169 | List<Type> typeArgs = mi.GetParameters() |
158 | .Select(p => p.ParameterType) | 170 | .Select(p => p.ParameterType) |
159 | .ToList(); | 171 | .ToList(); |
160 | 172 | ||
161 | if (mi.ReturnType == typeof(void)) | 173 | if (mi.ReturnType == typeof(void)) |
162 | { | 174 | { |
163 | delegateType = Expression.GetActionType(typeArgs.ToArray()); | 175 | delegateType = Expression.GetActionType(typeArgs.ToArray()); |
164 | } | 176 | } |
165 | else | 177 | else |
166 | { | 178 | { |
167 | typeArgs.Add(mi.ReturnType); | 179 | typeArgs.Add(mi.ReturnType); |
168 | delegateType = Expression.GetFuncType(typeArgs.ToArray()); | 180 | delegateType = Expression.GetFuncType(typeArgs.ToArray()); |
169 | } | 181 | } |
170 | 182 | ||
171 | Delegate fcall = Delegate.CreateDelegate(delegateType, target, mi); | 183 | Delegate fcall; |
184 | if (!(target is Type)) | ||
185 | fcall = Delegate.CreateDelegate(delegateType, target, mi); | ||
186 | else | ||
187 | fcall = Delegate.CreateDelegate(delegateType, (Type)target, mi.Name); | ||
172 | 188 | ||
173 | lock (m_scriptInvocation) | 189 | lock (m_scriptInvocation) |
174 | { | 190 | { |
175 | ParameterInfo[] parameters = fcall.Method.GetParameters (); | 191 | ParameterInfo[] parameters = fcall.Method.GetParameters(); |
176 | if (parameters.Length < 2) // Must have two UUID params | 192 | if (parameters.Length < 2) // Must have two UUID params |
177 | return; | 193 | return; |
178 | 194 | ||
179 | // Hide the first two parameters | 195 | // Hide the first two parameters |
180 | Type[] parmTypes = new Type[parameters.Length - 2]; | 196 | Type[] parmTypes = new Type[parameters.Length - 2]; |
181 | for (int i = 2 ; i < parameters.Length ; i++) | 197 | for (int i = 2; i < parameters.Length; i++) |
182 | parmTypes[i - 2] = parameters[i].ParameterType; | 198 | parmTypes[i - 2] = parameters[i].ParameterType; |
183 | m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType); | 199 | m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType); |
184 | } | 200 | } |
185 | } | 201 | } |
202 | |||
203 | public void RegisterScriptInvocation(Type target, string[] methods) | ||
204 | { | ||
205 | foreach (string method in methods) | ||
206 | { | ||
207 | MethodInfo mi = GetMethodInfoFromType(target, method, false); | ||
208 | if (mi == null) | ||
209 | m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}", method); | ||
210 | else | ||
211 | RegisterScriptInvocation(target, mi); | ||
212 | } | ||
213 | } | ||
186 | 214 | ||
187 | public Delegate[] GetScriptInvocationList() | 215 | public Delegate[] GetScriptInvocationList() |
188 | { | 216 | { |