Exemplo n.º 1
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());
            }
        }
Exemplo n.º 2
0
        // --------------------------------------------------------------------------

        private Class(ClassPtr p, Type c)
        {
            ptr      = p;
            extclass = c;
        }
Exemplo n.º 3
0
 private extern static bool RegisterClass(ClassPtr ptr, Symbol sym, ClassType cflags, MethodFlags mflags);
Exemplo n.º 4
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());
            }
        }
Exemplo n.º 5
0
        // --------------------------------------------------------------------------        

        private Class(ClassPtr p,Type c)
        {
            ptr = p;
            extclass = c;
        }
Exemplo n.º 6
0
 private extern static bool RegisterClass(ClassPtr ptr, Symbol sym, ClassType cflags, MethodFlags mflags);