Back to home page

Enduro/X

 
 

    


0001 <html><head>
0002       <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
0003    <title>Pscript 3.0 Reference Manual</title><link rel="stylesheet" href="pscript.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.62.4"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="book" lang="en"><div class="titlepage"><div><div><h1 class="title"><a name="d0e2"></a>Pscript 3.0 Reference Manual</h1></div><div><h2 class="subtitle">version 3.0.7 release stable</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Alberto</span> <span class="surname">Demichelis</span></h3></div></div><div><p class="othercredit"><span class="contrib">Extensive review</span>: <span class="firstname">Wouter</span> <span class="surname">Van Oortmersern</span></p></div><div><p class="copyright">Copyright &copy; 2003-2015 Alberto Demichelis</p></div><div><div class="legalnotice"><p>
0004     Permission is hereby granted, free of charge, to any person obtaining a copy
0005     of this software and associated documentation files (the "Software"), to deal
0006     in the Software without restriction, including without limitation the rights
0007     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0008     copies of the Software, and to permit persons to whom the Software is
0009     furnished to do so, subject to the following conditions:</p><p>The above copyright notice and this permission notice shall be included in
0010     all copies or substantial portions of the Software.</p><p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0011     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0012     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0013     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0014     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0015     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0016     THE SOFTWARE.</p></div></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="#d0e33">1. Introduction</a></span></dt><dt><span class="chapter"><a href="#d0e39">2. The language</a></span></dt><dd><dl><dt><span class="sect1"><a href="#d0e45">Lexical structure</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e49">Identifiers</a></span></dt><dt><span class="sect2"><a href="#d0e61">Keywords</a></span></dt><dt><span class="sect2"><a href="#d0e183">Operators</a></span></dt><dt><span class="sect2"><a href="#d0e291">Other tokens</a></span></dt><dt><span class="sect2"><a href="#d0e335">Literals</a></span></dt><dt><span class="sect2"><a href="#d0e410">Comments</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e448">Values and Data types</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e457">Integer</a></span></dt><dt><span class="sect2"><a href="#d0e465">Float</a></span></dt><dt><span class="sect2"><a href="#d0e473">String</a></span></dt><dt><span class="sect2"><a href="#d0e492">Null</a></span></dt><dt><span class="sect2"><a href="#d0e500">Bool</a></span></dt><dt><span class="sect2"><a href="#d0e514">Table</a></span></dt><dt><span class="sect2"><a href="#d0e522">Array</a></span></dt><dt><span class="sect2"><a href="#d0e530">Function</a></span></dt><dt><span class="sect2"><a href="#d0e536">Class</a></span></dt><dt><span class="sect2"><a href="#d0e542">Class instance</a></span></dt><dt><span class="sect2"><a href="#d0e551">Generator</a></span></dt><dt><span class="sect2"><a href="#d0e560">Userdata</a></span></dt><dt><span class="sect2"><a href="#d0e569">Thread</a></span></dt><dt><span class="sect2"><a href="#d0e575">Weak References</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e584">Execution Context</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e599">Variables</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e654">Statements</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e668">Block</a></span></dt><dt><span class="sect2"><a href="#d0e680">Control Flow Statements</a></span></dt><dt><span class="sect2"><a href="#d0e758">Loops</a></span></dt><dt><span class="sect2"><a href="#d0e790">break</a></span></dt><dt><span class="sect2"><a href="#d0e802">continue</a></span></dt><dt><span class="sect2"><a href="#d0e814">return</a></span></dt><dt><span class="sect2"><a href="#d0e826">yield</a></span></dt><dt><span class="sect2"><a href="#d0e841">Local variables declaration</a></span></dt><dt><span class="sect2"><a href="#d0e855">Function declaration</a></span></dt><dt><span class="sect2"><a href="#d0e867">Class declaration</a></span></dt><dt><span class="sect2"><a href="#d0e879">try/catch</a></span></dt><dt><span class="sect2"><a href="#d0e891">throw</a></span></dt><dt><span class="sect2"><a href="#d0e903">const</a></span></dt><dt><span class="sect2"><a href="#d0e919">enum</a></span></dt><dt><span class="sect2"><a href="#d0e936">expression statement</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e948">Expressions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e955">Assignment(=) &amp; new slot(&lt;-)</a></span></dt><dt><span class="sect2"><a href="#d0e987">Operators</a></span></dt><dt><span class="sect2"><a href="#d0e1216">Table constructor</a></span></dt><dt><span class="sect2"><a href="#d0e1274">clone</a></span></dt><dt><span class="sect2"><a href="#d0e1299">Array constructor</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1317">Tables</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1327">Construction</a></span></dt><dt><span class="sect2"><a href="#d0e1336">Slot creation</a></span></dt><dt><span class="sect2"><a href="#d0e1361">Slot deletion</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1377">Arrays</a></span></dt><dt><span class="sect1"><a href="#d0e1393">Functions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1403">Function declaration</a></span></dt><dt><span class="sect2"><a href="#d0e1470">Function calls</a></span></dt><dt><span class="sect2"><a href="#d0e1496">Binding an environment to a function</a></span></dt><dt><span class="sect2"><a href="#d0e1514">Lambda expressions</a></span></dt><dt><span class="sect2"><a href="#d0e1556">Free variables</a></span></dt><dt><span class="sect2"><a href="#d0e1569">Tail recursion</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1580">Classes</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1590">Class declaration</a></span></dt><dt><span class="sect2"><a href="#d0e1672">Class instances</a></span></dt><dt><span class="sect2"><a href="#d0e1738">Inheritance</a></span></dt><dt><span class="sect2"><a href="#d0e1779">Metamethods</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1827">Generators</a></span></dt><dt><span class="sect1"><a href="#d0e1858">Constants &amp; Enumerations</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1869">Constants</a></span></dt><dt><span class="sect2"><a href="#d0e1892">Enumerations</a></span></dt><dt><span class="sect2"><a href="#d0e1924">Implementation notes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1954">Threads</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1965">Using threads</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1995">Weak References</a></span></dt><dt><span class="sect1"><a href="#d0e2038">Delegation</a></span></dt><dt><span class="sect1"><a href="#d0e2057">Metamethods</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e2079">_set</a></span></dt><dt><span class="sect2"><a href="#d0e2092">_get</a></span></dt><dt><span class="sect2"><a href="#d0e2105">_newslot</a></span></dt><dt><span class="sect2"><a href="#d0e2120">_delslot</a></span></dt><dt><span class="sect2"><a href="#d0e2135">_add</a></span></dt><dt><span class="sect2"><a href="#d0e2148">_sub</a></span></dt><dt><span class="sect2"><a href="#d0e2159">_mul</a></span></dt><dt><span class="sect2"><a href="#d0e2170">_div</a></span></dt><dt><span class="sect2"><a href="#d0e2181">_modulo</a></span></dt><dt><span class="sect2"><a href="#d0e2192">_unm</a></span></dt><dt><span class="sect2"><a href="#d0e2205">_typeof</a></span></dt><dt><span class="sect2"><a href="#d0e2218">_cmp</a></span></dt><dt><span class="sect2"><a href="#d0e2263">_call</a></span></dt><dt><span class="sect2"><a href="#d0e2276">_cloned</a></span></dt><dt><span class="sect2"><a href="#d0e2289">_nexti</a></span></dt><dt><span class="sect2"><a href="#d0e2304">_tostring</a></span></dt><dt><span class="sect2"><a href="#d0e2322">_inherited</a></span></dt><dt><span class="sect2"><a href="#d0e2343">_newmember</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e2358">Built-in functions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e2365">Global symbols</a></span></dt><dt><span class="sect2"><a href="#d0e2615">Default delegates</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#d0e3772">3. Embedding Pscript</a></span></dt><dd><dl><dt><span class="sect1"><a href="#d0e3783">Memory management</a></span></dt><dt><span class="sect1"><a href="#d0e3800">Unicode</a></span></dt><dt><span class="sect1"><a href="#d0e3806">Pscript on 64 bits architectures</a></span></dt><dt><span class="sect1"><a href="#d0e3811">Userdata alignment</a></span></dt><dt><span class="sect1"><a href="#d0e3819">Stand-alone VM without compiler</a></span></dt><dt><span class="sect1"><a href="#d0e3825">Error conventions</a></span></dt><dt><span class="sect1"><a href="#d0e3833">Initializing Pscript</a></span></dt><dt><span class="sect1"><a href="#d0e3849">The Stack</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e3855">Stack indexes</a></span></dt><dt><span class="sect2"><a href="#d0e3933">Stack manipulation</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e4000">Runtime error handling</a></span></dt><dt><span class="sect1"><a href="#d0e4011">Compiling a script</a></span></dt><dt><span class="sect1"><a href="#d0e4046">Calling a function</a></span></dt><dt><span class="sect1"><a href="#d0e4060">Create a C function</a></span></dt><dt><span class="sect1"><a href="#d0e4108">Tables and arrays manipulation</a></span></dt><dt><span class="sect1"><a href="#d0e4177">Userdata and UserPointers</a></span></dt><dt><span class="sect1"><a href="#d0e4201">The registry table</a></span></dt><dt><span class="sect1"><a href="#d0e4213">Mantaining strong references to Pscript values from the C API</a></span></dt><dt><span class="sect1"><a href="#d0e4221">Debug Interface</a></span></dt></dl></dd><dt><span class="chapter"><a href="#d0e4257">4. API Reference</a></span></dt><dt><span class="index"><a href="#d0e11543">Index</a></span></dt></dl></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="d0e33"></a>Chapter&nbsp;1.&nbsp;Introduction</h2></div></div><div></div></div><p>
0017         Pscript is a high level imperative-OO programming language, designed to be a powerful
0018         scripting tool that fits in the size, memory bandwidth, and real-time requirements of
0019         applications like games.
0020         Although Pscript offers a wide range of features like dynamic typing, delegation, higher
0021         order functions, generators, tail recursion, exception handling, automatic memory
0022         management, both compiler and virtual machine fit together in about 6k lines of C++
0023         code.
0024     </p></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="d0e39"></a>Chapter&nbsp;2.&nbsp;The language</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#d0e45">Lexical structure</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e49">Identifiers</a></span></dt><dt><span class="sect2"><a href="#d0e61">Keywords</a></span></dt><dt><span class="sect2"><a href="#d0e183">Operators</a></span></dt><dt><span class="sect2"><a href="#d0e291">Other tokens</a></span></dt><dt><span class="sect2"><a href="#d0e335">Literals</a></span></dt><dt><span class="sect2"><a href="#d0e410">Comments</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e448">Values and Data types</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e457">Integer</a></span></dt><dt><span class="sect2"><a href="#d0e465">Float</a></span></dt><dt><span class="sect2"><a href="#d0e473">String</a></span></dt><dt><span class="sect2"><a href="#d0e492">Null</a></span></dt><dt><span class="sect2"><a href="#d0e500">Bool</a></span></dt><dt><span class="sect2"><a href="#d0e514">Table</a></span></dt><dt><span class="sect2"><a href="#d0e522">Array</a></span></dt><dt><span class="sect2"><a href="#d0e530">Function</a></span></dt><dt><span class="sect2"><a href="#d0e536">Class</a></span></dt><dt><span class="sect2"><a href="#d0e542">Class instance</a></span></dt><dt><span class="sect2"><a href="#d0e551">Generator</a></span></dt><dt><span class="sect2"><a href="#d0e560">Userdata</a></span></dt><dt><span class="sect2"><a href="#d0e569">Thread</a></span></dt><dt><span class="sect2"><a href="#d0e575">Weak References</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e584">Execution Context</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e599">Variables</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e654">Statements</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e668">Block</a></span></dt><dt><span class="sect2"><a href="#d0e680">Control Flow Statements</a></span></dt><dt><span class="sect2"><a href="#d0e758">Loops</a></span></dt><dt><span class="sect2"><a href="#d0e790">break</a></span></dt><dt><span class="sect2"><a href="#d0e802">continue</a></span></dt><dt><span class="sect2"><a href="#d0e814">return</a></span></dt><dt><span class="sect2"><a href="#d0e826">yield</a></span></dt><dt><span class="sect2"><a href="#d0e841">Local variables declaration</a></span></dt><dt><span class="sect2"><a href="#d0e855">Function declaration</a></span></dt><dt><span class="sect2"><a href="#d0e867">Class declaration</a></span></dt><dt><span class="sect2"><a href="#d0e879">try/catch</a></span></dt><dt><span class="sect2"><a href="#d0e891">throw</a></span></dt><dt><span class="sect2"><a href="#d0e903">const</a></span></dt><dt><span class="sect2"><a href="#d0e919">enum</a></span></dt><dt><span class="sect2"><a href="#d0e936">expression statement</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e948">Expressions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e955">Assignment(=) &amp; new slot(&lt;-)</a></span></dt><dt><span class="sect2"><a href="#d0e987">Operators</a></span></dt><dt><span class="sect2"><a href="#d0e1216">Table constructor</a></span></dt><dt><span class="sect2"><a href="#d0e1274">clone</a></span></dt><dt><span class="sect2"><a href="#d0e1299">Array constructor</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1317">Tables</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1327">Construction</a></span></dt><dt><span class="sect2"><a href="#d0e1336">Slot creation</a></span></dt><dt><span class="sect2"><a href="#d0e1361">Slot deletion</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1377">Arrays</a></span></dt><dt><span class="sect1"><a href="#d0e1393">Functions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1403">Function declaration</a></span></dt><dt><span class="sect2"><a href="#d0e1470">Function calls</a></span></dt><dt><span class="sect2"><a href="#d0e1496">Binding an environment to a function</a></span></dt><dt><span class="sect2"><a href="#d0e1514">Lambda expressions</a></span></dt><dt><span class="sect2"><a href="#d0e1556">Free variables</a></span></dt><dt><span class="sect2"><a href="#d0e1569">Tail recursion</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1580">Classes</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1590">Class declaration</a></span></dt><dt><span class="sect2"><a href="#d0e1672">Class instances</a></span></dt><dt><span class="sect2"><a href="#d0e1738">Inheritance</a></span></dt><dt><span class="sect2"><a href="#d0e1779">Metamethods</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1827">Generators</a></span></dt><dt><span class="sect1"><a href="#d0e1858">Constants &amp; Enumerations</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1869">Constants</a></span></dt><dt><span class="sect2"><a href="#d0e1892">Enumerations</a></span></dt><dt><span class="sect2"><a href="#d0e1924">Implementation notes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1954">Threads</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1965">Using threads</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1995">Weak References</a></span></dt><dt><span class="sect1"><a href="#d0e2038">Delegation</a></span></dt><dt><span class="sect1"><a href="#d0e2057">Metamethods</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e2079">_set</a></span></dt><dt><span class="sect2"><a href="#d0e2092">_get</a></span></dt><dt><span class="sect2"><a href="#d0e2105">_newslot</a></span></dt><dt><span class="sect2"><a href="#d0e2120">_delslot</a></span></dt><dt><span class="sect2"><a href="#d0e2135">_add</a></span></dt><dt><span class="sect2"><a href="#d0e2148">_sub</a></span></dt><dt><span class="sect2"><a href="#d0e2159">_mul</a></span></dt><dt><span class="sect2"><a href="#d0e2170">_div</a></span></dt><dt><span class="sect2"><a href="#d0e2181">_modulo</a></span></dt><dt><span class="sect2"><a href="#d0e2192">_unm</a></span></dt><dt><span class="sect2"><a href="#d0e2205">_typeof</a></span></dt><dt><span class="sect2"><a href="#d0e2218">_cmp</a></span></dt><dt><span class="sect2"><a href="#d0e2263">_call</a></span></dt><dt><span class="sect2"><a href="#d0e2276">_cloned</a></span></dt><dt><span class="sect2"><a href="#d0e2289">_nexti</a></span></dt><dt><span class="sect2"><a href="#d0e2304">_tostring</a></span></dt><dt><span class="sect2"><a href="#d0e2322">_inherited</a></span></dt><dt><span class="sect2"><a href="#d0e2343">_newmember</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e2358">Built-in functions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e2365">Global symbols</a></span></dt><dt><span class="sect2"><a href="#d0e2615">Default delegates</a></span></dt></dl></dd></dl></div><p>
0025         This part of the document describes the syntax and semantics of the language.
0026     </p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e45"></a>Lexical structure</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e49"></a>Identifiers</h3></div></div><div></div></div><a class="indexterm" name="d0e50"></a><p>
0027                 Identifiers start with a alphabetic character or '_' followed by any number of alphabetic
0028                 characters, '_' or digits ([0-9]). Pscript is a case sensitive language, this means that the
0029                 lowercase and uppercase representation of the same alphabetic character are considered
0030                 different characters. For instance "foo", "Foo" and "fOo" will be treated as 3 distinct
0031                 identifiers.
0032             </p><pre class="programlisting"><span class="emphasis"><em>id:= [a-zA-Z_]+[a-zA-Z_0-9]*</em></span></pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e61"></a>Keywords</h3></div></div><div></div></div><a class="indexterm" name="d0e62"></a><p>
0033                 The following words are reserved words by the language and cannot be used as
0034                 identifiers:
0035             </p><div class="informaltable"><table border="0"><colgroup><col><col><col><col><col><col></colgroup><tbody><tr><td><tt class="literal">base</tt></td><td><tt class="literal">break</tt></td><td><tt class="literal">case</tt></td><td><tt class="literal">catch</tt></td><td><tt class="literal">class</tt></td><td><tt class="literal">clone</tt></td></tr><tr><td><tt class="literal">continue</tt></td><td><tt class="literal">const</tt></td><td><tt class="literal">default</tt></td><td><tt class="literal">delete</tt></td><td><tt class="literal">else</tt></td><td><tt class="literal">enum</tt></td></tr><tr><td><tt class="literal">extends</tt></td><td><tt class="literal">for</tt></td><td><tt class="literal">foreach</tt></td><td><tt class="literal">function</tt></td><td><tt class="literal">if</tt></td><td><tt class="literal">in</tt></td></tr><tr><td><tt class="literal">local</tt></td><td><tt class="literal">null</tt></td><td><tt class="literal">resume</tt></td><td><tt class="literal">return</tt></td><td><tt class="literal">switch</tt></td><td><tt class="literal">this</tt></td></tr><tr><td><tt class="literal">throw</tt></td><td><tt class="literal">try</tt></td><td><tt class="literal">typeof</tt></td><td><tt class="literal">while</tt></td><td><tt class="literal">yield</tt></td><td><tt class="literal">constructor</tt></td></tr><tr><td><tt class="literal">instanceof</tt></td><td><tt class="literal">true</tt></td><td><tt class="literal">false</tt></td><td><tt class="literal">static</tt></td><td class="auto-generated">&nbsp;</td><td class="auto-generated">&nbsp;</td></tr></tbody></table></div><p>
0036                 Keywords are covered in detail later in this document.
0037             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e183"></a>Operators</h3></div></div><div></div></div><a class="indexterm" name="d0e184"></a><p>
0038                 Pscript recognizes the following operators:
0039             </p><div class="informaltable"><table border="0"><colgroup><col><col><col><col><col><col><col><col></colgroup><tbody><tr><td><tt class="literal">! </tt></td><td><tt class="literal">!= </tt></td><td><tt class="literal">|| </tt></td><td><tt class="literal">== </tt></td><td><tt class="literal">&amp;&amp; </tt></td><td><tt class="literal">&lt;= </tt></td><td><tt class="literal">=&gt; </tt></td><td><tt class="literal">&gt; </tt></td></tr><tr><td><tt class="literal">&lt;=&gt;</tt></td><td><tt class="literal">+ </tt></td><td><tt class="literal">+= </tt></td><td><tt class="literal">- </tt></td><td><tt class="literal">-= </tt></td><td><tt class="literal">/ </tt></td><td><tt class="literal">/= </tt></td><td><tt class="literal">* </tt></td></tr><tr><td><tt class="literal">*= </tt></td><td><tt class="literal">% </tt></td><td><tt class="literal">%= </tt></td><td><tt class="literal">++ </tt></td><td><tt class="literal">-- </tt></td><td><tt class="literal">&lt;- </tt></td><td><tt class="literal">= </tt></td><td class="auto-generated">&nbsp;</td></tr><tr><td><tt class="literal">&amp; </tt></td><td><tt class="literal">^ </tt></td><td><tt class="literal">| </tt></td><td><tt class="literal">~ </tt></td><td><tt class="literal">&gt;&gt; </tt></td><td><tt class="literal">&lt;&lt; </tt></td><td><tt class="literal">&gt;&gt;&gt; </tt></td><td><tt class="literal"></tt></td></tr></tbody></table></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e291"></a>Other tokens</h3></div></div><div></div></div><p>
0040                 Other used tokens are:
0041             </p><div class="informaltable"><table border="0"><colgroup><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><tbody><tr><td><tt class="literal">{</tt></td><td><tt class="literal">}</tt></td><td><tt class="literal">[</tt></td><td><tt class="literal">]</tt></td><td><tt class="literal">.</tt></td><td><tt class="literal">:</tt></td><td><tt class="literal">::</tt></td><td><tt class="literal">'</tt></td><td><tt class="literal">;</tt></td><td><tt class="literal">"</tt></td><td><tt class="literal">@"</tt></td><td class="auto-generated">&nbsp;</td></tr></tbody></table></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e335"></a>Literals</h3></div></div><div></div></div><a class="indexterm" name="d0e336"></a><p>
0042                 Pscript accepts integer numbers, floating point numbers and strings literals.
0043             </p><div class="informaltable"><table border="0"><colgroup><col><col></colgroup><tbody><tr><td><tt class="literal">34</tt></td><td>Integer number(base 10)</td></tr><tr><td><tt class="literal">0xFF00A120</tt></td><td>Integer number(base 16)</td></tr><tr><td><tt class="literal">0753</tt></td><td>Integer number(base 8)</td></tr><tr><td><tt class="literal">'a'</tt></td><td>Integer number</td></tr><tr><td><tt class="literal">1.52</tt></td><td>Floating point number</td></tr><tr><td><tt class="literal">1.e2</tt></td><td>Floating point number</td></tr><tr><td><tt class="literal">1.e-2</tt></td><td>Floating point number</td></tr><tr><td><tt class="literal">"I'm a string"</tt></td><td>String</td></tr><tr><td><tt class="literal">@"I'm a verbatim string"</tt></td><td>String</td></tr><tr><td><tt class="literal">
0044 @" I'm a 
0045     multiline verbatim string
0046 "
0047                             
0048                         </tt></td><td>String</td></tr></tbody></table></div><pre class="programlisting"><span class="emphasis"><em>
0049 IntegerLiteral := [1-9][0-9]* | '0x' [0-9A-Fa-f]+ | ''' [.]+ ''' | 0[0-7]+
0050 FloatLiteral := [0-9]+ '.' [0-9]+
0051 FloatLiteral := [0-9]+ '.' 'e'|'E' '+'|'-' [0-9]+
0052 StringLiteral:= '"'[.]* '"'
0053 VerbatimStringLiteral:= '@''"'[.]* '"'
0054       </em></span></pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e410"></a>Comments</h3></div></div><div></div></div><a class="indexterm" name="d0e411"></a>
0055             A comment is text that the compiler ignores but that is useful for programmers. 
0056             Comments are normally used to embed annotations in the code. The compiler 
0057             treats them as white space.
0058             <p>
0059                 The <tt class="literal">/*</tt> (slash, asterisk) characters, followed by any 
0060                 sequence of characters (including new lines), 
0061                 followed by the <tt class="literal">*/</tt> characters. This syntax is the same as ANSI C.
0062                 </p><pre class="programlisting">
0063 /* 
0064 this is
0065 a multiline comment.
0066 this lines will be ignored by the compiler
0067 */              
0068                 </pre><p>
0069             </p><p>
0070                 The <tt class="literal">//</tt> (two slashes) characters, followed by any sequence of characters. 
0071                 A new line not immediately preceded by a backslash terminates this form of comment. 
0072                 It is commonly called a <tt class="literal">&#8220;single-line comment.&#8221;</tt> 
0073                 </p><pre class="programlisting">
0074 //this is a single line comment. this line will be ignored by the compiler 
0075                 </pre><p>
0076             </p><p>
0077         The character <tt class="literal">#</tt> is an alternative syntax for single line comment.
0078         </p><pre class="programlisting">
0079           
0080 #this is also a single line comment.
0081         </pre><p>
0082         This to facilitate the use of pscript in UNIX-style shell scripts.
0083       </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e448"></a>Values and Data types</h2></div></div><div></div></div><a class="indexterm" name="d0e449"></a><p>
0084             Pscript is a dynamically typed language so variables do not have a type, although they
0085             refer to a value that does have a type.
0086             Pscript basic types are integer, float, string, null, table, array, function, generator, 
0087             class, instance, bool, thread and
0088             userdata.
0089         </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e457"></a>Integer</h3></div></div><div></div></div><p>
0090                 An Integer represents a 32 bits (or better) signed number.
0091             </p><pre class="programlisting">
0092 local a = 123 //decimal
0093 local b = 0x0012 //hexadecimal
0094 local c = 075 //octal
0095 local d = 'w' //char code
0096       </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e465"></a>Float</h3></div></div><div></div></div><p>
0097                 A float represents a 32 bits (or better) floating point number.
0098             </p><pre class="programlisting">
0099 local a=1.0
0100 local b=0.234
0101             </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e473"></a>String</h3></div></div><div></div></div><p>
0102                 Strings are an immutable sequence of characters to modify a string is necessary create a new one.
0103             </p><p> Pscript's strings, behave like C or C++, are delimited by quotation marks(") and can contain
0104             escape sequences(\t,\a,\b,\n,\r,\v,\f,\\,\",\',\0,\x<span class="emphasis"><em>hhhh</em></span>).
0105             </p><p>Verbatim string literals begin with @" and end with the matching quote.
0106             Verbatim string literals also can extend over a line break. If they do, they  
0107             include any white space characters between the quotes:
0108             </p><pre class="programlisting">
0109 local a = "I'm a wonderful string\n"
0110 // has a newline at the end of the string
0111 local x = @"I'm a verbatim string\n"
0112 // the \n is copied in the string same as \\n in a regular string "I'm a verbatim string\n"
0113 </pre><p>The only exception to the "no escape sequence" rule for verbatim 
0114 string literals is that you can put a double quotation mark inside a 
0115 verbatim string by doubling it:</p><pre class="programlisting">
0116 local multiline = @"
0117     this is a multiline string
0118     it will ""embed"" all the new line 
0119     characters
0120 "
0121             </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e492"></a>Null</h3></div></div><div></div></div><p>
0122                 The null value is a primitive value that represents the null, empty, or non-existent
0123                 reference. The type Null has exactly one value, called null. 
0124             </p><pre class="programlisting">
0125 local a=null
0126             </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e500"></a>Bool</h3></div></div><div></div></div><p>
0127                 the bool data type can have only two. They are the literals <tt class="literal">true</tt>
0128                 and <tt class="literal">false</tt>. A bool value expresses the validity of a condition 
0129                 (tells whether the condition is true or false).
0130             </p><pre class="programlisting">
0131 local a = true;
0132             </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e514"></a>Table</h3></div></div><div></div></div><p>
0133                 Tables are associative containers implemented as pairs of key/value (called a slot).
0134             </p><pre class="programlisting">
0135 local t={}
0136 local test=
0137 {
0138     a=10
0139     b=function(a) { return a+1; }
0140 }
0141             </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e522"></a>Array</h3></div></div><div></div></div><p>
0142                 Arrays are simple sequence of objects, their size is dynamic and their index starts always from 0.
0143             </p><pre class="programlisting">
0144 local a=["I'm","an","array"]
0145 local b=[null]
0146 b[0]=a[2];
0147             </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e530"></a>Function</h3></div></div><div></div></div><p>
0148                 Functions are similar to those in other C-like languages and to most programming
0149                 languages in general, however there are a few key differences (see below).
0150             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e536"></a>Class</h3></div></div><div></div></div><p>
0151                 Classes are associative containers implemented as pairs of key/value. Classes are created through
0152                 a 'class expression' or a 'class statement'. class members can be inherited from another class object
0153                 at creation time. After creation members can be added until a instance of the class is created.
0154             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e542"></a>Class instance</h3></div></div><div></div></div><p>
0155                 Class instances are created by calling a <tt class="literal">class object</tt>. Instances, as tables, are
0156                 implemented as pair of key/value. Instances members cannot be dyncamically added or removed however 
0157                 the value of the members can be changed.
0158             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e551"></a>Generator</h3></div></div><div></div></div><p>
0159                 Generators are functions that can be suspended with the statement 'yield' and resumed
0160                 later (see <a href="#generators">Generators</a>).
0161             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e560"></a>Userdata</h3></div></div><div></div></div><p>
0162                 Userdata objects are blobs of memory(or pointers) defined by the host application but
0163                 stored into Pscript variables (See <a href="#userdandup">Userdata and UserPointers</a>).
0164             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e569"></a>Thread</h3></div></div><div></div></div><p>
0165                 Threads are objects that represents a cooperative thread of execution, also known as coroutines.
0166             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e575"></a>Weak References</h3></div></div><div></div></div><p>
0167                 Weak References are objects that point to another(non scalar) object but do not own a strong reference to it.
0168                 (See <a href="#weakrefs">Weak References</a>).
0169             </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e584"></a>Execution Context</h2></div></div><div></div></div><a class="indexterm" name="d0e585"></a><p>
0170             The execution context is the union of the function stack frame and the function
0171             environment object(this).
0172             The stack frame is the portion of stack where the local variables declared in its body are
0173             stored.
0174             The environment object is an implicit parameter that is automatically passed by the
0175             function caller (see <a href="#functions">Functions</a>).
0176             During the execution, the body of a function can only transparently refer to his execution
0177             context. This mean that a single identifier can refer either to a local variable or to an
0178             environment object slot; Global variables require a special syntax (see <a href="#variables">Variables</a>).
0179             The environment object can be explicitly accessed by the keyword this.
0180         </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e599"></a>Variables</h3></div></div><div></div></div><a name="variables"></a><a class="indexterm" name="d0e601"></a><p>
0181                 There are two types of variables in Pscript, local variables and tables/arrays slots.
0182                 Because global variables are stored in a table, they are table slots.
0183             </p><p>
0184                 A single identifier refers to a local variable or a slot in the environment object.
0185             </p><p><tt class="literal">derefexp := id;</tt></p><pre class="programlisting">
0186 _table["foo"]
0187 _array[10]</pre><p>
0188                 with tables we can also use the '.' syntax
0189             </p><p><tt class="literal">derefexp := exp '.' id </tt></p><pre class="programlisting">
0190 _table.foo</pre><p>
0191             Pscript first checks if an identifier is a local variable (function arguments are local
0192             variables) if not it checks if it is a member of the environment object (this).
0193             </p><p>For instance:</p><pre class="programlisting">
0194 function testy(arg)
0195 {
0196     local a=10;
0197     print(a);
0198     return arg;
0199 }           
0200             </pre><p>will access to local variable 'a' and prints 10.</p><pre class="programlisting">
0201 function testy(arg)
0202 {
0203     local a=10;
0204     return arg+foo;
0205 }
0206             </pre><p>in this case 'foo' will be equivalent to 'this.foo' or this["foo"].</p><p>
0207             Global variables are stored in a table called the root table. Usually in the global scope the
0208             environment object is the root table, but to explicitly access the global table from
0209             another scope, the slot name must be prefixed with '::' (::foo).
0210             </p><p><tt class="literal">exp:= '::' id</tt></p><p>For instance:</p><pre class="programlisting">
0211 function testy(arg)
0212 {
0213     local a=10;
0214     return arg+::foo;
0215 }
0216             </pre><p>accesses the global variable 'foo'.</p><p>
0217             However (since pscript 2.0) if a variable is not local and is not found in the 'this' object Pscript will search it
0218             in the root table.
0219 </p><pre class="programlisting">
0220 function test() {
0221     foo = 10;
0222 }
0223 </pre><p>
0224             is equivalent to write
0225 </p><pre class="programlisting">
0226 function test() {
0227     if("foo" in this) {
0228         this.foo = 10;
0229     }else {
0230         ::foo = 10;
0231     }
0232 }
0233 </pre><p>
0234             </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e654"></a>Statements</h2></div></div><div></div></div><a class="indexterm" name="d0e657"></a><p>A pscript program is a simple sequence of statements.</p><pre class="programlisting"><span class="emphasis"><em>stats := stat [';'|'\n'] stats</em></span></pre><p>
0235             Statements in pscript are comparable to the C-Family languages (C/C++, Java, C#
0236             etc...): assignment, function calls, program flow control structures etc.. plus some
0237             custom statement like yield, table and array constructors (All those will be covered in detail
0238             later in this document).
0239             Statements can be separated with a new line or ';' (or with the keywords case or default if
0240             inside a switch/case statement), both symbols are not required if the statement is
0241             followed by '}'.
0242         </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e668"></a>Block</h3></div></div><div></div></div><a class="indexterm" name="d0e669"></a><pre class="programlisting"><span class="emphasis"><em>stat := '{' stats '}'</em></span></pre><p>
0243                 A sequence of statements delimited by curly brackets ({ }) is called block; 
0244                 a block is a statement itself.
0245             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e680"></a>Control Flow Statements</h3></div></div><div></div></div><p>
0246                 pscript implements the most common control flow statements: <tt class="literal">if, while, do-while,
0247                 switch-case, for, foreach</tt>.
0248             </p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e688"></a>true and false</h4></div></div><div></div></div><a class="indexterm" name="d0e689"></a><p>
0249                     Pscript has a boolean type(bool) however like C++ it considers null, 0(integer) and 0.0(float)
0250                     as <span class="emphasis"><em>false</em></span>, any other value is considered <span class="emphasis"><em>true</em></span>.
0251                 </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e703"></a>if/else</h4></div></div><div></div></div><a class="indexterm" name="d0e704"></a><pre class="programlisting"><span class="emphasis"><em>stat:= 'if' '(' exp ')' stat ['else' stat]</em></span></pre><p>
0252                     Conditionally execute a statement depending on the result of an expression.
0253                 </p><pre class="programlisting">
0254 if(a&gt;b)
0255     a=b;
0256 else
0257     b=a;
0258 ////
0259 if(a==10)
0260 {
0261     b=a+b;
0262     return a;
0263 }
0264                 </pre></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e718"></a>while</h4></div></div><div></div></div><a class="indexterm" name="d0e719"></a><pre class="programlisting"><span class="emphasis"><em>stat:= 'while' '(' exp ')' stat</em></span></pre><p>Executes a statement while the condition is true.</p><pre class="programlisting">
0265                 
0266 function testy(n)
0267 {
0268     local a=0;
0269     while(a&lt;n) a+=1;
0270     
0271     while(1)
0272     {
0273         if(a&lt;0) break;
0274         a-=1;
0275     }
0276 }                   
0277                 </pre></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e732"></a>do/while</h4></div></div><div></div></div><a class="indexterm" name="d0e733"></a><pre class="programlisting"><span class="emphasis"><em>stat:= 'do' stat 'while' '(' expression ')'</em></span></pre><p>
0278                     Executes a statement once, and then repeats execution of the statement until a condition
0279                     expression evaluates to false.
0280                 </p><pre class="programlisting">
0281                 
0282 local a=0;
0283 do
0284 {
0285     print(a+"\n");
0286     a+=1;
0287 } while(a&gt;100)           
0288                 </pre></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e746"></a>switch</h4></div></div><div></div></div><a class="indexterm" name="d0e747"></a><pre class="programlisting"><span class="emphasis"><em>
0289 stat := 'switch' ''( exp ')' '{'
0290     'case' case_exp ':'
0291         stats
0292     ['default' ':'
0293         stats]
0294 '}'
0295                 </em></span></pre><p>
0296                     Is a control statement allows multiple selections of code by passing control to one of the
0297                     case statements within its body.
0298                     The control is transferred to the case label whose case_exp matches with exp if none of
0299                     the case match will jump to the default label (if present).
0300                     A switch statement can contain any number if case instances, if 2 case have the same
0301                     expression result the first one will be taken in account first. The default label is only
0302                     allowed once and must be the last one.
0303                     A break statement will jump outside the switch block.
0304                 </p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e758"></a>Loops</h3></div></div><div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e762"></a>for</h4></div></div><div></div></div><a class="indexterm" name="d0e763"></a><pre class="programlisting"><span class="emphasis"><em>stat:= 'for' '(' [initexp] ';' [condexp] ';' [incexp] ')' statement</em></span></pre><p>Executes a statement as long as a condition is different than false.</p><pre class="programlisting">
0305                 
0306 for(local a=0;a&lt;10;a+=1)
0307     print(a+"\n");
0308 //or
0309 glob &lt;- null
0310 for(glob=0;glob&lt;10;glob+=1){
0311     print(glob+"\n");
0312 }
0313 //or
0314 for(;;){
0315     print(loops forever+"\n");
0316 }               
0317                 </pre></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e776"></a>foreach</h4></div></div><div></div></div><a class="indexterm" name="d0e777"></a><pre class="programlisting"><span class="emphasis"><em>'foreach' '(' [index_id','] value_id 'in' exp ')' stat</em></span></pre><p>
0318                     Executes a statement for every element contained in an array, table, class, string or generator.
0319                     If exp is a generator it will be resumed every iteration as long as it is alive; the value will
0320                     be the result of 'resume' and the index the sequence number of the iteration starting
0321                     from 0.
0322                 </p><pre class="programlisting">
0323                 
0324 local a=[10,23,33,41,589,56]
0325 foreach(idx,val in a)
0326     print("index="+idx+" value="+val+"\n");
0327 //or
0328 foreach(val in a)
0329     print("value="+val+"\n");
0330                 
0331                 </pre></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e790"></a>break</h3></div></div><div></div></div><a class="indexterm" name="d0e791"></a><pre class="programlisting"><span class="emphasis"><em>stat := 'break'</em></span></pre><p>
0332                 The break statement terminates the execution of a loop (for, foreach, while or do/while)
0333                 or jumps out of switch statement;
0334             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e802"></a>continue</h3></div></div><div></div></div><a class="indexterm" name="d0e803"></a><pre class="programlisting"><span class="emphasis"><em>stat := 'continue'</em></span></pre><p>
0335                 The continue operator jumps to the next iteration of the loop skipping the execution of
0336                 the following statements.
0337             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e814"></a>return</h3></div></div><div></div></div><a class="indexterm" name="d0e815"></a><pre class="programlisting"><span class="emphasis"><em>stat:= return [exp]</em></span></pre><p>
0338                 The return statement terminates the execution of the current function/generator and
0339                 optionally returns the result of an expression. If the expression is omitted the function
0340                 will return null. If the return statement is used inside a generator, the generator will not
0341                 be resumable anymore.
0342             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e826"></a>yield</h3></div></div><div></div></div><a class="indexterm" name="d0e827"></a><pre class="programlisting"><span class="emphasis"><em>stat := yield [exp]</em></span></pre><p>
0343                 (see <a href="#generators">Generators</a>).
0344             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e841"></a>Local variables declaration</h3></div></div><div></div></div><a class="indexterm" name="d0e842"></a><pre class="programlisting"><span class="emphasis"><em>
0345 initz := id [= exp][',' initz]
0346 stat := 'local' initz
0347             </em></span></pre><p>
0348                 Local variables can be declared at any point in the program; they exist between their
0349                 declaration to the end of the block where they have been declared.
0350                 EXCEPTION: a local declaration statement is allowed as first expression in a for loop.
0351             </p><pre class="programlisting">
0352 for(local a=0;a&lt;10;a+=1)
0353     print(a); 
0354             </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e855"></a>Function declaration</h3></div></div><div></div></div><a class="indexterm" name="d0e856"></a><pre class="programlisting"><span class="emphasis"><em>
0355 funcname := id ['::' id]
0356 stat:= 'function' id ['::' id]+ '(' args ')'[':' '(' args ')'] stat
0357             </em></span></pre><p>
0358                 creates a new function.
0359             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e867"></a>Class declaration</h3></div></div><div></div></div><a class="indexterm" name="d0e868"></a><pre class="programlisting"><span class="emphasis"><em>
0360 memberdecl := id '=' exp [';'] |    '[' exp ']' '=' exp [';'] | functionstat | 'constructor' functionexp
0361 stat:= 'class' derefexp ['extends' derefexp] '{'
0362             [memberdecl]
0363         '}'
0364             </em></span></pre><p>
0365                 creates a new class.
0366             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e879"></a>try/catch</h3></div></div><div></div></div><a class="indexterm" name="d0e880"></a><pre class="programlisting"><span class="emphasis"><em>stat:= 'try' stat 'catch' '(' id ')' stat</em></span></pre><p>
0367                 The try statement encloses a block of code in which an exceptional condition can occur,
0368                 such as a runtime error or a throw statement. The catch clause provides the exceptionhandling
0369                 code. When a catch clause catches an exception, its id is bound to that
0370                 exception.
0371             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e891"></a>throw</h3></div></div><div></div></div><a class="indexterm" name="d0e892"></a><pre class="programlisting"><span class="emphasis"><em>stat:= 'throw' exp</em></span></pre><p>
0372                 Throws an exception. Any value can be thrown.
0373             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e903"></a>const</h3></div></div><div></div></div><a class="indexterm" name="d0e904"></a><pre class="programlisting"><span class="emphasis"><em>stat:= 'const' id '=' 'Integer | Float | StringLiteral</em></span>
0374       </pre><p>
0375         Declares a constant (see <a href="#constants">Constants &amp; Enumerations</a>).
0376       </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e919"></a>enum</h3></div></div><div></div></div><a class="indexterm" name="d0e920"></a><pre class="programlisting">
0377         <span class="emphasis"><em>
0378           enumerations := ( &#8216;id&#8217; '=' Integer | Float | StringLiteral ) [&#8216;,&#8217;]
0379           stat:= 'enum' id '{' enumerations '}'
0380         </em></span>
0381       </pre><p>
0382         Declares an enumeration (see <a href="#constants">Constants &amp; Enumerations</a>).
0383       </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e936"></a>expression statement</h3></div></div><div></div></div><a class="indexterm" name="d0e937"></a><pre class="programlisting"><span class="emphasis"><em>stat := exp</em></span></pre><p>
0384                 In Pscript every expression is also allowed as statement, if so, the result of the
0385                 expression is thrown away.
0386             </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e948"></a>Expressions</h2></div></div><div></div></div><a class="indexterm" name="d0e949"></a><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e955"></a>Assignment(<tt class="literal">=</tt>) &amp; new slot(<tt class="literal">&lt;-</tt>)</h3></div></div><div></div></div><a class="indexterm" name="d0e956"></a><a class="indexterm" name="d0e959"></a><pre class="programlisting"><span class="emphasis"><em>
0387 exp := derefexp '=' exp
0388 exp:= derefexp '&lt;-' exp
0389             </em></span></pre><p>
0390                 pscript implements 2 kind of assignment: the normal assignment(=)
0391             </p><pre class="programlisting">a=10;</pre><p>and the "new slot" assignment.</p><pre class="programlisting">a &lt;- 10;</pre><p>    
0392                 The new slot expression allows to add a new slot into a table(see <a href="#tables">Tables</a>). If the slot
0393                 already exists in the table it behaves like a normal assignment.
0394             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e987"></a>Operators</h3></div></div><div></div></div><a class="indexterm" name="d0e988"></a><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e994"></a>?: Operator</h4></div></div><div></div></div><a class="indexterm" name="d0e995"></a><pre class="programlisting"><span class="emphasis"><em>exp := exp_cond '?' exp1 ':' exp2</em></span></pre><p>conditionally evaluate an expression depending on the result of an expression.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1006"></a>Arithmetic</h4></div></div><div></div></div><a class="indexterm" name="d0e1007"></a><pre class="programlisting"><span class="emphasis"><em>exp:= 'exp' op 'exp'</em></span></pre><p>
0395                     Pscript supports the standard arithmetic operators +, -, *, / and %.
0396                     Other than that is also supports compact operators (+=,-=,*=,/=,%=) and
0397                     increment and decrement operators(++ and --);
0398                 </p><pre class="programlisting">
0399 a+=2;
0400 //is the same as writing
0401 a=a+2;
0402 x++
0403 //is the same as writing
0404 x=x+1
0405                 </pre><p>
0406                     All operators work normally with integers and floats; if one operand is an integer and one
0407                     is a float the result of the expression will be float.
0408                     The + operator has a special behavior with strings; if one of the operands is a string the
0409                     operator + will try to convert the other operand to string as well and concatenate both
0410                     together. For instances and tables, _tostring is invoked.
0411                 </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1022"></a>Relational</h4></div></div><div></div></div><a class="indexterm" name="d0e1023"></a><pre class="programlisting"><span class="emphasis"><em>exp:= 'exp' op 'exp'</em></span></pre><p>Relational operators in Pscript are : == &lt; &lt;= &gt; &gt;= !=</p><p>
0412                     These operators return true if the expression is false and a value different than true if the
0413                     expression is true. Internally the VM uses the integer 1 as true but this could change in
0414                     the future.
0415                 </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1036"></a>3 ways compare</h4></div></div><div></div></div><a class="indexterm" name="d0e1037"></a><pre class="programlisting"><span class="emphasis"><em>exp:= 'exp' op 'exp'</em></span></pre><p>
0416           the 3 ways compare operator &lt;=&gt; compares 2 values A and B and returns an integer less than 0
0417           if A &lt; B, 0 if A == B and an integer greater than 0 if A &gt; B.
0418         </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1048"></a>Logical</h4></div></div><div></div></div><a class="indexterm" name="d0e1049"></a><pre class="programlisting"><span class="emphasis"><em>
0419 exp := exp op exp
0420 exp := '!' exp
0421                 </em></span></pre><p>Logical operators in Pscript are : &amp;&amp; || !</p><p>
0422                     The operator &amp;&amp; (logical and) returns null if its first argument is null, otherwise returns
0423                     its second argument.        
0424                     The operator || (logical or) returns its first argument if is different than null, otherwise
0425                     returns the second argument.
0426                 </p><p>
0427                     The '!' operator will return null if the given value to negate was different than null, or a
0428                     value different than null if the given value was null.
0429                 </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1064"></a>in operator</h4></div></div><div></div></div><a class="indexterm" name="d0e1065"></a><pre class="programlisting"><span class="emphasis"><em>exp:= keyexp 'in' tableexp</em></span></pre><p>
0430                     Tests the existence of a slot in a table.
0431                     Returns true if keyexp is a valid key in tableexp
0432                 </p><pre class="programlisting">
0433 
0434 local t=
0435 {
0436     foo="I'm foo",
0437     [123]="I'm not foo"
0438 }
0439 
0440 if("foo" in t) dostuff("yep");
0441 if(123 in t) dostuff();
0442                 </pre></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1078"></a>instanceof operator</h4></div></div><div></div></div><a class="indexterm" name="d0e1079"></a><pre class="programlisting"><span class="emphasis"><em>exp:= instanceexp 'instanceof' classexp</em></span></pre><p>
0443                     Tests if a class instance is an instance of a certain class.
0444                     Returns true if instanceexp is an instance of classexp.
0445                 </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1090"></a>typeof operator</h4></div></div><div></div></div><a class="indexterm" name="d0e1091"></a><pre class="programlisting"><span class="emphasis"><em>exp:= 'typeof' exp</em></span></pre><p>returns the type name of a value as string.</p><pre class="programlisting">
0446 local a={},b="pscript"
0447 print(typeof a); //will print "table"
0448 print(typeof b); //will print "string"      
0449                 </pre></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1104"></a>comma operator</h4></div></div><div></div></div><a class="indexterm" name="d0e1105"></a><pre class="programlisting"><span class="emphasis"><em>exp:= exp ',' exp</em></span></pre><p>
0450                     The comma operator evaluates two expression left to right, the result of the operator is
0451                     the result of the expression on the right; the result of the left expression is discarded.
0452                 </p><pre class="programlisting">
0453 local j=0,k=0;
0454 for(local i=0; i&lt;10; i++ , j++)
0455 {
0456     k = i + j;
0457 }
0458 local a,k;
0459 a = (k=1,k+2); //a becomes 3        
0460                 </pre></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1118"></a>Bitwise Operators</h4></div></div><div></div></div><a class="indexterm" name="d0e1119"></a><pre class="programlisting"><span class="emphasis"><em>
0461 exp:= 'exp' op 'exp'
0462 exp := '~' exp
0463                 </em></span></pre><p>
0464                     Pscript supports the standard c-like bit wise operators &amp;,|,^,~,&lt;&lt;,&gt;&gt; plus the unsigned 
0465                     right shift operator &gt;&gt;&gt;. The unsigned right shift works exactly like the normal right shift operator(&gt;&gt;)
0466                     except for treating the left operand as an unsigned integer, so is not affected by the sign. Those operators
0467                     only work on integers values, passing of any other operand type to these operators will
0468                     cause an exception.
0469                 </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1130"></a>Operators precedence</h4></div></div><div></div></div><a class="indexterm" name="d0e1131"></a><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><tbody><tr><td><tt class="literal">-,~,!,typeof ,++,--</tt></td><td>highest</td></tr><tr><td><tt class="literal">/, *, %</tt></td><td>...</td></tr><tr><td><tt class="literal">+, -</tt></td><td>&nbsp;</td></tr><tr><td><tt class="literal">&lt;&lt;, &gt;&gt;,&gt;&gt;&gt;</tt></td><td>&nbsp;</td></tr><tr><td><tt class="literal">&lt;, &lt;=, &gt;, &gt;=</tt></td><td>&nbsp;</td></tr><tr><td><tt class="literal">==, !=, &lt;=&gt;</tt></td><td>&nbsp;</td></tr><tr><td><tt class="literal">&amp;</tt></td><td>&nbsp;</td></tr><tr><td><tt class="literal">^</tt></td><td>&nbsp;</td></tr><tr><td><tt class="literal">|</tt></td><td>&nbsp;</td></tr><tr><td><tt class="literal">&amp;&amp;, in</tt></td><td>&nbsp;</td></tr><tr><td><tt class="literal">||</tt></td><td>&nbsp;</td></tr><tr><td><tt class="literal">?:</tt></td><td>&nbsp;</td></tr><tr><td><tt class="literal">+=,=,-=</tt></td><td>...</td></tr><tr><td><tt class="literal">,(comma operator)</tt></td><td>lowest</td></tr></tbody></table></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1216"></a>Table constructor</h3></div></div><div></div></div><a class="indexterm" name="d0e1217"></a><a name="tableconstructor"></a><pre class="programlisting"><span class="emphasis"><em>
0470 tslots := ( &#8216;id&#8217; &#8216;=&#8217; exp | &#8216;[&#8216; exp &#8216;]&#8217; &#8216;=&#8217; exp ) [&#8216;,&#8217;]
0471 exp := &#8216;{&#8217; [tslots] &#8216;}&#8217;
0472             </em></span></pre><p>Creates a new table.</p><pre class="programlisting">
0473 local a={} //create an empty table              
0474             </pre><p>A table constructor can also contain slots declaration; With the syntax:</p><pre class="programlisting"><span class="emphasis"><em>id = exp [',']</em></span></pre><p>a new slot with id as key and exp as value is created</p><pre class="programlisting">
0475 local a=
0476 {
0477     slot1="I'm the slot value"
0478 }
0479             </pre><p>An alternative syntax can be</p><pre class="programlisting"><span class="emphasis"><em>'[' exp1 ']' = exp2 [',']</em></span></pre><p>A new slot with exp1 as key and exp2 as value is created</p><pre class="programlisting">
0480 local a=
0481 {
0482     [1]="I'm the value"
0483 }
0484             </pre><p>both syntaxes can be mixed</p><pre class="programlisting">
0485 local table=
0486 {
0487     a=10,
0488     b="string",
0489     [10]={},
0490     function bau(a,b)
0491     {
0492         return a+b;
0493     }
0494 }
0495             </pre><p>The comma between slots is optional.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1254"></a>Table with JSON syntax</h4></div></div><div></div></div><a class="indexterm" name="d0e1255"></a><a name="jsonsyntax"></a><p>Since Pscript 3.0 is possible to declare a table using JSON syntax(see http://www.wikipedia.org/wiki/JSON).</p><p>the following JSON snippet:</p><pre class="programlisting">
0496 local x = {
0497   "id": 1,
0498   "name": "Foo",
0499   "price": 123,
0500   "tags": ["Bar","Eek"]
0501 }
0502         </pre><p>is equivalent to the following pscript code:</p><pre class="programlisting">
0503 local x = {
0504   id = 1,
0505   name = "Foo",
0506   price = 123,
0507   tags = ["Bar","Eek"]
0508 }
0509        </pre></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1274"></a>clone</h3></div></div><div></div></div><a class="indexterm" name="d0e1275"></a><pre class="programlisting"><span class="emphasis"><em>exp:= &#8216;clone&#8217; exp</em></span></pre><p>
0510                 Clone performs shallow copy of a table, array or class instance (copies all slots in the new object without
0511                 recursion). If the source table has a delegate, the same delegate will be assigned as
0512                 delegate (not copied) to the new table (see <a href="#delegation">Delegation</a>).
0513             </p><p>After the new object is ready the &#8220;_cloned&#8221; meta method is called (see <a href="#metamethods">Metamethods</a>).</p><p>When a class instance is cloned the constructor is not invoked(initializations must rely on <tt class="literal">_cloned</tt> instead</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1299"></a>Array constructor</h3></div></div><div></div></div><a class="indexterm" name="d0e1300"></a><pre class="programlisting"><span class="emphasis"><em>exp := &#8216;[&#8217; [explist] &#8216;]&#8217;</em></span></pre><p>Creates a new array.</p><pre class="programlisting">
0514 a &lt;- [] //creates an empty array
0515             </pre><p>arrays can be initialized with values during the construction</p><pre class="programlisting">
0516 a &lt;- [1,"string!",[],{}] //creates an array with 4 elements
0517             </pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1317"></a>Tables</h2></div></div><div></div></div><a class="indexterm" name="d0e1318"></a><a name="tables"></a><p>
0518             Tables are associative containers implemented as pairs of key/value (called slot); values
0519             can be any possible type and keys any type except 'null'.
0520             Tables are pscript's skeleton, delegation and many other features are all implemented
0521             through this type; even the environment, where global variables are stored, is a table
0522             (known as root table).
0523         </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1327"></a>Construction</h3></div></div><div></div></div><p>Tables are created through the table constructor (see <a href="#tableconstructor">Table constructor</a>)</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1336"></a>Slot creation</h3></div></div><div></div></div><a class="indexterm" name="d0e1337"></a><p>
0524                 Adding a new slot in a existing table is done through the "new slot" operator '&lt;-'; this
0525                 operator behaves like a normal assignment except that if the slot does not exists it will
0526                 be created.
0527             </p><pre class="programlisting">
0528 local a={}
0529             </pre><p>
0530                 The following line will cause an exception because the slot named 'newslot' does not exist
0531                 in the table &#8216;a&#8217;
0532             </p><pre class="programlisting">
0533 a.newslot = 1234
0534             </pre><p>this will succeed:</p><pre class="programlisting">
0535 a.newslot &lt;- 1234;
0536             </pre><p>or</p><pre class="programlisting">
0537 a[1] &lt;- "I'm the value of the new slot";
0538             </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1361"></a>Slot deletion</h3></div></div><div></div></div><a class="indexterm" name="d0e1362"></a><pre class="programlisting"><span class="emphasis"><em>exp:= delete derefexp</em></span></pre><p>
0539                 Deletion of a slot is done through the keyword delete; the result of this expression will be
0540                 the value of the deleted slot.
0541             </p><pre class="programlisting">
0542 a &lt;- {
0543     test1=1234
0544     deleteme="now"
0545 }
0546 
0547 delete a.test1
0548 print(delete a.deleteme); //this will print the string "now"
0549             </pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1377"></a>Arrays</h2></div></div><div></div></div><a class="indexterm" name="d0e1378"></a><p>
0550             An array is a sequence of values indexed by a integer number from 0 to the size of the
0551             array minus 1. Arrays elements can be obtained through their index.
0552         </p><pre class="programlisting">
0553 local a=[&#8220;I&#8217;m a string&#8221;, 123]
0554 print(typeof a[0]) //prints "string"
0555 print(typeof a[1]) //prints "integer"           
0556         </pre><p>
0557             Resizing, insertion, deletion of arrays and arrays elements is done through a set of
0558             standard functions (see <a href="#builtin">built-in functions</a>).
0559         </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1393"></a>Functions</h2></div></div><div></div></div><a class="indexterm" name="d0e1394"></a><a name="functions"></a><p>
0560             Functions are first class values like integer or strings and can be stored in table slots,
0561             local variables, arrays and passed as function parameters.
0562             Functions can be implemented in Pscript or in a native language with calling conventions
0563             compatible with ANSI C.
0564         </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1403"></a>Function declaration</h3></div></div><div></div></div><a class="indexterm" name="d0e1404"></a><p>Functions are declared through the function expression</p><pre class="programlisting">
0565 local a= function(a,b,c) {return a+b-c;}        
0566             </pre><p>or with the syntactic sugar</p><pre class="programlisting">
0567 function ciao(a,b,c)
0568 {
0569     return a+b-c;
0570 }       
0571             </pre><p>that is equivalent to</p><pre class="programlisting">
0572 this.ciao &lt;- function(a,b,c)
0573 {
0574     return a+b-c;
0575 }
0576             </pre><p>a local function can be declared with this syntactic sugar</p><pre class="programlisting">
0577         
0578 local function tuna(a,b,c)
0579 {
0580     return a+b-c;
0581 }
0582             
0583       </pre><p>that is equivalent to</p><pre class="programlisting">
0584         
0585 local tuna = function(a,b,c)
0586 {
0587     return a+b-c;
0588 }
0589             
0590       </pre><p>is also possible to declare something like</p><pre class="programlisting">
0591 T &lt;- {}
0592 function T::ciao(a,b,c)
0593 {
0594     return a+b-c;
0595 }
0596 
0597 //that is equivalent to write
0598 
0599 T.ciao &lt;- function(a,b,c)
0600 {
0601     return a+b-c;
0602 }
0603 
0604 //or
0605 
0606 T &lt;- {
0607     function ciao(a,b,c)
0608     {
0609         return a+b-c;
0610     }
0611 }
0612             </pre><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1435"></a>Default Paramaters</h4></div></div><div></div></div>
0613         Pscript's functions can have default parameters.
0614         <p>A function with default parameters is declared as follows:</p><pre class="programlisting">
0615         
0616 function test(a,b,c = 10, d = 20)
0617 {
0618     ....
0619 }
0620         
0621         </pre><p>
0622           when the function <tt class="literal">test</tt> is invoked and the parameter c or d are not specified, 
0623           the VM autometically assigns the default value to the unspecified parameter. A default parameter can be
0624           any valid pscript expression. The expression is evaluated at runtime.
0625         </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1448"></a>Function with variable number of paramaters</h4></div></div><div></div></div>
0626         Pscript's functions can have variable number of parameters(varargs functions).
0627         <p>
0628                   A vararg function is declared by adding three dots (`...&acute;) at the end of its parameter list.
0629               </p><p>
0630                   When the function is called all the extra parameters will be accessible through the <span class="emphasis"><em>array</em></span>
0631                   called <tt class="literal">vargv</tt>, that is passed as implicit parameter.
0632               </p><p>
0633                   <tt class="literal">vargv</tt> is a regular pscript array and can be used accordingly. 
0634               </p><pre class="programlisting">
0635       
0636 function test(a,b,...)
0637 {
0638     for(local i = 0; i&lt; vargv.len(); i++)
0639     {
0640         ::print("varparam "+i+" = "+vargv[i]+"\n");
0641     }
0642   foreach(i,val in vargv)
0643     {
0644         ::print("varparam "+i+" = "+val+"\n");
0645     }
0646 }
0647 
0648 test("goes in a","goes in b",0,1,2,3,4,5,6,7,8);
0649               </pre></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1470"></a>Function calls</h3></div></div><div></div></div><a class="indexterm" name="d0e1471"></a><pre class="programlisting"><span class="emphasis"><em>exp:= derefexp &#8216;(&#8216; explist &#8216;)&#8217;</em></span></pre><p>
0650                 The expression is evaluated in this order: derefexp after the explist (arguments) and at
0651                 the end the call.
0652             </p><p>
0653                 Every function call in Pscript passes the environment object &#8216;this&#8217; as hidden parameter
0654                 to the called function. The &#8216;this&#8217; parameter is the object where the function was indexed
0655                 from.
0656             </p><p>
0657                 If we call a function with this syntax
0658             </p><pre class="programlisting">
0659 table.foo(a)
0660             </pre><p>the environment object passed to foo will be &#8216;table&#8217;</p><pre class="programlisting">
0661 foo(x,y) // equivalent to this.foo(x,y)
0662             </pre><p>The environment object will be &#8216;this&#8217; (the same of the caller function).</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1496"></a>Binding an environment to a function</h3></div></div><div></div></div><a class="indexterm" name="d0e1497"></a><p>
0663         while by default a pscript function call passes as environment object 'this', the object
0664         where the function was indexed from. However, is also possible to statically bind an evironment to a
0665         closure using the built-in method <tt class="literal">closure.bindenv(env_obj)</tt>.
0666         The method bindenv() returns a new instance of a closure with the environment bound to it.
0667         When an environment object is bound to a function, every time the function is invoked, its
0668         'this' parameter will always be the previously bound environent.
0669         This mechanism is useful to implement callbacks systems similar to C# delegates.
0670         </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
0671           The closure keeps a weak reference to the bound environmet object, because of this if
0672           the object is deleted, the next call to the closure will result in a <tt class="literal">null</tt>
0673           environment object.
0674         </div><p>
0675       </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1514"></a>Lambda expressions</h3></div></div><div></div></div><a class="indexterm" name="d0e1515"></a><p>
0676         <span class="emphasis"><em>exp := '@' '(' paramlist ')' exp</em></span>
0677         </p><p>
0678           Lambda expressions are a synctactic sugar to quickly define a function that consists of a single expression.
0679           This feature comes handy when functional programming patterns are applied, like map/reduce or passing a compare method to
0680           array.sort().
0681         </p><p>
0682         </p><p>here a lambda expression</p><p>
0683 </p><pre class="programlisting">
0684         local myexp = @(a,b) a + b
0685 </pre><p>
0686         </p><p>that is equivalent to</p><p>
0687 </p><pre class="programlisting">
0688         local myexp = function(a,b) { return a + b; }
0689 </pre><p>
0690         </p><p>a more useful usage could be</p><p>
0691 </p><pre class="programlisting">
0692         local arr = [2,3,5,8,3,5,1,2,6];
0693         arr.sort(@(a,b) a &lt;=&gt; b);
0694         arr.sort(@(a,b) -(a &lt;=&gt; b));
0695 </pre><p>
0696         </p><p>that could have been written as</p><p>
0697 </p><pre class="programlisting">
0698         local arr = [2,3,5,8,3,5,1,2,6];
0699         arr.sort(function(a,b) { return a &lt;=&gt; b; } );
0700         arr.sort(function(a,b) { return -(a &lt;=&gt; b); } );
0701 </pre><p>
0702         </p><p>other than being limited to a single expression lambdas support all features of regular functions.
0703         in fact are implemented as a compile time feature.</p><p>
0704       </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1556"></a>Free variables</h3></div></div><div></div></div><a class="indexterm" name="d0e1557"></a><p>
0705         A free variable is a variable external from the function scope as is not a local variable
0706         or parameter of the function.
0707         Free variables reference a local variable from a outer scope.
0708         In the following example the variables 'testy', 'x' and 'y' are bound to the function 'foo'.
0709       </p><pre class="programlisting">
0710 local x=10,y=20
0711 local testy=&#8220;I&#8217;m testy&#8221;
0712 
0713 function foo(a,b)
0714 {
0715     ::print(testy);
0716     return a+b+x+y;
0717 }
0718             </pre><p>
0719         A program can read or write a free variable.
0720             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1569"></a>Tail recursion</h3></div></div><div></div></div><a class="indexterm" name="d0e1570"></a><p>
0721                 Tail recursion is a method for partially transforming a recursion in a program into an
0722                 iteration: it applies when the recursive calls in a function are the last executed
0723                 statements in that function (just before the return).
0724                 If this happenes the pscript interpreter collapses the caller stack frame before the
0725                 recursive call; because of that very deep recursions are possible without risk of a stack
0726                 overflow.
0727             </p><pre class="programlisting">
0728 function loopy(n)
0729 {
0730     if(n&gt;0){
0731         ::print(&#8220;n=&#8221;+n+&#8221;\n&#8221;);
0732         return loopy(n-1);
0733     }
0734 }
0735 
0736 loopy(1000);
0737             </pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1580"></a>Classes</h2></div></div><div></div></div><a class="indexterm" name="d0e1581"></a><a name="classes"></a><p>
0738         Pscript implements a class mechanism similar to languages like Java/C++/etc... 
0739         however because of its dynamic nature it differs in several aspects.
0740         Classes are first class objects like integer or strings and can be stored in 
0741         table slots local variables, arrays and passed as function parameters.
0742         </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1590"></a>Class declaration</h3></div></div><div></div></div><a class="indexterm" name="d0e1591"></a><p>
0743             A class object is created through the keyword 'class' . The class object follows
0744             the same declaration syntax of a table(see tables) with the only difference
0745             of using ';' as optional separator rather than ','.
0746             </p><p>
0747         For instance:
0748 </p><pre class="programlisting">
0749 class Foo {
0750     //constructor
0751     constructor(a)
0752     {
0753         testy = ["stuff",1,2,3,a];
0754     }
0755     //member function
0756     function PrintTesty()
0757     {
0758         foreach(i,val in testy)
0759         {
0760             ::print("idx = "+i+" = "+val+" \n");
0761         }
0762     }
0763     //property
0764     testy = null;
0765     
0766 }
0767 </pre><p>
0768 the previous code examples is a syntactic sugar for:
0769 </p><pre class="programlisting">
0770 Foo &lt;- class {
0771     //constructor
0772     constructor(a)
0773     {
0774         testy = ["stuff",1,2,3,a];
0775     }
0776     //member function
0777     function PrintTesty()
0778     {
0779         foreach(i,val in testy)
0780         {
0781             ::print("idx = "+i+" = "+val+" \n");
0782         }
0783     }
0784     //property
0785     testy = null;
0786     
0787 }
0788 </pre><p>
0789 
0790 in order to emulate namespaces, is also possible to declare something like this
0791 </p><pre class="programlisting">
0792 //just 2 regular nested tables
0793 FakeNamespace &lt;- {
0794     Utils = {}
0795 }
0796 
0797 class FakeNamespace.Utils.SuperClass {
0798     constructor()
0799     {
0800         ::print("FakeNamespace.Utils.SuperClass")
0801     }
0802     function DoSomething()
0803     {
0804         ::print("DoSomething()")
0805     }
0806 }
0807 
0808 function FakeNamespace::Utils::SuperClass::DoSomethingElse()
0809 {
0810     ::print("FakeNamespace::Utils::SuperClass::DoSomethingElse()")
0811 }
0812 
0813 local testy = FakeNamespace.Utils.SuperClass();
0814 testy.DoSomething();
0815 testy.DoSomethingElse();
0816 </pre><p>
0817         After its declaration, methods or properties can be added or modified by following
0818         the same rules that apply to a table(operator <tt class="literal">&lt;-</tt> and <tt class="literal">=</tt>).
0819 </p><pre class="programlisting">
0820 //adds a new property
0821 Foo.stuff &lt;- 10;
0822 
0823 //modifies the default value of an existing property
0824 Foo.testy = "I'm a string";
0825 
0826 //adds a new method
0827 function Foo::DoSomething(a,b)
0828 {
0829     return a+b;
0830 }
0831 </pre><p>
0832         After a class is instantiated is no longer possible to add new properties however is possible to add or replace methods.
0833         </p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1618"></a>Static variables</h4></div></div><div></div></div><a class="indexterm" name="d0e1619"></a>
0834                 Pscript's classes support static member variables. A static variable shares its value
0835                 between all instances of the class. Statics are declared by prefixing the variable declaration
0836                 with the keyword <tt class="literal">static</tt>; the declaration must be in the class body.
0837                 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>Statics are read-only.</div><pre class="programlisting">
0838 class Foo {
0839     constructor()
0840     {
0841         //..stuff
0842     }
0843     name = "normal variable";
0844     //static variable
0845     static classname = "The class name is foo";
0846 };
0847 </pre></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1632"></a>Class attributes</h4></div></div><div></div></div><a class="indexterm" name="d0e1633"></a>
0848                 Classes allow to associate attributes to it's members. Attributes are a form of metadata
0849                 that can be used to store application specific informations, like documentations
0850                 strings, properties for IDEs, code generators etc...
0851                 Class attributes are declared in the class body by preceding the member declaration and
0852                 are delimited by the symbol <tt class="literal">&lt;/</tt> and <tt class="literal">/&gt;</tt>.
0853                 Here an example:
0854 <pre class="programlisting">
0855 class Foo &lt;/ test = "I'm a class level attribute" /&gt;{
0856     &lt;/ test = "freakin attribute" /&gt; //attributes of PrintTesty
0857     function PrintTesty()
0858     {
0859         foreach(i,val in testy)
0860         {
0861             ::print("idx = "+i+" = "+val+" \n");
0862         }
0863     }
0864     &lt;/ flippy = 10 , second = [1,2,3] /&gt; //attributes of testy
0865     testy = null;
0866     
0867 }
0868 </pre>
0869             Attributes are, matter of fact, a table. Pscript uses <tt class="literal">&lt;/ /&gt;</tt> syntax
0870             instead of curly brackets <tt class="literal">{}</tt> for the attribute declaration to increase readability.
0871             <p>
0872             This means that all rules that apply to tables apply to attributes.
0873             </p><p>
0874             Attributes can be retrieved through the built-in function <tt class="literal">classobj.getattributes(membername)</tt> (see <a href="#builtin">built-in functions</a>).
0875             and can be modified/added through the built-in function <tt class="literal">classobj.setattributes(membername,val)</tt>.
0876             </p><p>
0877             the following code iterates through the attributes of all Foo members.
0878 </p><pre class="programlisting">
0879 foreach(member,val in Foo)
0880 {
0881     ::print(member+"\n");
0882     local attr;
0883     if((attr = Foo.getattributes(member)) != null) {
0884         foreach(i,v in attr)
0885         {
0886             ::print("\t"+i+" = "+(typeof v)+"\n");
0887         }
0888     }
0889     else {
0890         ::print("\t&lt;no attributes&gt;\n")
0891     }
0892 }
0893 </pre><p>
0894             </p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1672"></a>Class instances</h3></div></div><div></div></div><a class="indexterm" name="d0e1673"></a><p>
0895             The class objects inherits several of the table's feature with the difference that multiple instances of the
0896             same class can be created.
0897             A class instance is an object that share the same structure of the table that created it but
0898             holds is own values.
0899             Class <span class="emphasis"><em>instantiation</em></span> uses function notation.
0900             A class instance is created by calling a class object. Can be useful to imagine a class like a function
0901             that returns a class instance.
0902             
0903 </p><pre class="programlisting">
0904 //creates a new instance of Foo
0905 local inst = Foo(); 
0906 </pre><p>
0907             When a class instance is created its member are initialized <span class="emphasis"><em>with the same value</em></span> specified in the
0908             class declaration. The values are copied verbatim, <span class="emphasis"><em>no cloning is performed</em></span> even if the value is a container or a class instances.
0909       </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
0910         FOR C# and Java programmers:
0911         <p>
0912           Pscript doesn't clone member's default values nor executes the member declaration for each instace(as C# or java).
0913           So consider this example:
0914           </p><pre class="programlisting">
0915 class Foo {
0916   myarray = [1,2,3]
0917   mytable = {}
0918 }
0919 
0920 local a = Foo();
0921 local b = Foo();
0922 </pre><p>
0923           In the snippet above both instances will refer to the same array and same table.To archieve what a C# or Java programmer would
0924           exepect, the following approach should be taken.
0925 </p><pre class="programlisting">
0926 class Foo {
0927   myarray = null
0928   mytable = null
0929   constructor()
0930   {
0931     myarray = [1,2,3]
0932     mytable = {}
0933   }
0934 }
0935 
0936 local a = Foo();
0937 local b = Foo();
0938 <p></p>
0939 </pre><p>
0940          
0941         </p></div><p>
0942             </p><p>
0943             When a class defines a method called 'constructor', the class instantiation operation will
0944             automatically invoke it for the newly created instance.
0945             The constructor method can have parameters, this will impact on the number of parameters
0946             that the <span class="emphasis"><em>instantiation operation</em></span> will require.
0947             Constructors, as normal functions, can have variable number of parameters (using the parameter <tt class="literal">...</tt>).
0948             </p><p>
0949 </p><pre class="programlisting">
0950 class Rect {
0951     constructor(w,h)
0952     {
0953         width = w;
0954         height = h;     
0955     }
0956     x = 0;
0957     y = 0;
0958     width = null;
0959     height = null;
0960 }
0961 
0962 //Rect's constructor has 2 parameters so the class has to be 'called'
0963 //with 2 parameters
0964 local rc = Rect(100,100);
0965  
0966 </pre><p>
0967                         
0968             After an instance is created, its properties can be set or fetched following the
0969             same rules that apply to tables. Methods cannot be set.
0970             </p><p>
0971                 Instance members cannot be removed.
0972             </p><p>
0973             </p><p>
0974                 The class object that created a certain instance can be retrieved through the built-in function
0975                 <tt class="literal">instance.getclass()</tt>(see <a href="#builtin">built-in functions</a>)
0976             </p><p>
0977             The operator <tt class="literal">instanceof</tt> tests if a class instance is an instance of a certain class.
0978 </p><pre class="programlisting">
0979 local rc = Rect(100,100);
0980 if(rc instanceof ::Rect) {
0981     ::print("It's a rect");
0982 }
0983 else {
0984     ::print("It isn't a rect");
0985 }
0986             </pre><p>
0987         </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>Since Pscript 3.x instanceof doesn't throw an exception if the left expression is not a class, it simply fails</div><p>
0988       </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1738"></a>Inheritance</h3></div></div><div></div></div><a class="indexterm" name="d0e1739"></a><p>
0989             Pscript's classes support single inheritance by adding the keyword <tt class="literal">extends</tt>, followed
0990             by an expression, in the class declaration.
0991             The syntax for a derived class is the following:
0992             </p><pre class="programlisting">
0993 class SuperFoo extends Foo {
0994     function DoSomething() {
0995         ::print("I'm doing something");
0996     }
0997 }
0998             </pre><p>
0999             When a derived class is declared, Pscript first copies all base's members in the
1000             new class then proceeds with evaluating the rest of the declaration.
1001             </p><p>
1002             </p><p>
1003             A derived class inherit all members and properties of it's base, if the derived class
1004             overrides a base function the base implementation is shadowed.
1005             It's possible to access a overridden method of the base class by fetching the method from
1006             through the 'base' keyword.
1007             </p><p>
1008             Here an example:
1009 </p><pre class="programlisting">
1010 class Foo {
1011     function DoSomething() {
1012         ::print("I'm the base");
1013     }
1014 };
1015 
1016 class SuperFoo extends Foo {
1017     //overridden method
1018     function DoSomething() {
1019         //calls the base method
1020         base.DoSomething();
1021         ::print("I'm doing something");
1022     }
1023 }
1024             </pre><p>
1025 Same rule apply to the constructor. The constructor is a regular function (apart from being automatically invoked on contruction).
1026 </p><pre class="programlisting">
1027   
1028 class BaseClass {
1029     constructor()
1030     {
1031         ::print("Base constructor\n");
1032     }
1033 }
1034 
1035 class ChildClass extends BaseClass {
1036     constructor()
1037     {
1038         base.constructor();
1039         ::print("Child constructor\n");
1040     }
1041 }
1042 
1043 local test = ChildClass();
1044 </pre><p>
1045             </p><p>
1046             The base class of a derived class can be retrieved through the built-in method <tt class="literal">getbase()</tt>.
1047             
1048             </p><pre class="programlisting">
1049 local thebaseclass = SuperFoo.getbase();
1050             </pre><p>
1051             </p>
1052             Note that because methods do not have special protection policies when calling methods of the same
1053             objects, a method of a base class that calls a method of the same class can end up calling a overridden method of the derived class.
1054       <p>
1055         A method of a base class can be explicitly invoked by a method of a derived class though the keyword <tt class="literal">base</tt>(as in base.MyMethod() ).
1056       </p></div><pre class="programlisting">
1057 class Foo {
1058     function DoSomething() {
1059         ::print("I'm the base");
1060     }
1061     function DoIt()
1062     {
1063         DoSomething();
1064     }
1065 };
1066 
1067 class SuperFoo extends Foo {
1068     //overridden method
1069     function DoSomething() {
1070         ::print("I'm the derived");
1071         
1072     }
1073     function DoIt() {
1074         base.DoIt();
1075     }
1076 }
1077 
1078 //creates a new instance of SuperFoo
1079 local inst = SuperFoo(); 
1080 
1081 //prints "I'm the derived"
1082 inst.DoIt();
1083 
1084 
1085             </pre><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1779"></a>Metamethods</h3></div></div><div></div></div><a class="indexterm" name="d0e1780"></a><p>
1086                 Class instances allow the customization of certain aspects of the
1087                 their semantics through metamethods(see <a href="#metamethods">Metamethods</a>).
1088                 For C++ programmers: "metamethods behave roughly like overloaded operators".
1089                 The metamethods supported by classes are <tt class="literal">_add, _sub, _mul, _div, _unm, _modulo,
1090                 _set, _get, _typeof, _nexti, _cmp, _call, _delslot,_tostring</tt>
1091                 </p><p>
1092         </p><p>
1093         Class objects instead support only 2 metamethods : <tt class="literal">_newmember and _inherited</tt>    
1094         </p><p>
1095 the following example show how to create a class that implements the metamethod <tt class="literal">_add</tt>.
1096 </p><pre class="programlisting">
1097 class Vector3 {
1098     constructor(...)
1099     {
1100         if(vargv.len() &gt;= 3) {
1101             x = vargv[0];
1102             y = vargv[1];
1103             z = vargv[2];
1104         }
1105     }
1106     function _add(other)
1107     {
1108         return ::Vector3(x+other.x,y+other.y,z+other.z);
1109     }
1110     
1111     x = 0;
1112     y = 0;
1113     z = 0;
1114 }
1115 
1116 local v0 = Vector3(1,2,3)
1117 local v1 = Vector3(11,12,13)
1118 local v2 = v0 + v1;
1119 ::print(v2.x+","+v2.y+","+v2.z+"\n");
1120 </pre><p>
1121             </p><p>
1122         </p><p>
1123           Since version 2.1, classes support 2 metamethods <tt class="literal">_inherited</tt> and <tt class="literal">_newmember</tt>. 
1124           <tt class="literal">_inherited</tt> is invoked when a class inherits from the one that implements <tt class="literal">_inherited</tt>.
1125           <tt class="literal">_newmember</tt> is invoked for each member that is added to the class(at declaration time).
1126         </p><p>
1127             </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1827"></a>Generators</h2></div></div><div></div></div><a class="indexterm" name="d0e1828"></a><a name="generators"></a><p>
1128             A function that contains a yield statement is called &#8216;generator function&#8217;.
1129             When a generator function is called, it does not execute the function body, instead it
1130             returns a new suspended generator.
1131             The returned generator can be resumed through the resume statement while it is alive.
1132             The yield keyword, suspends the execution of a generator and optionally returns the
1133             result of an expression to the function that resumed the generator.
1134             The generator dies when it returns, this can happen through an explicit return
1135             statement or by exiting the function body; If an unhandled exception (or runtime error)
1136             occurs while a generator is running, the generator will automatically die. A dead
1137             generator cannot be resumed anymore.
1138         </p><pre class="programlisting">
1139 function geny(n)
1140 {
1141     for(local i=0;i&lt;n;i+=1)
1142         yield i;
1143     return null;
1144 }
1145 
1146 local gtor=geny(10);
1147 local x;
1148 while(x=resume gtor) print(x+&#8221;\n&#8221;);
1149         </pre><p>the output of this program will be</p><pre class="programlisting">
1150 0
1151 1
1152 2
1153 3
1154 4
1155 5
1156 6
1157 7
1158 8
1159 9
1160         </pre>
1161     generators can also be iterated using the foreach statement. When a generator is evaluated
1162     by <tt class="literal">foreach</tt>, the generator will be resumed for each iteration until it returns. The value
1163     returned by the <tt class="literal">return</tt> statement will be ignored.
1164     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>A suspended generator will hold a strong reference to all the values stored in it's local variables except the <tt class="literal">this</tt>
1165      object that is only a weak reference. A running generator hold a strong reference also to the <tt class="literal">this</tt> object.
1166   </div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1858"></a>Constants &amp; Enumerations</h2></div></div><div></div></div><a class="indexterm" name="d0e1859"></a><a name="constants"></a><p>
1167       Pscript allows to bind constant values to an identifier that will be evaluated compile-time.
1168       This is archieved though constants and enumarations.
1169     </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1869"></a>Constants</h3></div></div><div></div></div><p>
1170         </p><p>
1171           Constants bind a specific value to an indentifier. Constants are similar to
1172           global values, except that they are evaluated compile time and their value cannot be changed.
1173         </p><p>
1174         </p><p>
1175           constants values can only be integers, floats or string literals. No expression are allowed.
1176           are declared with the following syntax.
1177         </p><p>
1178         </p><pre class="programlisting">
1179           
1180 const foobar = 100;
1181 const floatbar = 1.2;
1182 const stringbar = "I'm a contant string";
1183           
1184         </pre><p>
1185         </p><p>
1186           constants are always globally scoped, from the moment they are declared, any following code
1187           can reference them.
1188           Constants will shadow any global slot with the same name( the global slot will remain visible by using the <tt class="literal">::</tt> syntax).
1189         </p><p>
1190         </p><pre class="programlisting">
1191          
1192 local x = foobar * 2;
1193         
1194         </pre><p>
1195       </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1892"></a>Enumerations</h3></div></div><div></div></div><p>
1196         </p><p>
1197           As Constants, Enumerations bind a specific value to a name. Enumerations are also evaluated compile time 
1198           and their value cannot be changed.
1199         </p><p>
1200         </p><p>
1201           An enum declaration introduces a new enumeration into the program.
1202           Enumerations values can only be integers, floats or string literals. No expression are allowed.
1203         </p><p>
1204         </p><p>
1205         </p><pre class="programlisting">
1206         
1207 enum Stuff {
1208   first, //this will be 0
1209   second, //this will be 1
1210   third //this will be 2
1211 }
1212         
1213         </pre><p>
1214         
1215             or
1216         
1217  </p><pre class="programlisting">
1218 
1219 enum Stuff {
1220   first = 10
1221   second = "string"
1222   third = 1.2
1223 }
1224 
1225  </pre><p>
1226         </p><p>
1227         </p><p>
1228           An enum value is accessed in a manner that's similar to accessing a static class member.
1229           The name of the member must be qualified with the name of the enumeration, for example <tt class="literal">Stuff.second</tt>.
1230           Enumerations will shadow any global slot with the same name( the global slot will remain visible by using the <tt class="literal">::</tt> syntax).
1231         </p><p>
1232         </p><pre class="programlisting">
1233           
1234 local x = Stuff.first * 2;
1235 
1236         </pre><p>
1237       </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1924"></a>Implementation notes</h3></div></div><div></div></div><p>
1238         Enumerations and Contants are a compile-time feature. Only integers, string and floats can be declared as const/enum;
1239         No expressions are allowed(because they would have to be evaluated compile time).
1240         When a const or an enum is declared, it is added compile time to the <tt class="literal">consttable</tt>. This table is stored in the VM shared state
1241         and is shared by the VM and all its threads.
1242         The <tt class="literal">consttable</tt> is a regular pscript table; In the same way as the <tt class="literal">roottable</tt>
1243         it can be modified runtime.
1244         You can access the <tt class="literal">consttable</tt> through the built-in function <tt class="literal">getconsttable()</tt>
1245         and also change it through the built-in function <tt class="literal">setconsttable()</tt>
1246         </p><p>
1247         here some example:
1248         </p><pre class="programlisting">
1249           
1250 //create a constant
1251 getconsttable()["something"] &lt;- 10"
1252 //create an enumeration
1253 getconsttable()["somethingelse"] &lt;- { a = "10", c = "20", d = "200"};
1254 //deletes the constant
1255 delete getconsttable()["something"]
1256 //deletes the enumeration
1257 delete getconsttable()["somethingelse"]
1258         
1259         </pre><p>
1260           This system allows to procedurally declare constants and enumerations, it is also possible to assign any pscript type
1261           to a constant/enumeration(function,classes etc...). However this will make serialization of a code chunk impossible.
1262         </p><p>
1263         
1264       </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1954"></a>Threads</h2></div></div><div></div></div><a class="indexterm" name="d0e1955"></a><a name="threads"></a><p>
1265         Pscript supports cooperative threads(also known as coroutines).
1266         A cooperative thread is a subroutine that can suspended in mid-execution and provide a value to the 
1267         caller without returning program flow, then its execution can be resumed later from the same 
1268         point where it was suspended.
1269         At first look a Pscript thread can be confused with a generator, in fact their behaviour is quite similar.
1270         However while a generator runs in the caller stack and can suspend only the local routine stack a thread 
1271         has its own execution stack, global table and error handler; This allows a thread to suspend nested calls and
1272         have it's own error policies.
1273         </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1965"></a>Using threads</h3></div></div><div></div></div><a class="indexterm" name="d0e1966"></a><p>
1274             </p><p>
1275             Threads are created through the built-in function 'newthread(func)'; this function
1276             gets as parameter a pscript function and bind it to the new thread objecs(will be the thread body).
1277             The returned thread object is initially in 'idle' state. the thread can be started with the function
1278             'threadobj.call()'; the parameters passed to 'call' are passed to the thread function.
1279             </p><p>
1280             </p><p>
1281             A thread can be be suspended calling the function suspend(), when this happens the function
1282             that wokeup(or started) the thread returns (If a parametrer is passed to suspend() it will
1283             be the return value of the wakeup function , if no parameter is passed the return value will be null).
1284             A suspended thread can be resumed calling the funtion 'threadobj.wakeup', when this happens
1285             the function that suspended the thread will return(if a parameter is passed to wakeup it will
1286             be the return value of the suspend function, if no parameter is passed the return value will be null).
1287             </p><p>
1288             </p><p>         
1289             A thread terminates when its main function returns or when an unhandled exception occurs during its execution.
1290             </p><p>
1291         
1292         </p><pre class="programlisting">
1293 function coroutine_test(a,b)
1294 {
1295     ::print(a+" "+b+"\n");
1296     local ret = ::suspend("suspend 1");
1297     ::print("the coroutine says "+ret+"\n");
1298     ret = ::suspend("suspend 2");
1299     ::print("the coroutine says "+ret+"\n");
1300     ret = ::suspend("suspend 3");
1301     ::print("the coroutine says "+ret+"\n");
1302     return "I'm done"
1303 }
1304 
1305 local coro = ::newthread(coroutine_test);
1306 
1307 local susparam = coro.call("test","coroutine"); //starts the coroutine
1308 
1309 local i = 1;
1310 do
1311 {
1312     ::print("suspend passed ("+susparam+")\n")
1313     susparam = coro.wakeup("ciao "+i);
1314     ++i;
1315 }while(coro.getstatus()=="suspended")
1316 
1317 ::print("return passed ("+susparam+")\n")
1318         </pre><p>
1319         </p><p>the result of this program will be</p><p>
1320         </p><pre class="programlisting">
1321 test coroutine
1322 suspend passed (suspend 1)
1323 the coroutine says ciao 1
1324 suspend passed (suspend 2)
1325 the coroutine says ciao 2
1326 suspend passed (suspend 3)
1327 the coroutine says ciao 3
1328 return passed (I'm done).
1329         </pre><p>
1330         
1331         the following is an interesting example of how threads and tail recursion
1332         can be combined.
1333 </p><pre class="programlisting">        
1334 function state1()
1335 {
1336     ::suspend("state1");
1337     return state2(); //tail call
1338 }
1339 
1340 function state2()
1341 {
1342     ::suspend("state2");
1343     return state3(); //tail call
1344 }
1345 
1346 function state3()
1347 {
1348     ::suspend("state3");
1349     return state1(); //tail call
1350 }
1351 
1352 local statethread = ::newthread(state1)
1353 
1354 ::print(statethread.call()+"\n");
1355 
1356 for(local i = 0; i &lt; 10000; i++)
1357     ::print(statethread.wakeup()+"\n");
1358 </pre><p>   
1359         </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1995"></a>Weak References</h2></div></div><div></div></div><a class="indexterm" name="d0e1996"></a><a name="weakrefs"></a><p>
1360             The weak references allows the programmers to create references to objects without
1361             influencing the lifetime of the object itself.
1362             In pscript Weak references are first-class objects created through the built-in method obj.weakref().
1363             All types except null implement the weakref() method; however in bools,integers and float the method
1364             simply returns the object itself(this because this types are always passed by value).
1365             When a weak references is assigned to a container (table slot,array,class or
1366             instance) is treated differently than other objects; When a container slot that hold a weak
1367             reference is fetched, it always returns the value pointed by the weak reference instead of the weak
1368             reference object. This allow the programmer to ignore the fact that the value handled is weak.
1369             When the object pointed by weak reference is destroyed, the weak reference is automatically set to null.
1370             </p><p>
1371             </p><pre class="programlisting">
1372 local t = {}
1373 local a = ["first","second","third"]
1374 //creates a weakref to the array and assigns it to a table slot
1375 t.thearray &lt;- a.weakref();
1376             </pre><p>
1377             The table slot 'thearray' contains a weak reference to an array.
1378             The following line prints "first", because tables(and all other containers) always return
1379             the object pointed by a weak ref
1380             </p><pre class="programlisting">
1381 print(t.thearray[0]);
1382             </pre><p>
1383             the only strong reference to the array is owned by the local variable 'a', so
1384             because the following line assigns a integer to 'a' the array is destroyed.
1385             </p><pre class="programlisting">
1386 a = 123;
1387             </pre><p>
1388             When an object pointed by a weak ref is destroyed the weak ref is automatically set to null,
1389             so the following line will print "null".
1390             </p><pre class="programlisting">
1391 ::print(typeof(t.thearray))
1392             </pre><p>
1393             </p><p>
1394             </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2019"></a>Handling weak references explicitly</h3></div></div><div></div></div><p>
1395             If a weak reference is assigned to a local variable, then is treated as any other value.
1396             </p><pre class="programlisting">
1397 local t = {}
1398 local weakobj = t.weakref();
1399             </pre><p>
1400             the following line prints "weakref".
1401             </p><pre class="programlisting">
1402 ::print(typeof(weakobj))
1403             </pre><p>
1404             the object pointed by the weakref can be obtained through the built-in method weakref.ref().
1405             </p><p>
1406             The following line prints "table".
1407             </p><pre class="programlisting">
1408 ::print(typeof(weakobj.ref()))
1409             </pre><p>
1410             </p><p>
1411             </p></div><p>
1412         </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e2038"></a>Delegation</h2></div></div><div></div></div><a class="indexterm" name="d0e2039"></a><a name="delegation"></a><p>
1413             Pscript supports implicit delegation. Every table or userdata can have a parent table
1414             (delegate). A parent table is a normal table that allows the definition of special behaviors
1415             for his child.
1416             When a table (or userdata) is indexed with a key that doesn&#8217;t correspond to one of its
1417             slots, the interpreter automatically delegates the get (or set) operation to its parent.
1418         </p><pre class="programlisting">
1419   
1420 Entity &lt;- {
1421 }
1422 
1423 function Entity::DoStuff()
1424 {
1425     ::print(_name);
1426 }
1427 
1428 local newentity = {
1429     _name=&#8221;I&#8217;m the new entity&#8221;
1430 }
1431 newentity.setdelegate(Entity)
1432 
1433 newentity.DoStuff(); //prints &#8220;I&#8217;m the new entity&#8221;
1434         </pre><p>
1435             The delegate of a table can be retreived through built-in method <tt class="literal">table.getdelegate()</tt>.
1436         </p><pre class="programlisting">
1437 local thedelegate = newentity.getdelegate();
1438         </pre></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e2057"></a>Metamethods</h2></div></div><div></div></div><a class="indexterm" name="d0e2058"></a><a name="metamethods"></a><p>
1439       Metamethods are a mechanism that allows the customization of certain aspects of the
1440       language semantics. Those methods are normal functions placed in a table
1441       parent(delegate) or class declaration; Is possible to change many aspect of a table/class instance behavior by just defining
1442       a metamethod. Class objects(not instances) supports only 2 metamethods _newmember,_inherited.
1443       </p><p>
1444             For example when we use relational operators other than &#8216;==&#8217; on 2 tables, the VM will
1445             check if the table has a method in his parent called &#8216;_cmp&#8217; if so it will call it to determine
1446             the relation between the tables.
1447         
1448         </p><pre class="programlisting">
1449   
1450 local comparable={
1451     _cmp = function (other)
1452     {
1453         if(name&lt;other.name)return &#8211;1;
1454         if(name&gt;other.name)return 1;
1455         return 0;
1456     }
1457 }
1458 
1459 local a={ name="Alberto" }.setdelegate(comparable);
1460 local b={ name="Wouter" }.setdelegate(comparable);
1461 
1462 if(a&gt;b)
1463     print("a&gt;b")
1464 else
1465     print("b&lt;=a");
1466 </pre><p>
1467         </p><p>     
1468         </p><p>
1469         for classes the previous code become:
1470         
1471 </p><pre class="programlisting">
1472 class Comparable {
1473     constructor(n)
1474     {
1475         name = n;
1476     }
1477     function _cmp(other)
1478     {
1479         if(name&lt;other.name) return -1;
1480         if(name&gt;other.name) return 1;
1481         return 0;
1482     }
1483     name = null;
1484 }
1485 
1486 local a = Comparable("Alberto");
1487 local b = Comparable("Wouter");
1488 
1489 if(a&gt;b)
1490     print("a&gt;b")
1491 else
1492     print("b&lt;=a");
1493 
1494 </pre><p>
1495             </p><p>
1496         </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2079"></a>_set</h3></div></div><div></div></div><a class="indexterm" name="d0e2080"></a><p>
1497         invoked when the index idx is not present in the object or in its delegate chain.
1498         _set must 'throw null' to notify that a key wasn't found but the there were not runtime errors(clean failure).
1499         This allows the program to defferentieate between a runtime error and a 'index not found'.
1500       </p><pre class="programlisting">function _set(idx,val) //returns val</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2092"></a>_get</h3></div></div><div></div></div><a class="indexterm" name="d0e2093"></a><p>
1501         invoked when the index idx is not present in the object or in its delegate chain.
1502         _get must 'throw null' to notify that a key wasn't found but the there were not runtime errors(clean failure).
1503         This allows the program to defferentieate between a runtime error and a 'index not found'.
1504       </p><pre class="programlisting">function _get(idx) //return the fetched values</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2105"></a>_newslot</h3></div></div><div></div></div><a class="indexterm" name="d0e2106"></a><p>invoked when a script tries to add a new slot in a table.</p><pre class="programlisting">function _newslot(key,value) //returns val</pre><p>
1505                 if the slot already exists in the target table the method will not be invoked also if the
1506                 &#8220;new slot&#8221; operator is used.
1507             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2120"></a>_delslot</h3></div></div><div></div></div><a class="indexterm" name="d0e2121"></a><p>invoked when a script deletes a slot from a table.</p><p>if the method is invoked pscript will not try to delete the slot himself</p><pre class="programlisting">function _delslot(key)</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2135"></a>_add</h3></div></div><div></div></div><a class="indexterm" name="d0e2136"></a><p>the + operator</p><pre class="programlisting">function _add(op) //returns this+op</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2148"></a>_sub</h3></div></div><div></div></div><a class="indexterm" name="d0e2149"></a><p>the &#8211; operator (like _add)</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2159"></a>_mul</h3></div></div><div></div></div><a class="indexterm" name="d0e2160"></a><p>the * operator (like _add)</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2170"></a>_div</h3></div></div><div></div></div><a class="indexterm" name="d0e2171"></a><p>the / operator (like _add)</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2181"></a>_modulo</h3></div></div><div></div></div><a class="indexterm" name="d0e2182"></a><p>the % operator (like _add)</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2192"></a>_unm</h3></div></div><div></div></div><a class="indexterm" name="d0e2193"></a><p>the unary minus operator</p><pre class="programlisting">function _unm()</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2205"></a>_typeof</h3></div></div><div></div></div><a class="indexterm" name="d0e2206"></a><p>invoked by the typeof operator on tables ,userdata and class instances</p><pre class="programlisting">function _typeof() //returns the type of this as string</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2218"></a>_cmp</h3></div></div><div></div></div><a class="indexterm" name="d0e2219"></a><p>invoked to emulate the &lt; &gt; &lt;= &gt;= operators</p><pre class="programlisting">function _cmp(other)</pre><p>
1508                 <tt class="literal">returns an integer:</tt>
1509                 </p><div class="informaltable"><table border="0"><colgroup><col><col></colgroup><tbody><tr><td><tt class="literal">&gt;0</tt></td><td><tt class="literal">if this &gt; other</tt></td></tr><tr><td><tt class="literal">0</tt></td><td><tt class="literal">if this == other</tt></td></tr><tr><td><tt class="literal">&lt;0</tt></td><td><tt class="literal">if this &lt; other</tt></td></tr></tbody></table></div><p>
1510             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2263"></a>_call</h3></div></div><div></div></div><a class="indexterm" name="d0e2264"></a><p>invoked when a table, userdata or class instance is called</p><pre class="programlisting">function _call(original_this,params&#8230;)</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2276"></a>_cloned</h3></div></div><div></div></div><a class="indexterm" name="d0e2277"></a><p>invoked when a table or class instance is cloned(in the cloned table)</p><pre class="programlisting">function _cloned(original)</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2289"></a>_nexti</h3></div></div><div></div></div><a class="indexterm" name="d0e2290"></a><p>invoked when a userdata or class instance is iterated by a foreach loop</p><pre class="programlisting">function _nexti(previdx)</pre><p>
1511                 if previdx==null it means that it is the first iteration.
1512                 The function has to return the index of the &#8216;next&#8217; value.
1513             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2304"></a>_tostring</h3></div></div><div></div></div><a class="indexterm" name="d0e2305"></a><p>invoked when during string conacatenation or when the <tt class="literal">print</tt> function prints a table, instance or userdata.
1514             The method is also invoked by the ps_tostring() api</p><pre class="programlisting">function _tostring()</pre><p>
1515                 must return a string representation of the object.
1516             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2322"></a>_inherited</h3></div></div><div></div></div><a class="indexterm" name="d0e2323"></a><p>
1517         invoked when a class object inherits from the class implementing <tt class="literal">_inherited</tt>
1518         the <tt class="literal">this</tt> contains the new class.
1519       </p><pre class="programlisting">function _inherited(attributes)</pre><p>
1520         return value is ignored.
1521       </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2343"></a>_newmember</h3></div></div><div></div></div><a class="indexterm" name="d0e2344"></a><p>
1522         invoked for each member declared in a class body(at declaration time).
1523       </p><pre class="programlisting">function _newmember(index,value,attributes,isstatic)</pre><p>
1524         if the function is implemented, members will not be added to the class.
1525       </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e2358"></a>Built-in functions</h2></div></div><div></div></div><a name="builtin"></a><p>The pscript virtual machine has a set of built utility functions.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2365"></a>Global symbols</h3></div></div><div></div></div><p>
1526                 <a class="indexterm" name="d0e2370"></a>
1527                 </p><p><tt class="function">array(size,[fill])</tt></p><p>
1528                 create and returns array of a specified size.if the optional parameter <i class="parameter"><tt>fill</tt></i> is specified
1529                     its value will be used to fill the new array's slots. 
1530                     If the <i class="parameter"><tt>fill</tt></i> paramter is omitted <tt class="literal">null</tt> is used instead.
1531             </p><p>
1532                 <a class="indexterm" name="d0e2389"></a>
1533                 </p><p><tt class="function">seterrorhandler(func)</tt></p><p>
1534                 sets the runtime error handler
1535             </p><p>
1536         <a class="indexterm" name="d0e2399"></a>
1537         </p><p><tt class="function">callee()</tt></p><p>
1538         returns the currently running closure
1539       </p><p>
1540                 <a class="indexterm" name="d0e2409"></a>
1541                 </p><p><tt class="function">setdebughook(hook_func)</tt></p><p>
1542                 sets the debug hook
1543             </p><p>
1544                 <a class="indexterm" name="d0e2419"></a>
1545                 </p><p><tt class="function">enabledebuginfo(enable)</tt></p><p>
1546                 enable/disable the debug line information generation at compile time.
1547                 enable != null enables . enable == null disables.
1548             </p><p>
1549                 <a class="indexterm" name="d0e2429"></a>
1550                 </p><p><tt class="function">getroottable()</tt></p><p>
1551                 returns the root table of the VM.
1552             </p><p>
1553         <a class="indexterm" name="d0e2439"></a>
1554         </p><p><tt class="function">setroottable(table)</tt></p><p>
1555         sets the root table of the VM. And returns the previous root table.
1556       </p><p>
1557         <a class="indexterm" name="d0e2449"></a>
1558         </p><p><tt class="function">getconsttable()</tt>
1559         </p><p>returns the const table of the VM.
1560       </p><p><a class="indexterm" name="d0e2459"></a>
1561         </p><p><tt class="function">setconsttable(table)</tt></p><p>
1562         sets the const table of the VM. And returns the previous const table.
1563       </p><p>
1564                 <a class="indexterm" name="d0e2469"></a>
1565                 </p><p><tt class="function">assert(exp)</tt></p><p>
1566                 throws an exception if exp is null
1567             </p><p>
1568                 <a class="indexterm" name="d0e2479"></a>
1569                 </p><p><tt class="function">print(x)</tt></p><p>
1570                 prints x in the standard output
1571             </p><p>
1572         <a class="indexterm" name="d0e2489"></a>
1573         </p><p><tt class="function">error(x)</tt></p><p>
1574         prints x in the standard error output
1575       </p><p>
1576                 <a class="indexterm" name="d0e2499"></a>
1577                 </p><p><tt class="function">compilestring(string,[buffername])</tt></p><p>
1578                 compiles a string containing a pscript script into a function and
1579                 returns it
1580                 </p><pre class="programlisting">
1581 local compiledscript=compilestring("::print(\"ciao\")");
1582 //run the script                
1583 compiledscript();
1584                 </pre><p>
1585             </p><p>
1586                 <a class="indexterm" name="d0e2512"></a>
1587                 </p><p><tt class="function">collectgarbage()</tt></p><p>
1588         runs the garbage collector and returns the number of reference cycles found(and deleted)
1589         This function only works on garbage collector builds.
1590       </p><p>
1591         <a class="indexterm" name="d0e2522"></a>
1592         </p><p><tt class="function">resurrectunreachable()</tt></p><p>
1593         runs the garbage collector and returns an array containing all unreachable object found.
1594         If no unreachable object is found, null is returned instead. This function is meant to help debugging reference cycles.
1595         This function only works on garbage collector builds.
1596       </p><p>
1597                 <a class="indexterm" name="d0e2532"></a>
1598                 </p><p><tt class="function">type(obj)</tt></p><p>
1599                 return the 'raw' type of an object without invoking the metatmethod '_typeof'.
1600             </p><p>
1601                 <a class="indexterm" name="d0e2542"></a>
1602                 </p><p><tt class="function">getstackinfos(level)</tt></p><p>
1603                 returns the stack informations of a given call stack level.
1604                 returns a table formatted as follow:
1605                 </p><pre class="programlisting">
1606 {
1607     func="DoStuff", //function name
1608     
1609     src="test.nut", //source file
1610     
1611     line=10,        //line number
1612     
1613     locals = {      //a table containing the local variables
1614     
1615         a=10,
1616         
1617         testy="I'm a string"
1618     }
1619 }
1620                 </pre><p>
1621                 level = 0 is the current function, 
1622                 level = 1 is the caller and so on.
1623                 If the stack level doesn't exist the function returns null.
1624             </p><p>
1625                 <a class="indexterm" name="d0e2555"></a>
1626                 </p><p><tt class="function">newthread(threadfunc)</tt></p><p>
1627                 creates a new cooperative thread object(coroutine) and returns it
1628             </p><p>
1629         <a class="indexterm" name="d0e2565"></a>
1630         </p><p><tt class="function">_versionnumber_</tt></p><p>
1631         integer values describing the version of VM and compiler.
1632         eg. for Pscript 3.0.1 this value will be 301
1633       </p><p>
1634         <a class="indexterm" name="d0e2575"></a>
1635         </p><p><tt class="function">_version_</tt></p><p>
1636         string values describing the version of VM and compiler.
1637       </p><p>
1638         <a class="indexterm" name="d0e2585"></a>
1639         </p><p><tt class="function">_charsize_</tt>
1640         </p><p> 
1641         size in bytes of the internal VM rapresentation for characters(1 for ASCII builds 2 for UNICODE builds).
1642       </p><p>
1643         <a class="indexterm" name="d0e2596"></a>
1644         </p><p><tt class="function">_intsize_</tt></p><p>
1645         size in bytes of the internal VM rapresentation for integers(4 for 32bits builds 8 for 64bits builds).
1646       </p><p>
1647         <a class="indexterm" name="d0e2606"></a>
1648         </p><p><tt class="function">_floatsize_</tt></p><p>
1649         size in bytes of the internal VM rapresentation for floats(4 for single precision builds 8 for double precision builds).
1650       </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2615"></a>Default delegates</h3></div></div><div></div></div><p>
1651                 Except null and userdata every pscript object has a default delegate containing a set of
1652                 functions to manipulate and retrieve information from the object itself.
1653             </p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e2621"></a>Integer</h4></div></div><div></div></div><p>
1654                     <a class="indexterm" name="d0e2626"></a>
1655                     </p><p><tt class="function">tofloat()</tt></p><p>
1656                     convert the number to float and returns it
1657                 </p><p>
1658                     <a class="indexterm" name="d0e2638"></a>
1659                     </p><p><tt class="function">tostring()</tt></p><p>
1660                     converts the number to string and returns it
1661                 </p><p>
1662                     <a class="indexterm" name="d0e2650"></a>
1663                     </p><p><tt class="function">tointeger()</tt></p><p>
1664                     returns the value of the integer(dummy function)
1665                 </p><p>
1666                     <a class="indexterm" name="d0e2662"></a>
1667                     </p><p><tt class="function">tochar()</tt></p><p>
1668                     returns a string containing a single character rapresented by the integer.
1669                 </p><p>
1670                     <a class="indexterm" name="d0e2674"></a>
1671                     </p><p><tt class="function">weakref()</tt></p><p>
1672                     dummy function, returns the integer itself.
1673                 </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e2685"></a>Float</h4></div></div><div></div></div><p>
1674                     <a class="indexterm" name="d0e2690"></a>
1675                     </p><p><tt class="function">tofloat()</tt></p><p>
1676                     returns the value of the float(dummy function)
1677                 </p><p>
1678                     <a class="indexterm" name="d0e2702"></a>
1679                     </p><p><tt class="function">tointeger()</tt></p><p>
1680                     converts the number to integer and returns it
1681                 </p><p>
1682                     <a class="indexterm" name="d0e2714"></a>
1683                     </p><p><tt class="function">tostring()</tt></p><p>
1684                     converts the number to string and returns it
1685                 </p><p>
1686                     <a class="indexterm" name="d0e2726"></a>
1687                     </p><p><tt class="function">tochar()</tt></p><p>
1688                     returns a string containing a single character rapresented by the integer part of the float.
1689                 </p><p>
1690                     <a class="indexterm" name="d0e2738"></a>
1691                     </p><p><tt class="function">weakref()</tt></p><p>
1692                     dummy function, returns the float itself.
1693                 </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e2749"></a>Bool</h4></div></div><div></div></div><p>
1694                     <a class="indexterm" name="d0e2754"></a>
1695                     </p><p><tt class="function">tofloat()</tt></p><p>
1696                     returns 1.0 for <tt class="literal">true</tt> 0.0 for <tt class="literal">false</tt>
1697                 </p><p>
1698                     <a class="indexterm" name="d0e2772"></a>
1699                     </p><p><tt class="function">tointeger()</tt></p><p>
1700                     returns 1 for <tt class="literal">true</tt> 0 for <tt class="literal">false</tt>
1701                 </p><p>
1702                     <a class="indexterm" name="d0e2790"></a>
1703                     </p><p><tt class="function">tostring()</tt></p><p>
1704                     returns "true" for <tt class="literal">true</tt> "false" for <tt class="literal">false</tt>
1705                 </p><p>
1706                     <a class="indexterm" name="d0e2808"></a>
1707                     </p><p><tt class="function">weakref()</tt></p><p>
1708                     dummy function, returns the bool itself.
1709                 </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e2819"></a>String</h4></div></div><div></div></div><p>
1710                     <a class="indexterm" name="d0e2824"></a>
1711                     </p><p><tt class="function">len()</tt></p><p>
1712                     returns the string length
1713                 </p><p>
1714                     <a class="indexterm" name="d0e2836"></a>
1715                     </p><p><tt class="function">tointeger()</tt></p><p>
1716                     converts the string to integer and returns it
1717                 </p><p>
1718                     <a class="indexterm" name="d0e2848"></a>
1719                     </p><p><tt class="function">tofloat()</tt></p><p>
1720                     converts the string to float and returns it
1721                 </p><p>
1722                     <a class="indexterm" name="d0e2860"></a>
1723                     </p><p><tt class="function">tostring()</tt></p><p>
1724                     returns the string(dummy function)
1725                 </p><p>
1726                     <a class="indexterm" name="d0e2872"></a>
1727                     </p><p><tt class="function">slice(start,[end])</tt></p><p>
1728                     returns a section of the string as new string. Copies from start to the end (not included).
1729                     If start is negative the index is calculated as length + start, if end is negative the index is
1730                     calculated as length + end. If end is omitted end is equal to the string length.
1731                 </p><p>
1732                     <a class="indexterm" name="d0e2884"></a>
1733                     </p><p><tt class="function">find(substr,[startidx])</tt></p><p>
1734                     search a sub string(substr) starting from the index startidx and returns the index of its
1735                     first occurrence. If startidx is omitted the search operation starts from the beginning of
1736                     the string. The function returns null if substr is not found.
1737                 </p><p>
1738                     <a class="indexterm" name="d0e2896"></a>
1739                     </p><p><tt class="function">tolower()</tt></p><p>
1740                     returns a lowercase copy of the string.
1741                 </p><p>
1742                     <a class="indexterm" name="d0e2908"></a>
1743                     </p><p><tt class="function">toupper()</tt></p><p>
1744                     returns a uppercase copy of the string.
1745                 </p><p>
1746                     <a class="indexterm" name="d0e2920"></a>
1747                     </p><p><tt class="function">weakref()</tt></p><p>
1748                     returns a weak reference to the object.
1749                 </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e2931"></a>Table</h4></div></div><div></div></div><p>
1750                     <a class="indexterm" name="d0e2936"></a>
1751                     </p><p><tt class="function">len()</tt></p><p>
1752                     returns the number of slots contained in a table
1753                 </p><p>
1754                     <a class="indexterm" name="d0e2948"></a>
1755                     </p><p><tt class="function">rawget(key)</tt></p><p>
1756           tries to get a value from the slot &#8216;key&#8217; without employing delegation
1757         </p><p>
1758                     <a class="indexterm" name="d0e2960"></a>
1759                     </p><p><tt class="function">rawset(key,val)</tt></p><p>
1760                     sets the slot &#8216;key&#8217; with the value &#8216;val&#8217; without employing delegation.
1761                     If the slot does not exists , it will be created.
1762                 </p><p>
1763                     <a class="indexterm" name="d0e2972"></a>
1764                     </p><p><tt class="function">rawdelete()</tt></p><p>
1765                     deletes the slot key without emplying delegetion and retunrs his value.
1766                     if the slo does not exists returns always null.
1767                 </p><p>
1768                     <a class="indexterm" name="d0e2984"></a>
1769                     </p><p><tt class="function">rawin(key)</tt></p><p>
1770                     returns true if the slot &#8216;key&#8217; exists.
1771                     the function has the same eddect as the operator 'in' but does not employ delegation.
1772                 </p><p>
1773                     <a class="indexterm" name="d0e2996"></a>
1774                     </p><p><tt class="function">weakref()</tt></p><p>
1775                     returns a weak reference to the object.
1776                 </p><p>
1777                     <a class="indexterm" name="d0e3008"></a>
1778                     </p><p><tt class="function">tostring()</tt></p><p>
1779                     tries to invoke the _tostring metamethod, if failed. returns "(table : pointer)".
1780                 </p><p>
1781           <a class="indexterm" name="d0e3020"></a></p><p><tt class="function">clear()</tt></p><p>
1782           removes all the slot from the table
1783         </p><p>
1784           <a class="indexterm" name="d0e3031"></a>
1785           </p><p><tt class="function">setdelegate(table)</tt></p><p>
1786           sets the delegate of the table, to remove a delegate 'null' must be passed to the function.
1787           The function returns the table itself (eg. a.setdelegate(b) in this case 'a' is the return value).
1788         </p><p><a class="indexterm" name="d0e3042"></a>
1789           </p><p><tt class="function">getdelegate()</tt></p><p>
1790           returns the table's delegate or null if no delegate was set.
1791         </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e3053"></a>Array</h4></div></div><div></div></div><p>
1792                     <a class="indexterm" name="d0e3058"></a>
1793                     </p><p><tt class="function">len()</tt></p><p>
1794                     returns the length of the array
1795                 </p><p>
1796                     <a class="indexterm" name="d0e3070"></a>
1797                     </p><p><tt class="function">append(val)</tt></p><p>
1798                     appends the value &#8216;val&#8217; at the end of the array
1799                 </p><p>
1800           <a class="indexterm" name="d0e3082"></a>
1801           </p><p><tt class="function">push(val)</tt></p><p>appends the value &#8216;val&#8217; at the end of the array</p><p>
1802                     <a class="indexterm" name="d0e3094"></a>
1803                     </p><p><tt class="function">extend(array)</tt></p><p>
1804                     Extends the array by appending all the items in the given array.
1805                 </p><p>
1806                     <a class="indexterm" name="d0e3106"></a>
1807                     </p><p><tt class="function">pop()</tt></p><p>
1808                     removes a value from the back of the array and returns it.
1809                 </p><p>
1810                     <a class="indexterm" name="d0e3118"></a>
1811                     </p><p><tt class="function">top()</tt></p><p>
1812                     returns the value of the array with the higher index
1813                 </p><p>
1814                     <a class="indexterm" name="d0e3130"></a>
1815                     </p><p><tt class="function">insert(idx,val)</tt></p><p>
1816                     inserst the value &#8216;val&#8217; at the position &#8216;idx&#8217; in the array
1817                 </p><p>
1818                     <a class="indexterm" name="d0e3142"></a>
1819                     </p><p><tt class="function">remove(idx)</tt></p><p>
1820                     removes the value at the position &#8216;idx&#8217; in the array
1821                 </p><p>
1822                     <a class="indexterm" name="d0e3154"></a>
1823                     </p><p><tt class="function">resize(size,[fill])</tt></p><p>
1824                     resizes the array, if the optional parameter <i class="parameter"><tt>fill</tt></i> is specified
1825                     its value will be used to fill the new array's slots(if the size specified is bigger than the previous size) . 
1826                     If the <i class="parameter"><tt>fill</tt></i> paramter is omitted <tt class="literal">null</tt> is used instead.
1827                 </p><p>
1828                     <a class="indexterm" name="d0e3175"></a>
1829                     </p><p><tt class="function">sort([compare_func])</tt></p><p>
1830                     sorts the array.
1831                     a custom compare function can be optionally passed.The function prototype as to be the
1832                     following.
1833                     </p><pre class="programlisting">
1834 function custom_compare(a,b)
1835 {
1836     if(a&gt;b) return 1
1837     else if(a&lt;b) return -1
1838     return 0;
1839 }
1840                     </pre><p>
1841           
1842           a more compact version of a custom compare can be written using a lambda expression and the operator &lt;=&gt;
1843          </p><pre class="programlisting">
1844 arr.sort(@(a,b) a &lt;=&gt; b);
1845         </pre><p>
1846         </p><p>
1847                     <a class="indexterm" name="d0e3193"></a>
1848                     </p><p><tt class="function">reverse()</tt></p><p>
1849                     reverse the elements of the array in place
1850                 </p><p>
1851                     <a class="indexterm" name="d0e3205"></a>
1852                     </p><p><tt class="function">slice(start,[end])</tt></p><p>
1853                     returns a section of the array as new array. Copies from start to the end (not included).
1854                     If start is negative the index is calculated as length + start, if end is negative the index is
1855                     calculated as length + end. If end is omitted end is equal to the array length.
1856                 </p><p>
1857                     <a class="indexterm" name="d0e3217"></a>
1858                     </p><p><tt class="function">weakref()</tt></p><p>
1859                     returns a weak reference to the object.
1860                 </p><p>
1861                     <a class="indexterm" name="d0e3229"></a>
1862                     </p><p><tt class="function">tostring()</tt></p><p>
1863                     returns the string "(array : pointer)".
1864                 </p><p>
1865           <a class="indexterm" name="d0e3241"></a></p><p><tt class="function">clear()</tt></p><p>
1866           removes all the items from the array
1867         </p><p>
1868           <a class="indexterm" name="d0e3252"></a></p><p><tt class="function">map(func(a))</tt></p><p>
1869           creates a new array of the same size.
1870           for each element in the original array invokes the function 'func' and
1871           assigns the return value of the function to the corresponding element of the newly created array.
1872         </p><p>
1873           <a class="indexterm" name="d0e3263"></a>
1874           </p><p><tt class="function">apply(func(a))</tt></p><p>
1875            for each element in the array invokes the function 'func' and
1876           replace the original value of the element with the return value of the function.
1877         </p><p>
1878           <a class="indexterm" name="d0e3275"></a>
1879           </p><p><tt class="function">reduce(func(prevval,curval))</tt></p><p>
1880           Reduces an array to a single value.
1881           For each element in the array invokes the function 'func' passing the initial value (or value from the previous callback call)
1882           and the value of the current element. the return value of the function is then used as 'prevval' for the next element.
1883           Given an array of length 0, returns null. Given an array of length 1, returns the first element.
1884           Given an array with 2 or more elements calls the function with the first two elements as the parameters, gets that result, 
1885           then calls the function with that result and the third element, gets that result, 
1886           calls the function with that result and the fourth parameter and so on until all element have been processed.
1887           Finally returns the return value of the last invocation of func.
1888         </p><p>
1889           <a class="indexterm" name="d0e3287"></a>
1890           </p><p><tt class="function">filter(func(index,val))</tt></p><p>
1891           Creates a new array with all elements that pass the test implemented by the provided function.
1892           In detail, it creates a new array, for each element in the original array invokes the specified function
1893           passing the index of the element and it's value; if the function returns 'true', then the value 
1894           of the corresponding element is added on the newly created array.
1895         </p><p>
1896           <a class="indexterm" name="d0e3299"></a>
1897           </p><p><tt class="function">find(value)</tt></p><p>
1898           Performs a linear search for the value in the array. Returns the index of the value if it was found null otherwise.
1899         </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e3310"></a>Function</h4></div></div><div></div></div><p>
1900                     <a class="indexterm" name="d0e3315"></a>
1901                     </p><p><tt class="function">call(_this,args&#8230;)</tt></p><p>
1902                     calls the function with the specified environment object(&#8217;this&#8217;) and parameters
1903                 </p><p>
1904           <a class="indexterm" name="d0e3327"></a>
1905           </p><p><tt class="function">pcall(_this,args&#8230;)</tt></p><p>
1906           calls the function with the specified environment object(&#8217;this&#8217;) and parameters,
1907           this function will not invoke the error callback in case of failure(pcall stays for
1908           'protected call')
1909         </p><p>
1910                     <a class="indexterm" name="d0e3339"></a>
1911                     </p><p><tt class="function">acall(array_args)</tt></p><p>
1912           calls the function with the specified environment object(&#8217;this&#8217;) and parameters. The
1913           function accepts an array containing the parameters that will be passed to the called
1914           function.Where array_args has to contain the required 'this' object at the [0] position.
1915         </p><p>
1916           <a class="indexterm" name="d0e3351"></a>
1917           </p><p><tt class="function">pacall(array_args)</tt></p><p>
1918           calls the function with the specified environment object(&#8217;this&#8217;) and parameters. The
1919           function accepts an array containing the parameters that will be passed to the called
1920           function.Where array_args has to contain the required 'this' object at the [0] position.
1921           This function will not invoke the error callback in case of failure(pacall stays for
1922           'protected array call')
1923         </p><p>
1924                     <a class="indexterm" name="d0e3363"></a>
1925                     </p><p><tt class="function">weakref()</tt></p><p>
1926                     returns a weak reference to the object.
1927                 </p><p>
1928                     <a class="indexterm" name="d0e3375"></a>
1929                     </p><p><tt class="function">tostring()</tt></p><p>
1930                     returns the string "(closure : pointer)".
1931                 </p><p>
1932           <a class="indexterm" name="d0e3387"></a>
1933           </p><p><tt class="function">bindenv(env)</tt></p><p>
1934           clones the function(aka closure) and bind the enviroment object to it(table,class or instance).
1935           the <tt class="literal">this</tt> parameter of the newly create function will always be set to env.
1936           Note that the created function holds a weak reference to its environment object so cannot be used to
1937           control its lifetime.
1938         </p><p>
1939           <a class="indexterm" name="d0e3402"></a>
1940           </p><p><tt class="function">getinfos()</tt></p><p>
1941           returns a table containing informations about the function, like parameters, name and source name;
1942 </p><pre class="programlisting">
1943   
1944 //the data is returned as a table is in form
1945 //pure pscript function
1946 {
1947   native = false
1948   name = "zefuncname"
1949   src = "/somthing/something.nut"
1950   parameters = ["a","b","c"]
1951   defparams = [1,"def"]
1952   varargs = 2
1953 }
1954 //native C function
1955 {
1956   native = true
1957   name = "zefuncname"
1958   paramscheck = 2
1959   typecheck = [83886082,83886384] //this is the typemask (see C defines OT_INTEGER,OT_FLOAT etc...)
1960 }
1961 
1962   
1963 </pre><p>
1964         </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e3416"></a>Class</h4></div></div><div></div></div><p>
1965           <a class="indexterm" name="d0e3421"></a>
1966           </p><p><tt class="function">instance()</tt></p><p>
1967           returns a new instance of the class. this function does not invoke the instance constructor. 
1968           The constructor must be explicitly called( eg. class_inst.constructor(class_inst) ).
1969         </p><p>
1970                     <a class="indexterm" name="d0e3433"></a>
1971                     </p><p><tt class="function">getattributes(membername)</tt></p><p>
1972                     returns the attributes of the specified member. if the parameter member is null the function
1973                     returns the class level attributes.
1974                 </p><p>
1975                     <a class="indexterm" name="d0e3445"></a>
1976                     </p><p><tt class="function">setattributes(membername,attr)</tt></p><p>
1977                     sets the attribute of the specified member and returns the previous attribute value.
1978                     if the parameter member is null the function sets the class level attributes.
1979                 </p><p>
1980                     <a class="indexterm" name="d0e3457"></a>
1981                     </p><p><tt class="function">rawin(key)</tt></p><p>
1982                     returns true if the slot &#8216;key&#8217; exists.
1983                     the function has the same eddect as the operator 'in' but does not employ delegation.
1984                 </p><p>
1985                     <a class="indexterm" name="d0e3469"></a>
1986                     </p><p><tt class="function">weakref()</tt></p><p>
1987                     returns a weak reference to the object.
1988                 </p><p>
1989                     <a class="indexterm" name="d0e3481"></a>
1990                     </p><p><tt class="function">tostring()</tt></p><p>
1991                     returns the string "(class : pointer)".
1992                 </p><p>
1993           <a class="indexterm" name="d0e3493"></a>
1994           </p><p><tt class="function">rawget(key)</tt></p><p>
1995           tries to get a value from the slot &#8216;key&#8217; without employing delegation
1996         </p><p>
1997           <a class="indexterm" name="d0e3505"></a>
1998           </p><p><tt class="function">rawset(key,val)</tt></p><p>
1999           sets the slot &#8216;key&#8217; with the value &#8216;val&#8217; without employing delegation.
2000           If the slot does not exists , it will be created.
2001         </p><p>
2002           <a class="indexterm" name="d0e3517"></a>
2003           </p><p><tt class="function">newmember(key,val,[attrs],[bstatic])</tt></p><p>
2004           sets/adds the slot &#8216;key&#8217; with the value &#8216;val&#8217; and attributes 'attrs' and if present invokes the _newmember metamethod.
2005           If bstatic is true the slot will be added as static.
2006           If the slot does not exists , it will be created.
2007         </p><p>
2008           <a class="indexterm" name="d0e3529"></a>
2009           </p><p><tt class="function">rawnewmember(key,val,[attrs],[bstatic])</tt></p><p>
2010           sets/adds the slot &#8216;key&#8217; with the value &#8216;val&#8217; and attributes 'attrs'.If bstatic is true the slot will be added as static.
2011           If the slot does not exists , it will be created. It doesn't invoke any metamethod.
2012         </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e3540"></a>Class Instance</h4></div></div><div></div></div><p>
2013                     <a class="indexterm" name="d0e3545"></a>
2014                     </p><p><tt class="function">getclass()</tt></p><p>
2015                     returns the class that created the instance.
2016                 </p><p>
2017                     <a class="indexterm" name="d0e3557"></a>
2018                     </p><p><tt class="function">rawin(key)</tt></p><p>
2019                     returns true if the slot &#8216;key&#8217; exists.
2020                     the function has the same eddect as the operator 'in' but does not employ delegation.
2021                 </p><p>
2022                     <a class="indexterm" name="d0e3569"></a>
2023                     </p><p><tt class="function">weakref()</tt></p><p>
2024                     returns a weak reference to the object.
2025                 </p><p>
2026                     <a class="indexterm" name="d0e3581"></a>
2027                     </p><p><tt class="function">tostring()</tt></p><p>
2028                     tries to invoke the _tostring metamethod, if failed. returns "(insatnce : pointer)".
2029                 </p><p>
2030           <a class="indexterm" name="d0e3593"></a>
2031           </p><p><tt class="function">rawget(key)</tt></p><p>
2032           tries to get a value from the slot &#8216;key&#8217; without employing delegation
2033         </p><p>
2034           <a class="indexterm" name="d0e3605"></a>
2035           </p><p><tt class="function">rawset(key,val)</tt></p><p>
2036           sets the slot &#8216;key&#8217; with the value &#8216;val&#8217; without employing delegation.
2037           If the slot does not exists , it will be created.
2038         </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e3616"></a>Generator</h4></div></div><div></div></div><p>
2039                     <a class="indexterm" name="d0e3621"></a>
2040                     </p><p><tt class="function">getstatus()</tt></p><p>
2041                     returns the status of the generator as string : &#8220;running&#8221;, &#8221;dead&#8221; or &#8221;suspended&#8221;.
2042                 </p><p>
2043                     <a class="indexterm" name="d0e3633"></a>
2044                     </p><p><tt class="function">weakref()</tt></p><p>
2045                     returns a weak reference to the object.
2046                 </p><p>
2047                     <a class="indexterm" name="d0e3645"></a>
2048                     </p><p><tt class="function">tostring()</tt></p><p>
2049                     returns the string "(generator : pointer)".
2050                 </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e3656"></a>Thread</h4></div></div><div></div></div><p>
2051                     <a class="indexterm" name="d0e3661"></a>
2052                     </p><p><tt class="function">call(...)</tt></p><p>
2053                     starts the thread with the specified parameters
2054                 </p><p>
2055                     <a class="indexterm" name="d0e3673"></a>
2056                     </p><p><tt class="function">wakeup([wakeupval])</tt></p><p>
2057                     wakes up a suspended thread, accepts a optional parameter that will be used
2058                     as return value for the function that suspended the thread(usually suspend())
2059                 </p><p>
2060                     <a class="indexterm" name="d0e3685"></a>
2061                     </p><p><tt class="function">getstatus()</tt></p><p>
2062                     returns the status of the thread ("idle","running","suspended")
2063                 </p><p>
2064                     <a class="indexterm" name="d0e3697"></a>
2065                     </p><p><tt class="function">weakref()</tt></p><p>
2066                     returns a weak reference to the object.
2067                 </p><p>
2068                     <a class="indexterm" name="d0e3709"></a>
2069                     </p><p><tt class="function">tostring()</tt></p><p>
2070                     returns the string "(thread : pointer)".
2071                 </p><p>
2072           <a class="indexterm" name="d0e3721"></a>
2073           </p><p><tt class="function">getstackinfos(stacklevel)</tt></p><p>
2074           returns the stack frame informations at the given stack level (0 is the current function 1 is the caller and so on).
2075         </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e3732"></a>Weak Reference</h4></div></div><div></div></div><p>
2076                     <a class="indexterm" name="d0e3737"></a>
2077                     </p><p><tt class="function">ref()</tt></p><p>
2078                     returns the object that the weak reference is pointing at, null if the object that
2079                     was point at was destroyed.
2080                 </p><p>
2081                     <a class="indexterm" name="d0e3749"></a>
2082                     </p><p><tt class="function">weakref()</tt></p><p>
2083                     returns a weak reference to the object.
2084                 </p><p>
2085                     <a class="indexterm" name="d0e3761"></a>
2086                     </p><p><tt class="function">tostring()</tt></p><p>
2087                     returns the string "(weakref : pointer)".
2088                 </p></div></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="d0e3772"></a>Chapter&nbsp;3.&nbsp;Embedding Pscript</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#d0e3783">Memory management</a></span></dt><dt><span class="sect1"><a href="#d0e3800">Unicode</a></span></dt><dt><span class="sect1"><a href="#d0e3806">Pscript on 64 bits architectures</a></span></dt><dt><span class="sect1"><a href="#d0e3811">Userdata alignment</a></span></dt><dt><span class="sect1"><a href="#d0e3819">Stand-alone VM without compiler</a></span></dt><dt><span class="sect1"><a href="#d0e3825">Error conventions</a></span></dt><dt><span class="sect1"><a href="#d0e3833">Initializing Pscript</a></span></dt><dt><span class="sect1"><a href="#d0e3849">The Stack</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e3855">Stack indexes</a></span></dt><dt><span class="sect2"><a href="#d0e3933">Stack manipulation</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e4000">Runtime error handling</a></span></dt><dt><span class="sect1"><a href="#d0e4011">Compiling a script</a></span></dt><dt><span class="sect1"><a href="#d0e4046">Calling a function</a></span></dt><dt><span class="sect1"><a href="#d0e4060">Create a C function</a></span></dt><dt><span class="sect1"><a href="#d0e4108">Tables and arrays manipulation</a></span></dt><dt><span class="sect1"><a href="#d0e4177">Userdata and UserPointers</a></span></dt><dt><span class="sect1"><a href="#d0e4201">The registry table</a></span></dt><dt><span class="sect1"><a href="#d0e4213">Mantaining strong references to Pscript values from the C API</a></span></dt><dt><span class="sect1"><a href="#d0e4221">Debug Interface</a></span></dt></dl></div><p>
2089         <span class="emphasis"><em>
2090             This section describes how to embed Pscript in a host application, C language
2091             knowledge is required to understand this part of the manual.
2092         </em></span>
2093     </p><p>
2094         Because of his nature of extension language, Pscript&#8217;s compiler and virtual machine are
2095         implemented as C library.
2096         The library exposes a set of functions to compile scripts, call functions, manipulate data
2097         and extend the virtual machine.
2098         All declarations needed for embedding the language in an application are in the header
2099         file &#8216;pscript.h&#8217;.
2100     </p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e3783"></a>Memory management</h2></div></div><div></div></div><p>
2101             Pscript uses reference counting (RC) as primary system for memory management;
2102             however, the virtual machine (VM) has an auxiliary
2103             mark and sweep garbage collector that can be invoked on demand.
2104         </p><p>
2105             There are 2 possible compile time options:
2106         </p><div class="itemizedlist"><ul type="disc"><li><p>
2107                 The default configuration consists in RC plus a mark and sweep garbage collector. 
2108                 The host program can call the function ps_collectgarbage() and perform a garbage collection cycle
2109                 during the program execution. The garbage collector isn&#8217;t invoked by the VM and has to
2110                 be explicitly called by the host program.
2111             </p></li><li><p>
2112                 The second a situation consists in RC only(define NO_GARBAGE_COLLECTOR); in this case is impossible for
2113                 the VM to detect reference cycles, so is the programmer that has to solve them explicitly in order to
2114                 avoid memory leaks.
2115             </p></li></ul></div><p>
2116             The only advantage introduced by the second option is that saves 2 additional
2117             pointers that have to be stored for each object in the default configuration with 
2118             garbage collector(8 bytes for 32 bits systems).
2119             The types involved are: tables, arrays, functions, threads, userdata and generators; all other
2120             types are untouched. These options do not affect execution speed.
2121         </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e3800"></a>Unicode</h2></div></div><div></div></div><p>
2122       By default Pscript strings are plain 8-bits ASCII characters; however if the symbol
2123       'PSUNICODE' is defined the VM, compiler and API will use 16-bits characters.
2124     </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e3806"></a>Pscript on 64 bits architectures</h2></div></div><div></div></div><p>
2125       Pscript can be compiled on 64 bits architectures by defining '_PS64' in the C++
2126       preprocessor. This flag should be defined in any project that includes 'pscript.h'.
2127     </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e3811"></a>Userdata alignment</h2></div></div><div></div></div><p>
2128       Both class instances and userdatas can have a buffer associated to them.
2129       Pscript specifies the alignment(in bytes) through the peroprocessor defining 'PS_ALIGNMENT'.
2130       By default PS_ALIGNMENT is defined as 4 for 32 bits builds and 8 for 64bits builds and builds that use 64bits floats.
2131       It is possible to override the value of PS_ALIGNMENT respecting the following rules.
2132       PS_ALIGNMENT shall be less than or equal to PS_MALLOC alignments, and it shall be power of 2.
2133       </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>This only applies for userdata allocated by the VM, specified via ps_setclassudsize() or belonging to a userdata object.
2134       userpointers specified by the user are not affected by alignemnt rules.</div><p>
2135     </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e3819"></a>Stand-alone VM without compiler</h2></div></div><div></div></div><p>
2136       Pscript's VM can be compiled without it's compiler by defining 'NO_COMPILER' in the C++ preprocessor.
2137       When 'NO_COMPILER' is defined all function related to the compiler (eg. ps_compile) will fail. Other functions
2138       that conditionally load precompiled bytecode or compile a file (eg. psstd_dofile) will only work with
2139       precompiled bytecode.
2140     </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e3825"></a>Error conventions</h2></div></div><div></div></div><p>
2141             Most of the functions in the API return a PSRESULT value; PSRESULT indicates if a
2142             function completed successfully or not.
2143             The macros PS_SUCCEEDED() and PS_FAILED() are used to test the result of a function.
2144         </p><pre class="programlisting">
2145 if(PS_FAILED(ps_getstring(v,-1,&amp;s)))
2146     printf(&#8220;getstring failed&#8221;);
2147         </pre></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e3833"></a>Initializing Pscript</h2></div></div><div></div></div><p>
2148             The first thing that a host application has to do, is create a virtual machine.
2149             The host application can create any number of virtual machines through the function
2150             <tt class="literal">ps_open()</tt>.
2151         </p><p>
2152             Every single VM has to be released with the function <tt class="literal">ps_close()</tt> when it is not
2153             needed anymore.
2154         </p><pre class="programlisting">
2155 int main(int argc, char* argv[])
2156 {
2157     HPSCRIPTVM v;
2158     v = ps_open(1024); //creates a VM with initial stack size 1024
2159     
2160     //do some stuff with pscript here
2161     
2162     ps_close(v);
2163 }
2164         </pre></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e3849"></a>The Stack</h2></div></div><div></div></div><p>
2165             Pscript exchanges values with the virtual machine through a stack. This mechanism has
2166             been inherited from the language Lua.
2167             For instance to call a Pscript function from C it is necessary to push the function and the
2168             arguments in the stack and then invoke the function; also when Pscript calls a C
2169             function the parameters will be in the stack as well.
2170         </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e3855"></a>Stack indexes</h3></div></div><div></div></div><p>
2171                 Many API functions can arbitrarily refer to any element in the stack through an index.
2172                 The stack indexes follow those conventions:
2173                 </p><div class="itemizedlist"><ul type="disc"><li>1 is the stack base</li><li>
2174                         Negative indexes are considered an offset from top of the stack. For instance &#8211;1 is
2175                         the top of the stack.
2176                     </li><li>0 is an invalid index</li></ul></div><p>
2177             </p><p>Here an example (let&#8217;s pretend that this table is the VM stack)</p><div class="informaltable"><table border="1"><colgroup><col><col><col><col></colgroup><tbody><tr><td><span class="emphasis"><em>STACK</em></span></td><td>&nbsp;</td><td><span class="emphasis"><em>positive index</em></span></td><td><span class="emphasis"><em>negative index</em></span></td></tr><tr><td><tt class="literal">"test"</tt></td><td>&nbsp;</td><td>4</td><td>-1(top)</td></tr><tr><td><tt class="literal">1</tt></td><td>&nbsp;</td><td>3</td><td>-2</td></tr><tr><td><tt class="literal">0.5</tt></td><td>&nbsp;</td><td>2</td><td>-3</td></tr><tr><td><tt class="literal">"foo"</tt></td><td>&nbsp;</td><td>1(base)</td><td>-4</td></tr></tbody></table></div><p>
2178                 In this case, the function <tt class="literal">ps_gettop</tt> would return 4;
2179             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e3933"></a>Stack manipulation</h3></div></div><div></div></div><p>The API offers several functions to push and retrieve data from the Pscript stack.</p><p>
2180                 To push a value that is already present in the stack in the top position
2181                 </p><pre class="programlisting">void ps_push(HPSCRIPTVM v,PSInteger idx);</pre><p>
2182             </p><p>
2183                 To pop an arbitrary number of elements
2184                 </p><pre class="programlisting">void ps_pop(HPSCRIPTVM v,PSInteger nelemstopop);</pre><p>
2185             </p><p>
2186                 To remove an element from the stack
2187                 </p><pre class="programlisting">void ps_remove(HPSCRIPTVM v,PSInteger idx);</pre><p>
2188             </p><p>
2189                 To retrieve the top index (and size) of the current 
2190                 virtual stack you must call <tt class="literal">ps_gettop</tt>
2191                 </p><pre class="programlisting">PSInteger ps_gettop(HPSCRIPTVM v);</pre><p>
2192             </p><p>
2193                 To force the stack to a certain size you can call <tt class="literal">ps_settop</tt>
2194                 </p><pre class="programlisting">void ps_settop(HPSCRIPTVM v,PSInteger newtop);</pre><p>
2195             </p><p>
2196                 If the newtop is bigger than the previous one, the new posistions in the stack will be
2197                 filled with null values.
2198             </p><p>The following function pushes a C value into the stack</p><pre class="programlisting">
2199 void ps_pushstring(HPSCRIPTVM v,const PSChar *s,PSInteger len);
2200 void ps_pushfloat(HPSCRIPTVM v,PSFloat f);
2201 void ps_pushinteger(HPSCRIPTVM v,PSInteger n);
2202 void ps_pushuserpointer(HPSCRIPTVM v,PSUserPointer p);
2203 void ps_pushbool(HPSCRIPTVM v,PSBool b);
2204             </pre><p>
2205                 this function pushes a null into the stack
2206                 </p><pre class="programlisting">void ps_pushnull(HPSCRIPTVM v);</pre><p>
2207             </p><p>
2208                 returns the type of the value in a arbitrary position in the stack
2209                 </p><pre class="programlisting">PSObjectType ps_gettype(HPSCRIPTVM v,PSInteger idx);</pre><p>
2210             </p><p>
2211                 the result can be one of the following values:
2212                 </p><pre class="programlisting">
2213 OT_NULL,OT_INTEGER,OT_FLOAT,OT_STRING,OT_TABLE,OT_ARRAY,OT_USERDATA,
2214 OT_CLOSURE,OT_NATIVECLOSURE,OT_GENERATOR,OT_USERPOINTER,OT_BOOL,OT_INSTANCE,OT_CLASS,OT_WEAKREF
2215                 </pre><p>
2216             </p><p>The following functions convert a pscript value in the stack to a C value</p><pre class="programlisting">
2217 PSRESULT ps_getstring(HPSCRIPTVM v,PSInteger idx,const PSChar **c);
2218 PSRESULT ps_getinteger(HPSCRIPTVM v,PSInteger idx,PSInteger *i);
2219 PSRESULT ps_getfloat(HPSCRIPTVM v,PSInteger idx,PSFloat *f);
2220 PSRESULT ps_getuserpointer(HPSCRIPTVM v,PSInteger idx,PSUserPointer *p);
2221 PSRESULT ps_getuserdata(HPSCRIPTVM v,PSInteger idx,PSUserPointer *p,PSUserPointer *typetag);
2222 PSRESULT ps_getbool(HPSCRIPTVM v,PSInteger idx,PSBool *p);
2223             </pre><p>
2224                 The function ps_cmp compares 2 values from the stack and returns their relation (like
2225                 strcmp() in ANSI C).
2226                 </p><pre class="programlisting">PSInteger ps_cmp(HPSCRIPTVM v);</pre><p>
2227             </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4000"></a>Runtime error handling</h2></div></div><div></div></div><p>
2228             When an exception is not handled by Pscript code with a try/catch statement, a runtime
2229             error is raised and the execution of the current program is interrupted. It is possible to
2230             set a call back function to intercept the runtime error from the host program; this is
2231             useful to show meaningful errors to the script writer and for implementing visual
2232             debuggers.
2233             The following API call pops a Pscript function from the stack and sets it as error handler.
2234             </p><pre class="programlisting">PSCRIPT_API void ps_seterrorhandler(HPSCRIPTVM v);</pre><p>
2235         </p><p>
2236             The error handler is called with 2 parameters, an environment object (this) and a object.
2237             The object can be any pscript type.
2238         </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4011"></a>Compiling a script</h2></div></div><div></div></div><p>You can compile a Pscript script with the function <tt class="literal">ps_compile</tt>.</p><pre class="programlisting">
2239 typedef PSInteger (*PSLEXREADFUNC)(PSUserPointer userdata);
2240 
2241 PSRESULT ps_compile(HPSCRIPTVM v,PSREADFUNC read,PSUserPointer p,
2242     const PSChar *sourcename,PSBool raiseerror);
2243         </pre><p>
2244             In order to compile a script is necessary for the host application to implement a reader
2245             function (PSLEXREADFUNC); this function is used to feed the compiler with the script
2246             data.
2247             The function is called every time the compiler needs a character; It has to return a
2248             character code if succeed or 0 if the source is finished.
2249         </p><p>
2250             If ps_compile succeeds, the compiled script will be pushed as Pscript function in the
2251             stack.
2252             </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
2253                 In order to execute the script, the function generated by <tt class="literal">ps_compile()</tt> has 
2254                 to be called through <tt class="literal">ps_call()</tt></div><p>
2255         </p><p>
2256             Here an example of a &#8216;read&#8217; function that read from a file:
2257         </p><pre class="programlisting">
2258 PSInteger file_lexfeedASCII(PSUserPointer file)
2259 {
2260     int ret;
2261     char c;
2262     if( ( ret=fread(&amp;c,sizeof(c),1,(FILE *)file )&gt;0) )
2263         return c;
2264     return 0;
2265 }
2266 
2267 int compile_file(HPSCRIPTVM v,const char *filename)
2268 {
2269     FILE *f=fopen(filename,&#8221;rb&#8221;);
2270     if(f)
2271     {
2272          ps_compile(v,file_lexfeedASCII,f,filename,1);
2273          fclose(f);
2274          return 1;
2275     }
2276     return 0;
2277 }
2278         </pre><p>
2279             When the compiler fails for a syntax error it will try to call the &#8216;compiler error handler&#8217;;
2280             this function must be declared as follow
2281         </p><pre class="programlisting">
2282 typedef void (*PSCOMPILERERROR)(HPSCRIPTVM /*v*/,const PSChar * /*desc*/,const PSChar *
2283 /*source*/,PSInteger /*line*/,PSInteger /*column*/);
2284         </pre><p>and can be set with the following API call</p><pre class="programlisting">void ps_setcompilererrorhandler(HPSCRIPTVM v,PSCOMPILERERROR f);</pre></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4046"></a>Calling a function</h2></div></div><div></div></div><p>
2285             To call a pscript function it is necessary to push the function in the stack followed by the
2286             parameters and then call the function ps_call.
2287             The function will pop the parameters and push the return value if the last ps_call
2288             parameter is &gt;0.
2289         </p><pre class="programlisting">
2290 ps_pushroottable(v);
2291 ps_pushstring(v,&#8220;foo&#8221;,-1);
2292 ps_get(v,-2); //get the function from the root table
2293 ps_pushroottable(v); //&#8217;this&#8217; (function environment object)
2294 ps_pushinteger(v,1);
2295 ps_pushfloat(v,2.0);
2296 ps_pushstring(v,&#8221;three&#8221;,-1);
2297 ps_call(v,4,PSFalse);
2298 ps_pop(v,2); //pops the roottable and the function
2299         </pre><p>this is equivalent to the following Pscript code</p><pre class="programlisting">foo(1,2.0,&#8221;three&#8221;);</pre><p>
2300             If a runtime error occurs (or a exception is thrown) during the pscript code execution
2301             the ps_call will fail.
2302         </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4060"></a>Create a C function</h2></div></div><div></div></div><p>A native C function must have the following prototype:</p><pre class="programlisting">typedef PSInteger (*PSFUNCTION)(HPSCRIPTVM);</pre><p>
2303             The parameters is an handle to the calling VM and the return value is an integer
2304             respecting the following rules:
2305         </p><div class="itemizedlist"><ul type="disc"><li><p>1 if the function returns a value</p></li><li><p>0 if the function does not return a value</p></li><li><p>PS_ERROR runtime error is thrown</p></li></ul></div><p>
2306             In order to obtain a new callable pscript function from a C function pointer, is necessary
2307             to call ps_newclosure() passing the C function to it; the new Pscript function will be
2308             pushed in the stack.
2309         </p><p>
2310             When the function is called, the stackbase is the first parameter of the function and the
2311             top is the last. In order to return a value the function has to push it in the stack and
2312             return 1.
2313         </p><p>
2314       Function parameters are in the stack from postion 1 ('this') to <tt class="literal">n</tt>.
2315       <tt class="literal">ps_gettop()</tt> can be used to determinate the number of parameters.
2316     </p><p>
2317       If the function has free variables, those will be in the stack after the explicit parameters
2318       an can be handled as normal parameters. Note also that the value returned by<tt class="literal">ps_gettop()</tt> will be
2319       affected by free variables. <tt class="literal">ps_gettop()</tt> will return the number of parameters plus
2320       number of free variables.
2321     </p><p>
2322             Here an example, the following function print the value of each argument and return the
2323             number of arguments.
2324         </p><pre class="programlisting">
2325                   
2326 PSInteger print_args(HPSCRIPTVM v)
2327 {
2328     PSInteger nargs = ps_gettop(v); //number of arguments
2329     for(PSInteger n=1;n&lt;=nargs;n++)
2330     {
2331         printf("arg %d is ",n);
2332         switch(ps_gettype(v,n))
2333         {
2334             case OT_NULL:
2335                 printf("null");        
2336                 break;
2337             case OT_INTEGER:
2338                 printf("integer");
2339                 break;
2340             case OT_FLOAT:
2341                 printf("float");
2342                 break;
2343             case OT_STRING:
2344                 printf("string");
2345                 break;    
2346             case OT_TABLE:
2347                 printf("table");
2348                 break;
2349             case OT_ARRAY:
2350                 printf("array");
2351                 break;
2352             case OT_USERDATA:
2353                 printf("userdata");
2354                 break;
2355             case OT_CLOSURE:        
2356                 printf("closure(function)");    
2357                 break;
2358             case OT_NATIVECLOSURE:
2359                 printf("native closure(C function)");
2360                 break;
2361             case OT_GENERATOR:
2362                 printf("generator");
2363                 break;
2364             case OT_USERPOINTER:
2365                 printf("userpointer");
2366                 break;
2367             case OT_CLASS:
2368                 printf("class");
2369                 break;
2370             case OT_INSTANCE:
2371                 printf("instance");
2372                 break;
2373             case OT_WEAKREF:
2374                 printf("weak reference");
2375                 break;
2376             default:
2377                 return ps_throwerror(v,"invalid param"); //throws an exception
2378         }
2379     }
2380     printf("\n");
2381     ps_pushinteger(v,nargs); //push the number of arguments as return value
2382     return 1; //1 because 1 value is returned
2383 }
2384         </pre><p>Here an example of how to register a function</p><pre class="programlisting">
2385 PSInteger register_global_func(HPSCRIPTVM v,PSFUNCTION f,const char *fname)
2386 {
2387     ps_pushroottable(v);
2388     ps_pushstring(v,fname,-1);
2389     ps_newclosure(v,f,0,0); //create a new function
2390     ps_newslot(v,-3,PSFalse); 
2391     ps_pop(v,1); //pops the root table    
2392 }
2393         </pre></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4108"></a>Tables and arrays manipulation</h2></div></div><div></div></div><p>
2394                 A new table is created calling ps_newtable, this function pushes a new table in the stack.
2395                 </p><pre class="programlisting">void ps_newtable (HPSCRIPTVM v);</pre><p>
2396             </p><p>
2397                 To create a new slot
2398                 </p><pre class="programlisting">PSRESULT ps_newslot(HPSCRIPTVM v,PSInteger idx,PSBool bstatic);</pre><p>
2399             </p><p>
2400                 To set or get the table delegate
2401                 </p><pre class="programlisting">
2402 PSRESULT ps_setdelegate(HPSCRIPTVM v,PSInteger idx);
2403 PSRESULT ps_getdelegate(HPSCRIPTVM v,PSInteger idx);
2404                 </pre><p>
2405             </p><p>
2406                 A new array is created calling ps_newarray, the function pushes a new array in the
2407                 stack; if the parameters size is bigger than 0 the elements are initialized to null.
2408                 </p><pre class="programlisting">void ps_newarray (HPSCRIPTVM v,PSInteger size);</pre><p>
2409             </p><p>
2410                 To append a value to the back of the array
2411                 </p><pre class="programlisting">PSRESULT ps_arrayappend(HPSCRIPTVM v,PSInteger idx);</pre><p>
2412             </p><p>
2413                 To remove a value from the back of the array
2414                 </p><pre class="programlisting">PSRESULT ps_arraypop(HPSCRIPTVM v,PSInteger idx,PSInteger pushval);</pre><p>
2415             </p><p>
2416                 To resize the array
2417                 </p><pre class="programlisting">PSRESULT ps_arrayresize(HPSCRIPTVM v,PSInteger idx,PSInteger newsize);</pre><p>
2418             </p><p>
2419                 To retrieve the size of a table or an array you must use ps_getsize()
2420                 </p><pre class="programlisting">PSInteger ps_getsize(HPSCRIPTVM v,PSInteger idx);</pre><p>
2421             </p><p>
2422                 To set a value in an array or table
2423                 </p><pre class="programlisting">PSRESULT ps_set(HPSCRIPTVM v,PSInteger idx);</pre><p>
2424             </p><p>
2425                 To get a value from an array or table
2426                 </p><pre class="programlisting">PSRESULT ps_get(HPSCRIPTVM v,PSInteger idx);</pre><p>
2427             </p><p>
2428                 To get or set a value from a table without employ delegation
2429                 </p><pre class="programlisting">
2430 PSRESULT ps_rawget(HPSCRIPTVM v,PSInteger idx);
2431 PSRESULT ps_rawset(HPSCRIPTVM v,PSInteger idx);
2432                 </pre><p>
2433             </p><p>
2434                 To iterate a table or an array
2435                 </p><pre class="programlisting">PSRESULT ps_next(HPSCRIPTVM v,PSInteger idx);</pre><p>
2436             </p><p>
2437                 Here an example of how to perform an iteration:
2438                 </p><pre class="programlisting">
2439 //push your table/array here
2440 ps_pushnull(v)  //null iterator
2441 while(PS_SUCCEEDED(ps_next(v,-2)))
2442 {
2443     //here -1 is the value and -2 is the key
2444     
2445     ps_pop(v,2); //pops key and val before the nex iteration
2446 }
2447 
2448 ps_pop(v,1); //pops the null iterator
2449                 </pre><p>
2450             </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4177"></a>Userdata and UserPointers</h2></div></div><div></div></div><a name="userdandup"></a><p>
2451                 Pscript allows the host application put arbitrary data chunks into a Pscript value, this is
2452                 possible through the data type userdata.
2453                 </p><pre class="programlisting">PSUserPointer ps_newuserdata (HPSCRIPTVM v,PSUnsignedInteger size);</pre><p>
2454             </p><p>
2455                 When the function <tt class="literal">ps_newuserdata</tt> is called, Pscript allocates a new userdata with the
2456                 specified size, returns a pointer to his payload buffer and push the object in the stack; at
2457                 this point the application can do whatever it want with this memory chunk, the VM will
2458                 automatically take cake of the memory deallocation like for every other built-in type.
2459                 A userdata can be passed to a function or stored in a table slot. By default Pscript
2460                 cannot manipulate directly userdata; however is possible to assign a delegate to it and
2461                 define a behavior like it would be a table.
2462                 Because the application would want to do something with the data stored in a userdata
2463                 object when it get deleted, is possible to assign a callback that will be called by the VM
2464                 just before deleting a certain userdata.
2465                 This is done through the API call <tt class="literal">ps_setreleasehook</tt>.
2466             </p><pre class="programlisting">
2467 typedef PSInteger (*PSRELEASEHOOK)(PSUserPointer,PSInteger size);
2468 
2469 void ps_setreleasehook(HPSCRIPTVM v,PSInteger idx,PSRELEASEHOOK hook);
2470             </pre><p>
2471                 Another kind of userdata is the userpointer; this type is not a memory chunk like the
2472                 normal userdata, but just a &#8216;void*&#8217; pointer. It cannot have a delegate and is passed by
2473                 value, so pushing a userpointer doesn&#8217;t cause any memory allocation.
2474             </p><pre class="programlisting">void ps_pushuserpointer(HPSCRIPTVM v,PSUserPointer p);</pre></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4201"></a>The registry table</h2></div></div><div></div></div><p>
2475                 The registry table is an hidden table shared between vm and all his thread(friend vms).
2476                 This table is accessible only through the C API and is ment to be an utility structure
2477                 for native C library implementation.
2478                 For instance the psstdlib(pscript standard library)uses it to store configuration and shared objects
2479                 delegates.
2480                 The registry is accessible through the API call <tt class="function">ps_pushregistrytable</tt>.
2481                 </p><pre class="programlisting">void ps_pushregistrytable(HPSCRIPTVM v);</pre><p>
2482             </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4213"></a>Mantaining strong references to Pscript values from the C API</h2></div></div><div></div></div><p>
2483           Pscript allows to reference values through the C API; the function ps_getstackobj() gets
2484           a handle to a pscript object(any type). The object handle can be used to control the lifetime
2485           of an object by adding or removing references to it( see ps_addref() and ps_release()).
2486           The object can be also re-pushed in the VM stack using ps_pushobject().
2487         </p><pre class="programlisting">
2488 HPSOBJECT obj;
2489 
2490 ps_resetobject(v,&amp;obj) //initialize the handle
2491 ps_getstackobj(v,-2,&amp;obj); //retrieve an object handle from the pos &#8211;2
2492 ps_addref(v,&amp;obj); //adds a reference to the object
2493 
2494 &#8230; //do stuff
2495 
2496 ps_pushobject(v,&amp;obj); //push the object in the stack
2497 ps_release(v,&amp;obj); //relese the object
2498                 </pre></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4221"></a>Debug Interface</h2></div></div><div></div></div><p>
2499         The pscript VM exposes a very simple debug interface that allows to easily built a full
2500         featured debugger.
2501         Through the functions ps_setdebughook and ps_setnativedebughook is possible in fact to set a callback function that
2502         will be called every time the VM executes an new line of a script or if a function get
2503         called/returns. The callback will pass as argument the current line the current source and the
2504         current function name (if any).
2505         </p><pre class="programlisting">PSCRIPT_API void ps_setdebughook(HPSCRIPTVM v);</pre><p>
2506         or
2507         </p><pre class="programlisting">PSCRIPT_API void ps_setnativedebughook(HPSCRIPTVM v,PSDEBUGHOOK hook);</pre><p>
2508             </p><p>
2509                 The following code shows how a debug hook could look like(obviously is possible to
2510                 implement this function in C as well).
2511             </p><pre class="programlisting">
2512 function debughook(event_type,sourcefile,line,funcname)
2513 {
2514     local fname=funcname?funcname:"unknown";
2515     local srcfile=sourcefile?sourcefile:"unknown"
2516     switch (event_type) {
2517     case 'l': //called every line(that contains some code)
2518         ::print("LINE line [" + line + "] func [" + fname + "]");
2519         ::print("file [" + srcfile + "]\n");
2520         break;
2521     case 'c': //called when a function has been called
2522         ::print("LINE line [" + line + "] func [" + fname + "]");
2523         ::print("file [" + srcfile + "]\n");
2524         break;
2525     case 'r': //called when a function returns
2526         ::print("LINE line [" + line + "] func [" + fname + "]");
2527         ::print("file [" + srcfile + "]\n");
2528         break;
2529     }
2530 }
2531             </pre><p>
2532             The parameter <tt class="literal">event_type</tt> can be 'l' ,'c' or 'r' ; a hook with a 'l' event is called for each line that
2533             gets executed, 'c' every time a function gets called and 'r' every time a function returns.
2534             </p><p>
2535                 A full-featured debugger always allows displaying local variables and calls stack.
2536                 The call stack information are retrieved through ps_getstackinfos()
2537                 </p><pre class="programlisting">PSInteger ps_stackinfos(HPSCRIPTVM v,PSInteger level,PSStackInfos *si);</pre><p>
2538             </p><p>
2539                 While the local variables info through ps_getlocal()
2540                 </p><pre class="programlisting">PSInteger ps_getlocal(HPSCRIPTVM v,PSUnsignedInteger level,PSUnsignedInteger nseq);</pre><p>
2541             </p><p>
2542                 In order to receive line callbacks the scripts have to be compiled with debug infos enabled
2543                 this is done through ps_enabledebuginfo();
2544                 </p><pre class="programlisting">void ps_enabledebuginfo(HPSCRIPTVM v, PSInteger debuginfo);</pre><p>
2545             </p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="d0e4257"></a>Chapter&nbsp;4.&nbsp;API Reference</h2></div></div><div></div></div><div class="reference" lang="en"><a name="d0e4260"></a><div class="titlepage"><div><div><h1 class="title"><a name="d0e4260"></a>Virtual Machine</h1></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ps_close">ps_close</a> - </dt><dt><a href="#ps_geterrorfunc">ps_geterrorfunc</a> - </dt><dt><a href="#ps_getforeignptr">ps_getforeignptr</a> - </dt><dt><a href="#ps_getprintfunc">ps_getprintfunc</a> - </dt><dt><a href="#ps_getversion">ps_getversion</a> - </dt><dt><a href="#ps_getvmstate">ps_getvmstate</a> - </dt><dt><a href="#ps_move">ps_move</a> - </dt><dt><a href="#ps_newthread">ps_newthread</a> - </dt><dt><a href="#ps_open">ps_open</a> - </dt><dt><a href="#ps_pushconsttable">ps_pushconsttable</a> - </dt><dt><a href="#ps_pushregistrytable">ps_pushregistrytable</a> - </dt><dt><a href="#ps_pushroottable">ps_pushroottable</a> - </dt><dt><a href="#ps_setconsttable">ps_setconsttable</a> - </dt><dt><a href="#ps_seterrorhandler">ps_seterrorhandler</a> - </dt><dt><a href="#ps_setforeignptr">ps_setforeignptr</a> - </dt><dt><a href="#ps_setprintfunc">ps_setprintfunc</a> - </dt><dt><a href="#ps_setroottable">ps_setroottable</a> - </dt><dt><a href="#ps_suspendvm">ps_suspendvm</a> - </dt><dt><a href="#ps_wakeupvm">ps_wakeupvm</a> - </dt></dl></div><div class="refentry" lang="en"><a name="ps_close"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_close<a class="indexterm" name="d0e4274"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_close</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2546                 releases a pscript VM and all related friend VMs
2547             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2548                 the target VM
2549             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_geterrorfunc"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_geterrorfunc<a class="indexterm" name="d0e4312"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSPRINTFUNCTION&nbsp;<b class="fsfunc">ps_geterrorfunc</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2550         returns the current error function of the given Virtual machine.
2551         (see ps_setprintfunc())
2552       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2553         the target VM
2554       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2555         a pointer to a PSPRINTFUNCTION, or NULL if no function has been set.
2556       <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getforeignptr"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getforeignptr<a class="indexterm" name="d0e4357"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSUserPointer&nbsp;<b class="fsfunc">ps_getforeignptr</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2557                 Returns the foreign pointer of a VM instance.
2558             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2559                 the target VM
2560             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2561                 the current VMs foreign pointer.
2562             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getprintfunc"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getprintfunc<a class="indexterm" name="d0e4402"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSPRINTFUNCTION&nbsp;<b class="fsfunc">ps_getprintfunc</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2563                 returns the current print function of the given Virtual machine.
2564                 (see ps_setprintfunc())
2565             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2566                 the target VM
2567             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2568             a pointer to a PSPRINTFUNCTION, or NULL if no function has been set.
2569             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getversion"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getversion<a class="indexterm" name="d0e4447"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSInteger&nbsp;<b class="fsfunc">ps_getversion</b>(</code><code>)</code>;</p></div><p>
2570         returns the version number of the vm.
2571       </p><div class="variablelist"><dl><dt><span class="term">return:</span></dt><dd><p>
2572         version number of the vm(as in PSCRIPT_VERSION_NUMBER).
2573       <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getvmstate"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getvmstate<a class="indexterm" name="d0e4478"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSInteger&nbsp;<b class="fsfunc">ps_getvmstate</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2574                 returns the execution state of a virtual machine
2575             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2576                 the target VM
2577             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2578                 the state of the vm encoded as integer value.
2579                 The following constants are defined: PS_VMSTATE_IDLE, PS_VMSTATE_RUNNING, PS_VMSTATE_SUSPENDED.
2580             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_move"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_move<a class="indexterm" name="d0e4523"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_move</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;dest</var>, <var class="pdparam">HPSCRIPTVM&nbsp;src</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
2581                 pushes the object at the position 'idx' of the source vm stack in the
2582                 destination vm stack.
2583             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;dest</tt></i></span></dt><dd><p>
2584                 the destination VM
2585             </p></dd><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;src</tt></i></span></dt><dd><p>
2586                 the source VM
2587             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2588                 the index in the source stack of the value that has to be moved
2589             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_newthread"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_newthread<a class="indexterm" name="d0e4579"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">HPSCRIPTVM&nbsp;<b class="fsfunc">ps_newthread</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;friendvm</var>, <var class="pdparam">PSInteger&nbsp;initialstacksize</var><code>)</code>;</p></div><p>
2590                 creates a new vm friendvm of the one passed 
2591                 as first parmeter and pushes it in its stack
2592                 as "thread" object.
2593             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;friendvm</tt></i></span></dt><dd><p>
2594                 a friend VM
2595             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;initialstacksize</tt></i></span></dt><dd><p>
2596                 the size of the stack in slots(number of objects)
2597             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2598                 a pointer to the new VM.
2599             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
2600                 By default the roottable is shared with the VM passed
2601                 as first parameter.
2602                 The new VM lifetime is bound to the "thread" object pushed
2603                 in the stack and behave like a normal pscript object.
2604             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_open"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_open<a class="indexterm" name="d0e4639"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">HPSCRIPTVM&nbsp;<b class="fsfunc">ps_open</b>(</code><var class="pdparam">PSInteger&nbsp;initialstacksize</var><code>)</code>;</p></div><p>
2605                 creates a new instance of a pscript VM that consists in a new execution stack.
2606             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;initialstacksize</tt></i></span></dt><dd><p>
2607                 the size of the stack in slots(number of objects)
2608             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2609                 an handle to a pscript vm
2610             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
2611                 the returned VM has to be released with ps_releasevm
2612             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_pushconsttable"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_pushconsttable<a class="indexterm" name="d0e4690"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_pushconsttable</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2613         pushes the current const table in the stack
2614       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2615         the target VM
2616       </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_pushregistrytable"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_pushregistrytable<a class="indexterm" name="d0e4728"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_pushregistrytable</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2617                 pushes the registry table in the stack
2618             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2619                 the target VM
2620             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_pushroottable"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_pushroottable<a class="indexterm" name="d0e4766"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_pushroottable</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2621                 pushes the current root table in the stack
2622             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2623                 the target VM
2624             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setconsttable"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setconsttable<a class="indexterm" name="d0e4804"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_setconsttable</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2625         pops a table from the stack and set it as const table
2626       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2627         the target VM
2628       </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_seterrorhandler"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_seterrorhandler<a class="indexterm" name="d0e4842"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_seterrorhandler</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2629                 pops from the stack a closure or native closure an sets it as runtime-error handler.
2630             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2631                 the target VM
2632             </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
2633                 the error handler is shared by friend VMs
2634             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setforeignptr"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setforeignptr<a class="indexterm" name="d0e4886"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_setforeignptr</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSUserPointer&nbsp;p</var><code>)</code>;</p></div><p>
2635                 Sets the foreign pointer of a certain VM instance. The foreign pointer is an arbitrary
2636                 user defined pointer associated to a VM (by default is value id 0). This pointer is
2637                 ignored by the VM.
2638             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2639                 the target VM
2640             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer&nbsp;p</tt></i></span></dt><dd><p>
2641                 The pointer that has to be set
2642             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setprintfunc"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setprintfunc<a class="indexterm" name="d0e4933"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_setprintfunc</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSPRINTFUNCTION&nbsp;printfunc</var>, <var class="pdparam">PSPRINTFUNCTION&nbsp;errorfunc</var><code>)</code>;</p></div><p>
2643                 sets the print function of the virtual machine.
2644                 This function is used by the built-in function '::print()'
2645                 to output text.
2646             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2647                 the target VM
2648             </p></dd><dt><span class="term"><i class="parameter"><tt>PSPRINTFUNCTION&nbsp;printfunc</tt></i></span></dt><dd><p>
2649                 a pointer to the print func or NULL to disable the
2650                 output.
2651             </p></dd><dt><span class="term"><i class="parameter"><tt>PSPRINTFUNCTION&nbsp;errorfunc</tt></i></span></dt><dd><p>
2652         a pointer to the error func or NULL to disable the
2653         output.
2654       </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
2655             the print func has the following prototype:
2656             void printfunc(HPSCRIPTVM v,const PSChar *s,...)
2657             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setroottable"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setroottable<a class="indexterm" name="d0e4995"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_setroottable</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2658                 pops a table from the stack and set it as root table
2659             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2660                 the target VM
2661             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_suspendvm"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_suspendvm<a class="indexterm" name="d0e5033"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">HRESULT&nbsp;<b class="fsfunc">ps_suspendvm</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2662                 Suspends the execution of the specified vm.
2663             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2664                 the target VM
2665             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2666                 an PSRESULT(that has to be returned by a C function)
2667             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
2668                 ps_result can only be called as return expression of a C function.
2669                 The function will fail is the suspension is done through
2670                 more C calls or in a metamethod.
2671             </p></dd><dt><span class="term">eg.</span></dt><dd><pre class="programlisting">
2672 PSInteger suspend_vm_example(HPSCRIPTVM v)
2673 {
2674     return ps_suspendvm(v);
2675 }
2676                 </pre></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_wakeupvm"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_wakeupvm<a class="indexterm" name="d0e5091"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">HRESULT&nbsp;<b class="fsfunc">ps_wakeupvm</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSBool&nbsp;resumedret</var>, <var class="pdparam">PSBool&nbsp;retval</var>, <var class="pdparam">PSBool&nbsp;raiseerror</var>, <var class="pdparam">PSBool&nbsp;throwerror</var><code>)</code>;</p></div><p>
2677         Wake up the execution a previously suspended virtual machine.
2678       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2679         the target VM
2680       </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;resumedret</tt></i></span></dt><dd><p>
2681         if true the function will pop a value from the stack
2682         and use it as return value for the function that has previously
2683         suspended the virtual machine.
2684       </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;retval</tt></i></span></dt><dd><p>
2685         if true the function will push the return value of the function
2686         that suspend the excution or the main function one.
2687       </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;raiseerror</tt></i></span></dt><dd><p>
2688         if true, if a runtime error occurs during the execution of the call,
2689         the vm will invoke the error handler.
2690       </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;throwerror</tt></i></span></dt><dd><p>
2691         if true, the vm will thow an exception as soon as is resumed. the exception
2692         payload must be set beforehand invoking ps_thowerror().
2693       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2694         an HRESULT.
2695       <br></p></dd></dl></div></div></div><div class="reference" lang="en"><a name="d0e5161"></a><div class="titlepage"><div><div><h1 class="title"><a name="d0e5161"></a>Compiler</h1></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ps_compile">ps_compile</a> - </dt><dt><a href="#ps_compilebuffer">ps_compilebuffer</a> - </dt><dt><a href="#ps_enabledebuginfo">ps_enabledebuginfo</a> - </dt><dt><a href="#ps_notifyallexceptions">ps_notifyallexceptions</a> - </dt><dt><a href="#ps_setcompilererrorhandler">ps_setcompilererrorhandler</a> - </dt></dl></div><div class="refentry" lang="en"><a name="ps_compile"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_compile<a class="indexterm" name="d0e5175"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_compile</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">HPSLEXREADFUNC&nbsp;read</var>, <var class="pdparam">PSUserPointer&nbsp;p</var>, <var class="pdparam">const PSChar *&nbsp;sourcename</var>, <var class="pdparam">PSBool&nbsp;raiseerror</var><code>)</code>;</p></div><p>
2696                 compiles a pscript program; if it succeeds, push the compiled script as function in
2697                 the stack.
2698             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2699                 the target VM
2700             </p></dd><dt><span class="term"><i class="parameter"><tt>HPSLEXREADFUNC&nbsp;read</tt></i></span></dt><dd><p>
2701                 a pointer to a read function that will feed the compiler with the program.
2702             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer&nbsp;p</tt></i></span></dt><dd><p>
2703                 a user defined pointer that will be passed by the compiler to the read function at
2704                 each invocation.
2705             </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar *&nbsp;sourcename</tt></i></span></dt><dd><p>
2706                 the symbolic name of the program (used only for more meaningful runtime
2707                 errors)
2708             </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;raiseerror</tt></i></span></dt><dd><p>
2709                 if this value is true the compiler error handler will be called in case of an
2710                 error
2711             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2712                 a PSRESULT. If the ps_compile fails nothing is pushed in the
2713                 stack.
2714             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
2715                 in case of an error the function will call the function set by
2716                 ps_setcompilererrorhandler().
2717             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_compilebuffer"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_compilebuffer<a class="indexterm" name="d0e5262"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_compilebuffer</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">const PSChar*&nbsp;s</var>, <var class="pdparam">PSInteger&nbsp;size</var>, <var class="pdparam">const PSChar *&nbsp;sourcename</var>, <var class="pdparam">PSBool&nbsp;raiseerror</var><code>)</code>;</p></div><p>
2718                 compiles a pscript program from a memory buffer; if it succeeds, push the compiled script as function in
2719                 the stack.
2720             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2721                 the target VM
2722             </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar*&nbsp;s</tt></i></span></dt><dd><p>
2723                 a pointer to the buffer that has to be compiled.
2724             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;size</tt></i></span></dt><dd><p>
2725                 size in characters of the buffer passed in the parameter 's'.
2726             </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar *&nbsp;sourcename</tt></i></span></dt><dd><p>
2727                 the symbolic name of the program (used only for more meaningful runtime
2728                 errors)
2729             </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;raiseerror</tt></i></span></dt><dd><p>
2730                 if this value true the compiler error handler will be called in case of an
2731                 error
2732             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2733                 a PSRESULT. If the ps_compilebuffer fails nothing is pushed in the
2734                 stack.
2735             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
2736                 in case of an error the function will call the function set by
2737                 ps_setcompilererrorhandler().
2738             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_enabledebuginfo"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_enabledebuginfo<a class="indexterm" name="d0e5349"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_enabledebuginfo</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSBool&nbsp;enable</var><code>)</code>;</p></div><p>
2739                 enable/disable the debug line information generation at compile time.
2740             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2741                 the target VM
2742             </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;enable</tt></i></span></dt><dd><p>
2743                 if true enables the debug info generation, if == 0 disables it.
2744             </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
2745                 The function affects all threads as well.
2746             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_notifyallexceptions"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_notifyallexceptions<a class="indexterm" name="d0e5402"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_notifyallexceptions</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSBool&nbsp;enable</var><code>)</code>;</p></div><p>
2747         enable/disable the error callback notification of handled exceptions.
2748       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2749         the target VM
2750       </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;enable</tt></i></span></dt><dd><p>
2751         if true enables the error callback notification of handled exceptions.
2752       </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
2753         By default the VM will invoke the error callback only if an exception is
2754         not handled (no try/catch traps are present in the call stack).
2755         If notifyallexceptions is enabled, the VM will call the error callback for 
2756         any exception even if between try/catch blocks. This feature is useful
2757         for implementing debuggers.
2758       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setcompilererrorhandler"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setcompilererrorhandler<a class="indexterm" name="d0e5455"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_setcompilererrorhandler</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSCOMPILERERROR&nbsp;f</var><code>)</code>;</p></div><p>
2759                 sets the compiler error handler function
2760             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2761                 the target VM
2762             </p></dd><dt><span class="term"><i class="parameter"><tt>PSCOMPILERERROR&nbsp;f</tt></i></span></dt><dd><p>
2763                 A pointer to the error handler function
2764             </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
2765                 if the parameter f is NULL no function will be called when a compiler error occurs.
2766                 The compiler error handler is shared between friend VMs.
2767             </p></dd></dl></div></div></div><div class="reference" lang="en"><a name="d0e5497"></a><div class="titlepage"><div><div><h1 class="title"><a name="d0e5497"></a>Stack Operations</h1></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ps_cmp">ps_cmp</a> - </dt><dt><a href="#ps_gettop">ps_gettop</a> - </dt><dt><a href="#ps_pop">ps_pop</a> - </dt><dt><a href="#ps_poptop">ps_poptop</a> - </dt><dt><a href="#ps_push">ps_push</a> - </dt><dt><a href="#ps_remove">ps_remove</a> - </dt><dt><a href="#ps_reservestack">ps_reservestack</a> - </dt><dt><a href="#ps_settop">ps_settop</a> - </dt></dl></div><div class="refentry" lang="en"><a name="ps_cmp"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_cmp<a class="indexterm" name="d0e5511"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSInteger&nbsp;<b class="fsfunc">ps_cmp</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2768                 compares 2 object from the stack and compares them.
2769             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2770                 the target VM
2771             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>&gt; 0 if obj1&gt;obj2<br>== 0 if obj1==obj2<br>&lt; 0 if obj1&lt;obj2<br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_gettop"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_gettop<a class="indexterm" name="d0e5560"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSInteger&nbsp;<b class="fsfunc">ps_gettop</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2772                 returns the index of the top of the stack
2773             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2774                 the target VM
2775             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2776                 an integer representing the index of the top of the stack
2777             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_pop"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_pop<a class="indexterm" name="d0e5605"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_pop</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;nelementstopop</var><code>)</code>;</p></div><p>
2778                 pops n elements from the stack
2779             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2780                 the target VM
2781             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;nelementstopop</tt></i></span></dt><dd><p>
2782                 the number of elements to pop
2783             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_poptop"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_poptop<a class="indexterm" name="d0e5652"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_poptop</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
2784                 pops 1 object from the stack
2785             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2786                 the target VM
2787             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_push"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_push<a class="indexterm" name="d0e5690"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_push</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
2788         pushes in the stack the value at the index idx
2789       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2790         the target VM
2791       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2792         the index in the stack of the value that has to be pushed
2793       </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_remove"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_remove<a class="indexterm" name="d0e5737"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_remove</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
2794                 removes an element from an arbitrary position in the stack
2795             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2796                 the target VM
2797             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2798                 index of the element that has to be removed
2799             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_reservestack"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_reservestack<a class="indexterm" name="d0e5784"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_reservestack</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;nsize</var><code>)</code>;</p></div><p>
2800         ensure that the stack space left is at least of a specified size.If the stack
2801         is smaller it will automatically grow.
2802         if there's a memtamethod currently running the function will fail and the stack will not be resized,
2803         this situatuation has to be considered a "stack overflow".
2804       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2805                 the target VM
2806             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;nsize</tt></i></span></dt><dd><p>
2807                 required stack size
2808             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2809         a PSRESULT
2810       <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_settop"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_settop<a class="indexterm" name="d0e5838"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_settop</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;v</var><code>)</code>;</p></div><p>
2811                 resize the stack, if new top is bigger then the current top the function will push nulls.
2812             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2813                 the target VM
2814             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;v</tt></i></span></dt><dd><p>
2815                 the new top index
2816             </p></dd></dl></div></dd></dl></div></div></div><div class="reference" lang="en"><a name="d0e5874"></a><div class="titlepage"><div><div><h1 class="title"><a name="d0e5874"></a>Object creation and handling</h1></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ps_bindenv">ps_bindenv</a> - </dt><dt><a href="#ps_createinstance">ps_createinstance</a> - </dt><dt><a href="#ps_getbool">ps_getbool</a> - </dt><dt><a href="#ps_getbyhandle">ps_getbyhandle</a> - </dt><dt><a href="#ps_getclosureinfo">ps_getclosureinfo</a> - </dt><dt><a href="#ps_getclosurename">ps_getclosurename</a> - </dt><dt><a href="#ps_getfloat">ps_getfloat</a> - </dt><dt><a href="#ps_gethash">ps_gethash</a> - </dt><dt><a href="#ps_getinstanceup">ps_getinstanceup</a> - </dt><dt><a href="#ps_getinteger">ps_getinteger</a> - </dt><dt><a href="#ps_getmemberhandle">ps_getmemberhandle</a> - </dt><dt><a href="#ps_getscratchpad">ps_getscratchpad</a> - </dt><dt><a href="#ps_getsize">ps_getsize</a> - </dt><dt><a href="#ps_getstring">ps_getstring</a> - </dt><dt><a href="#ps_getthread">ps_getthread</a> - </dt><dt><a href="#ps_gettype">ps_gettype</a> - </dt><dt><a href="#ps_gettypetag">ps_gettypetag</a> - </dt><dt><a href="#ps_getuserdata">ps_getuserdata</a> - </dt><dt><a href="#ps_getuserpointer">ps_getuserpointer</a> - </dt><dt><a href="#ps_newarray">ps_newarray</a> - </dt><dt><a href="#ps_newclass">ps_newclass</a> - </dt><dt><a href="#ps_newclosure">ps_newclosure</a> - </dt><dt><a href="#ps_newtable">ps_newtable</a> - </dt><dt><a href="#ps_newtableex">ps_newtableex</a> - </dt><dt><a href="#ps_newuserdata">ps_newuserdata</a> - </dt><dt><a href="#ps_pushbool">ps_pushbool</a> - </dt><dt><a href="#ps_pushfloat">ps_pushfloat</a> - </dt><dt><a href="#ps_pushinteger">ps_pushinteger</a> - </dt><dt><a href="#ps_pushnull">ps_pushnull</a> - </dt><dt><a href="#ps_pushstring">ps_pushstring</a> - </dt><dt><a href="#ps_pushuserpointer">ps_pushuserpointer</a> - </dt><dt><a href="#ps_setbyhandle">ps_setbyhandle</a> - </dt><dt><a href="#ps_setclassudsize">ps_setclassudsize</a> - </dt><dt><a href="#ps_setinstanceup">ps_setinstanceup</a> - </dt><dt><a href="#ps_setnativeclosurename">ps_setnativeclosurename</a> - </dt><dt><a href="#ps_setparamscheck">ps_setparamscheck</a> - </dt><dt><a href="#ps_setreleasehook">ps_setreleasehook</a> - </dt><dt><a href="#ps_settypetag">ps_settypetag</a> - </dt><dt><a href="#ps_tobool">ps_tobool</a> - </dt><dt><a href="#ps_tostring">ps_tostring</a> - </dt><dt><a href="#ps_typeof">ps_typeof</a> - </dt></dl></div><div class="refentry" lang="en"><a name="ps_bindenv"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_bindenv<a class="indexterm" name="d0e5888"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_bindenv</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
2817         pops an object from the stack(must be a table,instance or class) clones the closure at position
2818         idx in the stack and sets the popped object as environment of the cloned closure.
2819         Then pushes the new cloned closure on top of the stack.
2820       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2821         the target VM
2822       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2823         index of the target closure
2824       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2825         a PSRESULT
2826       <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
2827         the cloned closure holds the environment object as weak reference
2828       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_createinstance"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_createinstance<a class="indexterm" name="d0e5948"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_createinstance</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
2829                 creates an instance of the class at 'idx' position in the stack. The new class instance
2830                 is pushed on top of the stack.
2831             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2832                 the target VM
2833             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2834                 index of the target class
2835             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2836                 a PSRESULT
2837             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
2838                 the function doesn't invoke the instance contructor. To create an instance and automatically
2839                 invoke its contructor, ps_call must be used instead.
2840             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getbool"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getbool<a class="indexterm" name="d0e6008"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getbool</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSBool *&nbsp;b</var><code>)</code>;</p></div><p>
2841                 gets the value of the bool at the idx position in the stack.
2842             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2843                 the target VM
2844             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2845                 an index in the stack
2846             </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool *&nbsp;b</tt></i></span></dt><dd><p>
2847                 A pointer to the bool that will store the value
2848             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2849                 a PSRESULT
2850             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getbyhandle"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getbyhandle<a class="indexterm" name="d0e6071"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getbyhandle</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">HPSMEMBERHANDLE*&nbsp;handle</var><code>)</code>;</p></div><p>
2851         pushes the value of a class or instance member using a member handle (see ps_getmemberhandle)
2852       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2853         the target VM
2854       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2855         an index in the stack pointing to the class
2856       </p></dd><dt><span class="term"><i class="parameter"><tt>HPSMEMBERHANDLE*&nbsp;handle</tt></i></span></dt><dd><p>
2857         a pointer the member handle
2858       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>a PSRESULT<br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getclosureinfo"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getclosureinfo<a class="indexterm" name="d0e6134"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getclosureinfo</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSUnsignedInteger *&nbsp;nparams</var>, <var class="pdparam">PSUnsignedInteger *&nbsp;nfreevars</var><code>)</code>;</p></div><p>
2859                 retrieves number of parameters and number of freevariables from a pscript closure.
2860             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2861                 the target VM
2862             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2863                 index of the target closure
2864             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUnsignedInteger *&nbsp;nparams</tt></i></span></dt><dd><p>
2865                 a pointer to an unsigned integer that will store the number of parameters
2866             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUnsignedInteger *&nbsp;nfreevars</tt></i></span></dt><dd><p>
2867                 a pointer to an unsigned integer that will store the number of free variables
2868             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2869                 an PSRESULT
2870             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getclosurename"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getclosurename<a class="indexterm" name="d0e6206"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getclosurename</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
2871         pushes the name of the closure at poistion idx in the stack. Note that the name can be a string or null 
2872         if the closure is anonymous or a native closure with no name assigned to it.
2873       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2874         the target VM
2875       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2876         index of the target closure
2877       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2878         an PSRESULT
2879       <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getfloat"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getfloat<a class="indexterm" name="d0e6260"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getfloat</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSFloat *&nbsp;f</var><code>)</code>;</p></div><p>
2880                 gets the value of the float at the idx position in the stack.
2881             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2882                 the target VM
2883             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2884                 an index in the stack
2885             </p></dd><dt><span class="term"><i class="parameter"><tt>PSFloat *&nbsp;f</tt></i></span></dt><dd><p>
2886                 A pointer to the float that will store the value
2887             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2888                 a PSRESULT
2889             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_gethash"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_gethash<a class="indexterm" name="d0e6323"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSHash&nbsp;<b class="fsfunc">ps_gethash</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
2890         returns the hash key of a value at the idx position in the stack.
2891       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2892         the target VM
2893       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2894         an index in the stack
2895       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2896         the hash key of the value at the position idx in the stack
2897       <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
2898         the hash value function is the same used by the VM.
2899       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getinstanceup"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getinstanceup<a class="indexterm" name="d0e6383"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getinstanceup</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSUserPointer *&nbsp;up</var>, <var class="pdparam">PSUSerPointer&nbsp;typetag</var><code>)</code>;</p></div><p>
2900                 gets the userpointer of the class instance at position idx in the stack.
2901                 if the parameter 'typetag' is different than 0, the function checks that the class or a base
2902                 class of the instance is tagged with the specified tag; if not the function fails.
2903                 If 'typetag' is 0 the function will ignore the tag check.
2904             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2905                 the target VM
2906             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2907                 an index in the stack
2908             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer *&nbsp;up</tt></i></span></dt><dd><p>
2909                 a pointer to the userpointer that will store the result
2910             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUSerPointer&nbsp;typetag</tt></i></span></dt><dd><p>
2911                 the typetag that has to be checked, if this value is set to 0 the typetag is ignored.
2912             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2913                 a PSRESULT
2914             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getinteger"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getinteger<a class="indexterm" name="d0e6455"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getinteger</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSInteger *&nbsp;i</var><code>)</code>;</p></div><p>
2915                 gets the value of the integer at the idx position in the stack.
2916             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2917                 the target VM
2918             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2919                 an index in the stack
2920             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger *&nbsp;i</tt></i></span></dt><dd><p>
2921                 A pointer to the integer that will store the value
2922             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2923                 a PSRESULT
2924             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getmemberhandle"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getmemberhandle<a class="indexterm" name="d0e6518"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getmemberhandle</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">HPSMEMBERHANDLE*&nbsp;handle</var><code>)</code>;</p></div><p>
2925         pops a value from the stack and uses it as index to fetch the handle of a class member.
2926         The handle can be later used to set or get the member value using ps_getbyhandle(),ps_setbyhandle().
2927       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2928         the target VM
2929       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2930         an index in the stack pointing to the class
2931       </p></dd><dt><span class="term"><i class="parameter"><tt>HPSMEMBERHANDLE*&nbsp;handle</tt></i></span></dt><dd><p>
2932         a pointer to the variable that will store the handle
2933       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>a PSRESULT<br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
2934         This method works only with classes and instances. 
2935         A handle retrieved through a class can be later used to set or get values from one of the class instances and vice-versa.
2936         Handles retrieved from base classes are still valid in derived classes and respect inheritance rules.
2937       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getscratchpad"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getscratchpad<a class="indexterm" name="d0e6587"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSChar *&nbsp;<b class="fsfunc">ps_getscratchpad</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;minsize</var><code>)</code>;</p></div><p>
2938                 returns a pointer to a memory buffer that is at least as big as minsize.
2939             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2940                 the target VM
2941             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;minsize</tt></i></span></dt><dd><p>
2942                 the requested size for the scratchpad buffer
2943             </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
2944                 the buffer is valid until the next call to ps_getscratchpad
2945             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getsize"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getsize<a class="indexterm" name="d0e6640"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSObjectType&nbsp;<b class="fsfunc">ps_getsize</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
2946         returns the size of a value at the idx position in the stack, if the value is a class or a class instance
2947         the size returned is the size of the userdata buffer(see ps_setclassudsize).
2948       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2949         the target VM
2950       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2951         an index in the stack
2952       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2953         the size of the value at the position idx in the stack
2954       <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
2955         this function only works with strings,arrays,tables,classes,instances and userdata if the value is not a valid type
2956         types the function will return &#8211;1.
2957       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getstring"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getstring<a class="indexterm" name="d0e6700"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getstring</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">const PSChar **&nbsp;c</var><code>)</code>;</p></div><p>
2958                 gets a pointer to the string at the idx position in the stack.
2959             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2960                 the target VM
2961             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2962                 an index in the stack
2963             </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar **&nbsp;c</tt></i></span></dt><dd><p>
2964                 a pointer to the pointer that will point to the string
2965             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2966                 a PSRESULT
2967             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getthread"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getthread<a class="indexterm" name="d0e6763"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getthread</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">HPSCRIPTVM*&nbsp;v</var><code>)</code>;</p></div><p>
2968                 gets a a pointer to the thread the idx position in the stack.
2969             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2970                 the target VM
2971             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2972                 an index in the stack
2973             </p></dd><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM*&nbsp;v</tt></i></span></dt><dd><p>
2974                 A pointer to the variable that will store the thread pointer
2975             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2976                 a PSRESULT
2977             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_gettype"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_gettype<a class="indexterm" name="d0e6826"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSObjectType&nbsp;<b class="fsfunc">ps_gettype</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
2978                 returns the type of the value at the position idx in the stack
2979             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2980                 the target VM
2981             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2982                 an index in the stack
2983             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2984             the type of the value at the position idx in the stack
2985             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_gettypetag"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_gettypetag<a class="indexterm" name="d0e6880"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_gettypetag</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSUserPointer *&nbsp;typetag</var><code>)</code>;</p></div><p>
2986                 gets the typetag of the object(userdata or class) at position idx in the stack.
2987             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
2988                 the target VM
2989             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
2990                 an index in the stack
2991             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer *&nbsp;typetag</tt></i></span></dt><dd><p>
2992                 a pointer to the variable that will store the tag
2993             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
2994                 a PSRESULT
2995             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
2996                 the function works also with instances. if the taget object is an instance,
2997                 the typetag of it's base class is fetched.
2998             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getuserdata"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getuserdata<a class="indexterm" name="d0e6949"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getuserdata</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSUserPointer *&nbsp;p</var>, <var class="pdparam">PSUserPointer *&nbsp;typetag</var><code>)</code>;</p></div><p>
2999                 gets a pointer to the value of the userdata at the idx position in the stack.
3000             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3001                 the target VM
3002             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3003                 an index in the stack
3004             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer *&nbsp;p</tt></i></span></dt><dd><p>
3005                 A pointer to the userpointer that will point to the userdata's payload
3006             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer *&nbsp;typetag</tt></i></span></dt><dd><p>
3007                 A pointer to a PSUserPointer that will store the userdata tag(see ps_settypetag).
3008                 The parameter can be NULL.
3009             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3010                 a PSRESULT
3011             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getuserpointer"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getuserpointer<a class="indexterm" name="d0e7021"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getuserpointer</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSUserPointer *&nbsp;p</var><code>)</code>;</p></div><p>
3012                 gets the value of the userpointer at the idx position in the stack.
3013             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3014                 the target VM
3015             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3016                 an index in the stack
3017             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer *&nbsp;p</tt></i></span></dt><dd><p>
3018                 A pointer to the userpointer that will store the value
3019             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3020                 a PSRESULT
3021             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_newarray"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_newarray<a class="indexterm" name="d0e7084"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_newarray</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;size</var><code>)</code>;</p></div><p>
3022                 creates a new array and pushes it in the stack
3023             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3024                 the target VM
3025             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;size</tt></i></span></dt><dd><p>
3026                 the size of the array that as to be created
3027             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_newclass"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_newclass<a class="indexterm" name="d0e7131"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_newclass</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSBool&nbsp;hasbase</var><code>)</code>;</p></div><p>
3028                 creates a new class object. If the parameter 'hasbase' is different than 0,
3029                 the function pops a class from the stack and inherits the new created class from it.
3030             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3031                 the target VM
3032             </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;hasbase</tt></i></span></dt><dd><p>
3033                 if the parameter is true the function expects
3034                 a base class on top of the stack.
3035             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3036                 a PSRESULT
3037             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_newclosure"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_newclosure<a class="indexterm" name="d0e7185"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_newclosure</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">HPSFUNCTION&nbsp;func</var>, <var class="pdparam">PSInteger&nbsp;nfreevars</var><code>)</code>;</p></div><p>
3038                 create a new native closure, pops n values set those as free variables of the new
3039                 closure, and push the new closure in the stack.
3040             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3041                 the target VM
3042             </p></dd><dt><span class="term"><i class="parameter"><tt>HPSFUNCTION&nbsp;func</tt></i></span></dt><dd><p>
3043                 a pointer to a native-function
3044             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;nfreevars</tt></i></span></dt><dd><p>
3045                 number of free variables(can be 0)
3046             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_newtable"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_newtable<a class="indexterm" name="d0e7241"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_newtable</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
3047                 creates a new table and pushes it in the stack
3048             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3049                 the target VM
3050             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_newtableex"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_newtableex<a class="indexterm" name="d0e7279"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_newtableex</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;initialcapacity</var><code>)</code>;</p></div><p>
3051         creates a new table and pushes it in the stack. 
3052         This function allows to specify the initial capacity of the table to prevent unnecessary rehashing
3053         when the number of slots required is known at creation-time.
3054       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3055         the target VM
3056       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;initialcapacity</tt></i></span></dt><dd><p>
3057         number of key/value pairs to preallocate
3058       </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_newuserdata"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_newuserdata<a class="indexterm" name="d0e7326"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSUserPointer&nbsp;<b class="fsfunc">ps_newuserdata</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSUnsignedInteger&nbsp;size</var><code>)</code>;</p></div><p>
3059                 creates a new userdata and pushes it in the stack
3060             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3061                 the target VM
3062             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUnsignedInteger&nbsp;size</tt></i></span></dt><dd><p>
3063                 the size of the userdata that as to be created in bytes
3064             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_pushbool"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_pushbool<a class="indexterm" name="d0e7373"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_pushbool</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSBool&nbsp;b</var><code>)</code>;</p></div><p>
3065                 pushes a bool into the stack
3066             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3067                 the target VM
3068             </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;b</tt></i></span></dt><dd><p>
3069                 the bool that has to be pushed(PSTrue or PSFalse)
3070             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_pushfloat"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_pushfloat<a class="indexterm" name="d0e7420"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_pushfloat</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSFloat&nbsp;f</var><code>)</code>;</p></div><p>
3071                 pushes a float into the stack
3072             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3073                 the target VM
3074             </p></dd><dt><span class="term"><i class="parameter"><tt>PSFloat&nbsp;f</tt></i></span></dt><dd><p>
3075                 the float that has to be pushed
3076             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_pushinteger"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_pushinteger<a class="indexterm" name="d0e7467"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_pushinteger</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;n</var><code>)</code>;</p></div><p>
3077                 pushes a integer into the stack
3078             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3079                 the target VM
3080             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;n</tt></i></span></dt><dd><p>
3081                 the integer that has to be pushed
3082             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_pushnull"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_pushnull<a class="indexterm" name="d0e7514"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_pushnull</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
3083                 pushes a null value into the stack
3084             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3085                 the target VM
3086             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_pushstring"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_pushstring<a class="indexterm" name="d0e7552"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_pushstring</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">const PSChar *&nbsp;s</var>, <var class="pdparam">PSInteger&nbsp;len</var><code>)</code>;</p></div><p>
3087                 pushes a string in the stack
3088             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3089                 the target VM
3090             </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar *&nbsp;s</tt></i></span></dt><dd><p>
3091                 pointer to the string that has to be pushed
3092             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;len</tt></i></span></dt><dd><p>
3093                 lenght of the string pointed by s
3094             </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
3095                 if the parameter len is less than 0 the VM will calculate the length using strlen(s)
3096             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_pushuserpointer"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_pushuserpointer<a class="indexterm" name="d0e7614"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_pushuserpointer</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSUserPointer&nbsp;p</var><code>)</code>;</p></div><p>
3097                 pushes a userpointer into the stack
3098             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3099                 the target VM
3100             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer&nbsp;p</tt></i></span></dt><dd><p>
3101                 the pointer that as to be pushed
3102             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setbyhandle"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setbyhandle<a class="indexterm" name="d0e7661"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_setbyhandle</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">HPSMEMBERHANDLE*&nbsp;handle</var><code>)</code>;</p></div><p>
3103         pops a value from the stack and sets it to a class or instance member using a member handle (see ps_getmemberhandle)
3104       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3105         the target VM
3106       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3107         an index in the stack pointing to the class
3108       </p></dd><dt><span class="term"><i class="parameter"><tt>HPSMEMBERHANDLE*&nbsp;handle</tt></i></span></dt><dd><p>
3109         a pointer the member handle
3110       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>a PSRESULT<br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setclassudsize"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setclassudsize<a class="indexterm" name="d0e7724"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_setclassudsize</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSInteger&nbsp;udsize</var><code>)</code>;</p></div><p>
3111         Sets the user data size of a class.
3112         If a class 'user data size' is greater than 0. When an instance of the class is created
3113         additional space will is reserved at the end of the memory chunk where the instance is stored. 
3114         The userpointer of the instance will also be automatically set to this memory area.
3115         This allows to minimize allocations in applications that have to carry data along with the class instance.
3116       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3117         the target VM
3118       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3119         an index in the stack pointing to the class
3120       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;udsize</tt></i></span></dt><dd><p>
3121         size in bytes reserved for user data
3122       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3123         a PSRESULT
3124       <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setinstanceup"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setinstanceup<a class="indexterm" name="d0e7787"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_setinstanceup</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSUserPointer&nbsp;up</var><code>)</code>;</p></div><p>
3125                 sets the userpointer of the class instance at position idx in the stack.
3126             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3127                 the target VM
3128             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3129                 an index in the stack
3130             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer&nbsp;up</tt></i></span></dt><dd><p>
3131                 an arbitrary user pointer
3132             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3133                 a PSRESULT
3134             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setnativeclosurename"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setnativeclosurename<a class="indexterm" name="d0e7850"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_setnativeclosurename</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">const PSChar *&nbsp;name</var><code>)</code>;</p></div><p>
3135                 sets the name of the native closure at the position idx in the stack.
3136                 the name of a native closure is purely for debug pourposes. The name is retieved
3137                 trough the function ps_stackinfos() while the closure is in the call stack.
3138             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3139                 the target VM
3140             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3141                 index of the target native closure
3142             </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar *&nbsp;name</tt></i></span></dt><dd><p>
3143                 the name that has to be set
3144             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3145                 an PSRESULT
3146             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setparamscheck"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setparamscheck<a class="indexterm" name="d0e7913"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_setparamscheck</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;nparamscheck</var>, <var class="pdparam">const PSChar *&nbsp;typemask</var><code>)</code>;</p></div><p>
3147                 Sets the parameters validation scheme for the native closure at
3148                 the top position in the stack.
3149                 Allows to validate the number of paramters accepted by the function
3150                 and optionally their types. If the function call do not comply with
3151                 the parameter schema set by ps_setparamscheck, an exception is thrown.
3152             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3153                 the target VM
3154             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;nparamscheck</tt></i></span></dt><dd><p>
3155                 defines the parameters number check policy(0 disable the param checking).
3156                 if nparamscheck is greater than 0 the VM ensures that the number of parameters is exactly the
3157                 number specified in nparamscheck(eg. if nparamscheck == 3 the function can only be called with 3 parameters).
3158                 if nparamscheck is less than 0 the VM ensures that the closure is called with at least the absolute value
3159                 of the number specified in nparamcheck(eg. nparamscheck == -3 will check that the function is called with at least 3 parameters).
3160                 the hidden paramater 'this' is included in this number free variables aren't.
3161                 If PS_MATCHTYPEMASKSTRING is passed instead of the number of parameters, the function will automatically extrapolate
3162                 the number of parameters to check from the typemask(eg. if the typemask is ".sn" is like passing 3).
3163             </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar *&nbsp;typemask</tt></i></span></dt><dd><p>
3164                 defines a mask to validate the parametes types passed to the function.
3165                 if the parameter is NULL no typechecking is applyed(default).
3166             </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
3167                 The typemask consists in a zero teminated string that represent the expected parameter type.
3168                 The types are expressed as follows: 'o' null, 'i' integer, 'f' float, 'n' integer or float, 's' string, 't' table,
3169                 'a' array, 'u' userdata, 'c' closure and nativeclosure, 'g' generator, 'p' userpointer, 'v' thread, 'x' instance(class instance),
3170                 'y' class, 'b' bool.
3171                 and '.' any type. The symbol '|' can be used as 'or' to accept multiple types on the same parameter.
3172                 There isn't any limit on the number of 'or' that can be used. Spaces are ignored so can be inserted between types
3173                 to increase readbility.
3174                 For instance to check a function that espect a table as 'this' a string as first parameter and
3175                 a number or a userpointer as second parameter, the string would be "tsn|p" (table,string,number or userpointer).
3176                 If the parameters mask is contains less parameters than 'nparamscheck' the remaining parameters will
3177                 not be typechecked.
3178             </p></dd><dt><span class="term">eg.</span></dt><dd><pre class="programlisting">
3179 //example
3180 PSInteger testy(HPSCRIPTVM v)
3181 {
3182     PSUserPointer p;
3183     const PSChar *s;
3184     PSInteger i;
3185     //no type checking, if the call comply to the mask 
3186     //surely the functions will succeed.
3187     ps_getuserdata(v,1,&amp;p,NULL);
3188     ps_getstring(v,2,&amp;s);
3189     ps_getinteger(v,3,&amp;i);
3190     //... do something
3191     return 0;
3192 }
3193 
3194 //the reg code
3195 
3196 //....stuff
3197 ps_newclosure(v,testy,0);
3198 //expects exactly 3 parameters(userdata,string,number)
3199 ps_setparamscheck(v,3,_SC("usn")); 
3200 //....stuff
3201             </pre></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setreleasehook"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setreleasehook<a class="indexterm" name="d0e7982"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_setreleasehook</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSRELEASEHOOK&nbsp;hook</var><code>)</code>;</p></div><p>
3202         sets the release hook of the userdata, class instance or class at position idx in the stack.
3203       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3204                 the target VM
3205             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3206                 an index in the stack
3207             </p></dd><dt><span class="term"><i class="parameter"><tt>PSRELEASEHOOK&nbsp;hook</tt></i></span></dt><dd><p>
3208                 a function pointer to the hook(see sample below)
3209             </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
3210                 the function hook is called by the VM before the userdata memory is deleted.
3211             </p></dd><dt><span class="term">eg.</span></dt><dd><pre class="programlisting">
3212 
3213 /* tyedef PSInteger (*PSRELEASEHOOK)(PSUserPointer,PSInteger size); */
3214 
3215 PSInteger my_release_hook(PSUserPointer p,PSInteger size)
3216 {
3217     /* do something here */
3218     return 1;
3219 }
3220                 </pre></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_settypetag"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_settypetag<a class="indexterm" name="d0e8051"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_settypetag</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSUserPointer&nbsp;typetag</var><code>)</code>;</p></div><p>
3221                 sets the typetag of the object(userdata or class) at position idx in the stack.
3222             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3223                 the target VM
3224             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3225                 an index in the stack
3226             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer&nbsp;typetag</tt></i></span></dt><dd><p>
3227                 an arbitrary PSUserPointer
3228             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3229                 a PSRESULT
3230             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_tobool"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_tobool<a class="indexterm" name="d0e8114"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_tobool</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSBool *&nbsp;b</var><code>)</code>;</p></div><p>
3231         gets the value at position idx in the stack as bool. 
3232       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3233         the target VM
3234       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3235         an index in the stack
3236       </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool *&nbsp;b</tt></i></span></dt><dd><p>
3237         A pointer to the bool that will store the value
3238       </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
3239         if the object is not a bool the function converts the value too bool 
3240         according to pscript's rules.
3241         For instance the number 1 will result in true, and the number 0 in false.
3242       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_tostring"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_tostring<a class="indexterm" name="d0e8176"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_tostring</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3243         converts the object at position idx in the stack to string and pushes the
3244         resulting string in the stack.
3245       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3246         the target VM
3247       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3248         an index in the stack
3249       </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_typeof"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_typeof<a class="indexterm" name="d0e8223"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSObjectType&nbsp;<b class="fsfunc">ps_typeof</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3250         pushes the type name of the value at the position idx in the stack, 
3251         it also invokes the _typeof metamethod for tables and class instances that implement it;
3252         in that case the pushed object could be something other than a string (is up to the _typeof implementation).
3253       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3254         the target VM
3255       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3256         an index in the stack
3257       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3258         a PSRESULT
3259       <br></p></dd></dl></div></div></div><div class="reference" lang="en"><a name="d0e8266"></a><div class="titlepage"><div><div><h1 class="title"><a name="d0e8266"></a>Calls</h1></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ps_call">ps_call</a> - </dt><dt><a href="#ps_getcallee">ps_getcallee</a> - </dt><dt><a href="#ps_getlasterror">ps_getlasterror</a> - </dt><dt><a href="#ps_getlocal">ps_getlocal</a> - </dt><dt><a href="#ps_reseterror">ps_reseterror</a> - </dt><dt><a href="#ps_resume">ps_resume</a> - </dt><dt><a href="#ps_throwerror">ps_throwerror</a> - </dt><dt><a href="#ps_throwobject">ps_throwobject</a> - </dt></dl></div><div class="refentry" lang="en"><a name="ps_call"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_call<a class="indexterm" name="d0e8280"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_call</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;params</var>, <var class="pdparam">PSBool&nbsp;retval</var>, <var class="pdparam">PSBool&nbsp;raiseerror</var><code>)</code>;</p></div><p>
3260                 calls a closure or a native closure.
3261             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3262                 the target VM
3263             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;params</tt></i></span></dt><dd><p>
3264                 number of parameters of the function
3265             </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;retval</tt></i></span></dt><dd><p>
3266                 if true the function will push the return value in the stack
3267             </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;raiseerror</tt></i></span></dt><dd><p>
3268         if true, if a runtime error occurs during the execution of the call,
3269         the vm will invoke the error handler.
3270       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3271                 a PSRESULT
3272             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3273                 the function pops all the parameters and leave the closure in the stack; 
3274                 if retval is true the return value of the closure is pushed.
3275                 If the execution of the function is suspended through ps_suspendvm(), the closure
3276                 and the arguments will not be automatically popped from the stack.
3277             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getcallee"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getcallee<a class="indexterm" name="d0e8358"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getcallee</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
3278         push in the stack the currently running closure.
3279       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3280         the target VM
3281       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3282         a PSRESULT
3283       <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getlasterror"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getlasterror<a class="indexterm" name="d0e8403"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getlasterror</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
3284                 pushes the last error in the stack.
3285             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3286                 the target VM
3287             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3288                 a PSRESULT
3289             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3290                 the pushed error descriptor can be any valid pscript type.
3291             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getlocal"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getlocal<a class="indexterm" name="d0e8454"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">const PSChar *&nbsp;<b class="fsfunc">ps_getlocal</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSUnsignedInteger&nbsp;level</var>, <var class="pdparam">PSUnsignedInteger&nbsp;nseq</var><code>)</code>;</p></div><p>
3292                 Returns the name of a local variable given stackframe and sequence in the stack and
3293                 pushes is current value.
3294         Free variables are treated as local variables, by ps_getlocal(), and will be returned 
3295         as they would be at the base of the stack, just before the real local variables.
3296             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3297                 the target VM
3298             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUnsignedInteger&nbsp;level</tt></i></span></dt><dd><p>
3299                 the function index in the calls stack, 0 is the current function
3300             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUnsignedInteger&nbsp;nseq</tt></i></span></dt><dd><p>
3301                 the index of the local variable in the stack frame (0 is &#8216;this&#8217;)
3302             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3303                 the name of the local variable if a variable exists at the given level/seq otherwise NULL.
3304             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_reseterror"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_reseterror<a class="indexterm" name="d0e8517"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_reseterror</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
3305                 reset the last error in the virtual machine to null
3306             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3307                 the target VM
3308             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_resume"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_resume<a class="indexterm" name="d0e8555"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_resume</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSBool&nbsp;retval</var>, <var class="pdparam">PSBool&nbsp;raiseerror</var><code>)</code>;</p></div><p>
3309                 resumes the generator at the top position of the stack.
3310             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3311                 the target VM
3312             </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;retval</tt></i></span></dt><dd><p>
3313                 if true the function will push the return value in the stack
3314             </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;raiseerror</tt></i></span></dt><dd><p>
3315         if true, if a runtime error occurs during the execution of the call, 
3316         the vm will invoke the error handler.
3317       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3318                 a PSRESULT
3319             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3320                 if retval != 0 the return value of the generator is pushed.
3321             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_throwerror"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_throwerror<a class="indexterm" name="d0e8624"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_throwerror</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">const PSChar *&nbsp;err</var><code>)</code>;</p></div><p>
3322                 sets the last error in the virtual machine and returns the value that has to be
3323                 returned by a native closure in order to trigger an exception in the virtual machine.
3324             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3325                 the target VM
3326             </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar *&nbsp;err</tt></i></span></dt><dd><p>
3327                 the description of the error that has to be thrown
3328             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3329                 the value that has to be returned by a native closure in order to throw an exception in
3330                 the virtual machine.
3331             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_throwobject"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_throwobject<a class="indexterm" name="d0e8678"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_throwobject</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
3332         pops a value from the stack sets it as the last error in the virtual machine. Returns the value that has to be
3333         returned by a native closure in order to trigger an exception in the virtual machine (aka PS_ERROR).
3334       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3335         the target VM
3336       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3337         the value that has to be returned by a native closure in order to throw an exception in
3338         the virtual machine.
3339       <br></p></dd></dl></div></div></div><div class="reference" lang="en"><a name="d0e8712"></a><div class="titlepage"><div><div><h1 class="title"><a name="d0e8712"></a>Objects manipulation</h1></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ps_arrayappend">ps_arrayappend</a> - </dt><dt><a href="#ps_arrayinsert">ps_arrayinsert</a> - </dt><dt><a href="#ps_arraypop">ps_arraypop</a> - </dt><dt><a href="#ps_arrayremove">ps_arrayremove</a> - </dt><dt><a href="#ps_arrayresize">ps_arrayresize</a> - </dt><dt><a href="#ps_arrayreverse">ps_arrayreverse</a> - </dt><dt><a href="#ps_clear">ps_clear</a> - </dt><dt><a href="#ps_clone">ps_clone</a> - </dt><dt><a href="#ps_createslot">ps_createslot</a> - </dt><dt><a href="#ps_deleteslot">ps_deleteslot</a> - </dt><dt><a href="#ps_get">ps_get</a> - </dt><dt><a href="#ps_getattributes">ps_getattributes</a> - </dt><dt><a href="#ps_getclass">ps_getclass</a> - </dt><dt><a href="#ps_getdelegate">ps_getdelegate</a> - </dt><dt><a href="#ps_getfreevariable">ps_getfreevariable</a> - </dt><dt><a href="#ps_getweakrefval">ps_getweakrefval</a> - </dt><dt><a href="#ps_instanceof">ps_instanceof</a> - </dt><dt><a href="#ps_newmember">ps_newmember</a> - </dt><dt><a href="#ps_newslot">ps_newslot</a> - </dt><dt><a href="#ps_next">ps_next</a> - </dt><dt><a href="#ps_rawdeleteslot">ps_rawdeleteslot</a> - </dt><dt><a href="#ps_rawget">ps_rawget</a> - </dt><dt><a href="#ps_rawnewmember">ps_rawnewmember</a> - </dt><dt><a href="#ps_rawset">ps_rawset</a> - </dt><dt><a href="#ps_set">ps_set</a> - </dt><dt><a href="#ps_setattributes">ps_setattributes</a> - </dt><dt><a href="#ps_setdelegate">ps_setdelegate</a> - </dt><dt><a href="#ps_setfreevariable">ps_setfreevariable</a> - </dt><dt><a href="#ps_weakref">ps_weakref</a> - </dt></dl></div><div class="refentry" lang="en"><a name="ps_arrayappend"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_arrayappend<a class="indexterm" name="d0e8726"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_arrayappend</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3340                 pops a value from the stack and pushes it in the back of the array at the position idx
3341                 in the stack.
3342             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3343                 the target VM
3344             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3345                 index of the target array in the stack
3346             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3347                 a PSRESULT
3348             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3349                 Only works on arrays.
3350             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_arrayinsert"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_arrayinsert<a class="indexterm" name="d0e8786"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_arrayinsert</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSInteger&nbsp;destpos</var><code>)</code>;</p></div><p>
3351         pops a value from the stack and inserts it in an array at the specified position
3352       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3353         the target VM
3354       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3355         index of the target array in the stack
3356       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;destpos</tt></i></span></dt><dd><p>
3357         the postion in the array where the item has to be inserted
3358       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3359         a PSRESULT
3360       <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3361         Only works on arrays.
3362       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_arraypop"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_arraypop<a class="indexterm" name="d0e8855"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_arraypop</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3363                 pops a value from the back of the array at the position idx in the stack.
3364             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3365                 the target VM
3366             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3367                 index of the target array in the stack
3368             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3369                 a PSRESULT
3370             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3371                 Only works on arrays.
3372             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_arrayremove"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_arrayremove<a class="indexterm" name="d0e8915"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_arrayremove</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSInteger&nbsp;itemidx</var><code>)</code>;</p></div><p>
3373         removes an item from an array
3374       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3375         the target VM
3376       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3377         index of the target array in the stack
3378       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;itemidx</tt></i></span></dt><dd><p>
3379         the index of the item in the array that has to be removed
3380       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3381         a PSRESULT
3382       <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3383         Only works on arrays.
3384       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_arrayresize"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_arrayresize<a class="indexterm" name="d0e8984"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_arrayresize</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSInteger&nbsp;newsize</var><code>)</code>;</p></div><p>
3385                 resizes the array at the position idx in the stack.
3386             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3387                 the target VM
3388             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3389                 index of the target array in the stack
3390             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;newsize</tt></i></span></dt><dd><p>
3391                 requested size of the array
3392             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3393                 a PSRESULT
3394             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3395                 Only works on arrays.if newsize if greater than the current size
3396                 the new array slots will be filled with nulls.
3397             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_arrayreverse"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_arrayreverse<a class="indexterm" name="d0e9053"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_arrayreverse</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3398                 reverse an array in place.
3399             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3400                 the target VM
3401             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3402                 index of the target array in the stack
3403             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3404                 a PSRESULT
3405             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3406                 Only works on arrays.
3407             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_clear"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_clear<a class="indexterm" name="d0e9113"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_clear</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3408         clears all the element of the table/array at position idx in the stack.
3409       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3410         the target VM
3411       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3412         index of the target object in the stack
3413       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3414         a PSRESULT
3415       <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3416         Only works on tables and arrays.
3417       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_clone"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_clone<a class="indexterm" name="d0e9173"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_clone</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3418                 Clones the table, array or class instance at the position idx, clones it and pushes the new object in
3419                 the stack.
3420             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3421                 the target VM
3422             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3423                 index of the target object in the stack
3424             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3425                 a PSRESULT
3426             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_createslot"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_createslot<a class="indexterm" name="d0e9227"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_createslot</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3427                 pops a key and a value from the stack and performs a set operation on the table or class that is at
3428                 position idx in the stack, if the slot does not exits it will be created.
3429             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3430                 the target VM
3431             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3432                 index of the target table in the stack
3433             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3434                 a PSRESULT
3435             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3436                 invoke the _newslot metamethod in the table delegate. it only works on tables.
3437                 [this function is deperecated since version 2.0.5 use ps_newslot() instead]
3438             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_deleteslot"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_deleteslot<a class="indexterm" name="d0e9287"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_deleteslot</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSBool&nbsp;pushval</var><code>)</code>;</p></div><p>
3439                 pops a key from the stack and delete the slot indexed by it from the table at
3440                 position idx in the stack, if the slot does not exits nothing happens.
3441             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3442                 the target VM
3443             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3444                 index of the target table in the stack
3445             </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;pushval</tt></i></span></dt><dd><p>
3446                 if this param is true the function will push the value
3447                 of the deleted slot.
3448             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3449                 a PSRESULT
3450             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3451                 invoke the _delslot metamethod in the table delegate. it only works on tables.
3452             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_get"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_get<a class="indexterm" name="d0e9356"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_get</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3453                 pops a key from the stack and performs a get operation on the object at the position
3454                 idx in the stack, and pushes the result in the stack.
3455             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3456                 the target VM
3457             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3458                 index of the target object in the stack
3459             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3460                 a PSRESULT
3461             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3462                 this call will invokes the delegation system like a normal dereference it only works on
3463                 tables, arrays and userdata. if the function fails nothing will be pushed in the stack.
3464             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getattributes"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getattributes<a class="indexterm" name="d0e9416"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getattributes</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3465                 Gets the attribute of a class mameber.
3466                 The function pops a key from the stack and pushes the attribute of the class member indexed
3467                 by they key from class at position idx in the stack.
3468                 If key is null the function gets the class level attribute.
3469             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3470                 the target VM
3471             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3472                 index of the target class in the stack
3473             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3474                 a PSRESULT
3475             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getclass"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getclass<a class="indexterm" name="d0e9470"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getclass</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3476                 pushes the class of the 'class instance' at stored position idx in the stack.
3477             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3478                 the target VM
3479             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3480                 index of the target class instance in the stack
3481             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3482                 a PSRESULT
3483             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getdelegate"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getdelegate<a class="indexterm" name="d0e9524"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getdelegate</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3484                 pushes the current delegate of the object at the position idx in the stack.
3485             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3486                 the target VM
3487             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3488                 index of the target object in the stack
3489             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3490                 a PSRESULT
3491             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getfreevariable"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getfreevariable<a class="indexterm" name="d0e9578"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">const PSChar *&nbsp;<b class="fsfunc">ps_getfreevariable</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSInteger&nbsp;nval</var><code>)</code>;</p></div><p>
3492                 gets the value of the free variable of the closure at the position
3493                 idx in the stack.
3494             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3495                 the target VM
3496             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3497                 index of the target object in the stack(closure)
3498             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;nval</tt></i></span></dt><dd><p>
3499                 0 based index of the free variable(relative to the closure).
3500             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3501                 the name of the free variable for pure pscript closures. NULL in case of error or if the
3502                 index of the variable is out of range.
3503         In case the target closure is a native closure, the return name is always "@NATIVE".
3504             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3505                 The function works for both pscript closure and native closure.
3506             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getweakrefval"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getweakrefval<a class="indexterm" name="d0e9647"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getweakrefval</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3507                 pushes the object pointed by the weak reference at position idx in the stack.
3508             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3509                 the target VM
3510             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3511                 index of the target weak reference
3512             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3513                 a PSRESULT
3514             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3515                 if the function fails, nothing is pushed in the stack.
3516             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_instanceof"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_instanceof<a class="indexterm" name="d0e9707"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSBool&nbsp;<b class="fsfunc">ps_instanceof</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
3517         Determintes if an object is an instance of a certain class.
3518         Expects an istance and a class in the stack.
3519       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3520         the target VM
3521       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3522         PSTrue if the instance at position -2 in the stack is an instance of the class object at position -1 in the stack.
3523       <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3524         The function doesn't pop any object from the stack.
3525       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_newmember"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_newmember<a class="indexterm" name="d0e9758"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_newmember</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSBool&nbsp;bstatic</var><code>)</code>;</p></div><p>
3526         pops a key, a value and an object(that will be set as attribute of the member) from the stack and performs a new slot operation on the class that is at
3527         position idx in the stack, if the slot does not exits it will be created.
3528       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3529         the target VM
3530       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3531         index of the target table in the stack
3532       </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;bstatic</tt></i></span></dt><dd><p>
3533         if PSTrue creates a static member.
3534       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3535         a PSRESULT
3536       <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3537         Invokes the _newmember metamethod in the class. it only works on classes.
3538       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_newslot"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_newslot<a class="indexterm" name="d0e9827"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_newslot</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSBool&nbsp;bstatic</var><code>)</code>;</p></div><p>
3539                 pops a key and a value from the stack and performs a set operation on the table or class that is at
3540                 position idx in the stack, if the slot does not exits it will be created.
3541             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3542                 the target VM
3543             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3544                 index of the target table in the stack
3545             </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;bstatic</tt></i></span></dt><dd><p>
3546                 if PSTrue creates a static member. This parameter is only used if the target object
3547                 is a class.
3548             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3549                 a PSRESULT
3550             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3551                 Invokes the _newslot metamethod in the table delegate. it only works on tables and classes.
3552             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_next"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_next<a class="indexterm" name="d0e9896"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_next</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3553                 Pushes in the stack the next key and value of an array, table or class slot.
3554                 To start the iteration this function expects a null value on top of the stack; at every
3555                 call the function will substitute the null value with an iterator and push key and value
3556                 of the container slot. Every iteration the application has to pop the previous key and
3557                 value but leave the iterator(that is used as reference point for the next iteration). The
3558                 function will fail when all slots have been iterated(see Tables and arrays
3559                 manipulation).
3560             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3561                 the target VM
3562             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3563                 index of the target object in the stack
3564             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3565                 a PSRESULT
3566             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_rawdeleteslot"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_rawdeleteslot<a class="indexterm" name="d0e9950"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_rawdeleteslot</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSBool&nbsp;pushval</var><code>)</code>;</p></div><p>
3567                 Deletes a slot from a table without employing the _delslot metamethod.
3568                 pops a key from the stack and delete the slot indexed by it from the table at
3569                 position idx in the stack, if the slot does not exits nothing happens.
3570             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3571                 the target VM
3572             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3573                 index of the target table in the stack
3574             </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;pushval</tt></i></span></dt><dd><p>
3575                 if this param is true the function will push the value
3576                 of the deleted slot.
3577             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3578                 a PSRESULT
3579             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_rawget"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_rawget<a class="indexterm" name="d0e10013"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_rawget</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3580                 pops a key from the stack and performs a get operation on the object at position idx
3581                 in the stack, without employing delegation or metamethods.
3582             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3583                 the target VM
3584             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3585                 index of the target object in the stack
3586             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3587                 a PSRESULT
3588             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3589                 Only works on tables and arrays.
3590             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_rawnewmember"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_rawnewmember<a class="indexterm" name="d0e10073"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_rawnewmember</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSBool&nbsp;bstatic</var><code>)</code>;</p></div><p>
3591         pops a key, a value and an object(that will be set as attribute of the member) from the stack and performs a new slot operation on the class that is at
3592         position idx in the stack, if the slot does not exits it will be created.
3593       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3594         the target VM
3595       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3596         index of the target table in the stack
3597       </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;bstatic</tt></i></span></dt><dd><p>
3598         if PSTrue creates a static member.
3599       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3600         a PSRESULT
3601       <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3602         it only works on classes.
3603       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_rawset"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_rawset<a class="indexterm" name="d0e10142"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_rawset</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3604                 pops a key and a value from the stack and performs a set operation on the object at
3605                 position idx in the stack, without employing delegation or metamethods.
3606             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3607                 the target VM
3608             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3609                 index of the target object in the stack
3610             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3611                 a PSRESULT
3612             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3613                 it only works on tables and arrays. if the function fails nothing will be pushed in the stack.
3614             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_set"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_set<a class="indexterm" name="d0e10202"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_set</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3615                 pops a key and a value from the stack and performs a set operation on the object at
3616                 position idx in the stack.
3617             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3618                 the target VM
3619             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3620                 index of the target object in the stack
3621             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3622                 a PSRESULT
3623             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3624                 this call will invoke the delegation system like a normal assignment, it only works on
3625                 tables, arrays and userdata.
3626             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setattributes"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setattributes<a class="indexterm" name="d0e10262"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_setattributes</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3627                 Sets the attribute of a class mameber.
3628                 The function pops a key and a value from the stack and sets the attribute (indexed
3629                 by they key) on the class at position idx in the stack.
3630                 If key is null the function sets the class level attribute.
3631                 If the function succeed, the old attribute value is pushed in the stack.
3632             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3633                 the target VM
3634             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3635                 index of the target class in the stack.
3636             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3637                 a PSRESULT
3638             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setdelegate"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setdelegate<a class="indexterm" name="d0e10316"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_setdelegate</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3639                 pops a table from the stack and sets it as delegate of the object at the position idx in
3640                 the stack.
3641             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3642                 the target VM
3643             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3644                 index of the target object in the stack
3645             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3646                 a PSRESULT
3647             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3648                 to remove the delgate from an object is necessary to use null as delegate instead of a table.
3649             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setfreevariable"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setfreevariable<a class="indexterm" name="d0e10376"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_setfreevariable</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSInteger&nbsp;nval</var><code>)</code>;</p></div><p>
3650                 pops a value from the stack and sets it as free variable of the closure at the position
3651                 idx in the stack.
3652             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3653                 the target VM
3654             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3655                 index of the target object in the stack
3656             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;nval</tt></i></span></dt><dd><p>
3657                 0 based index of the free variable(relative to the closure).
3658             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3659                 a PSRESULT
3660             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_weakref"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_weakref<a class="indexterm" name="d0e10439"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_weakref</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
3661                 pushes a weak reference to the object at position idx in the stack.
3662             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3663                 the target VM
3664             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3665                 index to the target object in the stack
3666             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3667                 a PSRESULT
3668             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3669                 if the object at idx position is an integer,float,bool or null the object
3670                 itself is pushed instead of a weak ref.
3671             </p></dd></dl></div></div></div><div class="reference" lang="en"><a name="d0e10488"></a><div class="titlepage"><div><div><h1 class="title"><a name="d0e10488"></a>Bytecode serialization</h1></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ps_readclosure">ps_readclosure</a> - </dt><dt><a href="#ps_writeclosure">ps_writeclosure</a> - </dt></dl></div><div class="refentry" lang="en"><a name="ps_readclosure"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_readclosure<a class="indexterm" name="d0e10502"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_readclosure</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSREADFUNC&nbsp;readf</var>, <var class="pdparam">PSUserPointer&nbsp;up</var><code>)</code>;</p></div><p>
3672                 serialize (read) a closure and pushes it on top of the stack, the source
3673                 is user defined through a read callback.
3674             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3675                 the target VM
3676             </p></dd><dt><span class="term"><i class="parameter"><tt>PSREADFUNC&nbsp;readf</tt></i></span></dt><dd><p>
3677                 pointer to a read function that will be invoked by the vm during
3678                 the serialization.
3679             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer&nbsp;up</tt></i></span></dt><dd><p>
3680                 pointer that will be passed to each call to the read function
3681             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3682                 a PSRESULT
3683             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_writeclosure"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_writeclosure<a class="indexterm" name="d0e10565"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_writeclosure</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSWRITEFUNC&nbsp;writef</var>, <var class="pdparam">PSUserPointer&nbsp;up</var><code>)</code>;</p></div><p>
3684                 serialize(write) the closure on top of the stack, the desination
3685                 is user defined through a write callback.
3686             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3687                 the target VM
3688             </p></dd><dt><span class="term"><i class="parameter"><tt>PSWRITEFUNC&nbsp;writef</tt></i></span></dt><dd><p>
3689                 pointer to a write function that will be invoked by the vm during
3690                 the serialization.
3691             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer&nbsp;up</tt></i></span></dt><dd><p>
3692                 pointer that will be passed to each call to the write function
3693             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3694                 a PSRESULT
3695             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3696                 closures with free variables cannot be serialized
3697             </p></dd></dl></div></div></div><div class="reference" lang="en"><a name="d0e10623"></a><div class="titlepage"><div><div><h1 class="title"><a name="d0e10623"></a>Raw object handling</h1></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ps_addref">ps_addref</a> - </dt><dt><a href="#ps_getobjtypetag">ps_getobjtypetag</a> - </dt><dt><a href="#ps_getrefcount">ps_getrefcount</a> - </dt><dt><a href="#ps_getstackobj">ps_getstackobj</a> - </dt><dt><a href="#ps_objtobool">ps_objtobool</a> - </dt><dt><a href="#ps_objtofloat">ps_objtofloat</a> - </dt><dt><a href="#ps_objtointeger">ps_objtointeger</a> - </dt><dt><a href="#ps_objtostring">ps_objtostring</a> - </dt><dt><a href="#ps_objtouserpointer">ps_objtouserpointer</a> - </dt><dt><a href="#ps_pushobject">ps_pushobject</a> - </dt><dt><a href="#ps_release">ps_release</a> - </dt><dt><a href="#ps_resetobject">ps_resetobject</a> - </dt></dl></div><div class="refentry" lang="en"><a name="ps_addref"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_addref<a class="indexterm" name="d0e10637"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_addref</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">HPSOBJECT *&nbsp;po</var><code>)</code>;</p></div><p>
3698                 adds a reference to an object handler.
3699             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3700                 the target VM
3701             </p></dd><dt><span class="term"><i class="parameter"><tt>HPSOBJECT *&nbsp;po</tt></i></span></dt><dd><p>
3702                 pointer to an object handler
3703             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getobjtypetag"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getobjtypetag<a class="indexterm" name="d0e10684"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getobjtypetag</b>(</code><var class="pdparam">HPSOBJECT *&nbsp;o</var>, <var class="pdparam">PSUserPointer *&nbsp;typetag</var><code>)</code>;</p></div><p>
3704                 gets the typetag of a raw object reference(userdata or class).
3705             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSOBJECT *&nbsp;o</tt></i></span></dt><dd><p>
3706                 pointer to an object handler
3707             </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer *&nbsp;typetag</tt></i></span></dt><dd><p>
3708                 a pointer to the variable that will store the tag
3709             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3710                 a PSRESULT
3711             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3712                 the function works also with instances. if the taget object is an instance,
3713                 the typetag of it's base class is fetched.
3714             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getrefcount"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getrefcount<a class="indexterm" name="d0e10744"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSUnsignedInteger&nbsp;<b class="fsfunc">ps_getrefcount</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">HPSOBJECT&nbsp;*po</var><code>)</code>;</p></div><p>
3715         returns the number of references of a given object.
3716       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3717         the target VM
3718       </p></dd><dt><span class="term"><i class="parameter"><tt>HPSOBJECT&nbsp;*po</tt></i></span></dt><dd><p>
3719         object handler
3720       </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_getstackobj"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getstackobj<a class="indexterm" name="d0e10791"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getstackobj</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">HPSOBJECT *&nbsp;po</var><code>)</code>;</p></div><p>
3721                 gets an object from the stack and stores it in a object handler.
3722             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3723                 the target VM
3724             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
3725                 index of the target object in the stack
3726             </p></dd><dt><span class="term"><i class="parameter"><tt>HPSOBJECT *&nbsp;po</tt></i></span></dt><dd><p>
3727                 pointer to an object handler
3728             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3729                 a PSRESULT
3730             <br></p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_objtobool"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_objtobool<a class="indexterm" name="d0e10854"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSBool&nbsp;<b class="fsfunc">ps_objtobool</b>(</code><var class="pdparam">HPSOBJECT *&nbsp;po</var><code>)</code>;</p></div><p>
3731                 return the bool value of a raw object reference.
3732             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSOBJECT *&nbsp;po</tt></i></span></dt><dd><p>
3733                 pointer to an object handler
3734             </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
3735                 If the object is not a bool will always return false.
3736             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_objtofloat"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_objtofloat<a class="indexterm" name="d0e10898"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSFloat&nbsp;<b class="fsfunc">ps_objtofloat</b>(</code><var class="pdparam">HPSOBJECT *&nbsp;po</var><code>)</code>;</p></div><p>
3737                 return the float value of a raw object reference.
3738             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSOBJECT *&nbsp;po</tt></i></span></dt><dd><p>
3739                 pointer to an object handler
3740             </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
3741                 If the object is an integer will convert it to float.
3742                 If the object is not a number will always return 0.
3743             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_objtointeger"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_objtointeger<a class="indexterm" name="d0e10942"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSInteger&nbsp;<b class="fsfunc">ps_objtointeger</b>(</code><var class="pdparam">HPSOBJECT *&nbsp;po</var><code>)</code>;</p></div><p>
3744                 return the integer value of a raw object reference.
3745             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSOBJECT *&nbsp;po</tt></i></span></dt><dd><p>
3746                 pointer to an object handler
3747             </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
3748                 If the object is a float will convert it to integer.
3749                 If the object is not a number will always return 0.
3750             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_objtostring"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_objtostring<a class="indexterm" name="d0e10986"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">const PSChar *&nbsp;<b class="fsfunc">ps_objtostring</b>(</code><var class="pdparam">HPSOBJECT *&nbsp;po</var><code>)</code>;</p></div><p>
3751                 return the string value of a raw object reference.
3752             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSOBJECT *&nbsp;po</tt></i></span></dt><dd><p>
3753                 pointer to an object handler
3754             </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p> 
3755                 If the object doesn't reference a string it returns NULL.
3756             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_objtouserpointer"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_objtouserpointer<a class="indexterm" name="d0e11030"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSUserPointer&nbsp;<b class="fsfunc">ps_objtouserpointer</b>(</code><var class="pdparam">HPSOBJECT *&nbsp;po</var><code>)</code>;</p></div><p>
3757         return the userpointer value of a raw object reference.
3758       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSOBJECT *&nbsp;po</tt></i></span></dt><dd><p>
3759         pointer to an object handler
3760       </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
3761         If the object doesn't reference a userpointer it returns NULL.
3762       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_pushobject"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_pushobject<a class="indexterm" name="d0e11074"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_pushobject</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">HPSOBJECT&nbsp;obj</var><code>)</code>;</p></div><p>
3763                 push an object referenced by an object handler into the stack.
3764             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3765                 the target VM
3766             </p></dd><dt><span class="term"><i class="parameter"><tt>HPSOBJECT&nbsp;obj</tt></i></span></dt><dd><p>
3767                 object handler
3768             </p></dd></dl></div></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_release"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_release<a class="indexterm" name="d0e11121"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSBool&nbsp;<b class="fsfunc">ps_release</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">HPSOBJECT *&nbsp;po</var><code>)</code>;</p></div><p>
3769                 remove a reference from an object handler.
3770             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3771                 the target VM
3772             </p></dd><dt><span class="term"><i class="parameter"><tt>HPSOBJECT *&nbsp;po</tt></i></span></dt><dd><p>
3773                 pointer to an object handler
3774             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3775                 PSTrue if the object handler released has lost all is references(the ones added with ps_addref).
3776                 PSFalse otherwise.
3777             <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3778                 the function will reset the object handler to null when it losts all references.
3779             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_resetobject"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_resetobject<a class="indexterm" name="d0e11181"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_resetobject</b>(</code><var class="pdparam">HPSOBJECT *&nbsp;po</var><code>)</code>;</p></div><p>
3780                 resets(initialize) an object handler.
3781             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSOBJECT *&nbsp;po</tt></i></span></dt><dd><p>
3782                 pointer to an object handler
3783             </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
3784                 Every object handler has to be initialized with this function.
3785             </p></dd></dl></div></div></div><div class="reference" lang="en"><a name="d0e11214"></a><div class="titlepage"><div><div><h1 class="title"><a name="d0e11214"></a>Garbage Collector</h1></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ps_collectgarbage">ps_collectgarbage</a> - </dt><dt><a href="#ps_resurrectunreachable">ps_resurrectunreachable</a> - </dt></dl></div><div class="refentry" lang="en"><a name="ps_collectgarbage"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_collectgarbage<a class="indexterm" name="d0e11228"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSInteger&nbsp;<b class="fsfunc">ps_collectgarbage</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
3786         runs the garbage collector and returns the number of reference cycles found(and deleted)
3787       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3788         the target VM
3789       </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
3790         this api only works with gabage collector builds (NO_GARBAGE_COLLECTOR is not defined)
3791       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_resurrectunreachable"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_resurrectunreachable<a class="indexterm" name="d0e11272"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_resurrectunreachable</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
3792         runs the garbage collector and pushes an array in the stack containing all unreachable object found.
3793         If no unreachable object is found, null is pushed instead. This function is meant to help debugging reference cycles.
3794       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3795         the target VM
3796       </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
3797         this api only works with gabage collector builds (NO_GARBAGE_COLLECTOR is not defined)
3798       </p></dd></dl></div></div></div><div class="reference" lang="en"><a name="d0e11305"></a><div class="titlepage"><div><div><h1 class="title"><a name="d0e11305"></a>Debug interface</h1></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ps_getfunctioninfo">ps_getfunctioninfo</a> - </dt><dt><a href="#ps_setdebughook">ps_setdebughook</a> - </dt><dt><a href="#ps_setnativedebughook">ps_setnativedebughook</a> - </dt><dt><a href="#ps_stackinfos">ps_stackinfos</a> - </dt></dl></div><div class="refentry" lang="en"><a name="ps_getfunctioninfo"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_getfunctioninfo<a class="indexterm" name="d0e11319"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_getfunctioninfo</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;level</var>, <var class="pdparam">PSFunctionInfo *&nbsp;fi</var><code>)</code>;</p></div><p></p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3799         the target VM
3800       </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;level</tt></i></span></dt><dd><p>
3801         calls stack level
3802       </p></dd><dt><span class="term"><i class="parameter"><tt>PSFunctionInfo *&nbsp;fi</tt></i></span></dt><dd><p>
3803         pointer to the PSFunctionInfo structure that will store the closure informations
3804       </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3805         a PSRESULT.
3806       <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
3807         the member 'funcid' of the returned PSFunctionInfo structure is a unique identifier of the function; this
3808         can be useful to identify a specific piece of pscript code in an application like for instance a profiler.
3809         this method will fail if the closure in the stack is a native C closure.
3810       </p></dd><dt><span class="term">eg.</span></dt><dd><pre class="programlisting">
3811         
3812 typedef struct tagPSFunctionInfo {
3813     PSUserPointer funcid; //unique idetifier for a function (all it's closures will share the same funcid)
3814     const PSChar *name; //function name
3815     const PSChar *source; //function source file name
3816 }PSFunctionInfo;
3817       
3818       </pre></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setdebughook"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setdebughook<a class="indexterm" name="d0e11394"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_setdebughook</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
3819         pops a closure from the stack an sets it as debug hook.
3820         When a debug hook is set it overrides any previously set native or non native hooks.
3821         if the hook is null the debug hook will be disabled.
3822       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3823                 the target VM
3824             </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
3825                 In order to receive a 'per line' callback, is necessary to compile the scripts with the line informations.
3826                 Without line informations activated, only the 'call/return' callbacks will be invoked.
3827             </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_setnativedebughook"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_setnativedebughook<a class="indexterm" name="d0e11438"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">ps_setnativedebughook</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSDEBUGHOOK&nbsp;hook</var><code>)</code>;</p></div><p>
3828         sets the native debug hook. When a native hook is set it overrides any previously set native or non native hooks.
3829         if the hook is NULL the debug hook will be disabled.
3830       </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3831         the target VM
3832       </p></dd><dt><span class="term"><i class="parameter"><tt>PSDEBUGHOOK&nbsp;hook</tt></i></span></dt><dd><p>
3833         the native hook function
3834       </p></dd></dl></div></dd><dt><span class="term">remarks:</span></dt><dd><p>
3835         In order to receive a 'per line' callback, is necessary to compile the scripts with the line informations.
3836         Without line informations activated, only the 'call/return' callbacks will be invoked.
3837       </p></dd></dl></div></div><div class="refentry" lang="en"><div class="refentry.separator"><hr></div><a name="ps_stackinfos"></a><div class="titlepage"><div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">ps_stackinfos<a class="indexterm" name="d0e11491"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">ps_stackinfos</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;level</var>, <var class="pdparam">PSStackInfos *&nbsp;si</var><code>)</code>;</p></div><p>
3838                 retrieve the calls stack informations of a ceratain level in the calls stack.
3839             </p><div class="variablelist"><dl><dt><span class="term">parameters:</span></dt><dd><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>HPSCRIPTVM&nbsp;v</tt></i></span></dt><dd><p>
3840                 the target VM
3841             </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;level</tt></i></span></dt><dd><p>
3842                 calls stack level
3843             </p></dd><dt><span class="term"><i class="parameter"><tt>PSStackInfos *&nbsp;si</tt></i></span></dt><dd><p>
3844                 pointer to the PSStackInfos structure that will store the stack informations
3845             </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
3846                 a PSRESULT.
3847             <br></p></dd></dl></div></div></div></div><div class="index"><div class="titlepage"><div><div><h2 class="title"><a name="d0e11543"></a>Index</h2></div></div><div></div></div><div class="index"><div class="indexdiv"><h3>Symbols</h3><dl><dt>3 ways compare operator, <a href="#d0e1036">3 ways compare</a></dt><dt>?: operator, <a href="#d0e994">?: Operator</a></dt><dt>_charsize_, <a href="#d0e2365">Global symbols</a></dt><dt>_floatsize_, <a href="#d0e2365">Global symbols</a></dt><dt>_intsize_, <a href="#d0e2365">Global symbols</a></dt><dt>_version_, <a href="#d0e2365">Global symbols</a></dt><dt>_versionnumber_, <a href="#d0e2365">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>A</h3><dl><dt>arithmetic operators, <a href="#d0e1006">Arithmetic</a></dt><dt>array, <a href="#d0e2365">Global symbols</a></dt><dd><dl><dt>append, <a href="#d0e3053">Array</a></dt><dt>apply, <a href="#d0e3053">Array</a></dt><dt>clear, <a href="#d0e3053">Array</a></dt><dt>extend, <a href="#d0e3053">Array</a></dt><dt>filter, <a href="#d0e3053">Array</a></dt><dt>find, <a href="#d0e3053">Array</a></dt><dt>insert, <a href="#d0e3053">Array</a></dt><dt>len, <a href="#d0e3053">Array</a></dt><dt>map, <a href="#d0e3053">Array</a></dt><dt>pop, <a href="#d0e3053">Array</a></dt><dt>push, <a href="#d0e3053">Array</a></dt><dt>reduce, <a href="#d0e3053">Array</a></dt><dt>remove, <a href="#d0e3053">Array</a></dt><dt>resize, <a href="#d0e3053">Array</a></dt><dt>reverse, <a href="#d0e3053">Array</a></dt><dt>slice, <a href="#d0e3053">Array</a></dt><dt>sort, <a href="#d0e3053">Array</a></dt><dt>top, <a href="#d0e3053">Array</a></dt><dt>tostring, <a href="#d0e3053">Array</a></dt><dt>weakref, <a href="#d0e3053">Array</a></dt></dl></dd><dt>array constructor, <a href="#d0e1299">Array constructor</a></dt><dt>arrays, <a href="#d0e1377">Arrays</a></dt><dt>assert, <a href="#d0e2365">Global symbols</a></dt><dt>assignment(=), <a href="#d0e955">Assignment(=) &amp; new slot(&lt;-)</a></dt></dl></div><div class="indexdiv"><h3>B</h3><dl><dt>binding an environment to a function, <a href="#d0e1496">Binding an environment to a function</a></dt><dt>bitwise Operators, <a href="#d0e1118">Bitwise Operators</a></dt><dt>block statement, <a href="#d0e668">Block</a></dt><dt>bool</dt><dd><dl><dt>tofloat, <a href="#d0e2749">Bool</a></dt><dt>tointeger, <a href="#d0e2749">Bool</a></dt><dt>tostring, <a href="#d0e2749">Bool</a></dt><dt>weakref, <a href="#d0e2749">Bool</a></dt></dl></dd><dt>break statement, <a href="#d0e790">break</a></dt></dl></div><div class="indexdiv"><h3>C</h3><dl><dt>callee, <a href="#d0e2365">Global symbols</a></dt><dt>class</dt><dd><dl><dt>getattributes, <a href="#d0e3416">Class</a></dt><dt>instance, <a href="#d0e3416">Class</a></dt><dt>newmember, <a href="#d0e3416">Class</a></dt><dt>rawget, <a href="#d0e3416">Class</a></dt><dt>rawin, <a href="#d0e3416">Class</a></dt><dt>rawset, <a href="#d0e3416">Class</a></dt><dt>setattributes, <a href="#d0e3416">Class</a></dt><dt>tostring, <a href="#d0e3416">Class</a></dt><dt>weakref, <a href="#d0e3416">Class</a></dt></dl></dd><dt>class attributes, <a href="#d0e1632">Class attributes</a></dt><dt>class declaration, <a href="#d0e867">Class declaration</a>, <a href="#d0e1590">Class declaration</a></dt><dt>class instance metamethods, <a href="#d0e1779">Metamethods</a></dt><dt>class instances, <a href="#d0e1672">Class instances</a></dt><dt>classes, <a href="#d0e1580">Classes</a></dt><dt>clone, <a href="#d0e1274">clone</a></dt><dt>collectgarbage, <a href="#d0e2365">Global symbols</a></dt><dt>comma operator, <a href="#d0e1104">comma operator</a></dt><dt>comments, <a href="#d0e410">Comments</a></dt><dt>compilestring, <a href="#d0e2365">Global symbols</a></dt><dt>const statement, <a href="#d0e903">const</a></dt><dt>constants, <a href="#d0e1858">Constants &amp; Enumerations</a></dt><dt>continue statement, <a href="#d0e802">continue</a></dt></dl></div><div class="indexdiv"><h3>D</h3><dl><dt>data types, <a href="#d0e448">Values and Data types</a></dt><dt>delegation, <a href="#d0e2038">Delegation</a></dt><dt>do/while statement, <a href="#d0e732">do/while</a></dt></dl></div><div class="indexdiv"><h3>E</h3><dl><dt>enabledebuginfo, <a href="#d0e2365">Global symbols</a></dt><dt>enum statement, <a href="#d0e919">enum</a></dt><dt>error, <a href="#d0e2365">Global symbols</a></dt><dt>execution context, <a href="#d0e584">Execution Context</a></dt><dt>expression statement, <a href="#d0e936">expression statement</a></dt><dt>expressions, <a href="#d0e948">Expressions</a></dt></dl></div><div class="indexdiv"><h3>F</h3><dl><dt>float</dt><dd><dl><dt>tochar, <a href="#d0e2685">Float</a></dt><dt>tofloat, <a href="#d0e2685">Float</a></dt><dt>tointeger, <a href="#d0e2685">Float</a></dt><dt>tostring, <a href="#d0e2685">Float</a></dt><dt>weakref, <a href="#d0e2685">Float</a></dt></dl></dd><dt>for loop, <a href="#d0e762">for</a></dt><dt>foreach loop, <a href="#d0e776">foreach</a></dt><dt>free variables, <a href="#d0e1556">Free variables</a></dt><dt>function</dt><dd><dl><dt>acall, <a href="#d0e3310">Function</a></dt><dt>bindenv, <a href="#d0e3310">Function</a></dt><dt>call, <a href="#d0e3310">Function</a></dt><dt>getinfos, <a href="#d0e3310">Function</a></dt><dt>pacall, <a href="#d0e3310">Function</a></dt><dt>pcall, <a href="#d0e3310">Function</a></dt><dt>tostring, <a href="#d0e3310">Function</a></dt><dt>weakref, <a href="#d0e3310">Function</a></dt></dl></dd><dt>function declaration, <a href="#d0e855">Function declaration</a></dt><dt>functions, <a href="#d0e1393">Functions</a></dt><dd><dl><dt>calls, <a href="#d0e1470">Function calls</a></dt><dt>declaration, <a href="#d0e1403">Function declaration</a></dt></dl></dd></dl></div><div class="indexdiv"><h3>G</h3><dl><dt>generator</dt><dd><dl><dt>getstatus, <a href="#d0e3616">Generator</a></dt><dt>tostring, <a href="#d0e3616">Generator</a></dt><dt>weakref, <a href="#d0e3616">Generator</a></dt></dl></dd><dt>generators, <a href="#d0e1827">Generators</a></dt><dt>getconsttable, <a href="#d0e2365">Global symbols</a></dt><dt>getroottable, <a href="#d0e2365">Global symbols</a></dt><dt>getstackinfos, <a href="#d0e2365">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>I</h3><dl><dt>identifiers, <a href="#d0e49">Identifiers</a></dt><dt>if/else statement, <a href="#d0e703">if/else</a></dt><dt>in operator, <a href="#d0e1064">in operator</a></dt><dt>inheritance, <a href="#d0e1738">Inheritance</a></dt><dt>instance</dt><dd><dl><dt>getclass, <a href="#d0e3540">Class Instance</a></dt><dt>rawget, <a href="#d0e3540">Class Instance</a></dt><dt>rawin, <a href="#d0e3540">Class Instance</a></dt><dt>rawset, <a href="#d0e3540">Class Instance</a></dt><dt>tostring, <a href="#d0e3540">Class Instance</a></dt><dt>weakref, <a href="#d0e3540">Class Instance</a></dt></dl></dd><dt>instanceof operator, <a href="#d0e1078">instanceof operator</a></dt><dt>integer</dt><dd><dl><dt>tochar, <a href="#d0e2621">Integer</a></dt><dt>tofloat, <a href="#d0e2621">Integer</a></dt><dt>tointeger, <a href="#d0e2621">Integer</a></dt><dt>tostring, <a href="#d0e2621">Integer</a></dt><dt>weakref, <a href="#d0e2621">Integer</a></dt></dl></dd></dl></div><div class="indexdiv"><h3>J</h3><dl><dt>JSON, <a href="#d0e1254">Table with JSON syntax</a></dt></dl></div><div class="indexdiv"><h3>K</h3><dl><dt>keywords, <a href="#d0e61">Keywords</a></dt></dl></div><div class="indexdiv"><h3>L</h3><dl><dt>lambda expression, <a href="#d0e1514">Lambda expressions</a></dt><dt>literals, <a href="#d0e335">Literals</a></dt><dt>local variables declaration, <a href="#d0e841">Local variables declaration</a></dt><dt>logical operators, <a href="#d0e1048">Logical</a></dt></dl></div><div class="indexdiv"><h3>M</h3><dl><dt>metamethods, <a href="#d0e2057">Metamethods</a></dt><dd><dl><dt>_add, <a href="#d0e2135">_add</a></dt><dt>_call, <a href="#d0e2263">_call</a></dt><dt>_cloned, <a href="#d0e2276">_cloned</a></dt><dt>_cmp, <a href="#d0e2218">_cmp</a></dt><dt>_delslot, <a href="#d0e2120">_delslot</a></dt><dt>_div, <a href="#d0e2170">_div</a></dt><dt>_get, <a href="#d0e2092">_get</a></dt><dt>_inherited, <a href="#d0e2322">_inherited</a></dt><dt>_modulo, <a href="#d0e2181">_modulo</a></dt><dt>_mul, <a href="#d0e2159">_mul</a></dt><dt>_newmember, <a href="#d0e2343">_newmember</a></dt><dt>_newslot, <a href="#d0e2105">_newslot</a></dt><dt>_nexti, <a href="#d0e2289">_nexti</a></dt><dt>_set, <a href="#d0e2079">_set</a></dt><dt>_sub, <a href="#d0e2148">_sub</a></dt><dt>_tostring, <a href="#d0e2304">_tostring</a></dt><dt>_typeof, <a href="#d0e2205">_typeof</a></dt><dt>_unm, <a href="#d0e2192">_unm</a></dt></dl></dd></dl></div><div class="indexdiv"><h3>N</h3><dl><dt>new slot(&lt;-), <a href="#d0e955">Assignment(=) &amp; new slot(&lt;-)</a></dt><dt>newthread, <a href="#d0e2365">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>O</h3><dl><dt>operators, <a href="#d0e183">Operators</a>, <a href="#d0e987">Operators</a></dt><dt>operators precedence, <a href="#d0e1130">Operators precedence</a></dt></dl></div><div class="indexdiv"><h3>P</h3><dl><dt>print, <a href="#d0e2365">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>R</h3><dl><dt>relational operators, <a href="#d0e1022">Relational</a></dt><dt>resurrectunreachable, <a href="#d0e2365">Global symbols</a></dt><dt>return statement, <a href="#d0e814">return</a></dt></dl></div><div class="indexdiv"><h3>S</h3><dl><dt>setconsttable, <a href="#d0e2365">Global symbols</a></dt><dt>setdebughook, <a href="#d0e2365">Global symbols</a></dt><dt>seterrorhandler, <a href="#d0e2365">Global symbols</a></dt><dt>setroottable, <a href="#d0e2365">Global symbols</a></dt><dt>ps_addref, <a href="#ps_addref">ps_addref</a></dt><dt>ps_arrayappend, <a href="#ps_arrayappend">ps_arrayappend</a></dt><dt>ps_arrayinsert, <a href="#ps_arrayinsert">ps_arrayinsert</a></dt><dt>ps_arraypop, <a href="#ps_arraypop">ps_arraypop</a></dt><dt>ps_arrayremove, <a href="#ps_arrayremove">ps_arrayremove</a></dt><dt>ps_arrayresize, <a href="#ps_arrayresize">ps_arrayresize</a></dt><dt>ps_arrayreverse, <a href="#ps_arrayreverse">ps_arrayreverse</a></dt><dt>ps_bindenv, <a href="#ps_bindenv">ps_bindenv</a></dt><dt>ps_call, <a href="#ps_call">ps_call</a></dt><dt>ps_clear, <a href="#ps_clear">ps_clear</a></dt><dt>ps_clone, <a href="#ps_clone">ps_clone</a></dt><dt>ps_close, <a href="#ps_close">ps_close</a></dt><dt>ps_cmp, <a href="#ps_cmp">ps_cmp</a></dt><dt>ps_collectgarbage, <a href="#ps_collectgarbage">ps_collectgarbage</a></dt><dt>ps_compile, <a href="#ps_compile">ps_compile</a></dt><dt>ps_compilebuffer, <a href="#ps_compilebuffer">ps_compilebuffer</a></dt><dt>ps_createinstance, <a href="#ps_createinstance">ps_createinstance</a></dt><dt>ps_createslot, <a href="#ps_createslot">ps_createslot</a></dt><dt>ps_deleteslot, <a href="#ps_deleteslot">ps_deleteslot</a></dt><dt>ps_enabledebuginfo, <a href="#ps_enabledebuginfo">ps_enabledebuginfo</a></dt><dt>ps_get, <a href="#ps_get">ps_get</a></dt><dt>ps_getattributes, <a href="#ps_getattributes">ps_getattributes</a></dt><dt>ps_getbool, <a href="#ps_getbool">ps_getbool</a></dt><dt>ps_getbyhandle, <a href="#ps_getbyhandle">ps_getbyhandle</a></dt><dt>ps_getcallee, <a href="#ps_getcallee">ps_getcallee</a></dt><dt>ps_getclass, <a href="#ps_getclass">ps_getclass</a></dt><dt>ps_getclosureinfo, <a href="#ps_getclosureinfo">ps_getclosureinfo</a></dt><dt>ps_getclosurename, <a href="#ps_getclosurename">ps_getclosurename</a></dt><dt>ps_getdelegate, <a href="#ps_getdelegate">ps_getdelegate</a></dt><dt>ps_geterrorfunc, <a href="#ps_geterrorfunc">ps_geterrorfunc</a></dt><dt>ps_getfloat, <a href="#ps_getfloat">ps_getfloat</a></dt><dt>ps_getforeignptr, <a href="#ps_getforeignptr">ps_getforeignptr</a></dt><dt>ps_getfreevariable, <a href="#ps_getfreevariable">ps_getfreevariable</a></dt><dt>ps_getfunctioninfo, <a href="#ps_getfunctioninfo">ps_getfunctioninfo</a></dt><dt>ps_gethash, <a href="#ps_gethash">ps_gethash</a></dt><dt>ps_getinstanceup, <a href="#ps_getinstanceup">ps_getinstanceup</a></dt><dt>ps_getinteger, <a href="#ps_getinteger">ps_getinteger</a></dt><dt>ps_getlasterror, <a href="#ps_getlasterror">ps_getlasterror</a></dt><dt>ps_getlocal, <a href="#ps_getlocal">ps_getlocal</a></dt><dt>ps_getmemberhandle, <a href="#ps_getmemberhandle">ps_getmemberhandle</a></dt><dt>ps_getobjtypetag, <a href="#ps_getobjtypetag">ps_getobjtypetag</a></dt><dt>ps_getprintfunc, <a href="#ps_getprintfunc">ps_getprintfunc</a></dt><dt>ps_getrefcount, <a href="#ps_getrefcount">ps_getrefcount</a></dt><dt>ps_getscratchpad, <a href="#ps_getscratchpad">ps_getscratchpad</a></dt><dt>ps_getsize, <a href="#ps_getsize">ps_getsize</a></dt><dt>ps_getstackobj, <a href="#ps_getstackobj">ps_getstackobj</a></dt><dt>ps_getstring, <a href="#ps_getstring">ps_getstring</a></dt><dt>ps_getthread, <a href="#ps_getthread">ps_getthread</a></dt><dt>ps_gettop, <a href="#ps_gettop">ps_gettop</a></dt><dt>ps_gettype, <a href="#ps_gettype">ps_gettype</a></dt><dt>ps_gettypetag, <a href="#ps_gettypetag">ps_gettypetag</a></dt><dt>ps_getuserdata, <a href="#ps_getuserdata">ps_getuserdata</a></dt><dt>ps_getuserpointer, <a href="#ps_getuserpointer">ps_getuserpointer</a></dt><dt>ps_getversion, <a href="#ps_getversion">ps_getversion</a></dt><dt>ps_getvmstate, <a href="#ps_getvmstate">ps_getvmstate</a></dt><dt>ps_getweakrefval, <a href="#ps_getweakrefval">ps_getweakrefval</a></dt><dt>ps_instanceof, <a href="#ps_instanceof">ps_instanceof</a></dt><dt>ps_move, <a href="#ps_move">ps_move</a></dt><dt>ps_newarray, <a href="#ps_newarray">ps_newarray</a></dt><dt>ps_newclass, <a href="#ps_newclass">ps_newclass</a></dt><dt>ps_newclosure, <a href="#ps_newclosure">ps_newclosure</a></dt><dt>ps_newmember, <a href="#ps_newmember">ps_newmember</a></dt><dt>ps_newslot, <a href="#ps_newslot">ps_newslot</a></dt><dt>ps_newtable, <a href="#ps_newtable">ps_newtable</a></dt><dt>ps_newtableex, <a href="#ps_newtableex">ps_newtableex</a></dt><dt>ps_newthread, <a href="#ps_newthread">ps_newthread</a></dt><dt>ps_newuserdata, <a href="#ps_newuserdata">ps_newuserdata</a></dt><dt>ps_next, <a href="#ps_next">ps_next</a></dt><dt>ps_notifyallexceptions, <a href="#ps_notifyallexceptions">ps_notifyallexceptions</a></dt><dt>ps_objtobool, <a href="#ps_objtobool">ps_objtobool</a></dt><dt>ps_objtofloat, <a href="#ps_objtofloat">ps_objtofloat</a></dt><dt>ps_objtointeger, <a href="#ps_objtointeger">ps_objtointeger</a></dt><dt>ps_objtostring, <a href="#ps_objtostring">ps_objtostring</a></dt><dt>ps_objtouserpointer, <a href="#ps_objtouserpointer">ps_objtouserpointer</a></dt><dt>ps_open, <a href="#ps_open">ps_open</a></dt><dt>ps_pop, <a href="#ps_pop">ps_pop</a></dt><dt>ps_poptop, <a href="#ps_poptop">ps_poptop</a></dt><dt>ps_push, <a href="#ps_push">ps_push</a></dt><dt>ps_pushbool, <a href="#ps_pushbool">ps_pushbool</a></dt><dt>ps_pushconsttable, <a href="#ps_pushconsttable">ps_pushconsttable</a></dt><dt>ps_pushfloat, <a href="#ps_pushfloat">ps_pushfloat</a></dt><dt>ps_pushinteger, <a href="#ps_pushinteger">ps_pushinteger</a></dt><dt>ps_pushnull, <a href="#ps_pushnull">ps_pushnull</a></dt><dt>ps_pushobject, <a href="#ps_pushobject">ps_pushobject</a></dt><dt>ps_pushregistrytable, <a href="#ps_pushregistrytable">ps_pushregistrytable</a></dt><dt>ps_pushroottable, <a href="#ps_pushroottable">ps_pushroottable</a></dt><dt>ps_pushstring, <a href="#ps_pushstring">ps_pushstring</a></dt><dt>ps_pushuserpointer, <a href="#ps_pushuserpointer">ps_pushuserpointer</a></dt><dt>ps_rawdeleteslot, <a href="#ps_rawdeleteslot">ps_rawdeleteslot</a></dt><dt>ps_rawget, <a href="#ps_rawget">ps_rawget</a></dt><dt>ps_rawnewmember, <a href="#ps_rawnewmember">ps_rawnewmember</a></dt><dt>ps_rawset, <a href="#ps_rawset">ps_rawset</a></dt><dt>ps_readclosure, <a href="#ps_readclosure">ps_readclosure</a></dt><dt>ps_release, <a href="#ps_release">ps_release</a></dt><dt>ps_remove, <a href="#ps_remove">ps_remove</a></dt><dt>ps_reservestack, <a href="#ps_reservestack">ps_reservestack</a></dt><dt>ps_reseterror, <a href="#ps_reseterror">ps_reseterror</a></dt><dt>ps_resetobject, <a href="#ps_resetobject">ps_resetobject</a></dt><dt>ps_resume, <a href="#ps_resume">ps_resume</a></dt><dt>ps_resurrectunreachable, <a href="#ps_resurrectunreachable">ps_resurrectunreachable</a></dt><dt>ps_set, <a href="#ps_set">ps_set</a></dt><dt>ps_setattributes, <a href="#ps_setattributes">ps_setattributes</a></dt><dt>ps_setbyhandle, <a href="#ps_setbyhandle">ps_setbyhandle</a></dt><dt>ps_setclassudsize, <a href="#ps_setclassudsize">ps_setclassudsize</a></dt><dt>ps_setcompilererrorhandler, <a href="#ps_setcompilererrorhandler">ps_setcompilererrorhandler</a></dt><dt>ps_setconsttable, <a href="#ps_setconsttable">ps_setconsttable</a></dt><dt>ps_setdebughook, <a href="#ps_setdebughook">ps_setdebughook</a></dt><dt>ps_setdelegate, <a href="#ps_setdelegate">ps_setdelegate</a></dt><dt>ps_seterrorhandler, <a href="#ps_seterrorhandler">ps_seterrorhandler</a></dt><dt>ps_setforeignptr, <a href="#ps_setforeignptr">ps_setforeignptr</a></dt><dt>ps_setfreevariable, <a href="#ps_setfreevariable">ps_setfreevariable</a></dt><dt>ps_setinstanceup, <a href="#ps_setinstanceup">ps_setinstanceup</a></dt><dt>ps_setnativeclosurename, <a href="#ps_setnativeclosurename">ps_setnativeclosurename</a></dt><dt>ps_setnativedebughook, <a href="#ps_setnativedebughook">ps_setnativedebughook</a></dt><dt>ps_setparamscheck, <a href="#ps_setparamscheck">ps_setparamscheck</a></dt><dt>ps_setprintfunc, <a href="#ps_setprintfunc">ps_setprintfunc</a></dt><dt>ps_setreleasehook, <a href="#ps_setreleasehook">ps_setreleasehook</a></dt><dt>ps_setroottable, <a href="#ps_setroottable">ps_setroottable</a></dt><dt>ps_settop, <a href="#ps_settop">ps_settop</a></dt><dt>ps_settypetag, <a href="#ps_settypetag">ps_settypetag</a></dt><dt>ps_stackinfos, <a href="#ps_stackinfos">ps_stackinfos</a></dt><dt>ps_suspendvm, <a href="#ps_suspendvm">ps_suspendvm</a></dt><dt>ps_throwerror, <a href="#ps_throwerror">ps_throwerror</a></dt><dt>ps_throwobject, <a href="#ps_throwobject">ps_throwobject</a></dt><dt>ps_tobool, <a href="#ps_tobool">ps_tobool</a></dt><dt>ps_tostring, <a href="#ps_tostring">ps_tostring</a></dt><dt>ps_typeof, <a href="#ps_typeof">ps_typeof</a></dt><dt>ps_wakeupvm, <a href="#ps_wakeupvm">ps_wakeupvm</a></dt><dt>ps_weakref, <a href="#ps_weakref">ps_weakref</a></dt><dt>ps_writeclosure, <a href="#ps_writeclosure">ps_writeclosure</a></dt><dt>statements, <a href="#d0e654">Statements</a></dt><dt>static variables, <a href="#d0e1618">Static variables</a></dt><dt>string</dt><dd><dl><dt>find, <a href="#d0e2819">String</a></dt><dt>len, <a href="#d0e2819">String</a></dt><dt>slice, <a href="#d0e2819">String</a></dt><dt>tofloat, <a href="#d0e2819">String</a></dt><dt>tointeger, <a href="#d0e2819">String</a></dt><dt>tolower, <a href="#d0e2819">String</a></dt><dt>tostring, <a href="#d0e2819">String</a></dt><dt>toupper, <a href="#d0e2819">String</a></dt><dt>weakref, <a href="#d0e2819">String</a></dt></dl></dd><dt>switch statement, <a href="#d0e746">switch</a></dt></dl></div><div class="indexdiv"><h3>T</h3><dl><dt>table</dt><dd><dl><dt>clear, <a href="#d0e2931">Table</a></dt><dt>getdelegate, <a href="#d0e2931">Table</a></dt><dt>len, <a href="#d0e2931">Table</a></dt><dt>rawdelete, <a href="#d0e2931">Table</a></dt><dt>rawget, <a href="#d0e2931">Table</a></dt><dt>rawin, <a href="#d0e2931">Table</a></dt><dt>rawset, <a href="#d0e2931">Table</a></dt><dt>setdelegate, <a href="#d0e2931">Table</a></dt><dt>tostring, <a href="#d0e2931">Table</a></dt><dt>weakref, <a href="#d0e2931">Table</a></dt></dl></dd><dt>table constructor, <a href="#d0e1216">Table constructor</a></dt><dt>tables, <a href="#d0e1317">Tables</a></dt><dd><dl><dt>slot creation, <a href="#d0e1336">Slot creation</a></dt><dt>slot deletion, <a href="#d0e1361">Slot deletion</a></dt></dl></dd><dt>tail recursion, <a href="#d0e1569">Tail recursion</a></dt><dt>thread</dt><dd><dl><dt>call, <a href="#d0e3656">Thread</a></dt><dt>getstackinfos, <a href="#d0e3656">Thread</a></dt><dt>getstatus, <a href="#d0e3656">Thread</a></dt><dt>tostring, <a href="#d0e3656">Thread</a></dt><dt>wakeup, <a href="#d0e3656">Thread</a></dt><dt>weakref, <a href="#d0e3656">Thread</a></dt></dl></dd><dt>threads, <a href="#d0e1954">Threads</a></dt><dt>throw statement, <a href="#d0e891">throw</a></dt><dt>true and false, <a href="#d0e688">true and false</a></dt><dt>try/catch statement, <a href="#d0e879">try/catch</a></dt><dt>type, <a href="#d0e2365">Global symbols</a></dt><dt>typeof operator, <a href="#d0e1090">typeof operator</a></dt></dl></div><div class="indexdiv"><h3>U</h3><dl><dt>using threads, <a href="#d0e1965">Using threads</a></dt></dl></div><div class="indexdiv"><h3>V</h3><dl><dt>variables, <a href="#d0e599">Variables</a></dt></dl></div><div class="indexdiv"><h3>W</h3><dl><dt>weak refences, <a href="#d0e1995">Weak References</a></dt><dt>weakref</dt><dd><dl><dt>ref, <a href="#d0e3732">Weak Reference</a></dt><dt>tostring, <a href="#d0e3732">Weak Reference</a></dt><dt>weakref, <a href="#d0e3732">Weak Reference</a></dt></dl></dd><dt>while statement, <a href="#d0e718">while</a></dt></dl></div><div class="indexdiv"><h3>Y</h3><dl><dt>yield statement, <a href="#d0e826">yield</a></dt></dl></div></div></div></div></body></html>