// this one accepts all fields given to it
        public static void AddInterfaceConstants(Dictionary <string, ScriptConst> sc, IEnumerator <FieldInfo> fields)
        {
            if (sc == null)
            {
                sc = scriptConstants;
            }

            for (fields.Reset(); fields.MoveNext();)
            {
                FieldInfo constField = fields.Current;
                Type      fieldType  = constField.FieldType;
                CompValu  cv;

                // The location of a simple number is the number itself.
                // Access to the value gets compiled as an ldc instruction.
                if (fieldType == typeof(double))
                {
                    cv = new CompValuFloat(new TokenTypeFloat(null),
                                           (double)(double)constField.GetValue(null));
                }
                else if (fieldType == typeof(int))
                {
                    cv = new CompValuInteger(new TokenTypeInt(null),
                                             (int)constField.GetValue(null));
                }
                else if (fieldType == typeof(LSL_Integer))
                {
                    cv = new CompValuInteger(new TokenTypeInt(null),
                                             ((LSL_Integer)constField.GetValue(null)).value);
                }

                // The location of a string is the string itself.
                // Access to the value gets compiled as an ldstr instruction.
                else if (fieldType == typeof(string))
                {
                    cv = new CompValuString(new TokenTypeStr(null),
                                            (string)constField.GetValue(null));
                }
                else if (fieldType == typeof(LSL_String))
                {
                    cv = new CompValuString(new TokenTypeStr(null),
                                            (string)(LSL_String)constField.GetValue(null));
                }

                // The location of everything else (objects) is the static field in the interface definition.
                // Access to the value gets compiled as an ldsfld instruction.
                else
                {
                    cv = new CompValuSField(TokenType.FromSysType(null, fieldType), constField);
                }

                // Add to dictionary.
                new ScriptConst(sc, constField.Name, cv);
            }
        }
        /**
         * @brief Add arbitrary constant available to script compilation.
         * CAUTION: These values get compiled-in to a script and must not
         *          change over time as previously compiled scripts will
         *          still have the old values.
         */
        public static ScriptConst AddConstant(string name, object value)
        {
            CompValu cv = null;

            if (value is char)
            {
                cv = new CompValuChar(new TokenTypeChar(null), (char)value);
            }
            else if (value is double)
            {
                cv = new CompValuFloat(new TokenTypeFloat(null), (double)(double)value);
            }
            else if (value is float)
            {
                cv = new CompValuFloat(new TokenTypeFloat(null), (double)(float)value);
            }
            else if (value is int)
            {
                cv = new CompValuInteger(new TokenTypeInt(null), (int)value);
            }
            else if (value is string)
            {
                cv = new CompValuString(new TokenTypeStr(null), (string)value);
            }

            else if (value is LSL_Float)
            {
                cv = new CompValuFloat(new TokenTypeFloat(null), (double)((LSL_Float)value).value);
            }
            else if (value is LSL_Integer)
            {
                cv = new CompValuInteger(new TokenTypeInt(null), ((LSL_Integer)value).value);
            }
            else if (value is LSL_Rotation)
            {
                LSL_Rotation r = (LSL_Rotation)value;
                CompValu     x = new CompValuFloat(new TokenTypeFloat(null), r.x);
                CompValu     y = new CompValuFloat(new TokenTypeFloat(null), r.y);
                CompValu     z = new CompValuFloat(new TokenTypeFloat(null), r.z);
                CompValu     s = new CompValuFloat(new TokenTypeFloat(null), r.s);
                cv = new CompValuRot(new TokenTypeRot(null), x, y, z, s);
            }
            else if (value is LSL_String)
            {
                cv = new CompValuString(new TokenTypeStr(null), (string)(LSL_String)value);
            }
            else if (value is LSL_Vector)
            {
                LSL_Vector v = (LSL_Vector)value;
                CompValu   x = new CompValuFloat(new TokenTypeFloat(null), v.x);
                CompValu   y = new CompValuFloat(new TokenTypeFloat(null), v.y);
                CompValu   z = new CompValuFloat(new TokenTypeFloat(null), v.z);
                cv = new CompValuVec(new TokenTypeVec(null), x, y, z);
            }

            else if (value is OpenMetaverse.Quaternion)
            {
                OpenMetaverse.Quaternion r = (OpenMetaverse.Quaternion)value;
                CompValu x = new CompValuFloat(new TokenTypeFloat(null), r.X);
                CompValu y = new CompValuFloat(new TokenTypeFloat(null), r.Y);
                CompValu z = new CompValuFloat(new TokenTypeFloat(null), r.Z);
                CompValu s = new CompValuFloat(new TokenTypeFloat(null), r.W);
                cv = new CompValuRot(new TokenTypeRot(null), x, y, z, s);
            }
            else if (value is OpenMetaverse.UUID)
            {
                cv = new CompValuString(new TokenTypeKey(null), value.ToString());
            }
            else if (value is OpenMetaverse.Vector3)
            {
                OpenMetaverse.Vector3 v = (OpenMetaverse.Vector3)value;
                CompValu x = new CompValuFloat(new TokenTypeFloat(null), v.X);
                CompValu y = new CompValuFloat(new TokenTypeFloat(null), v.Y);
                CompValu z = new CompValuFloat(new TokenTypeFloat(null), v.Z);
                cv = new CompValuVec(new TokenTypeVec(null), x, y, z);
            }

            if (cv == null)
            {
                throw new Exception("bad type " + value.GetType().Name);
            }
            return(new ScriptConst(scriptConstants, name, cv));
        }