예제 #1
0
파일: JsHost.cs 프로젝트: Mofsy/jinxbot
        public JsHost(ScriptEngine engine, IJinxBotClient client)
        {
            Debug.Assert(engine != null);
            Debug.Assert(client != null);

            _engine = engine;
            _client = client;
            _jsClient = new JsJinxBotClientObjectInstance(client, this, engine);

            _engine.SetGlobalValue("Colors", new Colors(engine));
            _engine.SetGlobalValue("CssClasses", new CssClasses(engine));
            _engine.SetGlobalFunction("send", (Action<string>)send);
            _engine.SetGlobalFunction("addChat", (Action<ArrayInstance>)addChat);
            _engine.SetGlobalFunction("format", (Func<string, ArrayInstance, string>)format);
            _engine.SetGlobalFunction("setTimeout", (Func<double, ObjectInstance, int>)setTimeout);
            _engine.SetGlobalFunction("clearTimeout", (Action<int>)clearTimeout);
            _engine.SetGlobalFunction("setInterval", (Func<double, ObjectInstance, int>)setInterval);
            _engine.SetGlobalFunction("clearInterval", (Action<int>)clearInterval);

            FunctionInstance instance = engine.Evaluate(DUMP_FUNC) as FunctionInstance;
            engine.SetGlobalValue("dump", instance);
            engine.SetGlobalValue("client", _jsClient);

        }
예제 #2
0
        public JsHost(ScriptEngine engine, IJinxBotClient client)
        {
            Debug.Assert(engine != null);
            Debug.Assert(client != null);

            _engine   = engine;
            _client   = client;
            _jsClient = new JsJinxBotClientObjectInstance(client, this, engine);

            _engine.SetGlobalValue("Colors", new Colors(engine));
            _engine.SetGlobalValue("CssClasses", new CssClasses(engine));
            _engine.SetGlobalFunction("send", (Action <string>)send);
            _engine.SetGlobalFunction("addChat", (Action <ArrayInstance>)addChat);
            _engine.SetGlobalFunction("format", (Func <string, ArrayInstance, string>)format);
            _engine.SetGlobalFunction("setTimeout", (Func <double, ObjectInstance, int>)setTimeout);
            _engine.SetGlobalFunction("clearTimeout", (Action <int>)clearTimeout);
            _engine.SetGlobalFunction("setInterval", (Func <double, ObjectInstance, int>)setInterval);
            _engine.SetGlobalFunction("clearInterval", (Action <int>)clearInterval);

            FunctionInstance instance = engine.Evaluate(DUMP_FUNC) as FunctionInstance;

            engine.SetGlobalValue("dump", instance);
            engine.SetGlobalValue("client", _jsClient);
        }