Correct the design error I introduced into ScriptComms. Untested but about to
be.0.7.4.1
parent
cb44808504
commit
d7cc194e83
|
@ -31,7 +31,6 @@ using OpenMetaverse;
|
||||||
namespace OpenSim.Region.Framework.Interfaces
|
namespace OpenSim.Region.Framework.Interfaces
|
||||||
{
|
{
|
||||||
public delegate void ScriptCommand(UUID script, string id, string module, string command, string k);
|
public delegate void ScriptCommand(UUID script, string id, string module, string command, string k);
|
||||||
public delegate object ScriptInvocation(UUID script, object[] parms);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface for communication between OpenSim modules and in-world scripts
|
/// Interface for communication between OpenSim modules and in-world scripts
|
||||||
|
@ -46,10 +45,10 @@ namespace OpenSim.Region.Framework.Interfaces
|
||||||
/// </summary>
|
/// </summary>
|
||||||
event ScriptCommand OnScriptCommand;
|
event ScriptCommand OnScriptCommand;
|
||||||
|
|
||||||
void RegisterScriptInvocation(ScriptInvocation fn);
|
void RegisterScriptInvocation(Delegate fn);
|
||||||
ScriptInvocation[] GetScriptInvocationList();
|
Delegate[] GetScriptInvocationList();
|
||||||
|
|
||||||
ScriptInvocation LookupScriptInvocation(string fname);
|
Delegate LookupScriptInvocation(string fname);
|
||||||
string LookupModInvocation(string fname);
|
string LookupModInvocation(string fname);
|
||||||
Type[] LookupTypeSignature(string fname);
|
Type[] LookupTypeSignature(string fname);
|
||||||
Type LookupReturnType(string fname);
|
Type LookupReturnType(string fname);
|
||||||
|
|
|
@ -47,15 +47,15 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
|
||||||
#region ScriptInvocation
|
#region ScriptInvocation
|
||||||
protected class ScriptInvocationData
|
protected class ScriptInvocationData
|
||||||
{
|
{
|
||||||
public ScriptInvocation ScriptInvocationFn { get; private set; }
|
public Delegate ScriptInvocationDelegate { get; private set; }
|
||||||
public string FunctionName { get; private set; }
|
public string FunctionName { get; private set; }
|
||||||
public Type[] TypeSignature { get; private set; }
|
public Type[] TypeSignature { get; private set; }
|
||||||
public Type ReturnType { get; private set; }
|
public Type ReturnType { get; private set; }
|
||||||
|
|
||||||
public ScriptInvocationData(string fname, ScriptInvocation fn, Type[] callsig, Type returnsig)
|
public ScriptInvocationData(string fname, Delegate fn, Type[] callsig, Type returnsig)
|
||||||
{
|
{
|
||||||
FunctionName = fname;
|
FunctionName = fname;
|
||||||
ScriptInvocationFn = fn;
|
ScriptInvocationDelegate = fn;
|
||||||
TypeSignature = callsig;
|
TypeSignature = callsig;
|
||||||
ReturnType = returnsig;
|
ReturnType = returnsig;
|
||||||
}
|
}
|
||||||
|
@ -126,26 +126,30 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
|
||||||
m_scriptModule.PostScriptEvent(script, "link_message", args);
|
m_scriptModule.PostScriptEvent(script, "link_message", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterScriptInvocation(ScriptInvocation fcall)
|
public void RegisterScriptInvocation(Delegate fcall)
|
||||||
{
|
{
|
||||||
lock (m_scriptInvocation)
|
lock (m_scriptInvocation)
|
||||||
{
|
{
|
||||||
ParameterInfo[] parameters = fcall.Method.GetParameters ();
|
ParameterInfo[] parameters = fcall.Method.GetParameters ();
|
||||||
Type[] parmTypes = new Type[parameters.Length];
|
if (parameters.Length == 0) // Must have one UUID param
|
||||||
for (int i = 0 ; i < parameters.Length ; i++)
|
return;
|
||||||
parmTypes[i] = parameters[i].ParameterType;
|
|
||||||
|
// Hide the first parameter
|
||||||
|
Type[] parmTypes = new Type[parameters.Length - 1];
|
||||||
|
for (int i = 1 ; i < parameters.Length ; i++)
|
||||||
|
parmTypes[i - 1] = 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 ScriptInvocation[] GetScriptInvocationList()
|
public Delegate[] GetScriptInvocationList()
|
||||||
{
|
{
|
||||||
List<ScriptInvocation> ret = new List<ScriptInvocation>();
|
List<Delegate> ret = new List<Delegate>();
|
||||||
|
|
||||||
lock (m_scriptInvocation)
|
lock (m_scriptInvocation)
|
||||||
{
|
{
|
||||||
foreach (ScriptInvocationData d in m_scriptInvocation.Values)
|
foreach (ScriptInvocationData d in m_scriptInvocation.Values)
|
||||||
ret.Add(d.ScriptInvocationFn);
|
ret.Add(d.ScriptInvocationDelegate);
|
||||||
}
|
}
|
||||||
return ret.ToArray();
|
return ret.ToArray();
|
||||||
}
|
}
|
||||||
|
@ -177,13 +181,13 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptInvocation LookupScriptInvocation(string fname)
|
public Delegate LookupScriptInvocation(string fname)
|
||||||
{
|
{
|
||||||
lock (m_scriptInvocation)
|
lock (m_scriptInvocation)
|
||||||
{
|
{
|
||||||
ScriptInvocationData sid;
|
ScriptInvocationData sid;
|
||||||
if (m_scriptInvocation.TryGetValue(fname,out sid))
|
if (m_scriptInvocation.TryGetValue(fname,out sid))
|
||||||
return sid.ScriptInvocationFn;
|
return sid.ScriptInvocationDelegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -215,8 +219,12 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
|
||||||
|
|
||||||
public object InvokeOperation(UUID scriptid, string fname, params object[] parms)
|
public object InvokeOperation(UUID scriptid, string fname, params object[] parms)
|
||||||
{
|
{
|
||||||
ScriptInvocation fn = LookupScriptInvocation(fname);
|
List<object> olist = new List<object>();
|
||||||
return fn(scriptid,parms);
|
olist.Add(scriptid);
|
||||||
|
foreach (object o in parms)
|
||||||
|
olist.Add(o);
|
||||||
|
Delegate fn = LookupScriptInvocation(fname);
|
||||||
|
return fn.DynamicInvoke(olist.ToArray());
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue