当前位置: 首页>>代码示例>>C#>>正文


C# IokeObject.AllocateCopy方法代码示例

本文整理汇总了C#中Ioke.Lang.IokeObject.AllocateCopy方法的典型用法代码示例。如果您正苦于以下问题:C# IokeObject.AllocateCopy方法的具体用法?C# IokeObject.AllocateCopy怎么用?C# IokeObject.AllocateCopy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ioke.Lang.IokeObject的用法示例。


在下文中一共展示了IokeObject.AllocateCopy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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);
//.........这里部分代码省略.........
开发者ID:goking,项目名称:ioke,代码行数:101,代码来源:Regexp.cs

示例2: Init

        public static void Init(Runtime runtime)
        {
            IokeObject obj = new IokeObject(runtime, "A hook allow you to observe what happens to a specific object. All hooks have Hook in their mimic chain.");
            obj.Kind = "Hook";
            obj.MimicsWithoutCheck(runtime.Origin);
            runtime.IokeGround.RegisterCell("Hook", obj);

            obj.RegisterMethod(runtime.NewNativeMethod("Takes one or more arguments to hook into and returns a new Hook connected to them.",
                                                       new TypeCheckingNativeMethod("into", TypeCheckingArgumentsDefinition.builder()
                                                                                    .ReceiverMustMimic(obj)
                                                                                    .WithRequiredPositional("firstConnected")
                                                                                    .WithRest("restConnected")
                                                                                    .Arguments,
                                                                                    (method, on, args, keywords, context, message) => {
                                                                                        IokeObject hook = obj.AllocateCopy(context, message);
                                                                                        hook.MimicsWithoutCheck(obj);

                                                                                        IList objs = new SaneArrayList();
                                                                                        foreach(object o in args) {
                                                                                            objs.Add(IokeObject.As(o, context));
                                                                                        }
                                                                                        Hook h = new Hook(objs);
                                                                                        hook.Data = h;
                                                                                        h.Rewire(hook);
                                                                                        return hook;
                                                                                    })));

            obj.RegisterMethod(runtime.NewNativeMethod("returns the objects this hook is connected to",
                                                       new TypeCheckingNativeMethod.WithNoArguments("connectedObjects", obj,
                                                                                                    (method, on, args, keywords, context, message) => {
                                                                                                        Hook h = (Hook)IokeObject.dataOf(on);
                                                                                                        IList l = new SaneArrayList(h.connected);
                                                                                                        return method.runtime.NewList(l);
                                                                                                    })));

            obj.RegisterMethod(runtime.NewNativeMethod("Takes one argument and will add that to the list of connected objects",
                                                       new TypeCheckingNativeMethod("hook!", TypeCheckingArgumentsDefinition.builder()
                                                                                    .ReceiverMustMimic(obj)
                                                                                    .WithRequiredPositional("objectToHookInto")
                                                                                    .Arguments,
                                                                                    (method, on, args, keywords, context, message) => {
                                                                                        Hook h = (Hook)IokeObject.dataOf(on);
                                                                                        h.connected.Add(IokeObject.As(args[0], context));
                                                                                        h.Rewire(IokeObject.As(on, context));
                                                                                        return on;
                                                                                    })));
        }
开发者ID:goking,项目名称:ioke,代码行数:47,代码来源:Hook.cs

示例3: SendTo

        public object SendTo(IokeObject self, IokeObject context, object recv, IList args)
        {
            if(cached != null) {
                return cached;
            }

            IokeObject m = self.AllocateCopy(self, context);
            m.MimicsWithoutCheck(context.runtime.Message);
            m.Arguments.Clear();
            foreach(object o in args) m.Arguments.Add(o);
            return IokeObject.Perform(recv, context, m);
        }
开发者ID:fronx,项目名称:ioke,代码行数:12,代码来源:Message.cs

示例4: NewMethod

 public IokeObject NewMethod(String doc, IokeObject tp, Method impl)
 {
     IokeObject obj = tp.AllocateCopy(null, null);
     obj.SetDocumentation(doc, null, null);
     obj.MimicsWithoutCheck(tp);
     obj.Data = impl;
     return obj;
 }
开发者ID:goking,项目名称:ioke,代码行数:8,代码来源:Runtime.cs

示例5: NewList

 public IokeObject NewList(IList list, IokeObject orig)
 {
     IokeObject obj = orig.AllocateCopy(null, null);
     obj.MimicsWithoutCheck(orig);
     obj.Data = new IokeList(list);
     return obj;
 }
开发者ID:goking,项目名称:ioke,代码行数:7,代码来源:Runtime.cs

示例6: Send

        public static object Send(IokeObject self, IokeObject context, object recv, IList args)
        {
            object result;
            if((result = ((Message)self.data).cached) != null) {
                return result;
            }

            IokeObject m = self.AllocateCopy(self, context);
            m.Arguments.Clear();
            foreach(object o in args) m.Arguments.Add(o);
            return Perform(recv, context, m);
        }
开发者ID:goking,项目名称:ioke,代码行数:12,代码来源:Interpreter.cs


注:本文中的Ioke.Lang.IokeObject.AllocateCopy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。