Dynamically create the delegate type to reduce complexity in the caller
parent
4b76c52c41
commit
5e8d64c943
|
@ -26,6 +26,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
|
|
||||||
namespace OpenSim.Region.Framework.Interfaces
|
namespace OpenSim.Region.Framework.Interfaces
|
||||||
|
@ -45,7 +46,7 @@ namespace OpenSim.Region.Framework.Interfaces
|
||||||
/// </summary>
|
/// </summary>
|
||||||
event ScriptCommand OnScriptCommand;
|
event ScriptCommand OnScriptCommand;
|
||||||
|
|
||||||
void RegisterScriptInvocation(Delegate fn);
|
void RegisterScriptInvocation(object target, MethodInfo mi);
|
||||||
Delegate[] GetScriptInvocationList();
|
Delegate[] GetScriptInvocationList();
|
||||||
|
|
||||||
Delegate LookupScriptInvocation(string fname);
|
Delegate LookupScriptInvocation(string fname);
|
||||||
|
|
|
@ -35,6 +35,8 @@ using OpenSim.Region.Framework.Interfaces;
|
||||||
using OpenSim.Region.Framework.Scenes;
|
using OpenSim.Region.Framework.Scenes;
|
||||||
using Mono.Addins;
|
using Mono.Addins;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
|
namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
|
||||||
{
|
{
|
||||||
|
@ -126,8 +128,26 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
|
||||||
m_scriptModule.PostScriptEvent(script, "link_message", args);
|
m_scriptModule.PostScriptEvent(script, "link_message", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterScriptInvocation(Delegate fcall)
|
public void RegisterScriptInvocation(object target, MethodInfo mi)
|
||||||
{
|
{
|
||||||
|
Type delegateType;
|
||||||
|
|
||||||
|
var typeArgs = mi.GetParameters()
|
||||||
|
.Select(p => p.ParameterType)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (mi.ReturnType == typeof(void))
|
||||||
|
{
|
||||||
|
delegateType = Expression.GetActionType(typeArgs.ToArray());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
typeArgs.Add(mi.ReturnType);
|
||||||
|
delegateType = Expression.GetFuncType(typeArgs.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
Delegate fcall = Delegate.CreateDelegate(delegateType, target, mi);
|
||||||
|
|
||||||
lock (m_scriptInvocation)
|
lock (m_scriptInvocation)
|
||||||
{
|
{
|
||||||
ParameterInfo[] parameters = fcall.Method.GetParameters ();
|
ParameterInfo[] parameters = fcall.Method.GetParameters ();
|
||||||
|
|
Loading…
Reference in New Issue