From f9721573d956092c2d993ee41654f3f5e160401c Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 14 Sep 2012 13:17:07 +0100 Subject: Implementing ability to register script constants and invocations on a region module automatically --- .../Framework/Interfaces/IScriptModuleComms.cs | 23 ++++++++++++++++ .../ScriptModuleComms/ScriptModuleCommsModule.cs | 31 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs index dae7c00..277c9ed 100644 --- a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs +++ b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs @@ -75,6 +75,14 @@ namespace OpenSim.Region.Framework.Interfaces void RegisterScriptInvocation(Type target, string[] methods); /// + /// Automatically register script invocations by checking for methods + /// with . Should only check + /// public methods. + /// + /// + void RegisterScriptInvocations(IRegionModuleBase target); + + /// /// Returns an array of all registered script calls /// /// @@ -98,9 +106,24 @@ namespace OpenSim.Region.Framework.Interfaces /// For constants void RegisterConstant(string cname, object value); + + /// + /// Automatically register all constants on a region module by + /// checking for fields with . + /// + /// + void RegisterConstants(IRegionModuleBase target); object LookupModConstant(string cname); // For use ONLY by the script API void RaiseEvent(UUID script, string id, string module, string command, string key); } + + [AttributeUsage(AttributeTargets.Method)] + public class ScriptInvocationAttribute : Attribute + { } + + [AttributeUsage(AttributeTargets.Field)] + public class ScriptConstantAttribute : Attribute + { } } diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index 23cc633..98396ff 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -211,6 +211,23 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms RegisterScriptInvocation(target, mi); } } + + public void RegisterScriptInvocations(IRegionModuleBase target) + { + foreach(MethodInfo method in target.GetType().GetMethods( + BindingFlags.Public | BindingFlags.Instance | + BindingFlags.Static)) + { + if(method.GetCustomAttributes( + typeof(ScriptInvocationAttribute), true).Any()) + { + if(method.IsStatic) + RegisterScriptInvocation(target.GetType(), method); + else + RegisterScriptInvocation(target, method); + } + } + } public Delegate[] GetScriptInvocationList() { @@ -313,6 +330,20 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms } } + public void RegisterConstants(IRegionModuleBase target) + { + foreach (FieldInfo field in target.GetType().GetFields( + BindingFlags.Public | BindingFlags.Static | + BindingFlags.Instance)) + { + if (field.GetCustomAttributes( + typeof(ScriptConstantAttribute), true).Any()) + { + RegisterConstant(field.Name, field.GetValue(target)); + } + } + } + /// /// Operation to check for a registered constant /// -- cgit v1.1 From 0e5f5538bcaa031ae252468e5c0b70e5dce1a9b1 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Fri, 14 Sep 2012 13:20:14 +0100 Subject: Documentation of IScriptModuleComms.RegisterConstant and IScriptModuleComms.LookupModConstant Signed-off-by: Melanie --- .../Region/Framework/Interfaces/IScriptModuleComms.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs index 277c9ed..93930ce 100644 --- a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs +++ b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs @@ -104,7 +104,18 @@ namespace OpenSim.Region.Framework.Interfaces /// void DispatchReply(UUID scriptId, int code, string text, string key); - /// For constants + /// + /// Operation to for a region module to register a constant to be used + /// by the script engine + /// + /// + /// The name of the constant. LSL convention is for constant names to + /// be uppercase. + /// + /// + /// The value of the constant. Should be of a type that can be + /// converted to one of + /// void RegisterConstant(string cname, object value); /// @@ -113,6 +124,12 @@ namespace OpenSim.Region.Framework.Interfaces /// /// void RegisterConstants(IRegionModuleBase target); + + /// + /// Operation to check for a registered constant + /// + /// Name of constant + /// Value of constant or null if none found. object LookupModConstant(string cname); // For use ONLY by the script API -- cgit v1.1