This file is indexed.

/usr/share/qt5/doc/qtscript/qtscriptextensions.html is in qtscript5-doc-html 5.2.1+dfsg-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qtscriptextensions.qdoc -->
  <title>Creating Qt Script Extensions | QtScript </title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
    <div class="main">
    <div class="main-rounded">
        <div class="navigationbar">
        <ul>
<li>Qt 5.2</li>
<li><a href="qtscript-index.html">Qt Script</a></li>
<li>Creating Qt Script Extensions</li>
<li id="buildversion">
Qt 5.2.1 Reference Documentation</li>
    </ul>
    </div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#static-extensions">Static Extensions</a></li>
</ul>
</div>
<h1 class="title">Creating Qt Script Extensions</h1>
<span class="subtitle"></span>
<!-- $$$qtscriptextensions.html-description -->
<div class="descr"> <a name="details"></a>
<p>Qt Script extensions can make additional functionality available to scripts evaluated by a <a href="qscriptengine.html">QScriptEngine</a>. Extensions are imported by calling the <a href="qscriptengine.html#importExtension">QScriptEngine::importExtension</a>() function.</p>
<p>There are three ways to create an extension:</p>
<ul>
<li>Subclass <a href="qscriptextensionplugin.html">QScriptExtensionPlugin</a> and implement the desired functionality.</li>
<li>Implement the functionality in a script file.</li>
<li>Use a hybrid approach, where part of the functionality is implemented in a <a href="qscriptextensionplugin.html">QScriptExtensionPlugin</a>, and part is implemented in a script file.</li>
</ul>
<p>The (dot-qualified) extension name is used to determine the path (relative to the application's plugin path) where <a href="qscriptengine.html">QScriptEngine</a> will look for the script file that will initialize the extension; if a file called <tt>__init__.js</tt> (usually located in <tt>[application plugin path]/script/foo/</tt>) is found in the corresponding folder, its contents will be evaluated by the engine when the extension is imported. As an example, if the extension is called <tt>&quot;foo.bar.baz&quot;</tt>, the engine will look for <tt>__init__.js</tt> in <tt>foo/bar/baz</tt>. Additionally, before importing <tt>&quot;foo.bar.baz&quot;</tt>, the engine will ensure that the extensions <tt>&quot;foo&quot;</tt> and <tt>&quot;foo.bar&quot;</tt> are imported, locating and evaluating the corresponding <tt>__init__.js</tt> in the same manner (in folders <tt>foo</tt> and <tt>foo/bar</tt>, respectively).</p>
<p>The contents of <tt>__init__.js</tt> are evaluated in a new <a href="qscriptcontext.html">QScriptContext</a>, as if it were the body of a function. The engine's Global Object acts as the <tt>this</tt> object. The following local variables are initially available to the script:</p>
<ul>
<li><b>__extension__</b>: The name of the extension (e.g&#x2e; <tt>&quot;foo.bar.baz&quot;</tt>).</li>
<li><b>__setupPackage__</b>: A convenience function for setting up a &quot;namespace&quot; in the script environment. A typical application is to call <tt>__setupPackage__()</tt> with <tt>__extension__</tt> as argument; e.g&#x2e; <tt>__setupPackage__(&quot;foo.bar.baz&quot;)</tt> would ensure that the object chain represented by the expression <tt>foo.bar.baz</tt> exists in the script environment. (This function is semantically equivalent to <a href="qscriptextensionplugin.html#setupPackage">QScriptExtensionPlugin::setupPackage</a>().)</li>
<li><b>__postInit__</b>: By default, this variable is undefined. If you assign a function to it, that function will be called <b>after</b> the C++ plugin's initialize() function has been called. You can use this to perform further initialization that depends on e.g&#x2e; native functions that the C++ plugin registers.</li>
</ul>
<p>An example of a simple <tt>__init__.js</tt>:</p>
<pre class="js"><span class="name">print</span>(<span class="string">&quot;importing &quot;</span> <span class="operator">+</span> <span class="name">__extension__</span>);
<span class="name">__setupPackage__</span>(<span class="string">&quot;cool.stuff&quot;</span>);

<span class="name">cool</span>.<span class="name">stuff</span>.<span class="name">add</span> <span class="operator">=</span> <span class="keyword">function</span>(<span class="name">a</span>, b) { <span class="keyword">return</span> <span class="name">a</span> <span class="operator">+</span> <span class="name">b</span>; }
<span class="name">cool</span>.<span class="name">stuff</span>.<span class="name">subtract</span> <span class="operator">=</span> <span class="keyword">function</span>(<span class="name">a</span>, b) { <span class="keyword">return</span> <span class="name">a</span> <span class="operator">-</span> <span class="name">b</span>; }</pre>
<p><a href="qscriptengine.html">QScriptEngine</a> will look for a <a href="qscriptextensionplugin.html">QScriptExtensionPlugin</a> that provides the relevant extension by querying each plugin for its keys() until a match is found. The plugin's initialize() function will be called <b>after</b> the relevant <tt>__init__.js</tt> (if any) has been evaluated.</p>
<p>Continuining with the example of our imaginary extension <tt>&quot;foo.bar.baz&quot;</tt>, the following steps will be performed by <a href="qscriptengine.html#importExtension">QScriptEngine::importExtension</a>():</p>
<ul>
<li>If it exists, <tt>foo/__init__.js</tt> is evaluated.</li>
<li>If a plugin with <tt>&quot;foo&quot;</tt> in its list of keys is found, its initialize() function is called with <tt>&quot;foo&quot;</tt> as key.</li>
<li>If it exists, <tt>foo/bar/__init__.js</tt> is evaluated.</li>
<li>If a plugin with <tt>&quot;foo.bar&quot;</tt> in its list of keys is found, its initialize() function is called with <tt>&quot;foo.bar&quot;</tt> as key.</li>
<li>If it exists, <tt>foo/bar/baz/__init__.js</tt> is evaluated.</li>
<li>If a plugin with &quot;foo.bar.baz&quot; in its list of keys is found, its initialize() function is called with <tt>&quot;foo.bar.baz&quot;</tt> as key.</li>
</ul>
<a name="static-extensions"></a>
<h2>Static Extensions</h2>
<p>When an extension is compiled and linked into your application as a static plugin, Qt Script will look for the optional <tt>__init__.js</tt> script in a resource, prefixed by <tt>:/qtscriptextension</tt>. For example, if the extension key is &quot;foo.bar&quot;, Qt Script will evaluate the contents of the file <tt>:/qtscriptextension/foo/bar/__init__.js</tt>, if it exists. Note that if the resource is built into the plugin, you may need to use the Q_INIT_RESOURCE() macro to initialize the resource before importing the extension.</p>
</div>
<!-- @@@qtscriptextensions.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2013 Digia Plc and/or its
   subsidiaries. Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Digia, Qt and their respective logos are trademarks of Digia Plc     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>