Merge branch 'master' into careminster
commit
c0feaf54de
|
@ -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);
|
||||||
|
|
|
@ -130,13 +130,25 @@ 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);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,22 +180,38 @@ 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)
|
||||||
{
|
{
|
||||||
ParameterInfo[] parameters = fcall.Method.GetParameters ();
|
ParameterInfo[] parameters = fcall.Method.GetParameters();
|
||||||
if (parameters.Length < 2) // Must have two UUID params
|
if (parameters.Length < 2) // Must have two UUID params
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Hide the first two parameters
|
// Hide the first two parameters
|
||||||
Type[] parmTypes = new Type[parameters.Length - 2];
|
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;
|
parmTypes[i - 2] = parameters[i].ParameterType;
|
||||||
m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType);
|
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()
|
public Delegate[] GetScriptInvocationList()
|
||||||
{
|
{
|
||||||
List<Delegate> ret = new List<Delegate>();
|
List<Delegate> ret = new List<Delegate>();
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue