private static IEnumerator <RichActionBase> OutputPrint(Sandbox sb, RantObject that, [RichardPropertyArgument("object", "any", Description = "The object to print.")] RantObject obj) { sb.Print(obj.ToString()); yield break; }
private static IEnumerator <RichActionBase> ConvertToString(Sandbox sb, RantObject that, [RichardPropertyArgument("object", "any", Description = "The object to convert to a string.")] RantObject obj) { sb.ScriptObjectStack.Push(obj.ToString()); yield break; }
private static IEnumerator <RantAction> ListPopFront(Sandbox sb, RantObject that) { var first = (that.Value as RichList).Items.First(); (that.Value as RichList).InternalItems.RemoveAt(0); (that.Value as RichList).ItemsChanged = true; yield return(first); }
private static IEnumerator <RantAction> ListPushFront(Sandbox sb, RantObject that, [RichardPropertyArgument("item", "any", Description = "The item to push onto the list.")] RantObject obj) { (that.Value as RichList).InternalItems.Insert(0, new RichDummy(null, obj.Value)); (that.Value as RichList).ItemsChanged = true; yield break; }
private static IEnumerator <RantAction> ListPop(Sandbox sb, RantObject that) { var last = (that.Value as RichList).Items.Last(); (that.Value as RichList).InternalItems.RemoveAt((that.Value as RichList).Items.Count - 1); (that.Value as RichList).ItemsChanged = true; yield return(last); }
private static IEnumerator <RantAction> ListLast(Sandbox sb, RantObject that) { yield return(that.Value as RichList); var list = sb.ScriptObjectStack.Pop(); yield return((list as RichList).Items.Last()); }
private static IEnumerator <RantAction> ListLength(Sandbox sb, RantObject that) { yield return(that.Value as RichList); var list = sb.ScriptObjectStack.Pop(); yield return(new RichNumber((list as RichList).Items.Count, null)); }
private static IEnumerator <RichActionBase> TypeGet(Sandbox sb, RantObject that, [RichardPropertyArgument("object", "any", Description = "The object whose type will be returned.")] RantObject obj) { string type = Util.ScriptingObjectType(obj); sb.ScriptObjectStack.Push(type); yield break; }
static async void OnMessage(object sender, MessageEventArgs eventArgs) { var messageText = eventArgs.Message.Text; _rant["tense"] = new RantObject(messageText); var program = RantProgram.CompileString("Прости, я пока что не понимаю, что ты [if: [eq:[v: tense];present];<verb.present>;<verb.simple_past>]!"); var message = _rant.Do(program); await _client.SendTextMessageAsync(eventArgs.Message.Chat, message); }
private bool CheckIfSubroutineList(RantObject obj) { if (obj.Type != RantObjectType.List) { return(false); } var list = obj.Value as List <RantObject>; return(list.All(a => a.Value is RstDefineSubroutine)); }
private static IEnumerator <RantAction> ListJoin(Sandbox sb, RantObject that, [RichardPropertyArgument("seperator", "string", Description = "The string to seperate each item of the list.")] RantObject obj) { yield return(that.Value as RichList); var list = sb.ScriptObjectStack.Pop(); sb.ScriptObjectStack.Push(string.Join(obj.ToString(), (list as RichList).Items.Select(item => item.ToString()).ToArray())); yield break; }
/// <summary> /// Adds a RantPattern containing a subroutine to this module. /// </summary> /// <param name="name">The name of the function to add.</param> /// <param name="pattern">The pattern that will make up the body of the function.</param> public void AddSubroutineFunction(string name, RantPattern pattern) { var action = (pattern.Action.GetType() == typeof(RASequence) ? ((RASequence)pattern.Action).Actions[0] : pattern.Action); if (action.GetType() != typeof(RADefineSubroutine)) { throw new RantRuntimeException(pattern, pattern.Code, "Attempted to add non-subroutine pattern to a module."); } _objects[name] = new RantObject(action); }
private static IEnumerator <RichActionBase> SyncExists(Sandbox sb, RantObject that, [RichardPropertyArgument("syncName", "string", Description = "The name of the synchronizer whose existence will be checked.")] RantObject obj1) { string syncName = obj1.Value as string; if (syncName == null) { throw new RantRuntimeException(sb.Pattern, null, "syncName must be a string."); } sb.ScriptObjectStack.Push(sb.SyncManager.SynchronizerExists(syncName)); yield break; }
private static IEnumerator <RantAction> ListFill(Sandbox sb, RantObject that, [RichardPropertyArgument("value", "any", Description = "The value to fill the list with.")] RantObject obj) { var fillValue = obj.Value; (that.Value as RichList).InternalItems = (that.Value as RichList).Items.Select( x => (RichActionBase) new RichDummy(null, fillValue) ).ToList(); (that.Value as RichList).ItemsChanged = true; yield break; }
private static IEnumerator <RichActionBase> MathTruncate(Sandbox sb, RantObject that, [RichardPropertyArgument("n", "number", Description = "The number that will be used in this operation.")] RantObject obj) { var num = obj.Value; if (!(num is double)) { throw new RantRuntimeException(sb.Pattern, null, "N must be a number."); } sb.ScriptObjectStack.Push(Math.Truncate((double)num)); yield break; }
private static IEnumerator <RichActionBase> TargetClear(Sandbox sb, RantObject that, [RichardPropertyArgument("targetName", "string", Description = "The target name to clear.")] RantObject obj1) { string targetName = obj1.Value as string; if (targetName == null) { throw new RantRuntimeException(sb.Pattern, null, "targetName must be a string."); } sb.Output.Do(chain => chain.ClearTarget(targetName)); yield break; }
private static IEnumerator <RichActionBase> SyncUnpin(Sandbox sb, RantObject that, [RichardPropertyArgument("syncName", "string", Description = "The name of the synchronizer to unpin.")] RantObject obj1) { string syncName = obj1.Value as string; if (syncName == null) { throw new RantRuntimeException(sb.Pattern, null, "syncName must be a string."); } sb.SyncManager.SetPinned(syncName, false); yield break; }
private static IEnumerator <RantAction> ListRemove(Sandbox sb, RantObject that, [RichardPropertyArgument("position", "number", Description = "The position in this list to remove the item from.")] RantObject pos) { var position = pos.Value; if (!(position is double)) { throw new RantRuntimeException(sb.Pattern, null, "Position must be a number."); } (that.Value as RichList).InternalItems.RemoveAt(Convert.ToInt32(position)); (that.Value as RichList).ItemsChanged = true; yield break; }
private static IEnumerator <RichActionBase> ConvertToNumber(Sandbox sb, RantObject that, [RichardPropertyArgument("object", "any", Description = "The object to convert to a number.")] RantObject obj) { string val = obj.ToString(); double n; if (!Util.ParseDouble(val, out n)) { sb.ScriptObjectStack.Push(new RantObject()); } sb.ScriptObjectStack.Push(n); yield break; }
private static IEnumerator <RantAction> ListFilter(Sandbox sb, RantObject that, [RichardPropertyArgument("test", "function", Description = "The test function which will be called for every item in this list.")] RantObject test) { if (!(test.Value is RichFunction)) { throw new RantRuntimeException(sb.Pattern, null, "Test must be a function."); } List <RichActionBase> filteredObjects = new List <RichActionBase>(); var testFunction = (test.Value as RichFunction); foreach (RichActionBase action in (that.Value as RichList).Items) { var count = sb.ScriptObjectStack.Count; yield return(action); object currentObj = null; if (count < sb.ScriptObjectStack.Count) { currentObj = sb.ScriptObjectStack.Peek(); } count = sb.ScriptObjectStack.Count; if (testFunction.ArgCount != 1) { throw new RantRuntimeException(sb.Pattern, testFunction.Range, "Expected test function to accept only one argument."); } var enumerator = testFunction.Execute(sb); while (enumerator.MoveNext()) { yield return(enumerator.Current); } if (count > sb.ScriptObjectStack.Count) { throw new RantRuntimeException(sb.Pattern, testFunction.Range, "Expected boolean value from test function, got nothing."); } var testValue = sb.ScriptObjectStack.Pop(); if (!(testValue is bool)) { throw new RantRuntimeException(sb.Pattern, testFunction.Range, $"Expected boolean value from test function, got {Util.ScriptingObjectType(testValue)}."); } var testBool = (bool)testValue; if (testBool) { filteredObjects.Add(new RichDummy(testFunction.Range, currentObj)); } } sb.ScriptObjectStack.Push(new RichList(sb.CurrentAction.Range, filteredObjects, false)); yield break; }
private static IEnumerator <RichActionBase> SyncIsPinned(Sandbox sb, RantObject that, [RichardPropertyArgument("syncName", "string", Description = "The name of the synchronizer to check for pinnedness. Pinfulness?")] RantObject obj1) { string syncName = obj1.Value as string; if (syncName == null) { throw new RantRuntimeException(sb.Pattern, null, "syncName must be a string."); } if (!sb.SyncManager.SynchronizerExists(syncName)) { throw new RantRuntimeException(sb.Pattern, null, "Synchronizer does not exist."); } sb.ScriptObjectStack.Push(sb.SyncManager[syncName].Pinned); yield break; }
private static IEnumerator <RichActionBase> MathPow(Sandbox sb, RantObject that, [RichardPropertyArgument("base", "number", Description = "The base number of the exponent operation.")] RantObject baseObj, [RichardPropertyArgument("exponent", "number", Description = "The exponent that base will be raised to.")] RantObject expObj) { if (baseObj.Type != RantObjectType.Number) { throw new RantRuntimeException(sb.Pattern, null, "Base must be a number."); } if (expObj.Type != RantObjectType.Number) { throw new RantRuntimeException(sb.Pattern, null, "Exponent must be a number."); } sb.ScriptObjectStack.Push(Math.Pow((double)baseObj.Value, (double)expObj.Value)); yield break; }
private static IEnumerator <RantAction> ListInsert(Sandbox sb, RantObject that, [RichardPropertyArgument("item", "any", Description = "The item to insert into this list.")] RantObject item, [RichardPropertyArgument("position", "number", Description = "The position in this list to insert the item into.")] RantObject pos) { var obj = item.Value; var position = pos.Value; if (!(position is double)) { throw new RantRuntimeException(sb.Pattern, null, "Position must be a number."); } (that.Value as RichList).InternalItems.Insert(Convert.ToInt32(position), new RichDummy(null, obj)); (that.Value as RichList).ItemsChanged = true; yield break; }
private static IEnumerator <RichActionBase> SyncSetPinnedState(Sandbox sb, RantObject that, [RichardPropertyArgument("syncName", "string", Description = "The name of the synchronizer to set pinned state on.")] RantObject obj1, [RichardPropertyArgument("pinnedState", "bool", Description = "The pinned state that will be assigned to this synchronizer.")] RantObject obj2) { string syncName = obj1.Value as string; object pinnedState = obj2.Value; if (syncName == null) { throw new RantRuntimeException(sb.Pattern, null, "syncName must be a string."); } if (!(pinnedState is bool)) { throw new RantRuntimeException(sb.Pattern, null, "pinnedState must be a bool."); } sb.SyncManager.SetPinned(syncName, (bool)pinnedState); yield break; }
private static IEnumerator <RichActionBase> MathMin(Sandbox sb, RantObject that, [RichardPropertyArgument("a", "number")] RantObject arg1, [RichardPropertyArgument("b", "number")] RantObject arg2) { var a = arg1.Value; if (!(a is double)) { throw new RantRuntimeException(sb.Pattern, null, "A must be a number."); } var b = arg2.Value; if (!(b is double)) { throw new RantRuntimeException(sb.Pattern, null, "B must be a number."); } sb.ScriptObjectStack.Push(Math.Min((double)a, (double)b)); yield break; }
private static IEnumerator <RichActionBase> MathAtan2(Sandbox sb, RantObject that, [RichardPropertyArgument("y", "number", Description = "The Y value of the atan2 operation.")] RantObject arg1, [RichardPropertyArgument("x", "number", Description = "The X value of the atan2 operation.")] RantObject arg2) { var y = arg1.Value; if (!(y is double)) { throw new RantRuntimeException(sb.Pattern, null, "Y must be a number."); } var x = arg2.Value; if (!(x is double)) { throw new RantRuntimeException(sb.Pattern, null, "X must be a number."); } sb.ScriptObjectStack.Push(Math.Atan2((double)y, (double)x)); yield break; }
private static IEnumerator <RichActionBase> TargetSend(Sandbox sb, RantObject that, [RichardPropertyArgument("targetName", "string", Description = "The name of the target to write to.")] RantObject obj1, [RichardPropertyArgument("value", "string", Description = "The value to write to the target.")] RantObject obj2 ) { string targetName = obj1.Value as string; string value = obj2.Value as string; if (targetName == null) { throw new RantRuntimeException(sb.Pattern, null, "targetName must be a string."); } if (value == null) { throw new RantRuntimeException(sb.Pattern, null, "value must be a string."); } sb.Output.PrintToTarget(targetName, value); yield break; }
private static IEnumerator <RichActionBase> SyncSet(Sandbox sb, RantObject that, [RichardPropertyArgument("syncName", "string", Description = "The name of the synchronizer to create.")] RantObject obj1, [RichardPropertyArgument("syncType", "string", Description = "The type of synchronizer to create.")] RantObject obj2) { string syncName = obj1.Value as string; string syncType = obj2.Value as string; if (syncName == null) { throw new RantRuntimeException(sb.Pattern, null, "syncName must be a string."); } if (syncType == null) { throw new RantRuntimeException(sb.Pattern, null, "syncType must be a string."); } object type; Util.TryParseEnum(typeof(SyncType), syncType, out type); sb.SyncManager.Create(syncName, (SyncType)type, true); yield break; }
private static IEnumerator <RichActionBase> SyncReseed(Sandbox sb, RantObject that, [RichardPropertyArgument("syncName", "string", Description = "The name of the synchronizer to reseed.")] RantObject obj1, [RichardPropertyArgument("seed", "string", Description = "The value that the synchronizer will be seeded with.")] RantObject obj2) { string syncName = obj1.Value as string; string seed = obj2.Value as string; if (syncName == null) { throw new RantRuntimeException(sb.Pattern, null, "syncName must be a string."); } if (seed == null) { throw new RantRuntimeException(sb.Pattern, null, "seed must be a string."); } if (!sb.SyncManager.SynchronizerExists(syncName)) { throw new RantRuntimeException(sb.Pattern, null, "Synchronizer does not exist."); } sb.SyncManager[syncName].Reseed(seed); yield break; }
internal void AddActionFunction(string name, RantAction body) { _objects[name] = new RantObject(body); }