Пример #1
0
        public override void Init(IokeObject obj)
        {
            obj.Kind = "Method";
            obj.SetActivatable(true);

            obj.RegisterMethod(obj.runtime.NewNativeMethod("activates this method with the arguments given to call",
                                                           new NativeMethod("call", DefaultArgumentsDefinition.builder()
                                                                            .WithRestUnevaluated("arguments")
                                                                            .Arguments,
                                                                            (method, _context, message, on, outer) => {
                return(Interpreter.Activate(IokeObject.As(on, _context), _context, message, _context.RealContext));
            })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the name of the method",
                                                           new TypeCheckingNativeMethod.WithNoArguments("name", obj,
                                                                                                        (method, on, args, keywords, _context, message) => {
                return(_context.runtime.NewText(((Method)IokeObject.dataOf(on)).name));
            })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("Returns a text inspection of the object",
                                                           new TypeCheckingNativeMethod.WithNoArguments("inspect", obj,
                                                                                                        (method, on, args, keywords, _context, message) => {
                return(_context.runtime.NewText(Method.GetInspect(on)));
            })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("Returns a brief text inspection of the object",
                                                           new TypeCheckingNativeMethod.WithNoArguments("notice", obj,
                                                                                                        (method, on, args, keywords, _context, message) => {
                return(_context.runtime.NewText(Method.GetNotice(on)));
            })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the full code of this method, as a Text",
                                                           new TypeCheckingNativeMethod.WithNoArguments("code", obj,
                                                                                                        (method, on, args, keywords, _context, message) => {
                IokeData data = IokeObject.dataOf(on);
                if (data is Method)
                {
                    return(_context.runtime.NewText(((Method)data).CodeString));
                }
                else
                {
                    return(_context.runtime.NewText(((AliasMethod)data).CodeString));
                }
            })));
        }