From a76a289d11086dd99d345390e58a43b66b053470 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Tue, 31 Jul 2012 10:45:37 -0700 Subject: Adds support to ScriptModuleComms for region modules to export constants to the script engine. --- .../Shared/CodeTools/CSCodeGenerator.cs | 39 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') 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 { public class CSCodeGenerator : ICodeConverter { -// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private SYMBOL m_astRoot = null; private Dictionary, KeyValuePair> m_positionMap; @@ -255,7 +255,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools else if (s is IdentDotExpression) retstr += Generate(CheckName(((IdentDotExpression) s).Name) + "." + ((IdentDotExpression) s).Member, s); else if (s is IdentExpression) - retstr += Generate(CheckName(((IdentExpression) s).Name), s); + retstr += GenerateIdentifier(((IdentExpression) s).Name, s); else if (s is IDENT) retstr += Generate(CheckName(((TOKEN) s).yytext), s); else @@ -868,6 +868,41 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools } /// + /// Generates the code for an identifier + /// + /// The symbol name + /// The Symbol node. + /// String containing C# code for identifier reference. + private string GenerateIdentifier(string id, SYMBOL s) + { + if (m_comms != null) + { + object value = m_comms.LookupModConstant(id); + if (value != null) + { + string retval = null; + if (value is int) + retval = ((int)value).ToString(); + else if (value is float) + retval = String.Format("new LSL_Types.LSLFloat({0})",((float)value).ToString()); + else if (value is string) + retval = String.Format("new LSL_Types.LSLString(\"{0}\")",((string)value)); + else if (value is OpenMetaverse.UUID) + retval = String.Format("new LSL_Types.key(\"{0}\")",((OpenMetaverse.UUID)value).ToString()); + else if (value is OpenMetaverse.Vector3) + retval = String.Format("new LSL_Types.Vector3(\"{0}\")",((OpenMetaverse.Vector3)value).ToString()); + else if (value is OpenMetaverse.Quaternion) + retval = String.Format("new LSL_Types.Quaternion(\"{0}\")",((OpenMetaverse.Quaternion)value).ToString()); + else retval = id; + + return Generate(retval, s); + } + } + + return Generate(CheckName(id), s); + } + + /// /// Generates the code for a FunctionCall node. /// /// The FunctionCall node. -- cgit v1.1