diff options
author | Mic Bowman | 2012-03-15 13:16:02 -0700 |
---|---|---|
committer | Mic Bowman | 2012-03-15 13:16:02 -0700 |
commit | 402ff75d781d6f4e38eee8884d7b4411bb756c9b (patch) | |
tree | d51e46418d1edab07c762dc0b7c37bb0c6333177 /OpenSim/Region/ScriptEngine/Shared/Api | |
parent | Remove property/field duplication in ScriptInstance where it's unnecessary. (diff) | |
download | opensim-SC_OLD-402ff75d781d6f4e38eee8884d7b4411bb756c9b.zip opensim-SC_OLD-402ff75d781d6f4e38eee8884d7b4411bb756c9b.tar.gz opensim-SC_OLD-402ff75d781d6f4e38eee8884d7b4411bb756c9b.tar.bz2 opensim-SC_OLD-402ff75d781d6f4e38eee8884d7b4411bb756c9b.tar.xz |
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", ...)
Diffstat (limited to '')
3 files changed, 133 insertions, 0 deletions
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 | |||
116 | wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); | 116 | wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); |
117 | } | 117 | } |
118 | 118 | ||
119 | /// <summary> | ||
120 | /// | ||
121 | /// </summary> | ||
122 | /// <param name="fname">The name of the function to invoke</param> | ||
123 | /// <param name="fname">List of parameters</param> | ||
124 | /// <returns>string result of the invocation</returns> | ||
125 | public string modInvokeS(string fname, params object[] parms) | ||
126 | { | ||
127 | Type returntype = m_comms.LookupReturnType(fname); | ||
128 | if (returntype != typeof(string)) | ||
129 | MODError(String.Format("return type mismatch for {0}",fname)); | ||
130 | |||
131 | return (string)modInvoke(fname,parms); | ||
132 | } | ||
133 | |||
134 | public int modInvokeI(string fname, params object[] parms) | ||
135 | { | ||
136 | Type returntype = m_comms.LookupReturnType(fname); | ||
137 | if (returntype != typeof(int)) | ||
138 | MODError(String.Format("return type mismatch for {0}",fname)); | ||
139 | |||
140 | return (int)modInvoke(fname,parms); | ||
141 | } | ||
142 | |||
143 | public float modInvokeF(string fname, params object[] parms) | ||
144 | { | ||
145 | Type returntype = m_comms.LookupReturnType(fname); | ||
146 | if (returntype != typeof(float)) | ||
147 | MODError(String.Format("return type mismatch for {0}",fname)); | ||
148 | |||
149 | return (float)modInvoke(fname,parms); | ||
150 | } | ||
151 | |||
152 | /// <summary> | ||
153 | /// Invokes a preregistered function through the ScriptModuleComms class | ||
154 | /// </summary> | ||
155 | /// <param name="fname">The name of the function to invoke</param> | ||
156 | /// <param name="fname">List of parameters</param> | ||
157 | /// <returns>string result of the invocation</returns> | ||
158 | protected object modInvoke(string fname, params object[] parms) | ||
159 | { | ||
160 | if (!m_MODFunctionsEnabled) | ||
161 | { | ||
162 | MODShoutError("Module command functions not enabled"); | ||
163 | return ""; | ||
164 | } | ||
165 | |||
166 | Type[] signature = m_comms.LookupTypeSignature(fname); | ||
167 | if (signature.Length != parms.Length) | ||
168 | MODError(String.Format("wrong number of parameters to function {0}",fname)); | ||
169 | |||
170 | object[] convertedParms = new object[parms.Length]; | ||
171 | |||
172 | for (int i = 0; i < parms.Length; i++) | ||
173 | { | ||
174 | if (parms[i] is LSL_String) | ||
175 | { | ||
176 | if (signature[i] != typeof(string)) | ||
177 | MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); | ||
178 | |||
179 | convertedParms[i] = (string)(LSL_String)parms[i]; | ||
180 | } | ||
181 | else if (parms[i] is LSL_Integer) | ||
182 | { | ||
183 | if (signature[i] != typeof(int)) | ||
184 | MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); | ||
185 | |||
186 | convertedParms[i] = (int)(LSL_Integer)parms[i]; | ||
187 | } | ||
188 | else if (parms[i] is LSL_Float) | ||
189 | { | ||
190 | if (signature[i] != typeof(float)) | ||
191 | MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); | ||
192 | |||
193 | convertedParms[i] = (float)(LSL_Float)parms[i]; | ||
194 | } | ||
195 | else if (parms[i] is LSL_Key) | ||
196 | { | ||
197 | if (signature[i] != typeof(string)) | ||
198 | MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); | ||
199 | |||
200 | convertedParms[i] = (string)(LSL_Key)parms[i]; | ||
201 | } | ||
202 | else if (parms[i] is LSL_Rotation) | ||
203 | { | ||
204 | if (signature[i] != typeof(string)) | ||
205 | MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); | ||
206 | |||
207 | convertedParms[i] = (string)(LSL_Rotation)parms[i]; | ||
208 | } | ||
209 | else if (parms[i] is LSL_Vector) | ||
210 | { | ||
211 | if (signature[i] != typeof(string)) | ||
212 | MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); | ||
213 | |||
214 | convertedParms[i] = (string)(LSL_Vector)parms[i]; | ||
215 | } | ||
216 | else | ||
217 | { | ||
218 | if (signature[i] != parms[i].GetType()) | ||
219 | MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); | ||
220 | |||
221 | convertedParms[i] = parms[i]; | ||
222 | } | ||
223 | } | ||
224 | |||
225 | return m_comms.InvokeOperation(m_itemID,fname,convertedParms); | ||
226 | } | ||
227 | |||
119 | public string modSendCommand(string module, string command, string k) | 228 | public string modSendCommand(string module, string command, string k) |
120 | { | 229 | { |
121 | if (!m_MODFunctionsEnabled) | 230 | if (!m_MODFunctionsEnabled) |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs index e08eca5..756a59f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs | |||
@@ -40,6 +40,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
40 | { | 40 | { |
41 | public interface IMOD_Api | 41 | public interface IMOD_Api |
42 | { | 42 | { |
43 | // Invocation functions | ||
44 | string modInvokeS(string fname, params object[] parms); | ||
45 | int modInvokeI(string fname, params object[] parms); | ||
46 | float modInvokeF(string fname, params object[] parms); | ||
47 | // vector modInvokeV(string fname, params object[] parms); | ||
48 | // rotation modInvokeV(string fname, params object[] parms); | ||
49 | // key modInvokeK(string fname, params object[] parms); | ||
50 | // list modInvokeL(string fname, params object[] parms); | ||
51 | |||
43 | //Module functions | 52 | //Module functions |
44 | string modSendCommand(string modules, string command, string k); | 53 | string modSendCommand(string modules, string command, string k); |
45 | } | 54 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs index 6525c76..04b7f14 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs | |||
@@ -58,6 +58,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
58 | m_MOD_Functions = (IMOD_Api)api; | 58 | m_MOD_Functions = (IMOD_Api)api; |
59 | } | 59 | } |
60 | 60 | ||
61 | public string modInvokeS(string fname, params object[] parms) | ||
62 | { | ||
63 | return m_MOD_Functions.modInvokeS(fname, parms); | ||
64 | } | ||
65 | |||
66 | public int modInvokeI(string fname, params object[] parms) | ||
67 | { | ||
68 | return m_MOD_Functions.modInvokeI(fname, parms); | ||
69 | } | ||
70 | |||
71 | public float modInvokeF(string fname, params object[] parms) | ||
72 | { | ||
73 | return m_MOD_Functions.modInvokeF(fname, parms); | ||
74 | } | ||
75 | |||
61 | public string modSendCommand(string module, string command, string k) | 76 | public string modSendCommand(string module, string command, string k) |
62 | { | 77 | { |
63 | return m_MOD_Functions.modSendCommand(module, command, k); | 78 | return m_MOD_Functions.modSendCommand(module, command, k); |