diff options
author | Melanie | 2012-03-26 01:21:44 +0100 |
---|---|---|
committer | Melanie | 2012-03-26 01:21:44 +0100 |
commit | 5e8d64c9439fd25dd1ef23df223927e55f9a86b9 (patch) | |
tree | 5fe5ad45698da9c59b175f4eb728b4d638debffe /OpenSim/Region | |
parent | Correct the design error I introduced into ScriptComms. Untested but about to (diff) | |
download | opensim-SC-5e8d64c9439fd25dd1ef23df223927e55f9a86b9.zip opensim-SC-5e8d64c9439fd25dd1ef23df223927e55f9a86b9.tar.gz opensim-SC-5e8d64c9439fd25dd1ef23df223927e55f9a86b9.tar.bz2 opensim-SC-5e8d64c9439fd25dd1ef23df223927e55f9a86b9.tar.xz |
Dynamically create the delegate type to reduce complexity in the caller
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs | 3 | ||||
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 22 |
2 files changed, 23 insertions, 2 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs index 8a08fbe..34586f5 100644 --- a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs +++ b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Reflection; | ||
29 | using OpenMetaverse; | 30 | using OpenMetaverse; |
30 | 31 | ||
31 | namespace OpenSim.Region.Framework.Interfaces | 32 | namespace OpenSim.Region.Framework.Interfaces |
@@ -45,7 +46,7 @@ namespace OpenSim.Region.Framework.Interfaces | |||
45 | /// </summary> | 46 | /// </summary> |
46 | event ScriptCommand OnScriptCommand; | 47 | event ScriptCommand OnScriptCommand; |
47 | 48 | ||
48 | void RegisterScriptInvocation(Delegate fn); | 49 | void RegisterScriptInvocation(object target, MethodInfo mi); |
49 | Delegate[] GetScriptInvocationList(); | 50 | Delegate[] GetScriptInvocationList(); |
50 | 51 | ||
51 | Delegate LookupScriptInvocation(string fname); | 52 | Delegate LookupScriptInvocation(string fname); |
diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index e37e42e..e0683a0 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; | |||
35 | using OpenSim.Region.Framework.Scenes; | 35 | using OpenSim.Region.Framework.Scenes; |
36 | using Mono.Addins; | 36 | using Mono.Addins; |
37 | using OpenMetaverse; | 37 | using OpenMetaverse; |
38 | using System.Linq; | ||
39 | using System.Linq.Expressions; | ||
38 | 40 | ||
39 | namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | 41 | namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms |
40 | { | 42 | { |
@@ -126,8 +128,26 @@ 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(Delegate fcall) | 131 | public void RegisterScriptInvocation(object target, MethodInfo mi) |
130 | { | 132 | { |
133 | Type delegateType; | ||
134 | |||
135 | var typeArgs = mi.GetParameters() | ||
136 | .Select(p => p.ParameterType) | ||
137 | .ToList(); | ||
138 | |||
139 | if (mi.ReturnType == typeof(void)) | ||
140 | { | ||
141 | delegateType = Expression.GetActionType(typeArgs.ToArray()); | ||
142 | } | ||
143 | else | ||
144 | { | ||
145 | typeArgs.Add(mi.ReturnType); | ||
146 | delegateType = Expression.GetFuncType(typeArgs.ToArray()); | ||
147 | } | ||
148 | |||
149 | Delegate fcall = Delegate.CreateDelegate(delegateType, target, mi); | ||
150 | |||
131 | lock (m_scriptInvocation) | 151 | lock (m_scriptInvocation) |
132 | { | 152 | { |
133 | ParameterInfo[] parameters = fcall.Method.GetParameters (); | 153 | ParameterInfo[] parameters = fcall.Method.GetParameters (); |