本文整理汇总了C#中Ioke.Lang.IokeObject.AliasMethod方法的典型用法代码示例。如果您正苦于以下问题:C# IokeObject.AliasMethod方法的具体用法?C# IokeObject.AliasMethod怎么用?C# IokeObject.AliasMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ioke.Lang.IokeObject
的用法示例。
在下文中一共展示了IokeObject.AliasMethod方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
//.........这里部分代码省略.........
}
if(first > last || (!inclusive && first == last)) {
return context.runtime.NewList(new SaneArrayList());
}
if(!inclusive) {
last--;
}
var l = new SaneArrayList();
for(int i = first; i<last+1; i++) {
l.Add(o[i]);
}
return context.runtime.NewList(l);
}
if(!(IokeObject.dataOf(arg) is Number)) {
arg = IokeObject.ConvertToNumber(arg, message, context);
}
int index = ((Number)IokeObject.dataOf(arg)).AsNativeInteger();
var o2 = ((IokeList)IokeObject.dataOf(on)).List;
if(index < 0) {
index = o2.Count + index;
}
if(index >= 0 && index < o2.Count) {
return o2[index];
} else {
return context.runtime.nil;
}
})));
obj.AliasMethod("at", "[]", null, null);
obj.RegisterMethod(runtime.NewNativeMethod("returns the size of this list",
new TypeCheckingNativeMethod.WithNoArguments("size", runtime.List,
(method, on, args, keywords, context, message) => {
return context.runtime.NewNumber(((IokeList)IokeObject.dataOf(on)).List.Count);
})));
obj.AliasMethod("size", "length", null, null);
obj.RegisterMethod(runtime.NewNativeMethod("Returns a text inspection of the object",
new TypeCheckingNativeMethod.WithNoArguments("inspect", obj,
(method, on, args, keywords, context, message) => {
return method.runtime.NewText(IokeList.GetInspect(on));
})));
obj.RegisterMethod(runtime.NewNativeMethod("Returns a brief text inspection of the object",
new TypeCheckingNativeMethod.WithNoArguments("notice", obj,
(method, on, args, keywords, context, message) => {
return method.runtime.NewText(IokeList.GetNotice(on));
})));
obj.RegisterMethod(runtime.NewNativeMethod("Compares this object against the argument. The comparison is only based on the elements inside the lists, which are in turn compared using <=>.",
new TypeCheckingNativeMethod("<=>", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(obj)
.WithRequiredPositional("other")
.Arguments,
(method, on, args, keywords, context, message) => {
var one = IokeList.GetList(on);
object arg = args[0];
if(!(IokeObject.dataOf(arg) is IokeList)) {
return context.runtime.nil;
}
var two = IokeList.GetList(arg);
示例2: Init
public override void Init(IokeObject obj)
{
Runtime runtime = obj.runtime;
obj.Kind = "Regexp";
IokeObject regexpMatch = new IokeObject(runtime, "contains behavior related to assignment", new RegexpMatch(obj, null, null));
regexpMatch.MimicsWithoutCheck(runtime.Origin);
regexpMatch.Init();
obj.RegisterCell("Match", regexpMatch);
obj.RegisterMethod(runtime.NewNativeMethod("returns a hash for the regexp",
new NativeMethod.WithNoArguments("hash", (method, context, message, on, outer) => {
outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
Regexp r = (Regexp)IokeObject.dataOf(on);
return context.runtime.NewNumber(r.pattern.GetHashCode() + 13 * r.flags.GetHashCode());
})));
obj.RegisterMethod(runtime.NewNativeMethod("returns true if the left hand side pattern is equal to the right hand side pattern.",
new TypeCheckingNativeMethod("==", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(runtime.Regexp)
.WithRequiredPositional("other")
.Arguments,
(method, on, args, keywords, context, message) => {
Regexp d = (Regexp)IokeObject.dataOf(on);
object other = args[0];
return ((other is IokeObject) &&
(IokeObject.dataOf(other) is Regexp) &&
((on == context.runtime.Regexp || other == context.runtime.Regexp) ? on == other :
(d.pattern.Equals(((Regexp)IokeObject.dataOf(other)).pattern) &&
d.flags.Equals(((Regexp)IokeObject.dataOf(other)).flags)))) ? context.runtime.True : context.runtime.False;
})));
obj.RegisterMethod(runtime.NewNativeMethod("Returns the pattern use for this regular expression",
new TypeCheckingNativeMethod.WithNoArguments("pattern", obj,
(method, on, args, keywords, context, message) => {
return context.runtime.NewText(GetPattern(on));
})));
obj.RegisterMethod(runtime.NewNativeMethod("Takes one argument and tries to match that argument against the current pattern. Returns nil if no match can be done, or a Regexp Match object if a match succeeds",
new TypeCheckingNativeMethod("match", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(obj)
.WithRequiredPositional("other")
.Arguments,
(method, on, args, keywords, context, message) => {
IokeObject target = IokeObject.As(Interpreter.Send(context.runtime.asText, context, args[0]), context);
string arg = Text.GetText(target);
Matcher m = ((Regexp)IokeObject.dataOf(on)).regexp.Matcher(arg);
if(m.Find()) {
IokeObject match = regexpMatch.AllocateCopy(message, context);
match.MimicsWithoutCheck(regexpMatch);
match.Data = new RegexpMatch(IokeObject.As(on, context), m, target);
return match;
} else {
return context.runtime.nil;
}
})));
obj.AliasMethod("match", "=~", null, null);
obj.RegisterMethod(runtime.NewNativeMethod("Takes one argument that should be a text and returns a text that has all regexp meta characters quoted",
new NativeMethod("quote", DefaultArgumentsDefinition.builder()
.WithRequiredPositional("text")
.Arguments,
(method, on, args, keywords, context, message) => {
return context.runtime.NewText(Pattern.Quote(Text.GetText(Interpreter.Send(context.runtime.asText, context, args[0]))));
})));
obj.RegisterMethod(runtime.NewNativeMethod("Takes one or two text arguments that describes the regular expression to create. the first text is the pattern and the second is the flags.",
new NativeMethod("from", DefaultArgumentsDefinition.builder()
.WithRequiredPositional("pattern")
.WithOptionalPositional("flags", "")
.Arguments,
(method, on, args, keywords, context, message) => {
string pattern = Text.GetText(Interpreter.Send(context.runtime.asText, context, args[0]));
string flags = "";
if(args.Count > 1) {
flags = Text.GetText(Interpreter.Send(context.runtime.asText, context, args[1]));
}
return context.runtime.NewRegexp(pattern, flags, context, message);
})));
obj.RegisterMethod(runtime.NewNativeMethod("Takes one argument and tries to match that argument against the current pattern. Returns a list of all the texts that were matched.",
new TypeCheckingNativeMethod("allMatches", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(obj)
.WithRequiredPositional("other")
.Arguments,
(method, on, args, keywords, context, message) => {
string arg = Text.GetText(Interpreter.Send(context.runtime.asText, context, args[0]));
Matcher m = ((Regexp)IokeObject.dataOf(on)).regexp.Matcher(arg);
var result = new SaneArrayList();
MatchIterator iter = m.FindAll();
while(iter.HasMore) {
result.Add(runtime.NewText(iter.NextMatch.Group(0)));
}
return runtime.NewList(result);
//.........这里部分代码省略.........
示例3: Init
public override void Init(IokeObject obj)
{
Runtime runtime = obj.runtime;
obj.Kind = "Dict";
obj.Mimics(IokeObject.As(runtime.Mixins.GetCell(null, null, "Enumerable"), null), runtime.nul, runtime.nul);
obj.RegisterMethod(runtime.NewNativeMethod("takes one argument, that should be a default value, and returns a new mimic of the receiver, with the default value for that new dict set to the argument",
new TypeCheckingNativeMethod("withDefault", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(obj)
.WithRequiredPositional("defaultValue")
.Arguments,
(method, on, args, keywords, context, message) => {
object newDict = IokeObject.Mimic(on, message, context);
SetDefaultValue(newDict, IokeObject.As(args[0], context));
return newDict;
})));
obj.RegisterMethod(runtime.NewNativeMethod("creates a new Dict from the arguments provided, combined with the values in the receiver. the arguments provided will override those in the receiver. the rules for arguments are the same as for dict, except that dicts can also be provided. all positional arguments will be added before the keyword arguments.",
new TypeCheckingNativeMethod("merge", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(obj)
.WithRest("pairsAndDicts")
.WithKeywordRest("keywordPairs")
.Arguments,
(method, on, args, keywords, context, message) => {
var newMap = new SaneHashtable();
foreach(DictionaryEntry de in GetMap(on)) newMap[de.Key] = de.Value;
foreach(object o in args) {
if(IokeObject.dataOf(o) is Dict) {
foreach(DictionaryEntry de in GetMap(o)) newMap[de.Key] = de.Value;
} else if(IokeObject.dataOf(o) is Pair) {
newMap[Pair.GetFirst(o)] = Pair.GetSecond(o);
} else {
newMap[o] = context.runtime.nil;
}
}
foreach(var entry in keywords) {
string s = entry.Key;
object key = context.runtime.GetSymbol(s.Substring(0, s.Length-1));
object value = entry.Value;
if(value == null) {
value = context.runtime.nil;
}
newMap[key] = value;
}
return context.runtime.NewDict(newMap);
})));
obj.AliasMethod("merge", "+", null, null);
obj.RegisterMethod(runtime.NewNativeMethod("takes one argument, the key of the element to return. if the key doesn't map to anything in the dict, returns the default value",
new TypeCheckingNativeMethod("at", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(obj)
.WithRequiredPositional("key")
.Arguments,
(method, on, args, keywords, context, message) => {
object result = Dict.GetMap(on)[args[0]];
if(result == null) {
return GetDefaultValue(on, context, message);
} else {
return result;
}
})));
obj.RegisterMethod(runtime.NewNativeMethod("returns true if this dict is empty, false otherwise",
new TypeCheckingNativeMethod.WithNoArguments("empty?", obj,
(method, on, args, keywords, context, message) => {
return Dict.GetMap(on).Count == 0 ? context.runtime.True : context.runtime.False;
})));
obj.RegisterMethod(runtime.NewNativeMethod("takes one argument, the key to check if it is in the dict.",
new TypeCheckingNativeMethod("key?", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(obj)
.WithRequiredPositional("key")
.Arguments,
(method, on, args, keywords, context, message) => {
return (Dict.GetMap(on).Contains(args[0])) ? context.runtime.True : context.runtime.False;
})));
obj.RegisterMethod(runtime.NewNativeMethod("takes two arguments, the key of the element to set and the value to set it too. returns the value set",
new TypeCheckingNativeMethod("[]=", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(obj)
.WithRequiredPositional("key")
.WithRequiredPositional("value")
.Arguments,
(method, on, args, keywords, context, message) => {
Dict.GetMap(on)[args[0]] = args[1];
return args[1];
})));
obj.RegisterMethod(runtime.NewNativeMethod("Returns the number of pairs contained in this dict.",
new TypeCheckingNativeMethod.WithNoArguments("size", obj,
(method, on, args, keywords, context, message) => {
return runtime.NewNumber(Dict.GetMap(on).Count);
})));
obj.RegisterMethod(runtime.NewNativeMethod("Returns a text inspection of the object",
new TypeCheckingNativeMethod.WithNoArguments("inspect", obj,
(method, on, args, keywords, context, message) => {
//.........这里部分代码省略.........
示例4: Init
//.........这里部分代码省略.........
new TypeCheckingNativeMethod("->", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(obj)
.WithRequiredPositional("nextMessage")
.Arguments,
(method, on, args, keywords, context, message) => {
object arg = args[0];
if(arg == context.runtime.nil) {
Message.SetNext(IokeObject.As(on, context), null);
} else {
arg = context.runtime.Message.ConvertToThis(arg, message, context);
Message.SetNext(IokeObject.As(on, context), IokeObject.As(arg, context));
Message.SetPrev(IokeObject.As(arg, context), IokeObject.As(on, context));
}
return arg;
})));
obj.RegisterMethod(obj.runtime.NewNativeMethod("evaluates the argument and adds it to the beginning of the argument list of this message. it then returns the receiving message.",
new NativeMethod(">>", DefaultArgumentsDefinition.builder()
.WithRequiredPositional("newArgument")
.Arguments,
(method, on, args, keywords, context, message) => {
IokeObject.As(on, context).Arguments.Insert(0, args[0]);
return on;
})));
obj.RegisterMethod(obj.runtime.NewNativeMethod("evaluates the argument and adds it to the argument list of this message. it then returns the receiving message.",
new NativeMethod("appendArgument", DefaultArgumentsDefinition.builder()
.WithRequiredPositional("newArgument")
.Arguments,
(method, on, args, keywords, context, message) => {
IokeObject.As(on, context).Arguments.Add(args[0]);
return on;
})));
obj.AliasMethod("appendArgument", "<<", null, null);
obj.RegisterMethod(obj.runtime.NewNativeMethod("returns a string that describes this message as a stack trace elemtn",
new TypeCheckingNativeMethod.WithNoArguments("asStackTraceText", obj,
(method, on, args, keywords, context, message) => {
return context.runtime.NewText(Message.GetStackTraceText(on));
})));
obj.RegisterMethod(obj.runtime.NewNativeMethod("returns true if this message is a keyword parameter or not",
new TypeCheckingNativeMethod.WithNoArguments("keyword?", obj,
(method, on, args, keywords, context, message) => {
return ((Message)IokeObject.dataOf(on)).IsKeyword() ? context.runtime.True : context.runtime.False;
})));
obj.RegisterMethod(obj.runtime.NewNativeMethod("returns true if this message is a symbol message or not",
new TypeCheckingNativeMethod.WithNoArguments("symbol?", obj,
(method, on, args, keywords, context, message) => {
return ((Message)IokeObject.dataOf(on)).IsSymbolMessage ? context.runtime.True : context.runtime.False;
})));
obj.RegisterMethod(obj.runtime.NewNativeMethod("takes either one or two arguments. if one argument is given, it should be a message chain that will be sent to each message in the chain, recursively. the result will be thrown away. if two arguments are given, the first is an unevaluated name that will be set to each of the messages in the chain in succession, and then the second argument will be evaluated in a scope with that argument in it. the code will evaluate in a lexical context, and if the argument name is available outside the context, it will be shadowed. the method will return the original message.",
new NativeMethod("walk", DefaultArgumentsDefinition.builder()
.WithOptionalPositionalUnevaluated("argOrCode")
.WithOptionalPositionalUnevaluated("code")
.Arguments,
(method, context, message, on, outer) => {
outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
object onAsMessage = context.runtime.Message.ConvertToThis(on, message, context);
switch(message.Arguments.Count) {
case 1: {
IokeObject code = IokeObject.As(message.Arguments[0], context);
WalkWithReceiver(context, onAsMessage, code);
示例5: Init
public override void Init(IokeObject obj)
{
Runtime runtime = obj.runtime;
obj.Kind = "Regexp Match";
obj.RegisterMethod(runtime.NewNativeMethod("Returns the target that this match was created against",
new TypeCheckingNativeMethod.WithNoArguments("target", obj,
(method, on, args, keywords, context, message) => {
return GetTarget(on);
})));
obj.RegisterMethod(runtime.NewNativeMethod("returns a list of all the named groups in the regular expression used to create this match",
new TypeCheckingNativeMethod.WithNoArguments("names", obj,
(method, on, args, keywords, context, message) => {
var names = Regexp.GetRegexp(GetRegexp(on)).GroupNames;
var theNames = new SaneArrayList();
foreach(object name in names) {
theNames.Add(context.runtime.GetSymbol(((string)name)));
}
return context.runtime.NewList(theNames);
})));
obj.RegisterMethod(runtime.NewNativeMethod("returns the part of the target before the text that matched",
new TypeCheckingNativeMethod.WithNoArguments("beforeMatch", obj,
(method, on, args, keywords, context, message) => {
return context.runtime.NewText(GetMatchResult(on).Prefix);
})));
obj.RegisterMethod(runtime.NewNativeMethod("returns the part of the target after the text that matched",
new TypeCheckingNativeMethod.WithNoArguments("afterMatch", obj,
(method, on, args, keywords, context, message) => {
return context.runtime.NewText(GetMatchResult(on).Suffix);
})));
obj.RegisterMethod(runtime.NewNativeMethod("returns the text that matched",
new TypeCheckingNativeMethod.WithNoArguments("match", obj,
(method, on, args, keywords, context, message) => {
return context.runtime.NewText(GetMatchResult(on).Group(0));
})));
obj.AliasMethod("match", "asText", null, null);
obj.RegisterMethod(runtime.NewNativeMethod("returns the number of groups available in this match",
new TypeCheckingNativeMethod.WithNoArguments("length", obj,
(method, on, args, keywords, context, message) => {
return context.runtime.NewNumber(GetMatchResult(on).GroupCount);
})));
obj.RegisterMethod(runtime.NewNativeMethod("returns a list of all groups captured in this match. if a group is not matched it will be nil in the list. the actual match text is not included in this list.",
new TypeCheckingNativeMethod.WithNoArguments("captures", obj,
(method, on, args, keywords, context, message) => {
var groups = new SaneArrayList();
MatchResult mr = GetMatchResult(on);
int len = mr.GroupCount;
for(int i=1;i<len;i++) {
if(mr.IsCaptured(i)) {
groups.Add(context.runtime.NewText(mr.Group(i)));
} else {
groups.Add(context.runtime.nil);
}
}
return context.runtime.NewList(groups);
})));
obj.RegisterMethod(runtime.NewNativeMethod("returns a list of all groups captured in this match. if a group is not matched it will be nil in the list. the actual match text is the first element in the list.",
new TypeCheckingNativeMethod.WithNoArguments("asList", obj,
(method, on, args, keywords, context, message) => {
var groups = new SaneArrayList();
MatchResult mr = GetMatchResult(on);
int len = mr.GroupCount;
for(int i=0;i<len;i++) {
if(mr.IsCaptured(i)) {
groups.Add(context.runtime.NewText(mr.Group(i)));
} else {
groups.Add(context.runtime.nil);
}
}
return context.runtime.NewList(groups);
})));
obj.RegisterMethod(runtime.NewNativeMethod("Takes one optional argument that should be either a number or a symbol. this should be the name or index of a group to return the start index for. if no index is supplied, 0 is the default. if the group in question wasn't matched, returns -1.",
new TypeCheckingNativeMethod("start", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(obj)
.WithOptionalPositional("index", "0")
.Arguments,
(method, on, args, keywords, context, message) => {
int index = 0;
if(args.Count > 0) {
object arg = args[0];
if(IokeObject.dataOf(arg) is Number) {
index = Number.ExtractInt(arg, message, context);
} else {
string namedIndex = Text.GetText(((Message)IokeObject.dataOf(context.runtime.asText)).SendTo(context.runtime.asText, context, arg));
int ix = -1;
try {
ix = Regexp.GetRegexp(GetRegexp(on)).GroupId(namedIndex);
} catch(Exception) {
//.........这里部分代码省略.........