本文整理汇总了C#中Sandbox.AddOutputWriter方法的典型用法代码示例。如果您正苦于以下问题:C# Sandbox.AddOutputWriter方法的具体用法?C# Sandbox.AddOutputWriter怎么用?C# Sandbox.AddOutputWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sandbox
的用法示例。
在下文中一共展示了Sandbox.AddOutputWriter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public override IEnumerator<RantAction> Run(Sandbox sb)
{
if (sb.Objects[Name] == null)
throw new RantRuntimeException(sb.Pattern, _name, $"The subroutine '{Name}' does not exist.");
var sub = (RADefineSubroutine)sb.Objects[Name].Value;
if (sub.Parameters.Keys.Count != Arguments.Count)
throw new RantRuntimeException(sb.Pattern, _name, "Argument mismatch on subroutine call.");
var action = sub.Body;
var args = new Dictionary<string, RantAction>();
var parameters = sub.Parameters.Keys.ToArray();
for (var i = 0; i < Arguments.Count; i++)
{
if (sub.Parameters[parameters[i]] == SubroutineParameterType.Greedy)
{
sb.AddOutputWriter();
yield return Arguments[i];
var output = sb.Return();
args[parameters[i]] = new RAText(_name, output.Main);
}
else
args[parameters[i]] = Arguments[i];
}
sb.SubroutineArgs.Push(args);
yield return action;
sb.SubroutineArgs.Pop();
yield break;
}
示例2: Run
public override IEnumerator<RantAction> Run(Sandbox sb)
{
sb.AddOutputWriter();
yield return _sourceAction;
var input = sb.Return().Main;
var matches = _regex.Matches(input);
int start = 0;
foreach (Match match in matches)
{
sb.RegexMatches.Push(match);
sb.AddOutputWriter();
yield return _matchEvalAction;
var result = sb.Return().Main;
sb.Print(input.Substring(start, match.Index - start));
sb.Print(result);
sb.RegexMatches.Pop();
start = match.Index + match.Length;
}
sb.Print(input.Substring(start, input.Length - start));
}
示例3: Run
public override IEnumerator<RantAction> Run(Sandbox sb)
{
// Convert arguments to their native types
int paramc = _funcInfo.Parameters.Length;
var args = new object[_argc];
double d;
RantParameter p;
for (int i = 0; i < _argc; i++)
{
p = GetParameter(i);
switch (p.RantType)
{
// Patterns are passed right to the method
case RantParameterType.Pattern:
args[i] = _argActions[i];
break;
// Strings are evaluated
case RantParameterType.String:
sb.AddOutputWriter();
yield return _argActions[i];
args[i] = sb.Return().Main;
break;
// Numbers are evaluated, verified, and converted
case RantParameterType.Number:
{
sb.AddOutputWriter();
yield return _argActions[i];
var strNum = sb.Return().Main;
if (!Double.TryParse(strNum, out d))
{
d = 0;
int n;
if (Util.ParseInt(strNum, out n)) d = n;
}
args[i] = Convert.ChangeType(d, p.NativeType);
break;
}
// Modes are parsed into enumeration members
case RantParameterType.Mode:
{
sb.AddOutputWriter();
yield return _argActions[i];
var strMode = sb.Return().Main;
object value;
if (!Util.TryParseEnum(p.NativeType, strMode, out value))
{
throw new RantRuntimeException(sb.Pattern, _argActions[i].Range,
$"Unknown mode value '{strMode}'.");
}
args[i] = value;
break;
}
// Flags are parsed from strings to enum members and combined with OR.
case RantParameterType.Flags:
{
var enumType = p.NativeType;
sb.AddOutputWriter();
yield return _argActions[i];
long flags = 0;
var strFlags = sb.Return().Main;
object value;
foreach(var flag in strFlags.Split(new [] {' '}, StringSplitOptions.RemoveEmptyEntries))
{
if (!Util.TryParseEnum(enumType, flag, out value))
throw new RantRuntimeException(sb.Pattern, _argActions[i].Range,
$"Unknown flag value '{flag}'.");
flags |= Convert.ToInt64(value);
}
args[i] = Enum.ToObject(enumType, flags);
break;
}
}
}
// Invoke the function
IEnumerator<RantAction> requester;
if (_funcInfo.HasParamArray)
{
int required = paramc - 1;
int parrayCount = _argc - required;
var parray = Array.CreateInstance(_funcInfo.Parameters[required].NativeType, parrayCount);
Array.Copy(args, required, parray, 0, parrayCount);
requester = _funcInfo.Invoke(sb, args.Take(required).Concat(new[] { parray }).ToArray());
}
else
{
requester = _funcInfo.Invoke(sb, args);
}
while (requester.MoveNext())
{
yield return requester.Current;
}
}
示例4: Run
public override IEnumerator<RantAction> Run(Sandbox sb)
{
var attribs = sb.NextAttribs(this);
int next = -1;
int reps = attribs.RepEach ? _items.Count : attribs.Repetitions;
var block = new BlockState(attribs.Repetitions);
double weightSum = _constantWeightSum;
if (attribs.Start != null) yield return attribs.Start;
if (_weighted && attribs.Sync == null)
{
foreach (var dw in _dynamicWeights)
{
sb.AddOutputWriter();
yield return dw.Item2;
var strWeight = sb.Return().Main;
if (!Double.TryParse(strWeight, out _weights[dw.Item1]))
throw new RantRuntimeException(sb.Pattern, dw.Item2.Range,
$"Dynamic weight returned invalid weight value: '{strWeight}'");
weightSum += _weights[dw.Item1];
}
}
sb.Blocks.Push(block);
for (int i = 0; i < reps; i++)
{
if (_weighted)
{
double choice = sb.RNG.NextDouble(weightSum);
for (int j = 0; j < _count; j++)
{
if (choice < _weights[j])
{
next = j;
break;
}
choice -= _weights[j];
}
}
else
{
next = attribs.NextIndex(_count, sb.RNG);
}
if (next == -1) break;
block.Next(next);
sb.Blocks.Pop(); // Don't allow separator to access block state
// Separator
if (i > 0 && attribs.Separator != null) yield return attribs.Separator;
sb.Blocks.Push(block); // Now put it back
// Prefix
if (attribs.Before != null) yield return attribs.Before;
// Content
sb.Objects.EnterScope();
yield return _items[next];
sb.Objects.ExitScope();
// Affix
if (attribs.After != null) yield return attribs.After;
}
sb.Blocks.Pop();
if (attribs.End != null) yield return attribs.End;
}
示例5: Run
public override IEnumerator<RantAction> Run(Sandbox sb)
{
var attribs = sb.NextAttribs(this);
// Skip if chance doesn't fall within range
if (attribs.Chance < 100 && sb.RNG.NextDouble(0, 100) > attribs.Chance)
{
yield break;
}
int next = -1;
int reps = attribs.RepEach ? _items.Count : attribs.Repetitions;
var block = new BlockState(attribs.Repetitions);
double weightSum = _constantWeightSum;
if (attribs.Start != null) yield return attribs.Start;
if (_weighted && attribs.Sync == null)
{
foreach (var dw in _dynamicWeights)
{
sb.AddOutputWriter();
yield return dw.Item2;
var strWeight = sb.Return().Main;
if (!Double.TryParse(strWeight, out _weights[dw.Item1]))
throw new RantRuntimeException(sb.Pattern, dw.Item2.Range,
$"Dynamic weight returned invalid weight value: '{strWeight}'");
weightSum += _weights[dw.Item1];
}
}
sb.Blocks.Push(block);
for (int i = 0; i < reps; i++)
{
if (_weighted)
{
double choice = sb.RNG.NextDouble(weightSum);
for (int j = 0; j < _count; j++)
{
if (choice < _weights[j])
{
next = j;
break;
}
choice -= _weights[j];
}
}
else
{
next = attribs.NextIndex(_count, sb.RNG);
}
if (next == -1) break;
block.Next(next);
sb.Blocks.Pop(); // Don't allow separator to access block state
// Separator
if (i > 0 && attribs.Separator != null)
{
if (attribs.IsSeries)
{
// Check if we're on the last separator in a series
if (i == reps - 1)
{
// Add the oxford comma if specified
if (attribs.EndSeparator != null)
{
// If there are more than two items, print it!
if (reps > 2) yield return attribs.EndSeparator;
}
sb.Print(sb.Format.StandardSpace);
// Add conjunction if specified (it normally should be, if it's a series)
if (attribs.EndConjunction != null)
{
yield return attribs.EndConjunction;
sb.Print(sb.Format.StandardSpace);
}
}
else if (reps > 2)
{
yield return attribs.Separator;
sb.Print(sb.Format.StandardSpace);
}
}
else
{
yield return attribs.Separator;
}
}
sb.Blocks.Push(block); // Now put it back
// Prefix
if (attribs.Before != null) yield return attribs.Before;
// Content
sb.Objects.EnterScope();
yield return _items[next];
sb.Objects.ExitScope();
//.........这里部分代码省略.........