Ejemplo n.º 1
0
        private static void CallList(AtomList l)
        {
            External e = Internal.pass.ext;

            try { e.klass.m_list(e, (Atom[])l); }
            catch (Exception exc) { PostError(exc.ToString()); }
        }
Ejemplo n.º 2
0
        private static void CallPointer(Pointer p)
        {
            External e = Internal.pass.ext;

            try { e.klass.m_pointer(e, p); }
            catch (Exception exc) { PostError(exc.ToString()); }
        }
Ejemplo n.º 3
0
        private static void CallSymbol(Symbol s)
        {
            External e = Internal.pass.ext;

            try { e.klass.m_symbol(e, s); }
            catch (Exception exc) { PostError(exc.ToString()); }
        }
Ejemplo n.º 4
0
        private static void CallFloat(float f)
        {
            External e = Internal.pass.ext;

            try { e.klass.m_float(e, f); }
            catch (Exception exc) { PostError(exc.ToString()); }
        }
Ejemplo n.º 5
0
        private static void CallBang()
        {
            External e = Internal.pass.ext;

            try { e.klass.m_bang(e); }
            catch (Exception exc) { PostError(exc.ToString()); }
        }
Ejemplo n.º 6
0
        private static void CallObject(int inlet)
        {
//            Post("CLASS-OBJECT {0}", inlet);

            External e = Internal.pass.ext;

            try { e.klass.m_object(e, inlet, Internal.pass.obj); }
            catch (Exception exc) { PostError(exc.ToString()); }
        }
Ejemplo n.º 7
0
        private static void CallAnything(int inlet, Symbol s, AtomList l)
        {
//            Post("CLASS-ANYTHING {0}->{1}:{2}", inlet,s,l);

            try {
                External e = Internal.pass.ext;
                Class    c = e.klass;

                Hashtable h;
                try { h = (Hashtable)c.m_map[inlet]; }
                catch (IndexOutOfRangeException) { h = null; }

                if (h != null)
                {
                    object fnd = h[s];
                    if (fnd != null)
                    {
                        MapValue mv = (MapValue)fnd;
                        switch (mv.k)
                        {
                        case Kind.k_bang:
                        {
                            ((DynamicMethodBang)mv.d)(e);
                            return;
                        }

                        case Kind.k_float:
                        {
                            float f = l.Count > 0 ? (float)l[0] : 0;
                            ((DynamicMethodFloat)mv.d)(e, f);
                            return;
                        }

                        case Kind.k_symbol:
                        {
                            Symbol sym = l.Count > 0 ? (Symbol)l[0] : _;
                            ((DynamicMethodSymbol)mv.d)(e, sym);
                            return;
                        }

                        case Kind.k_pointer:
                        {
                            Pointer p = l.Count > 0 ? (Pointer)l[0] : new Pointer();
                            ((DynamicMethodPointer)mv.d)(e, p);
                            return;
                        }

                        case Kind.k_list:
                            ((DynamicMethodList)mv.d)(e, (Atom[])l);
                            return;

                        case Kind.k_anything:
                            ((DynamicMethodAnything)mv.d)(e, inlet, s, (Atom[])l);
                            return;

                        default:
                            throw new NotImplementedException("Selector " + s.ToString() + " not handled");
                        }
                    }
                }

                // no explicit method found...
                c.m_anything(e, inlet, s, (Atom[])l);
            }
            catch (Exception exc) { PostError(exc.ToString()); }
        }
Ejemplo n.º 8
0
        private static void NewClass(ClassPtr ptr, Symbol sym)
        {
            Internal.pass.klass = null;

            try
            {
                string name = sym.ToString();

                // load assembly according to name
                string file = SearchPath(name + ".dll");
                if (file.Length == 0)
                {
                    return;                   // throw new ArgumentException("Assembly file " + name + " not found");
                }
                Assembly assembly = Assembly.LoadFile(file);
                if (assembly == null)
                {
                    return;                   // throw new ArgumentException("Assembly " + name + " could not be loaded");
                }
                Type exttp = assembly.GetType(name);
                if (exttp == null)
                {
                    throw new ArgumentException("Class " + name + " could not be found");
                }

                Class klass = new Class(ptr, exttp);

                // create dummy external
                ConstructorInfo ctor = exttp.GetConstructor(System.Type.EmptyTypes);
                if (ctor == null)
                {
                    throw new MissingMethodException("External class must have a default constructor");
                }

                Internal.pass.klass = klass;
                Internal.extptr.Clear();

                External dummy = (External)ctor.Invoke(null);

                // reset flags
                methodflags = MethodFlags.f_none;

                // call Setup method
                MethodInfo setup = exttp.GetMethod("Setup", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[1] {
                    exttp
                }, null);
                if (setup == null)
                {
                    throw new MissingMethodException("External class must have a Setup function");
                }

                object ret = setup.Invoke(exttp, new object[1] {
                    dummy
                });
                ClassType classflags;
                try { classflags = (ClassType)ret; }
                catch { classflags = ClassType.Default; }

                // set callbacks
                RegisterClass(ptr, sym, classflags, methodflags);
            }
            catch (Exception exc)
            {
                Internal.pass.klass = null;
                PostError(exc.ToString());
            }
        }