From 794c5f5a6d464357101d3da649815251abdc9e10 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 31 Aug 2012 13:50:46 +0100 Subject: adding support for static method script invocations --- OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs | 11 +++++++++-- .../ScriptModuleComms/ScriptModuleCommsModule.cs | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs index ff8213c..dae7c00 100644 --- a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs +++ b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs @@ -54,9 +54,9 @@ namespace OpenSim.Region.Framework.Interfaces void RegisterScriptInvocation(object target, string method); /// - /// Register an instance method as a script call by method info + /// Register a static or instance method as a script call by method info /// - /// + /// If target is a Type object, will assume method is static. /// void RegisterScriptInvocation(object target, MethodInfo method); @@ -68,6 +68,13 @@ namespace OpenSim.Region.Framework.Interfaces void RegisterScriptInvocation(object target, string[] methods); /// + /// Register one or more static methods as script calls by method name + /// + /// + /// + void RegisterScriptInvocation(Type target, string[] methods); + + /// /// Returns an array of all registered script calls /// /// diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index bbaac3e..d6d96c9 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -181,7 +181,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms } Delegate fcall; + if (!(target is Type)) fcall = Delegate.CreateDelegate(delegateType, target, mi); + else + fcall = Delegate.CreateDelegate(delegateType, (Type)target, mi.Name); lock (m_scriptInvocation) { @@ -196,6 +199,18 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType); } } + + public void RegisterScriptInvocation(Type target, string[] methods) + { + foreach (string method in methods) + { + MethodInfo mi = GetMethodInfoFromType(target, method, false); + if (mi == null) + m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}", method); + else + RegisterScriptInvocation(target, mi); + } + } public Delegate[] GetScriptInvocationList() { -- cgit v1.1