Example #1
0
        // Returns declared signals
        public static Dictionary <MethodInfo, CPPMethod> GetSignalSignatures(Type iface)
        {
            Dictionary <MethodInfo, CPPMethod> signals;

            if (signalSignatures.TryGetValue(iface, out signals))
            {
                return(signals);
            }

            signals = new Dictionary <MethodInfo, CPPMethod>();
            signalSignatures[iface] = signals;

            // GetMethods() doesn't return inherited methods for interfaces
            MethodInfo[] mis = iface.GetMethods();

            /// the interface has no signals...
            if (mis.Length == 0)
            {
                return(signals);
            }

            foreach (MethodInfo mi in mis)
            {
                object[] attributes = mi.GetCustomAttributes(typeof(Q_SIGNAL), false);
                foreach (Q_SIGNAL attr in attributes)
                {
                    CPPMethod cppinfo = new CPPMethod();
                    string    sig     = attr.Signature;
                    if (sig == "")
                    {
                        sig = SignatureFromMethodInfo(mi).Trim();
                    }
                    sig = QMetaObject.NormalizedSignature(sig).ConstData();
                    GetCPPMethodInfo(sig, out cppinfo.signature, out cppinfo.type);
                    cppinfo.mi = mi;

                    if (mi.GetCustomAttributes(typeof(Q_SCRIPTABLE), false).Length > 0)
                    {
                        cppinfo.scriptable = true;
                    }

                    signals.Add(cppinfo.mi, cppinfo);
                }
            }

            return(signals);
        }
Example #2
0
        // Returns declared slots
        public static Dictionary <string, CPPMethod> GetSlotSignatures(Type t)
        {
            /// This Hashtable contains the slots of a class. The C++ type signature is the key, the appropriate array with the MethodInfo, signature and return type the value.
            Dictionary <string, CPPMethod> slots;

            if (slotSignatures.TryGetValue(t, out slots))
            {
                return(slots);
            }

            slots             = new Dictionary <string, CPPMethod>();
            slotSignatures[t] = slots;

            // only declared members
            MethodInfo[] mis = t.GetMethods(BindingFlags.Instance
                                            | BindingFlags.Public
                                            | BindingFlags.NonPublic
                                            | BindingFlags.DeclaredOnly);

            foreach (MethodInfo mi in mis)
            {
                object[] attributes = mi.GetCustomAttributes(typeof(Q_SLOT), false);
                foreach (Q_SLOT attr in attributes)
                {
                    CPPMethod cppinfo = new CPPMethod();

                    string sig = attr.Signature;
                    if (sig == "")
                    {
                        sig = SignatureFromMethodInfo(mi);
                    }

                    sig = QMetaObject.NormalizedSignature(sig).ConstData();
                    GetCPPMethodInfo(sig, out cppinfo.signature, out cppinfo.type);
                    cppinfo.mi = mi;

                    if (mi.GetCustomAttributes(typeof(Q_SCRIPTABLE), false).Length > 0)
                    {
                        cppinfo.scriptable = true;
                    }

                    slots.Add(cppinfo.signature, cppinfo);
                    break;
                }
            }
            return(slots);
        }
Example #3
0
 public QScriptValue NewQMetaObject(QMetaObject metaObject)
 {
     return (QScriptValue) interceptor.Invoke("newQMetaObject#", "newQMetaObject(const QMetaObject*)", typeof(QScriptValue), typeof(QMetaObject), metaObject);
 }
Example #4
0
 public QScriptValue NewQMetaObject(QMetaObject metaObject, QScriptValue ctor)
 {
     return (QScriptValue) interceptor.Invoke("newQMetaObject##", "newQMetaObject(const QMetaObject*, const QScriptValue&)", typeof(QScriptValue), typeof(QMetaObject), metaObject, typeof(QScriptValue), ctor);
 }
Example #5
0
        public static QMetaObject MakeMetaObject(Type t)
        {
            if (t == null)
            {
                return(null);
            }

            QMetaObject parentMeta      = null;
            string      parentClassName = null;

            if (!SmokeMarshallers.IsSmokeClass(t.BaseType) &&
                !metaObjects.TryGetValue(t.BaseType, out parentMeta))
            {
                // create QMetaObject
                parentMeta = MakeMetaObject(t.BaseType);
            }
            else
            {
                parentClassName = SmokeMarshallers.SmokeClassName(t.BaseType);
            }

            ICollection <CPPMethod> slots;

            // build slot table
            slots = GetSlotSignatures(t).Values;

            PropertyInfo pi = t.GetProperty("Emit", BindingFlags.Instance
                                            | BindingFlags.NonPublic
                                            | BindingFlags.DeclaredOnly);
            ICollection <CPPMethod> signals = null;

            if (pi == null)
            {
                signals = new List <CPPMethod>();
            }
            else
            {
                emitInterfaceCache[t] = pi.PropertyType;
                signals = GetSignalSignatures(pi.PropertyType).Values;
            }

            ICollection <CPPProperty> properties = GetProperties(t).Values;
            QyotoMetaData             metaData   = new QyotoMetaData(t.Name, signals, slots, GetClassInfos(t), properties);

            IntPtr metaObject;
            IntPtr parentMetaPtr = (IntPtr)0;

            unsafe
            {
                fixed(byte *stringdata = metaData.StringData)
                fixed(uint *data = metaData.Data)
                {
                    if (parentMeta != null)
                    {
#if DEBUG
                        parentMetaPtr = (IntPtr)DebugGCHandle.Alloc(parentMeta);
#else
                        parentMetaPtr = (IntPtr)GCHandle.Alloc(parentMeta);
#endif
                    }
                    metaObject = qyoto_make_metaObject(parentClassName,
                                                       parentMetaPtr,
                                                       (IntPtr)stringdata, metaData.StringData.Length,
                                                       (IntPtr)data, metaData.Data.Length);
                }
            }

            QMetaObject res = (QMetaObject)((GCHandle)metaObject).Target;
#if DEBUG
            DebugGCHandle.Free((GCHandle)metaObject);
#else
            ((GCHandle)metaObject).SynchronizedFree();
#endif
            metaObjects.Add(t, res);
            return(res);
        }
Example #6
0
 public QScriptValue NewQMetaObject(QMetaObject metaObject)
 {
     return((QScriptValue)interceptor.Invoke("newQMetaObject#", "newQMetaObject(const QMetaObject*)", typeof(QScriptValue), typeof(QMetaObject), metaObject));
 }
Example #7
0
 public QScriptValue NewQMetaObject(QMetaObject metaObject, QScriptValue ctor)
 {
     return((QScriptValue)interceptor.Invoke("newQMetaObject##", "newQMetaObject(const QMetaObject*, const QScriptValue&)", typeof(QScriptValue), typeof(QMetaObject), metaObject, typeof(QScriptValue), ctor));
 }