diff options
author | Mic Bowman | 2012-07-31 10:45:37 -0700 |
---|---|---|
committer | Mic Bowman | 2012-07-31 10:45:37 -0700 |
commit | a76a289d11086dd99d345390e58a43b66b053470 (patch) | |
tree | 60b1ef6d3890d9636a1bbb9b47758847e30b88dd /OpenSim/Region | |
parent | BulletSim: update the DLLs and SOs. This fixes the exception on shutdown (diff) | |
download | opensim-SC-a76a289d11086dd99d345390e58a43b66b053470.zip opensim-SC-a76a289d11086dd99d345390e58a43b66b053470.tar.gz opensim-SC-a76a289d11086dd99d345390e58a43b66b053470.tar.bz2 opensim-SC-a76a289d11086dd99d345390e58a43b66b053470.tar.xz |
Adds support to ScriptModuleComms for region modules to export
constants to the script engine.
Diffstat (limited to 'OpenSim/Region')
3 files changed, 74 insertions, 2 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs index bfe1e8d..ed71a95 100644 --- a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs +++ b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs | |||
@@ -67,6 +67,10 @@ namespace OpenSim.Region.Framework.Interfaces | |||
67 | /// <param name="key"></param> | 67 | /// <param name="key"></param> |
68 | void DispatchReply(UUID scriptId, int code, string text, string key); | 68 | void DispatchReply(UUID scriptId, int code, string text, string key); |
69 | 69 | ||
70 | /// For constants | ||
71 | void RegisterConstant(string cname, object value); | ||
72 | object LookupModConstant(string cname); | ||
73 | |||
70 | // For use ONLY by the script API | 74 | // For use ONLY by the script API |
71 | void RaiseEvent(UUID script, string id, string module, string command, string key); | 75 | void RaiseEvent(UUID script, string id, string module, string command, string key); |
72 | } | 76 | } |
diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index 74a85e2..705a847 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | |||
@@ -46,6 +46,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms | |||
46 | private static readonly ILog m_log = | 46 | private static readonly ILog m_log = |
47 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 47 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | 48 | ||
49 | private Dictionary<string,object> m_constants = new Dictionary<string,object>(); | ||
50 | |||
49 | #region ScriptInvocation | 51 | #region ScriptInvocation |
50 | protected class ScriptInvocationData | 52 | protected class ScriptInvocationData |
51 | { | 53 | { |
@@ -269,6 +271,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms | |||
269 | Delegate fn = LookupScriptInvocation(fname); | 271 | Delegate fn = LookupScriptInvocation(fname); |
270 | return fn.DynamicInvoke(olist.ToArray()); | 272 | return fn.DynamicInvoke(olist.ToArray()); |
271 | } | 273 | } |
274 | |||
275 | /// <summary> | ||
276 | /// Operation to for a region module to register a constant to be used | ||
277 | /// by the script engine | ||
278 | /// </summary> | ||
279 | public void RegisterConstant(string cname, object value) | ||
280 | { | ||
281 | m_log.DebugFormat("[MODULE COMMANDS] register constant <{0}> with value {1}",cname,value.ToString()); | ||
282 | lock (m_constants) | ||
283 | { | ||
284 | m_constants.Add(cname,value); | ||
285 | } | ||
286 | } | ||
287 | |||
288 | /// <summary> | ||
289 | /// Operation to check for a registered constant | ||
290 | /// </summary> | ||
291 | public object LookupModConstant(string cname) | ||
292 | { | ||
293 | // m_log.DebugFormat("[MODULE COMMANDS] lookup constant <{0}>",cname); | ||
294 | |||
295 | lock (m_constants) | ||
296 | { | ||
297 | object value = null; | ||
298 | if (m_constants.TryGetValue(cname,out value)) | ||
299 | return value; | ||
300 | } | ||
301 | |||
302 | return null; | ||
303 | } | ||
304 | |||
272 | #endregion | 305 | #endregion |
273 | 306 | ||
274 | } | 307 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs index b24f016..97dd0f6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs | |||
@@ -38,7 +38,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
38 | { | 38 | { |
39 | public class CSCodeGenerator : ICodeConverter | 39 | public class CSCodeGenerator : ICodeConverter |
40 | { | 40 | { |
41 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 41 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
42 | 42 | ||
43 | private SYMBOL m_astRoot = null; | 43 | private SYMBOL m_astRoot = null; |
44 | private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> m_positionMap; | 44 | private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> m_positionMap; |
@@ -255,7 +255,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
255 | else if (s is IdentDotExpression) | 255 | else if (s is IdentDotExpression) |
256 | retstr += Generate(CheckName(((IdentDotExpression) s).Name) + "." + ((IdentDotExpression) s).Member, s); | 256 | retstr += Generate(CheckName(((IdentDotExpression) s).Name) + "." + ((IdentDotExpression) s).Member, s); |
257 | else if (s is IdentExpression) | 257 | else if (s is IdentExpression) |
258 | retstr += Generate(CheckName(((IdentExpression) s).Name), s); | 258 | retstr += GenerateIdentifier(((IdentExpression) s).Name, s); |
259 | else if (s is IDENT) | 259 | else if (s is IDENT) |
260 | retstr += Generate(CheckName(((TOKEN) s).yytext), s); | 260 | retstr += Generate(CheckName(((TOKEN) s).yytext), s); |
261 | else | 261 | else |
@@ -868,6 +868,41 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
868 | } | 868 | } |
869 | 869 | ||
870 | /// <summary> | 870 | /// <summary> |
871 | /// Generates the code for an identifier | ||
872 | /// </summary> | ||
873 | /// <param name="id">The symbol name</param> | ||
874 | /// <param name="s">The Symbol node.</param> | ||
875 | /// <returns>String containing C# code for identifier reference.</returns> | ||
876 | private string GenerateIdentifier(string id, SYMBOL s) | ||
877 | { | ||
878 | if (m_comms != null) | ||
879 | { | ||
880 | object value = m_comms.LookupModConstant(id); | ||
881 | if (value != null) | ||
882 | { | ||
883 | string retval = null; | ||
884 | if (value is int) | ||
885 | retval = ((int)value).ToString(); | ||
886 | else if (value is float) | ||
887 | retval = String.Format("new LSL_Types.LSLFloat({0})",((float)value).ToString()); | ||
888 | else if (value is string) | ||
889 | retval = String.Format("new LSL_Types.LSLString(\"{0}\")",((string)value)); | ||
890 | else if (value is OpenMetaverse.UUID) | ||
891 | retval = String.Format("new LSL_Types.key(\"{0}\")",((OpenMetaverse.UUID)value).ToString()); | ||
892 | else if (value is OpenMetaverse.Vector3) | ||
893 | retval = String.Format("new LSL_Types.Vector3(\"{0}\")",((OpenMetaverse.Vector3)value).ToString()); | ||
894 | else if (value is OpenMetaverse.Quaternion) | ||
895 | retval = String.Format("new LSL_Types.Quaternion(\"{0}\")",((OpenMetaverse.Quaternion)value).ToString()); | ||
896 | else retval = id; | ||
897 | |||
898 | return Generate(retval, s); | ||
899 | } | ||
900 | } | ||
901 | |||
902 | return Generate(CheckName(id), s); | ||
903 | } | ||
904 | |||
905 | /// <summary> | ||
871 | /// Generates the code for a FunctionCall node. | 906 | /// Generates the code for a FunctionCall node. |
872 | /// </summary> | 907 | /// </summary> |
873 | /// <param name="fc">The FunctionCall node.</param> | 908 | /// <param name="fc">The FunctionCall node.</param> |