public static RichardPropertyInfo GetRichardObjectPropertyInfo(string name, string prop) { var property = RichardFunctions.GetObjectProperty(name, prop); var propAttribute = property.RawMethod.GetCustomAttributes(typeof(RichardGlobalObject), false)[0] as RichardGlobalObject; return(new RichardPropertyInfo() { Name = property.Name, Description = property.Description, IsFunction = property.TreatAsRichardFunction, Returns = propAttribute.Returns }); }
public static RichardPropertyInfo GetRichardPropertyInfo(Type type, string name) { var prop = RichardFunctions.GetPropertyFunction(type, name); var propAttribute = prop.RawMethod.GetCustomAttributes(typeof(RichardProperty), false)[0] as RichardProperty; return(new RichardPropertyInfo() { Name = prop.Name, Description = prop.Description, IsFunction = prop.TreatAsRichardFunction, Returns = propAttribute.Returns }); }
public static RichardArgumentInfo[] GetRichardPropertyArguments(Type type, string name) { return(RichardFunctions .GetPropertyFunction(type, name) .RawParameters .Select(x => x.GetCustomAttributes(typeof(RichardPropertyArgument), false).FirstOrDefault() as RichardPropertyArgument ) .Where(x => x != null) .Select(x => new RichardArgumentInfo() { Name = x.Name, Description = x.Description, Type = x.Type }) .ToArray()); }
public override object GetValue(Sandbox sb) { if (RichardFunctions.HasObject(Name)) { return(RichardFunctions.GetObject(Name)); } if (sb.Objects[Name] == null) { return(new RantObject(RantObjectType.Undefined)); } var obj = sb.Objects[Name]; if (obj.Type == RantObjectType.No) { return(obj); } return(obj.Value); }
public override IEnumerator <RantAction> Run(Sandbox sb) { string name = null; if (Name is string) { name = Name as string; } else if (Name is RichActionBase) { var count = sb.ScriptObjectStack.Count; yield return(Name as RichActionBase); if (count >= sb.ScriptObjectStack.Count) { throw new RantRuntimeException(sb.Pattern, Range, "Expected value in bracket indexer."); } name = sb.ScriptObjectStack.Pop().ToString(); } else { throw new RantRuntimeException(sb.Pattern, Range, "Invalid property name."); } yield return(_object); var obj = sb.ScriptObjectStack.Pop(); if (RichardFunctions.HasProperty(obj.GetType(), name)) { var prop = RichardFunctions.GetProperty(obj.GetType(), name); // bare property, like string.length if (!prop.TreatAsRichardFunction) { var enumerator = prop.Invoke(sb, new object[] { new RantObject(obj) }); while (enumerator.MoveNext()) { yield return(enumerator.Current); } } // function property, like list.push() else { // arg count is param count without the "that" property yield return new RichNativeFunction(Range, prop.ParamCount - 1, prop) { That = new RantObject(obj) } }; yield break; } else if (obj is RichList) { int index = -1; if (!int.TryParse(name, out index)) { yield break; } yield return(obj as RichList); obj = sb.ScriptObjectStack.Pop(); if (index > (obj as RichList).Items.Count - 1) { sb.ScriptObjectStack.Push(new RantObject(RantObjectType.Undefined)); } else { yield return((obj as RichList).Items[index]); } yield break; } else if (obj is RichObject) { var rObject = obj as RichObject; if (rObject.Values.ContainsKey(name)) { yield return(rObject.Values[name]); } yield break; } else if (obj is string) { int index = -1; if (!int.TryParse(name, out index)) { yield break; } if ((obj as string).Length <= index) { sb.ScriptObjectStack.Push(new RantObject(RantObjectType.Undefined)); } else { sb.ScriptObjectStack.Push((obj as string)[index].ToString()); } yield break; } if (obj == null || (obj is RantObject && (obj as RantObject).Value == null)) { throw new RantRuntimeException(sb.Pattern, Range, "Cannot access property of null object."); } sb.ScriptObjectStack.Push(new RantObject(RantObjectType.Undefined)); yield break; }
public static bool IsRichardPropertyFunction(Type type, string name) => RichardFunctions.GetPropertyFunction(type, name).TreatAsRichardFunction;
public static IEnumerable <string> GetRichardProperties(Type type) => RichardFunctions.GetProperties(type);
public static IEnumerable <Type> GetRichardPropertyTypes() => RichardFunctions.GetPropertyTypes();
public static bool IsRichardGlobalObjectPropertyFunction(string name, string prop) => RichardFunctions.GetObjectProperty(name, prop).TreatAsRichardFunction;
public static IEnumerable <string> GetRichardObjectProperties(string name) => RichardFunctions.GetObjectProperties(name);
public static IEnumerable <string> GetRichardGlobalObjects() => RichardFunctions.GetGlobalObjects();
static RantEngine() { RantFunctions.Load(); RichardFunctions.Load(); Engine.Compiler.Parselets.Parselet.Load(); }