private EcmaValue LoadScriptFile(string path) { if (!File.Exists(path)) { throw new EcmaRuntimeException("Unknown script path: " + path); } EcmaScript script = new EcmaScript(); script.BuildStandartLibary(); new DefaultScript(script); EcmaComplication com = script.RunCode(File.OpenText(path)); if (com.Type != EcmaComplicationType.Return) { throw new EcmaRuntimeException("A included file must return a value!"); } return(com.Value); }
public IrcScript(IrcConection connection, Form1 main) { this.energy.BuildStandartLibary(); new DefaultScript(this.energy); this.connection = connection; this.main = main; this.energy.CreateVariable("_identify", EcmaValue.String(connection.GetIdentify())); this.energy.CreateVariable("sendAction", EcmaValue.Object(new NativeFunctionInstance(2, State, SendAction))); this.energy.CreateVariable("on", EcmaValue.Object(new NativeFunctionInstance(2, State, On))); this.energy.CreateVariable("action", EcmaValue.Object(new NativeFunctionInstance(2, State, _Action))); this.energy.CreateVariable("privmsg", EcmaValue.Object(new NativeFunctionInstance(2, State, Privmsg))); this.energy.CreateVariable("myNick", EcmaValue.Object(new NativeFunctionInstance(0, State, MyNick))); this.energy.CreateVariable("isPm", EcmaValue.Object(new NativeFunctionInstance(1, State, IsPM))); this.energy.CreateVariable("join", EcmaValue.Object(new NativeFunctionInstance(1, State, Join))); this.energy.CreateVariable("whois", EcmaValue.Object(new NativeFunctionInstance(1, State, Whois))); this.energy.CreateVariable("sleep", EcmaValue.Object(new NativeFunctionInstance(1, State, Sleep))); MysqlScript.Init(energy); energy.RunCode(new StreamReader(File.OpenRead("script.js"))); }