From 402ff75d781d6f4e38eee8884d7b4411bb756c9b Mon Sep 17 00:00:00 2001
From: Mic Bowman
Date: Thu, 15 Mar 2012 13:16:02 -0700
Subject: Adds a new script command 'modInvoke' to invoke registered functions
from region modules. The LSL translator is extended to generate the modInvoke
format of commands for directly inlined function calls.
A region module can register a function Test() with the name "Test".
LSL code can call that function as "Test()". The compiler will translate
that invocation into modInvoke("Test", ...)
---
.../Shared/Api/Implementation/MOD_Api.cs | 109 +++++++++++++++++++++
1 file changed, 109 insertions(+)
(limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation')
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
index d4facdd..2942104 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
@@ -116,6 +116,115 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
}
+ ///
+ ///
+ ///
+ /// The name of the function to invoke
+ /// List of parameters
+ /// string result of the invocation
+ public string modInvokeS(string fname, params object[] parms)
+ {
+ Type returntype = m_comms.LookupReturnType(fname);
+ if (returntype != typeof(string))
+ MODError(String.Format("return type mismatch for {0}",fname));
+
+ return (string)modInvoke(fname,parms);
+ }
+
+ public int modInvokeI(string fname, params object[] parms)
+ {
+ Type returntype = m_comms.LookupReturnType(fname);
+ if (returntype != typeof(int))
+ MODError(String.Format("return type mismatch for {0}",fname));
+
+ return (int)modInvoke(fname,parms);
+ }
+
+ public float modInvokeF(string fname, params object[] parms)
+ {
+ Type returntype = m_comms.LookupReturnType(fname);
+ if (returntype != typeof(float))
+ MODError(String.Format("return type mismatch for {0}",fname));
+
+ return (float)modInvoke(fname,parms);
+ }
+
+ ///
+ /// Invokes a preregistered function through the ScriptModuleComms class
+ ///
+ /// The name of the function to invoke
+ /// List of parameters
+ /// string result of the invocation
+ protected object modInvoke(string fname, params object[] parms)
+ {
+ if (!m_MODFunctionsEnabled)
+ {
+ MODShoutError("Module command functions not enabled");
+ return "";
+ }
+
+ Type[] signature = m_comms.LookupTypeSignature(fname);
+ if (signature.Length != parms.Length)
+ MODError(String.Format("wrong number of parameters to function {0}",fname));
+
+ object[] convertedParms = new object[parms.Length];
+
+ for (int i = 0; i < parms.Length; i++)
+ {
+ if (parms[i] is LSL_String)
+ {
+ if (signature[i] != typeof(string))
+ MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
+
+ convertedParms[i] = (string)(LSL_String)parms[i];
+ }
+ else if (parms[i] is LSL_Integer)
+ {
+ if (signature[i] != typeof(int))
+ MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
+
+ convertedParms[i] = (int)(LSL_Integer)parms[i];
+ }
+ else if (parms[i] is LSL_Float)
+ {
+ if (signature[i] != typeof(float))
+ MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
+
+ convertedParms[i] = (float)(LSL_Float)parms[i];
+ }
+ else if (parms[i] is LSL_Key)
+ {
+ if (signature[i] != typeof(string))
+ MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
+
+ convertedParms[i] = (string)(LSL_Key)parms[i];
+ }
+ else if (parms[i] is LSL_Rotation)
+ {
+ if (signature[i] != typeof(string))
+ MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
+
+ convertedParms[i] = (string)(LSL_Rotation)parms[i];
+ }
+ else if (parms[i] is LSL_Vector)
+ {
+ if (signature[i] != typeof(string))
+ MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
+
+ convertedParms[i] = (string)(LSL_Vector)parms[i];
+ }
+ else
+ {
+ if (signature[i] != parms[i].GetType())
+ MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
+
+ convertedParms[i] = parms[i];
+ }
+ }
+
+ return m_comms.InvokeOperation(m_itemID,fname,convertedParms);
+ }
+
public string modSendCommand(string module, string command, string k)
{
if (!m_MODFunctionsEnabled)
--
cgit v1.1