Merge branch 'master' into careminster

avinationmerge
Melanie 2012-09-17 14:18:03 +01:00
commit d739246030
2 changed files with 72 additions and 1 deletions

View File

@ -74,6 +74,14 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="methods"></param>
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>
/// Returns an array of all registered script calls
/// </summary>
@ -96,11 +104,43 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="key"></param>
void DispatchReply(UUID scriptId, int code, string text, string key);
/// For constants
/// <summary>
/// Operation to for a region module to register a constant to be used
/// by the script engine
/// </summary>
/// <param name="cname">
/// The name of the constant. LSL convention is for constant names to
/// be uppercase.
/// </param>
/// <param name="value">
/// The value of the constant. Should be of a type that can be
/// converted to one of <see cref="OpenSim.Region.ScriptEngine.Shared.LSL_Types"/>
/// </param>
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);
/// <summary>
/// Operation to check for a registered constant
/// </summary>
/// <param name="cname">Name of constant</param>
/// <returns>Value of constant or null if none found.</returns>
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
{ }
}

View File

@ -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));
}
}
}
/// <summary>
/// Operation to check for a registered constant
/// </summary>