Example #1
0
        /// <summary>
        /// Runs the named macro.
        /// </summary>
        public void RunMacro(string s)
        {
            try
            {
                string sFile = GetMacroFile();
                VM     vm    = new VM();
                vm.InitializeVM();
                vm.RegisterDotNetType(typeof(HeronEditor));
                vm.RegisterDotNetType(typeof(CodeEditControl));
                vm.RegisterDotNetType(typeof(Preferences));

                //vm.RegisterAssembly(Assembly.GetExecutingAssembly());
                vm.RegisterCommonWinFormTypes();
                ModuleDefn m = vm.LoadModule(sFile);
                vm.LoadDependentModules(sFile);
                vm.ResolveTypes
                    ();
                ModuleInstance mi = m.Instantiate(vm, new HeronValue[] { }, null) as ModuleInstance;
                vm.RunMeta(mi);
                HeronValue f = mi.GetFieldOrMethod("RunMacro");
                if (f == null)
                {
                    throw new Exception("Could not find a 'Main' method to run");
                }
                f.Apply(vm, new HeronValue[] { DotNetObject.Marshal(this), DotNetObject.Marshal(s) });
            }
            catch (Exception e)
            {
                MessageBox.Show("Error during macro: " + e.Message);
            }
        }