コード例 #1
0
        public void UpdateKeyboardState(KeyboardDevice currentKeyboard)
        {
            if (v8.IsDisposed)
            {
                return;
            }

            // Copy keyboard state
            //TODO: copy state quicker. Should be able to transfer over in O(1)
            InternalHandle[] keyboard = new InternalHandle[(int)Key.LastKey];
            for (int i = 0; i < keyboard.Length; i++)
            {
                int k = currentKeyboard[(Key)i] ? 1 : 0;
                keyboard[i] = v8.CreateValue(k);
            }

            v8.GlobalObject.SetProperty("Keyboard", v8.CreateArray(keyboard));
        }
コード例 #2
0
ファイル: EngineCompiler.cs プロジェクト: dogfuntom/emmet.net
        /// <summary>
        /// Loads JavaScript extensions and preferences from the specified directory.
        /// </summary>
        /// <param name="extensionsDirectory">Pathname of the extensions directory.</param>
        public void LoadExtensions(string extensionsDirectory)
        {
            List <InternalHandle> extensions = new List <InternalHandle>();
            var          files = Directory.EnumerateFiles(extensionsDirectory, "*.*");
            ObjectHandle emmet = _engine.DynamicGlobalObject.window.emmet;

            foreach (string filePath in files)
            {
                if (0 != string.Compare(Path.GetFileName(filePath), PreferencesFileName, true))
                {
                    extensions.Add(_engine.CreateValue(filePath));
                    continue;
                }

                string content   = File.ReadAllText(filePath);
                Handle parameter = _engine.CreateValue(content);
                Handle result    = emmet.Call("loadUserData", emmet, parameter);

                if (result.IsError)
                {
                    this.TraceError($"Failed to load Emmet preferences from {filePath}: {result.AsString}");
                }
                else
                {
                    this.Trace($"Successfully loaded Emmet preferences from {filePath}");
                }
            }

            if (extensions.Count > 0)
            {
                var    parameter = _engine.CreateArray(extensions.ToArray());
                Handle result    = emmet.Call("loadExtensions", emmet, parameter);

                if (result.IsError)
                {
                    this.TraceError($"Failed to load Emmet extensions: {result.AsString}");
                }
                else
                {
                    this.Trace($"Successfully loaded {extensions.Count} Emmet extensions");
                }
            }
        }