private void InitEngine(ZipFile z) { _engine.Execute(Resources.query); _engine.Execute(Resources.Module); _engine.Add("RessourceReader", typeof(RessourceReader)); _engine.Add("host", new ExtendedHostFunctions()); _engine.Execute("$['res'] = function(plugin, name) {return new RessourceReader(plugin).Read(name);}"); // add function to script engine to control the properties _engine.Add <Delegate>("property", new StaticMethodFunc(args => { if (args.Length == 1) { return(Properties.Get(args[0].ToString())); } else if (args.Length == 2) { Properties.Set(args[0].ToString(), args[1]); return(null); } return(null); })); /*_engine.Add("require", new Action<string>(_ => * { * var i = new StreamReader(z[_].OpenReader()); * * _engine.Execute(i.ReadToEnd()); * }));*/ _engine.Add("import", new Action <string>(_ => { var l = Library.Load(_); l.Apply(_engine); Dependencies.Add(l); })); _engine.AddHostObject("globals", HostItemFlags.GlobalMembers, new Globals(this)); _engine.Add("math", new OpenIDE.Library.Math()); _engine.Add("JSON", new OpenIDE.Library.JSON()); _engine.Add("XmlHttpRequest", typeof(XmlHttpRequest)); _engine.Add("console", new OpenIDE.Library.Console.FirebugConsole()); _engine.Add("register_window", new Action <string, Window>((n, w) => Windows.Add(n, w))); _engine.Add("debug", Workspace.Output); Events.Fire("OnReady"); }
public static void Require(WindowsScriptEngine se, Assembly ass) { Type[] types = ass.GetTypes(); foreach (Type type in types) { object[] ca = type.GetCustomAttributes(typeof(ModuleAttribute), false); if (ca != null) { foreach (MethodInfo method in type.GetMethods()) { se.AddHostObject(method.Name, Delegate.CreateDelegate(type, method)); } } else { se.AddHostType(type.Name, type); } } }