Merge branch 'master' into careminster

avinationmerge
Melanie 2012-08-31 14:40:30 +01:00
commit c0feaf54de
3 changed files with 68 additions and 11 deletions

View File

@ -46,9 +46,38 @@ namespace OpenSim.Region.Framework.Interfaces
/// </summary> /// </summary>
event ScriptCommand OnScriptCommand; event ScriptCommand OnScriptCommand;
/// <summary>
/// Register an instance method as a script call by method name
/// </summary>
/// <param name="target"></param>
/// <param name="method"></param>
void RegisterScriptInvocation(object target, string method); void RegisterScriptInvocation(object target, string method);
/// <summary>
/// Register a static or instance method as a script call by method info
/// </summary>
/// <param name="target">If target is a Type object, will assume method is static.</param>
/// <param name="method"></param>
void RegisterScriptInvocation(object target, MethodInfo method); void RegisterScriptInvocation(object target, MethodInfo method);
/// <summary>
/// Register one or more instance methods as script calls by method name
/// </summary>
/// <param name="target"></param>
/// <param name="methods"></param>
void RegisterScriptInvocation(object target, string[] methods); void RegisterScriptInvocation(object target, string[] methods);
/// <summary>
/// Register one or more static methods as script calls by method name
/// </summary>
/// <param name="target"></param>
/// <param name="methods"></param>
void RegisterScriptInvocation(Type target, string[] methods);
/// <summary>
/// Returns an array of all registered script calls
/// </summary>
/// <returns></returns>
Delegate[] GetScriptInvocationList(); Delegate[] GetScriptInvocationList();
Delegate LookupScriptInvocation(string fname); Delegate LookupScriptInvocation(string fname);

View File

@ -130,10 +130,22 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms
m_scriptModule.PostScriptEvent(script, "link_message", args); m_scriptModule.PostScriptEvent(script, "link_message", args);
} }
private static MethodInfo GetMethodInfoFromType(Type target, string meth, bool searchInstanceMethods)
{
BindingFlags getMethodFlags =
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) public void RegisterScriptInvocation(object target, string meth)
{ {
MethodInfo mi = target.GetType().GetMethod(meth, MethodInfo mi = GetMethodInfoFromType(target.GetType(), meth, true);
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
if (mi == null) 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);
@ -154,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); m_log.DebugFormat("[MODULE COMMANDS] Register method {0} from type {1}", mi.Name, target.GetType().Name);
Type delegateType; Type delegateType;
var typeArgs = mi.GetParameters() List<Type> typeArgs = mi.GetParameters()
.Select(p => p.ParameterType) .Select(p => p.ParameterType)
.ToList(); .ToList();
@ -168,7 +180,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms
delegateType = Expression.GetFuncType(typeArgs.ToArray()); delegateType = Expression.GetFuncType(typeArgs.ToArray());
} }
Delegate fcall = Delegate.CreateDelegate(delegateType, target, mi); Delegate fcall;
if (!(target is Type))
fcall = Delegate.CreateDelegate(delegateType, target, mi);
else
fcall = Delegate.CreateDelegate(delegateType, (Type)target, mi.Name);
lock (m_scriptInvocation) lock (m_scriptInvocation)
{ {
@ -184,6 +200,18 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms
} }
} }
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() public Delegate[] GetScriptInvocationList()
{ {
List<Delegate> ret = new List<Delegate>(); List<Delegate> ret = new List<Delegate>();

View File

@ -341,7 +341,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return GetLinkParts(m_host, linkType); return GetLinkParts(m_host, linkType);
} }
private List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType) public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType)
{ {
List<SceneObjectPart> ret = new List<SceneObjectPart>(); List<SceneObjectPart> ret = new List<SceneObjectPart>();
if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)