Mercurial > pymonkey
diff docs/rendered/pymonkey.html @ 139:d08cb5a06c66
Added docs for Script, compile_script() and execute_script().
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 24 Aug 2009 11:39:58 -0700 |
parents | 0c81cb18c935 |
children | 96dc1beefc00 |
line wrap: on
line diff
--- a/docs/rendered/pymonkey.html Sun Aug 23 22:26:58 2009 -0700 +++ b/docs/rendered/pymonkey.html Mon Aug 24 11:39:58 2009 -0700 @@ -103,6 +103,18 @@ <a title="pymonkey.Object" class="reference" href="#pymonkey.Object"><tt class="xref docutils literal"><span class="pre">Object</span></tt></a>.</dd></dl> <dl class="class"> +<dt id="pymonkey.Script"> +<em class="property"> +class </em><tt class="descclassname">pymonkey.</tt><tt class="descname">Script</tt><a class="headerlink" href="#pymonkey.Script" title="Permalink to this definition">¶</a></dt> +<dd><p>This is the type of compiled JavaScript scripts; it’s actually a +subtype of <a title="pymonkey.Object" class="reference" href="#pymonkey.Object"><tt class="xref docutils literal"><span class="pre">Object</span></tt></a>, though when exposed to JS code it +doesn’t provide access to any special data or functionality.</p> +<p>Script instances have a read-only buffer interface that exposes +their bytecode. This can be accessed by passing an instance to +Python’s built-in <tt class="docutils literal"><span class="pre">buffer()</span></tt> function.</p> +</dd></dl> + +<dl class="class"> <dt id="pymonkey.Context"> <em class="property"> class </em><tt class="descclassname">pymonkey.</tt><tt class="descname">Context</tt><a class="headerlink" href="#pymonkey.Context" title="Permalink to this definition">¶</a></dt> @@ -230,6 +242,35 @@ </dd></dl> <dl class="method"> +<dt id="pymonkey.Context.compile_script"> +<tt class="descname">compile_script</tt><big>(</big><em>obj</em>, <em>code</em>, <em>filename</em>, <em>lineno</em><big>)</big><a class="headerlink" href="#pymonkey.Context.compile_script" title="Permalink to this definition">¶</a></dt> +<dd><p>Compiles the given string of code and returns a <a title="pymonkey.Script" class="reference" href="#pymonkey.Script"><tt class="xref docutils literal"><span class="pre">Script</span></tt></a> +instance that can be executed via <a title="pymonkey.Context.execute_script" class="reference" href="#pymonkey.Context.execute_script"><tt class="xref docutils literal"><span class="pre">execute_script()</span></tt></a>.</p> +<p><cite>filename</cite> and <cite>lineno</cite> are used just as in +<a title="pymonkey.Context.evaluate_script" class="reference" href="#pymonkey.Context.evaluate_script"><tt class="xref docutils literal"><span class="pre">evaluate_script()</span></tt></a>.</p> +<p><cite>obj</cite> is defined in the SpiderMonkey documentation to be +the “object with which the script is associated”, though it’s +unclear what its actual role is.</p> +</dd></dl> + +<dl class="method"> +<dt id="pymonkey.Context.execute_script"> +<tt class="descname">execute_script</tt><big>(</big><em>globalobj</em>, <em>script</em><big>)</big><a class="headerlink" href="#pymonkey.Context.execute_script" title="Permalink to this definition">¶</a></dt> +<dd><p>Executes the code in the given <a title="pymonkey.Script" class="reference" href="#pymonkey.Script"><tt class="xref docutils literal"><span class="pre">Script</span></tt></a> object, using +<cite>globalobj</cite> as the global object/scope, and returns the result.</p> +<p>For example:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">cx</span> <span class="o">=</span> <span class="n">pymonkey</span><span class="o">.</span><span class="n">Runtime</span><span class="p">()</span><span class="o">.</span><span class="n">new_context</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">obj</span> <span class="o">=</span> <span class="n">cx</span><span class="o">.</span><span class="n">new_object</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">cx</span><span class="o">.</span><span class="n">init_standard_classes</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">script</span> <span class="o">=</span> <span class="n">cx</span><span class="o">.</span><span class="n">compile_script</span><span class="p">(</span><span class="n">cx</span><span class="o">.</span><span class="n">new_object</span><span class="p">(),</span> <span class="s">'5 * Math'</span><span class="p">,</span> +<span class="gp">... </span> <span class="s">'<string>'</span><span class="p">,</span> <span class="mf">1</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">cx</span><span class="o">.</span><span class="n">execute_script</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">script</span><span class="p">)</span> +<span class="go">nan</span> +</pre></div> +</div> +</dd></dl> + +<dl class="method"> <dt id="pymonkey.Context.call_function"> <tt class="descname">call_function</tt><big>(</big><em>thisobj</em>, <em>func</em>, <em>args</em><big>)</big><a class="headerlink" href="#pymonkey.Context.call_function" title="Permalink to this definition">¶</a></dt> <dd><p>Calls a JavaScript function.</p>