public static string BuiltInConstVal(CompValu rVal) { if (rVal is CompValuInteger) { int x = ((CompValuInteger)rVal).x; return("0x" + x.ToString("X8") + " = " + x.ToString().PadLeft(11)); } if (rVal is CompValuFloat) { return(((CompValuFloat)rVal).x.ToString()); } if (rVal is CompValuString) { StringBuilder sb = new StringBuilder(); PrintParam(sb, ((CompValuString)rVal).x); return(sb.ToString()); } if (rVal is CompValuSField) { FieldInfo fi = ((CompValuSField)rVal).field; StringBuilder sb = new StringBuilder(); PrintParam(sb, fi.GetValue(null)); return(sb.ToString()); } return(rVal.ToString()); // just prints the type }
private ScriptConst(Dictionary <string, ScriptConst> lc, string name, CompValu rVal) { lc.Add(name, this); this.name = name; this.rVal = rVal; }
/** * @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)); }