From 3c019bea8c006c6d09e6fa5583f60e01a87b766b Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Thu, 30 Aug 2012 15:55:03 +0100 Subject: Implementing a vastly simpler means of allowing region modules to access GetLinkParts than mantis 6236 --- OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 45286c0..be22cb4 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -247,7 +247,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return GetLinkParts(m_host, linkType); } - private List GetLinkParts(SceneObjectPart part, int linkType) + public static List GetLinkParts(SceneObjectPart part, int linkType) { List ret = new List(); ret.Add(part); -- cgit v1.1 From 973f2e8be540163e12dd8d85fffad3acd96fe212 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 31 Aug 2012 12:50:32 +0100 Subject: adding documentation to script invokation methods --- .../Framework/Interfaces/IScriptModuleComms.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs index ed71a95..ff8213c 100644 --- a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs +++ b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs @@ -46,9 +46,31 @@ namespace OpenSim.Region.Framework.Interfaces /// event ScriptCommand OnScriptCommand; + /// + /// Register an instance method as a script call by method name + /// + /// + /// void RegisterScriptInvocation(object target, string method); + + /// + /// Register an instance method as a script call by method info + /// + /// + /// void RegisterScriptInvocation(object target, MethodInfo method); + + /// + /// Register one or more instance methods as script calls by method name + /// + /// + /// void RegisterScriptInvocation(object target, string[] methods); + + /// + /// Returns an array of all registered script calls + /// + /// Delegate[] GetScriptInvocationList(); Delegate LookupScriptInvocation(string fname); -- cgit v1.1 From dff746df7be488d8ff35c91a974f406216222423 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 31 Aug 2012 12:56:30 +0100 Subject: moving code that will be common into private static method --- .../Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index 705a847..de0e864 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -130,10 +130,17 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms m_scriptModule.PostScriptEvent(script, "link_message", args); } - public void RegisterScriptInvocation(object target, string meth) + private static MethodInfo GetMethodInfoFromType(object target, string meth) { MethodInfo mi = target.GetType().GetMethod(meth, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + + return mi; + } + + public void RegisterScriptInvocation(object target, string meth) + { + MethodInfo mi = GetMethodInfoFromType(target, meth); if (mi == null) { m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}",meth); -- cgit v1.1 From 05648c2c4ad1283f5bd975c4a50ca5a949e67994 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 31 Aug 2012 12:57:51 +0100 Subject: changing to use Type argument instead of object --- .../Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index de0e864..21aab84 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -130,9 +130,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms m_scriptModule.PostScriptEvent(script, "link_message", args); } - private static MethodInfo GetMethodInfoFromType(object target, string meth) + private static MethodInfo GetMethodInfoFromType(Type target, string meth) { - MethodInfo mi = target.GetType().GetMethod(meth, + MethodInfo mi = target.GetMethod(meth, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); return mi; @@ -140,7 +140,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms public void RegisterScriptInvocation(object target, string meth) { - MethodInfo mi = GetMethodInfoFromType(target, meth); + MethodInfo mi = GetMethodInfoFromType(target.GetType(), meth); if (mi == null) { m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}",meth); -- cgit v1.1 From 7a9eee8538f474a617a379a66854fe5fa6cb68cd Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 31 Aug 2012 12:59:07 +0100 Subject: no need to assign result to GetMethodInfoFromType --- .../Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index 21aab84..bbf0dac 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -132,10 +132,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms private static MethodInfo GetMethodInfoFromType(Type target, string meth) { - MethodInfo mi = target.GetMethod(meth, + return target.GetMethod(meth, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); - - return mi; } public void RegisterScriptInvocation(object target, string meth) -- cgit v1.1 From bcf944db4846b42a302e443050132aaea4b4d4d6 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 31 Aug 2012 13:01:07 +0100 Subject: assign binding flags to variable --- .../Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index bbf0dac..50d04cd 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -132,8 +132,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms private static MethodInfo GetMethodInfoFromType(Type target, string meth) { + BindingFlags getMethodFlags = + BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance; return target.GetMethod(meth, - BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + getMethodFlags); } public void RegisterScriptInvocation(object target, string meth) -- cgit v1.1 From e6f43023b6fe682971b78175fbb694c18848eff0 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 31 Aug 2012 13:09:15 +0100 Subject: adding support for finding static methods --- .../Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index 50d04cd..19130bd 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -130,17 +130,23 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms m_scriptModule.PostScriptEvent(script, "link_message", args); } - private static MethodInfo GetMethodInfoFromType(Type target, string meth) + private static MethodInfo GetMethodInfoFromType(Type target, string meth, bool searchInstanceMethods) { BindingFlags getMethodFlags = - BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance; + BindingFlags.NonPublic | BindingFlags.Public; + + if (searchInstanceMethods) + getMethodFlags |= BindingFlags.Instance; + else + getMethodFlags |= BindingFlags.Static; + return target.GetMethod(meth, getMethodFlags); } public void RegisterScriptInvocation(object target, string meth) { - MethodInfo mi = GetMethodInfoFromType(target.GetType(), meth); + MethodInfo mi = GetMethodInfoFromType(target.GetType(), meth, true); if (mi == null) { m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}",meth); -- cgit v1.1 From 4c58c1b116d99b72d7c579f2bd2cc87d55b71451 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 31 Aug 2012 13:10:17 +0100 Subject: formatting --- .../Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index 19130bd..d785a24 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -140,8 +140,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms else getMethodFlags |= BindingFlags.Static; - return target.GetMethod(meth, - getMethodFlags); + return target.GetMethod(meth, getMethodFlags); } public void RegisterScriptInvocation(object target, string meth) -- cgit v1.1 From 8cd415c2b0e7bb7989c64ac17cfaa1b892128b87 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 31 Aug 2012 13:10:23 +0100 Subject: formatting --- .../Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index d785a24..77d7e0a 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -148,7 +148,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms MethodInfo mi = GetMethodInfoFromType(target.GetType(), meth, true); if (mi == null) { - m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}",meth); + m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}", meth); return; } -- cgit v1.1 From 7e41559917dbdd9ff1f70765a5a33e2e8f67e9a3 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 31 Aug 2012 13:13:57 +0100 Subject: using specific type instead of var --- .../Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index 77d7e0a..6231624 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -166,7 +166,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms m_log.DebugFormat("[MODULE COMMANDS] Register method {0} from type {1}", mi.Name, target.GetType().Name); Type delegateType; - var typeArgs = mi.GetParameters() + List typeArgs = mi.GetParameters() .Select(p => p.ParameterType) .ToList(); -- cgit v1.1 From b62557978058512ed5b9c3387a507b51365cb8c4 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 31 Aug 2012 13:17:13 +0100 Subject: moving assignment to new line to make next commit easier to read in diffs --- .../Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index 6231624..bbaac3e 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -180,7 +180,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms delegateType = Expression.GetFuncType(typeArgs.ToArray()); } - Delegate fcall = Delegate.CreateDelegate(delegateType, target, mi); + Delegate fcall; + fcall = Delegate.CreateDelegate(delegateType, target, mi); lock (m_scriptInvocation) { -- cgit v1.1 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 From 054db94d5d14fdd50cb2ca9a95a8d5cac2ab234a Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 31 Aug 2012 13:51:00 +0100 Subject: formatting --- .../Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index d6d96c9..8d100e8 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -172,12 +172,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms if (mi.ReturnType == typeof(void)) { - delegateType = Expression.GetActionType(typeArgs.ToArray()); + delegateType = Expression.GetActionType(typeArgs.ToArray()); } else { - typeArgs.Add(mi.ReturnType); - delegateType = Expression.GetFuncType(typeArgs.ToArray()); + typeArgs.Add(mi.ReturnType); + delegateType = Expression.GetFuncType(typeArgs.ToArray()); } Delegate fcall; @@ -188,13 +188,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms lock (m_scriptInvocation) { - ParameterInfo[] parameters = fcall.Method.GetParameters (); + ParameterInfo[] parameters = fcall.Method.GetParameters(); if (parameters.Length < 2) // Must have two UUID params return; // Hide the first two parameters Type[] parmTypes = new Type[parameters.Length - 2]; - for (int i = 2 ; i < parameters.Length ; i++) + for (int i = 2; i < parameters.Length; i++) parmTypes[i - 2] = parameters[i].ParameterType; m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType); } -- cgit v1.1