Ejemplo n.º 1
0
        static BuiltInModules()
        {
            var modules = Assembly.GetExecutingAssembly().GetTypes()
                          .Where(p => p.IsSubclassOf(typeof(IodineModule)));

            foreach (Type type in modules)
            {
                if (type.IsDefined(typeof(IodineBuiltinModule), false))
                {
                    IodineBuiltinModule attr = (IodineBuiltinModule)type.GetCustomAttributes(
                        typeof(IodineBuiltinModule),
                        false
                        ).First();
                    IodineModule module = (IodineModule)Activator.CreateInstance(type);

                    BuiltinDocString docstr = type.GetCustomAttribute <BuiltinDocString> ();

                    if (docstr != null)
                    {
                        module.SetAttribute("__doc__", new IodineString(docstr.DocumentationString));
                    }
                    Modules.Add(attr.Name, module);
                }
            }
        }
        public BuiltinMethodCallback(IodineMethodDelegate callback, IodineObject self, bool setInvokeAttribute = true)
            : base(InternalMethodTypeDef)
        {
            Self     = self;
            Callback = callback;
            object[] attributes = callback.GetInvocationList() [0].Method.GetCustomAttributes(false);

            foreach (object attr in attributes)
            {
                if (attr is BuiltinDocString)
                {
                    BuiltinDocString docstr = attr as BuiltinDocString;
                    SetAttribute("__doc__", new InternalIodineProperty(vm => {
                        return(new IodineString(docstr.DocumentationString));
                    }, null));
                }
            }

            // This is needed to prevent a stackoverflow
            if (setInvokeAttribute)
            {
                // Set the invoke attribute so traits can match __invoke__
                SetAttribute("__invoke__", new BuiltinMethodCallback(Invoke, this, false));
            }
        }