Implementing ability to register script constants and invocations on a region module automatically
parent
c7948a669a
commit
f9721573d9
|
@ -74,6 +74,14 @@ namespace OpenSim.Region.Framework.Interfaces
|
||||||
/// <param name="methods"></param>
|
/// <param name="methods"></param>
|
||||||
void RegisterScriptInvocation(Type target, string[] methods);
|
void RegisterScriptInvocation(Type target, string[] methods);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Automatically register script invocations by checking for methods
|
||||||
|
/// with <see cref="ScriptInvocationAttribute"/>. Should only check
|
||||||
|
/// public methods.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="target"></param>
|
||||||
|
void RegisterScriptInvocations(IRegionModuleBase target);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns an array of all registered script calls
|
/// Returns an array of all registered script calls
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -98,9 +106,24 @@ namespace OpenSim.Region.Framework.Interfaces
|
||||||
|
|
||||||
/// For constants
|
/// For constants
|
||||||
void RegisterConstant(string cname, object value);
|
void RegisterConstant(string cname, object value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Automatically register all constants on a region module by
|
||||||
|
/// checking for fields with <see cref="ScriptConstantAttribute"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="target"></param>
|
||||||
|
void RegisterConstants(IRegionModuleBase target);
|
||||||
object LookupModConstant(string cname);
|
object LookupModConstant(string cname);
|
||||||
|
|
||||||
// For use ONLY by the script API
|
// For use ONLY by the script API
|
||||||
void RaiseEvent(UUID script, string id, string module, string command, string key);
|
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
|
||||||
|
{ }
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,6 +211,23 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms
|
||||||
RegisterScriptInvocation(target, mi);
|
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()
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Operation to check for a registered constant
|
/// Operation to check for a registered constant
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue