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 Standard Library 3.0</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 Standard Library 3.0</h1></div><div><div class="author"><h3 class="author"><span class="firstname">Alberto</span> <span class="surname">Demichelis</span></h3></div></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:
0010     </p><p>
0011       The above copyright notice and this permission notice shall be included in
0012       all copies or substantial portions of the Software.
0013     </p><p>
0014       THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015       IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016       FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0017       AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0018       LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0019       OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0020       THE SOFTWARE.
0021     </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="#d0e24">1. Introduction</a></span></dt><dt><span class="chapter"><a href="#d0e49">2. The Input/Output library</a></span></dt><dd><dl><dt><span class="sect1"><a href="#d0e56">Pscript API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e59">Global symbols</a></span></dt><dt><span class="sect2"><a href="#d0e152">File class</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e473">C API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e476">Initialization</a></span></dt><dt><span class="sect2"><a href="#d0e526">File object</a></span></dt><dt><span class="sect2"><a href="#d0e647">Script loading and serialization</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#d0e841">3. The Blob library</a></span></dt><dd><dl><dt><span class="sect1"><a href="#d0e851">Pscript API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e854">Global symbols</a></span></dt><dt><span class="sect2"><a href="#d0e947">The blob class</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1314">C API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1317">Initialization</a></span></dt><dt><span class="sect2"><a href="#d0e1367">Blob object</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#d0e1530">4. The Math library</a></span></dt><dd><dl><dt><span class="sect1"><a href="#d0e1537">Pscript API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1540">Global symbols</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1877">C API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1880">Initialization</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#d0e1931">5. The System library</a></span></dt><dd><dl><dt><span class="sect1"><a href="#d0e1938">Pscript API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1941">Global symbols</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e2119">C API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e2122">Initialization</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#d0e2173">6. The String library</a></span></dt><dd><dl><dt><span class="sect1"><a href="#d0e2180">Pscript API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e2183">Global symbols</a></span></dt><dt><span class="sect2"><a href="#d0e2591">Regexp class</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e2699">C API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e2702">Initialization</a></span></dt><dt><span class="sect2"><a href="#d0e2752">Formatting</a></span></dt><dt><span class="sect2"><a href="#d0e2829">Regular Expessions</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#d0e3212">7. The Aux library</a></span></dt><dd><dl><dt><span class="sect1"><a href="#d0e3219">C API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e3222">Error handling</a></span></dt></dl></dd></dl></dd><dt><span class="index"><a href="#d0e3293">Index</a></span></dt></dl></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="d0e24"></a>Chapter&nbsp;1.&nbsp;Introduction</h2></div></div><div></div></div><p>
0022         The pscript standard libraries consist in a set of modules implemented in C++.
0023         While are not essential for the language, they provide a set of useful services that are commonly
0024         used by a wide range of applications(file I/O, regular expressions, etc...),
0025         plus they offer a foundation for developing additional libraries.
0026     </p><p>
0027         All libraries are implemented through the pscript API and the ANSI C runtime library.
0028         The modules are organized in the following way:
0029         </p><div class="itemizedlist"><ul type="disc"><li><p> I/O : input and output </p></li><li><p> blob : binary buffers manipilation </p></li><li><p> math : basic mathematical routines </p></li><li><p> system : system access function </p></li><li><p> string : string formatting and manipulation </p></li></ul></div><p>
0030         The libraries can be registered independently,except for the IO library that depends from the bloblib.
0031     </p></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="d0e49"></a>Chapter&nbsp;2.&nbsp;The Input/Output library</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#d0e56">Pscript API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e59">Global symbols</a></span></dt><dt><span class="sect2"><a href="#d0e152">File class</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e473">C API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e476">Initialization</a></span></dt><dt><span class="sect2"><a href="#d0e526">File object</a></span></dt><dt><span class="sect2"><a href="#d0e647">Script loading and serialization</a></span></dt></dl></dd></dl></div><a class="indexterm" name="d0e50"></a><p>
0032             the input lib implements basic input/output routines.
0033         </p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e56"></a>Pscript API</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e59"></a>Global symbols</h3></div></div><div></div></div><p><a class="indexterm" name="d0e63"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">dofile</b>(</code><var class="pdparam">path</var>, <var class="pdparam">[raiseerror]</var><code>)</code>;</p></div><p>
0034                     compiles a pscript script or loads a precompiled one and executes it.
0035                     returns the value returned by the script or null if no value is returned.
0036                     if the optional parameter 'raiseerror' is true, the compiler error handler is invoked
0037                     in case of a syntax error. If raiseerror is omitted or set to false, the compiler
0038                     error handler is not ivoked.
0039                     When pscript is compiled in unicode mode the function can handle different character ecodings,
0040                     UTF8 with and without prefix and UCS-2 prefixed(both big endian an little endian).
0041                     If the source stream is not prefixed UTF8 ecoding is used as default.
0042                     </p><p><a class="indexterm" name="d0e80"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">loadfile</b>(</code><var class="pdparam">path</var>, <var class="pdparam">[raiseerror]</var><code>)</code>;</p></div><p>
0043                     compiles a pscript script or loads a precompiled one an returns it as as function.
0044                     if the optional parameter 'raiseerror' is true, the compiler error handler is invoked
0045                     in case of a syntax error. If raiseerror is omitted or set to false, the compiler
0046                     error handler is not ivoked.
0047                     When pscript is compiled in unicode mode the function can handle different character ecodings,
0048                     UTF8 with and without prefix and UCS-2 prefixed(both big endian an little endian).
0049                     If the source stream is not prefixed UTF8 ecoding is used as default.
0050                     </p><p><a class="indexterm" name="d0e97"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">writeclosuretofile</b>(</code><var class="pdparam">destpath</var>, <var class="pdparam">closure</var><code>)</code>;</p></div><p>
0051             serializes a closure to a bytecode file (destpath). The serialized file can be loaded 
0052             using loadfile() and dofile().
0053           </p><p><a class="indexterm" name="d0e114"></a><tt class="literal">stderr</tt></p><p>File object bound on the os <span class="emphasis"><em>standard error</em></span> stream</p><p><a class="indexterm" name="d0e127"></a><tt class="literal">stdin</tt></p><p>File object bound on the os <span class="emphasis"><em>standard input</em></span> stream</p><p><a class="indexterm" name="d0e140"></a><tt class="literal">stdout</tt></p><p>File object bound on the os <span class="emphasis"><em>standard output</em></span> stream</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e152"></a>File class</h3></div></div><div></div></div><p>
0054                     The file object implements a stream on a operating system file.
0055           It's contructor imitate the behaviour of the C runtime function fopen for eg.
0056  </p><pre class="programlisting">
0057           
0058 local myfile = file("test.xxx","wb+");
0059                     
0060         </pre><p>
0061            creates a file with read/write access in the current directory.
0062                 </p><p><a class="indexterm" name="d0e161"></a><a class="indexterm" name="d0e164"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">close</b>(</code><code>)</code>;</p></div><p>closes the file</p><p><a class="indexterm" name="d0e179"></a><a class="indexterm" name="d0e182"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">eos</b>(</code><code>)</code>;</p></div><p>returns a non null value if the read/write pointer is at the end of the stream.</p><p><a class="indexterm" name="d0e197"></a><a class="indexterm" name="d0e200"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">flush</b>(</code><code>)</code>;</p></div><p>flushes the stream.return a value != null if succeded, otherwise returns null</p><p><a class="indexterm" name="d0e215"></a><a class="indexterm" name="d0e218"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">len</b>(</code><code>)</code>;</p></div><p>returns the lenght of the stream</p><p><a class="indexterm" name="d0e233"></a><a class="indexterm" name="d0e236"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">readblob</b>(</code><var class="pdparam">size</var><code>)</code>;</p></div><p>read n bytes from the stream and retuns them as blob</p><p><a class="indexterm" name="d0e253"></a><a class="indexterm" name="d0e256"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">readn</b>(</code><var class="pdparam">type</var><code>)</code>;</p></div><p>reads a number from the stream according to the type parameter. 
0063                     <i class="parameter"><tt>type</tt></i> can have the following values:
0064                     </p><table class="simplelist" border="0" summary="Simple list"><tr><td><tt class="literal">'i'</tt></td><td>32bits number</td><td>returns an integer</td></tr><tr><td><tt class="literal">'s'</tt></td><td>16bits signed integer</td><td>returns an integer</td></tr><tr><td><tt class="literal">'w'</tt></td><td>16bits unsigned integer</td><td>returns an integer</td></tr><tr><td><tt class="literal">'c'</tt></td><td>8bits signed integer</td><td>returns an integer</td></tr><tr><td><tt class="literal">'b'</tt></td><td>8bits unsigned integer</td><td>returns an integer</td></tr><tr><td><tt class="literal">'f'</tt></td><td>32bits float</td><td>returns an float</td></tr><tr><td><tt class="literal">'d'</tt></td><td>64bits float</td><td>returns an float</td></tr></table><p>
0065                 </p><p><a class="indexterm" name="d0e327"></a><a class="indexterm" name="d0e330"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">seek</b>(</code><var class="pdparam">seek</var>, <var class="pdparam">[origin]</var><code>)</code>;</p></div><p>
0066                     Moves the read/write pointer to a specified location.
0067                     <i class="parameter"><tt>offset</tt></i> indicates the number of bytes from <i class="parameter"><tt>origin</tt></i>.
0068                     <i class="parameter"><tt>origin</tt></i> can be <tt class="literal">'b'</tt> beginning of the stream,<tt class="literal">'c'</tt> current location or <tt class="literal">'e'</tt> end of the stream.
0069                     If origin is omitted the parameter is defaulted as 'b'(beginning of the stream).
0070                 </p><p><a class="indexterm" name="d0e367"></a><a class="indexterm" name="d0e370"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">tell</b>(</code><code>)</code>;</p></div><p>returns read/write pointer absolute position</p><p><a class="indexterm" name="d0e385"></a><a class="indexterm" name="d0e388"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">writeblob</b>(</code><var class="pdparam">blob</var><code>)</code>;</p></div><p>writes a blob in the stream</p><p><a class="indexterm" name="d0e405"></a><a class="indexterm" name="d0e408"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">writen</b>(</code><var class="pdparam">n</var>, <var class="pdparam">type</var><code>)</code>;</p></div><p>writes a number in the stream formatted according to the type parameter.
0071                 <i class="parameter"><tt>type</tt></i> can have the following values:
0072                     </p><table class="simplelist" border="0" summary="Simple list"><tr><td><tt class="literal">'l'</tt></td><td>processor dependent, 32bits on 32bits processors, 64bits on 64bits prcessors</td></tr><tr><td>returns an integer</td><td><tt class="literal">'i'</tt></td></tr><tr><td>32bits number</td><td><tt class="literal">'s'</tt></td></tr><tr><td>16bits signed integer</td><td><tt class="literal">'w'</tt></td></tr><tr><td>16bits unsigned integer</td><td><tt class="literal">'c'</tt></td></tr><tr><td>8bits signed integer</td><td><tt class="literal">'b'</tt></td></tr><tr><td>8bits unsigned integer</td><td><tt class="literal">'f'</tt></td></tr><tr><td>32bits float</td><td><tt class="literal">'d'</tt></td></tr><tr><td>64bits float</td><td>&nbsp;</td></tr></table><p>
0073                 </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e473"></a>C API</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e476"></a>Initialization</h3></div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_register_iolib<a class="indexterm" name="d0e486"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">psstd_register_iolib</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
0074                     initialize and register the io library in the given VM. 
0075                 </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>
0076                     the target VM
0077                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0078                     an PSRESULT
0079                 <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
0080                     The function aspects a table on top of the stack where to register the global
0081                     library functions.
0082                 </p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e526"></a>File object</h3></div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_createfile<a class="indexterm" name="d0e536"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">psstd_createfile</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSFILE&nbsp;file</var>, <var class="pdparam">PSBool&nbsp;own</var><code>)</code>;</p></div><p>
0083                     creates a file object bound to the PSFILE passed as parameter
0084                     and pushes it in the stack
0085                 </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>
0086                     the target VM
0087                 </p></dd><dt><span class="term"><i class="parameter"><tt>PSFILE&nbsp;file</tt></i></span></dt><dd><p>
0088                     the stream that will be rapresented by the file object
0089                 </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;own</tt></i></span></dt><dd><p>
0090                     if different true the stream will be automatically closed
0091                     when the newly create file object is destroyed.
0092                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0093                     an PSRESULT
0094                 <br></p></dd></dl></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_getfile<a class="indexterm" name="d0e595"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">psstd_getfile</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSFILE *&nbsp;file</var><code>)</code>;</p></div><p>
0095                     retrieve the pointer of a stream handle from an arbitrary
0096                     position in the stack.
0097                 </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>
0098                     the target VM
0099                 </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
0100                     and index in the stack
0101                 </p></dd><dt><span class="term"><i class="parameter"><tt>PSFILE *&nbsp;file</tt></i></span></dt><dd><p>
0102                     A pointer to a PSFILE handle that will store the result
0103                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0104                     an PSRESULT
0105                 <br></p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e647"></a>Script loading and serialization</h3></div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_loadfile<a class="indexterm" name="d0e657"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">psstd_loadfile</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">const PSChar *&nbsp;filename</var>, <var class="pdparam">PSBool&nbsp;printerror</var><code>)</code>;</p></div><p>
0106                     compiles a pscript script or loads a precompiled one an pushes it as closure in the stack.
0107                     When pscript is compiled in unicode mode the function can handle different character ecodings,
0108                     UTF8 with and without prefix and UCS-2 prefixed(both big endian an little endian).
0109                     If the source stream is not prefixed UTF8 ecoding is used as default.
0110                 </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>
0111                     the target VM
0112                 </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar *&nbsp;filename</tt></i></span></dt><dd><p>
0113                     path of the script that has to be loaded
0114                 </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;printerror</tt></i></span></dt><dd><p>
0115                     if true the compiler error handler will be called if a error occurs.
0116                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0117                     an PSRESULT
0118                 <br></p></dd></dl></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_dofile<a class="indexterm" name="d0e716"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">psstd_dofile</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">const PSChar *&nbsp;filename</var>, <var class="pdparam">PSBool&nbsp;retval</var>, <var class="pdparam">PSBool&nbsp;printerror</var><code>)</code>;</p></div><p>
0119                     Compiles a pscript script or loads a precompiled one and executes it.
0120                     Optionally pushes the return value of the executed script in the stack.
0121                     When pscript is compiled in unicode mode the function can handle different character ecodings,
0122                     UTF8 with and without prefix and UCS-2 prefixed(both big endian an little endian).
0123                     If the source stream is not prefixed UTF8 ecoding is used as default.
0124                 </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>
0125                     the target VM
0126                 </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar *&nbsp;filename</tt></i></span></dt><dd><p>
0127                     path of the script that has to be loaded
0128                 </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;retval</tt></i></span></dt><dd><p>
0129                     if true the function will push the return value of the executed script
0130                     in the stack.
0131                 </p></dd><dt><span class="term"><i class="parameter"><tt>PSBool&nbsp;printerror</tt></i></span></dt><dd><p>
0132                     if true the compiler error handler will be called if a error occurs.
0133                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0134                     an PSRESULT
0135                 <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
0136                     the function aspects a table on top of the stack that will be used as 'this' for the
0137                     execution of the script. The 'this' parameter is left untouched in the stack.
0138                     
0139                 </p></dd><dt><span class="term">eg.</span></dt><dd><pre class="programlisting">
0140 ps_pushroottable(v); //push the root table(were the globals of the script will are stored)
0141 psstd_dofile(v, _SC("test.nut"), PSFalse, PSTrue);// also prints syntax errors if any 
0142                 </pre></dd></dl></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_writeclosuretofile<a class="indexterm" name="d0e797"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">psstd_writeclosuretofile</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">const PSChar *&nbsp;filename</var><code>)</code>;</p></div><p>
0143                     serializes the closure at the top position in the stack as bytecode in 
0144                     the file specified by the paremeter filename. If a file with the
0145                     same name already exists, it will be overwritten.
0146                 </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>
0147                     the target VM
0148                 </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar *&nbsp;filename</tt></i></span></dt><dd><p>
0149                     path of the script that has to be loaded
0150                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0151                     an PSRESULT
0152                 <br></p></dd></dl></div></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="d0e841"></a>Chapter&nbsp;3.&nbsp;The Blob library</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#d0e851">Pscript API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e854">Global symbols</a></span></dt><dt><span class="sect2"><a href="#d0e947">The blob class</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1314">C API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1317">Initialization</a></span></dt><dt><span class="sect2"><a href="#d0e1367">Blob object</a></span></dt></dl></dd></dl></div><a class="indexterm" name="d0e842"></a><p>
0153             The blob library implements binary data manipulations routines. The library is
0154             based on <tt class="literal">blob objects</tt> that rapresent a buffer of arbitrary
0155             binary data.
0156         </p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e851"></a>Pscript API</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e854"></a>Global symbols</h3></div></div><div></div></div><p><a class="indexterm" name="d0e858"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">blob</b>(</code><var class="pdparam">size</var><code>)</code>;</p></div><p>returns a new instance of a blob class of the specified size in bytes</p><p><a class="indexterm" name="d0e873"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">castf2i</b>(</code><var class="pdparam">f</var><code>)</code>;</p></div><p>casts a float to a int</p><p><a class="indexterm" name="d0e888"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">casti2f</b>(</code><var class="pdparam">n</var><code>)</code>;</p></div><p>casts a int to a float</p><p><a class="indexterm" name="d0e903"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">swap2</b>(</code><var class="pdparam">n</var><code>)</code>;</p></div><p>swap the byte order of a number (like it would be a 16bits integer)</p><p><a class="indexterm" name="d0e918"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">swap4</b>(</code><var class="pdparam">n</var><code>)</code>;</p></div><p>swap the byte order of an integer</p><p><a class="indexterm" name="d0e933"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">swapfloat</b>(</code><var class="pdparam">f</var><code>)</code>;</p></div><p>swaps the byteorder of a float</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e947"></a>The blob class</h3></div></div><div></div></div><p>
0157                     The blob object is a buffer of arbitrary binary data. The object behaves like
0158                     a file stream, it has a read/write pointer and it automatically grows if data
0159                     is written out of his boundary.<br>
0160                     A blob can also be accessed byte by byte through the <tt class="literal">[]</tt> operator.
0161                 </p><p><a class="indexterm" name="d0e958"></a><a class="indexterm" name="d0e961"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">eos</b>(</code><code>)</code>;</p></div><p>returns a non null value if the read/write pointer is at the end of the stream.</p><p><a class="indexterm" name="d0e976"></a><a class="indexterm" name="d0e979"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">flush</b>(</code><code>)</code>;</p></div><p>flushes the stream.return a value != null if succeded, otherwise returns null</p><p><a class="indexterm" name="d0e994"></a><a class="indexterm" name="d0e997"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">len</b>(</code><code>)</code>;</p></div><p>returns the lenght of the stream</p><p><a class="indexterm" name="d0e1012"></a><a class="indexterm" name="d0e1015"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">readblob</b>(</code><var class="pdparam">size</var><code>)</code>;</p></div><p>read n bytes from the stream and retuns them as blob</p><p><a class="indexterm" name="d0e1032"></a><a class="indexterm" name="d0e1035"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">readn</b>(</code><var class="pdparam">type</var><code>)</code>;</p></div><p>reads a number from the stream according to the type pameter. 
0162                     <i class="parameter"><tt>type</tt></i> can have the following values:
0163                     </p><table class="simplelist" border="0" summary="Simple list"><tr><td><tt class="literal">'l'</tt></td><td>processor dependent, 32bits on 32bits processors, 64bits on 64bits prcessors</td><td>returns an integer</td></tr><tr><td><tt class="literal">'i'</tt></td><td>32bits number</td><td>returns an integer</td></tr><tr><td><tt class="literal">'s'</tt></td><td>16bits signed integer</td><td>returns an integer</td></tr><tr><td><tt class="literal">'w'</tt></td><td>16bits unsigned integer</td><td>returns an integer</td></tr><tr><td><tt class="literal">'c'</tt></td><td>8bits signed integer</td><td>returns an integer</td></tr><tr><td><tt class="literal">'b'</tt></td><td>8bits unsigned integer</td><td>returns an integer</td></tr><tr><td><tt class="literal">'f'</tt></td><td>32bits float</td><td>returns an float</td></tr><tr><td><tt class="literal">'d'</tt></td><td>64bits float</td><td>returns an float</td></tr></table><p>
0164                 </p><p><a class="indexterm" name="d0e1113"></a><a class="indexterm" name="d0e1116"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">resize</b>(</code><var class="pdparam">size</var><code>)</code>;</p></div><p>resizes the blob to the specified <i class="parameter"><tt>size</tt></i></p><p><a class="indexterm" name="d0e1135"></a><a class="indexterm" name="d0e1138"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">seek</b>(</code><var class="pdparam">seek</var>, <var class="pdparam">[origin]</var><code>)</code>;</p></div><p>
0165                     Moves the read/write pointer to a specified location.
0166                     <i class="parameter"><tt>offset</tt></i> indicates the number of bytes from <i class="parameter"><tt>origin</tt></i>.
0167                     <i class="parameter"><tt>origin</tt></i> can be <tt class="literal">'b'</tt> beginning of the stream,<tt class="literal">'c'</tt> current location or <tt class="literal">'e'</tt> end of the stream.
0168                     If origin is omitted the parameter is defaulted as 'b'(beginning of the stream).
0169                 </p><p><a class="indexterm" name="d0e1175"></a><a class="indexterm" name="d0e1178"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">swap2</b>(</code><code>)</code>;</p></div><p>swaps the byte order of the blob content as it would be an array of <tt class="literal">16bits integers</tt></p><p><a class="indexterm" name="d0e1195"></a><a class="indexterm" name="d0e1198"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">swap4</b>(</code><code>)</code>;</p></div><p>swaps the byte order of the blob content as it would be an array of <tt class="literal">32bits integers</tt></p><p><a class="indexterm" name="d0e1215"></a><a class="indexterm" name="d0e1218"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">tell</b>(</code><code>)</code>;</p></div><p>returns read/write pointer absolute position</p><p><a class="indexterm" name="d0e1233"></a><a class="indexterm" name="d0e1236"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">writeblob</b>(</code><var class="pdparam">blob</var><code>)</code>;</p></div><p>writes a blob in the stream</p><p><a class="indexterm" name="d0e1253"></a><a class="indexterm" name="d0e1256"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">writen</b>(</code><var class="pdparam">n</var>, <var class="pdparam">type</var><code>)</code>;</p></div><p>writes a number in the stream formatted according to the type pameter.
0170                 <i class="parameter"><tt>type</tt></i> can have the following values:
0171                     </p><table class="simplelist" border="0" summary="Simple list"><tr><td><tt class="literal">'i'</tt></td><td>32bits number</td></tr><tr><td><tt class="literal">'s'</tt></td><td>16bits signed integer</td></tr><tr><td><tt class="literal">'w'</tt></td><td>16bits unsigned integer</td></tr><tr><td><tt class="literal">'c'</tt></td><td>8bits signed integer</td></tr><tr><td><tt class="literal">'b'</tt></td><td>8bits unsigned integer</td></tr><tr><td><tt class="literal">'f'</tt></td><td>32bits float</td></tr><tr><td><tt class="literal">'d'</tt></td><td>64bits float</td></tr></table><p>
0172                 </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1314"></a>C API</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1317"></a>Initialization</h3></div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_register_bloblib<a class="indexterm" name="d0e1327"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">psstd_register_bloblib</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
0173                     initialize and register the blob library in the given VM.
0174                 </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>
0175                     the target VM
0176                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0177                     an PSRESULT
0178                 <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
0179                     The function aspects a table on top of the stack where to register the global
0180                     library functions.
0181                 </p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1367"></a>Blob object</h3></div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_getblob<a class="indexterm" name="d0e1377"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">psstd_getblob</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var>, <var class="pdparam">PSUserPointer *&nbsp;ptr</var><code>)</code>;</p></div><p>
0182                     retrieve the pointer of a blob's payload from an arbitrary
0183                     position in the stack.
0184                 </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>
0185                     the target VM
0186                 </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
0187                     and index in the stack
0188                 </p></dd><dt><span class="term"><i class="parameter"><tt>PSUserPointer *&nbsp;ptr</tt></i></span></dt><dd><p>
0189                     A pointer to the userpointer that will point to the blob's payload
0190                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0191                     an PSRESULT
0192                 <br></p></dd></dl></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_getblobsize<a class="indexterm" name="d0e1436"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSInteger&nbsp;<b class="fsfunc">psstd_getblobsize</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;idx</var><code>)</code>;</p></div><p>
0193                     retrieve the size of a blob's payload from an arbitrary
0194                     position in the stack.
0195                 </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>
0196                     the target VM
0197                 </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;idx</tt></i></span></dt><dd><p>
0198                     and index in the stack
0199                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0200                     the size of the blob at idx position
0201                 <br></p></dd></dl></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_createblob<a class="indexterm" name="d0e1486"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSUserPointer&nbsp;<b class="fsfunc">psstd_createblob</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;size</var><code>)</code>;</p></div><p>
0202                     creates a blob with the given payload size and pushes it in the stack.
0203                 </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>
0204                     the target VM
0205                 </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;size</tt></i></span></dt><dd><p>
0206                     the size of the blob payload that has to be created
0207                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0208                     a pointer to the newly created blob payload
0209                 <br></p></dd></dl></div></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="d0e1530"></a>Chapter&nbsp;4.&nbsp;The Math library</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#d0e1537">Pscript API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1540">Global symbols</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e1877">C API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1880">Initialization</a></span></dt></dl></dd></dl></div><a class="indexterm" name="d0e1531"></a><p>
0210             the math lib provides basic mathematic routines. The library mimics the
0211             C runtime library implementation.
0212         </p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1537"></a>Pscript API</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1540"></a>Global symbols</h3></div></div><div></div></div><p><a class="indexterm" name="d0e1544"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">abs</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns the absolute value of <i class="parameter"><tt>x</tt></i> as integer</p><p><a class="indexterm" name="d0e1562"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">acos</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns the arccosine of <i class="parameter"><tt>x</tt></i></p><p><a class="indexterm" name="d0e1579"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">asin</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns the arcsine of <i class="parameter"><tt>x</tt></i></p><p><a class="indexterm" name="d0e1596"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">atan</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns the arctangent of <i class="parameter"><tt>x</tt></i></p><p><a class="indexterm" name="d0e1613"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">atan2</b>(</code><var class="pdparam">x</var>, <var class="pdparam">y</var><code>)</code>;</p></div><p>returns the arctangent of <i class="parameter"><tt>y/x</tt></i>.</p><p><a class="indexterm" name="d0e1633"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">ceil</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns a float value representing the smallest integer that is greater than or equal to <i class="parameter"><tt>x</tt></i></p><p><a class="indexterm" name="d0e1650"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">cos</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns the cosine of <i class="parameter"><tt>x</tt></i></p><p><a class="indexterm" name="d0e1667"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">exp</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns the exponential value of the float parameter <i class="parameter"><tt>x</tt></i></p><p><a class="indexterm" name="d0e1684"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">fabs</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns the absolute value of <i class="parameter"><tt>x</tt></i> as float</p><p><a class="indexterm" name="d0e1702"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">floor</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns a float value representing the largest integer that is less than or equal to <i class="parameter"><tt>x</tt></i></p><p><a class="indexterm" name="d0e1719"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">log</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns the natural logarithm of <i class="parameter"><tt>x</tt></i></p><p><a class="indexterm" name="d0e1736"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">log10</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns the logarithm base-10 of <i class="parameter"><tt>x</tt></i></p><p><a class="indexterm" name="d0e1753"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">pow</b>(</code><var class="pdparam">x</var>, <var class="pdparam">y</var><code>)</code>;</p></div><p>returns <i class="parameter"><tt>x</tt></i> raised to the power of <i class="parameter"><tt>y</tt></i>.</p><p><a class="indexterm" name="d0e1776"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">rand</b>(</code><code>)</code>;</p></div><p>returns a pseudorandom integer in the range 0 to RAND_MAX</p><p><a class="indexterm" name="d0e1789"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">sin</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns the sine of <i class="parameter"><tt>x</tt></i></p><p><a class="indexterm" name="d0e1806"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">psrt</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns the psuare root of <i class="parameter"><tt>x</tt></i></p><p><a class="indexterm" name="d0e1823"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">srand</b>(</code><var class="pdparam">seed</var><code>)</code>;</p></div><p>sets the starting point for generating a series of pseudorandom integers</p><p><a class="indexterm" name="d0e1838"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">tan</b>(</code><var class="pdparam">x</var><code>)</code>;</p></div><p>returns the tangent of <i class="parameter"><tt>x</tt></i></p><p><a class="indexterm" name="d0e1855"></a><tt class="literal">PI</tt></p><p>The numeric constant pi (3.141592) is the ratio of the circumference of a circle to its diameter</p><p><a class="indexterm" name="d0e1865"></a><tt class="literal">RAND_MAX</tt></p><p>the maximum value that can be returned by the <tt class="function">rand()</tt> function</p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1877"></a>C API</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1880"></a>Initialization</h3></div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_register_mathlib<a class="indexterm" name="d0e1890"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">psstd_register_mathlib</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
0213                     initialize and register the math library in the given VM.
0214                 </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>
0215                     the target VM
0216                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0217                     an PSRESULT
0218                 <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
0219                     The function aspects a table on top of the stack where to register the global
0220                     library functions.
0221                 </p></dd></dl></div></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="d0e1931"></a>Chapter&nbsp;5.&nbsp;The System library</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#d0e1938">Pscript API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e1941">Global symbols</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e2119">C API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e2122">Initialization</a></span></dt></dl></dd></dl></div><a class="indexterm" name="d0e1932"></a><p>
0222             The system library exposes operating system facilities like environment variables,
0223             date time manipulation etc..
0224         </p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1938"></a>Pscript API</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1941"></a>Global symbols</h3></div></div><div></div></div><p><a class="indexterm" name="d0e1945"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">clock</b>(</code><code>)</code>;</p></div><p>returns a float representing the number of seconds elapsed since the start of the process</p><p><a class="indexterm" name="d0e1958"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">date</b>(</code><var class="pdparam">[time]</var>, <var class="pdparam">[format]</var><code>)</code>;</p></div><p>returns a table containing a date/time splitted in the slots:</p><p>
0225                         </p><table class="simplelist" border="0" summary="Simple list"><tr><td><tt class="literal">sec</tt></td><td>Seconds after minute (0 - 59).</td></tr><tr><td><tt class="literal">min</tt></td><td>Minutes after hour (0 - 59). </td></tr><tr><td><tt class="literal">hour</tt></td><td>Hours since midnight (0 - 23).</td></tr><tr><td><tt class="literal">day</tt></td><td>Day of month (1 - 31). </td></tr><tr><td><tt class="literal">month</tt></td><td>Month (0 - 11; January = 0). </td></tr><tr><td><tt class="literal">year</tt></td><td>Year (current year). </td></tr><tr><td><tt class="literal">wday</tt></td><td>Day of week (0 - 6; Sunday = 0).  </td></tr><tr><td><tt class="literal">yday</tt></td><td>Day of year (0 - 365; January 1 = 0). </td></tr></table><p>
0226                     </p><p>
0227                         if <i class="parameter"><tt>time</tt></i> is omitted the current time is used. <br>
0228                         if <i class="parameter"><tt>format</tt></i> can be 'l' local time or 'u' UTC time, if omitted is defaulted as 'l'(local time).
0229                     </p><p><a class="indexterm" name="d0e2029"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">getenv</b>(</code><var class="pdparam">varaname</var><code>)</code>;</p></div><p>Returns a string containing the value of the environment variable <i class="parameter"><tt>varname</tt></i></p><p><a class="indexterm" name="d0e2046"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">remove</b>(</code><var class="pdparam">path</var><code>)</code>;</p></div><p>deletes the file specified by <i class="parameter"><tt>path</tt></i></p><p><a class="indexterm" name="d0e2063"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">rename</b>(</code><var class="pdparam">oldname</var>, <var class="pdparam">newname</var><code>)</code>;</p></div><p>renames the file or directory specified by <i class="parameter"><tt>oldname</tt></i> to the name given by <i class="parameter"><tt>newname</tt></i></p><p><a class="indexterm" name="d0e2085"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">system</b>(</code><var class="pdparam">cmd</var><code>)</code>;</p></div><p>executes the string <i class="parameter"><tt>cmd</tt></i> through the os command interpreter.</p><p><a class="indexterm" name="d0e2103"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">time</b>(</code><code>)</code>;</p></div><p>returns the number of seconds elapsed since midnight 00:00:00, January 1, 1970. </p><p>the result of this function can be formatted through the faunction <tt class="function">date</tt></p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e2119"></a>C API</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2122"></a>Initialization</h3></div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_register_systemlib<a class="indexterm" name="d0e2132"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">psstd_register_systemlib</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
0230                     initialize and register the system library in the given VM.
0231                 </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>
0232                     the target VM
0233                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0234                     an PSRESULT
0235                 <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
0236                     The function aspects a table on top of the stack where to register the global
0237                     library functions.
0238                 </p></dd></dl></div></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="d0e2173"></a>Chapter&nbsp;6.&nbsp;The String library</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#d0e2180">Pscript API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e2183">Global symbols</a></span></dt><dt><span class="sect2"><a href="#d0e2591">Regexp class</a></span></dt></dl></dd><dt><span class="sect1"><a href="#d0e2699">C API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e2702">Initialization</a></span></dt><dt><span class="sect2"><a href="#d0e2752">Formatting</a></span></dt><dt><span class="sect2"><a href="#d0e2829">Regular Expessions</a></span></dt></dl></dd></dl></div><a class="indexterm" name="d0e2174"></a><p>
0239             the string lib implements string formatting and regular expression matching routines.
0240         </p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e2180"></a>Pscript API</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2183"></a>Global symbols</h3></div></div><div></div></div><p><a class="indexterm" name="d0e2187"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">format</b>(</code><var class="pdparam">formatstr</var>, <var class="pdparam">...</var><code>)</code>;</p></div><p>
0241                         </p><p>Returns a string formatted according <i class="parameter"><tt>formatstr</tt></i> and the optional parameters following it.
0242                 The format string follows the same rules as the <tt class="function">printf</tt> family of 
0243                  standard C&nbsp;functions( the "*" is not supported).</p><p>
0244                         </p><p>
0245                             </p><pre class="programlisting">
0246 eg.
0247 ps&gt; print(format("%s %d 0x%02X\n","this is a test :",123,10));
0248 this is a test : 123 0x0A
0249 
0250                     </pre><p>
0251                         </p><p>
0252                     </p><p><a class="indexterm" name="d0e2219"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">lstrip</b>(</code><var class="pdparam">str</var><code>)</code>;</p></div><p>
0253             Strips white-space-only characters that might appear at the beginning of the given string
0254             and returns the new stripped string.
0255           </p><p><a class="indexterm" name="d0e2234"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">regexp</b>(</code><var class="pdparam">pattern</var><code>)</code>;</p></div><p>
0256                             </p><p>
0257                     compiles a regular expression pattern and returns it as a new regexp class instance.
0258                     </p><p>
0259                                         </p><table class="simplelist" border="0" summary="Simple list"><tr><td>
0260                                                 <tt class="literal">\</tt>
0261                                             </td><td>Quote the next metacharacter</td></tr><tr><td>
0262                                                 <tt class="literal">^</tt>
0263                                             </td><td>Match the beginning of the string</td></tr><tr><td>
0264                                                 <tt class="literal">.</tt>
0265                                             </td><td>Match any character</td></tr><tr><td>
0266                                                 <tt class="literal">$</tt>
0267                                             </td><td>Match the end of the string</td></tr><tr><td>
0268                                                 <tt class="literal">|</tt>
0269                                             </td><td>Alternation</td></tr><tr><td>
0270                                                 <tt class="literal">(subexp)</tt>
0271                                             </td><td>Grouping (creates a capture)</td></tr><tr><td>
0272                                                 <tt class="literal">(?:subexp)</tt>
0273                                             </td><td>No Capture Grouping (no capture)</td></tr><tr><td>
0274                                                 <tt class="literal">[]</tt>
0275                                             </td><td>Character class </td></tr></table><p>
0276                                     </p><p>
0277                     </p><p><b>GREEDY CLOSURES.&nbsp;</b>
0278                                         </p><table class="simplelist" border="0" summary="Simple list"><tr><td>
0279                                                 <tt class="literal">*</tt>
0280                                             </td><td> Match 0 or more times                         </td></tr><tr><td>
0281                                                 <tt class="literal">+</tt>
0282                                             </td><td> Match 1 or more times                       </td></tr><tr><td>
0283                                                 <tt class="literal">?</tt>
0284                                             </td><td> Match 1 or 0 times                              </td></tr><tr><td>
0285                                                 <tt class="literal">{n}</tt>
0286                                             </td><td>  Match exactly n times                          </td></tr><tr><td>
0287                                                 <tt class="literal">{n,}</tt>
0288                                             </td><td>  Match at least n times                         </td></tr><tr><td>
0289                                                 <tt class="literal">{n,m}</tt>
0290                                             </td><td>  Match at least n but not more than m times     </td></tr></table><p>
0291                                     </p><p>
0292                     </p><p><b>ESCAPE CHARACTERS.&nbsp;</b>
0293                                         </p><table class="simplelist" border="0" summary="Simple list"><tr><td>
0294                                                 <tt class="literal">\t</tt>
0295                                             </td><td>   tab                   (HT, TAB)</td></tr><tr><td>
0296                                                 <tt class="literal">\n</tt>
0297                                             </td><td>   newline               (LF, NL) </td></tr><tr><td>
0298                                                 <tt class="literal">\r</tt>
0299                                             </td><td>   return                (CR)     </td></tr><tr><td>
0300                                                 <tt class="literal">\f</tt>
0301                                             </td><td>   form feed             (FF)     </td></tr></table><p>
0302                                     </p><p>         
0303                     </p><p><b>PREDEFINED CLASSES.&nbsp;</b>
0304                                         </p><table class="simplelist" border="0" summary="Simple list"><tr><td>
0305                                                 <tt class="literal">\l</tt>
0306                                             </td><td>       lowercase next char         </td></tr><tr><td>
0307                                                 <tt class="literal">\u</tt>
0308                                             </td><td>       uppercase next char         </td></tr><tr><td>
0309                                                 <tt class="literal">\a</tt>
0310                                             </td><td>       letters                     </td></tr><tr><td>
0311                                                 <tt class="literal">\A</tt>
0312                                             </td><td>       non letters                 </td></tr><tr><td>
0313                                                 <tt class="literal">\w</tt>
0314                                             </td><td>       alphanumeric [_0-9a-zA-Z]   </td></tr><tr><td>
0315                                                 <tt class="literal">\W</tt>
0316                                             </td><td>       non alphanumeric [^_0-9a-zA-Z]  </td></tr><tr><td>
0317                                                 <tt class="literal">\s</tt>
0318                                             </td><td>       space                       </td></tr><tr><td>
0319                                                 <tt class="literal">\S</tt>
0320                                             </td><td>       non space                   </td></tr><tr><td>
0321                                                 <tt class="literal">\d</tt>
0322                                             </td><td>       digits                      </td></tr><tr><td>
0323                                                 <tt class="literal">\D</tt>
0324                                             </td><td>       non nondigits               </td></tr><tr><td>
0325                                                 <tt class="literal">\x</tt>
0326                                             </td><td>       exadecimal digits           </td></tr><tr><td>
0327                                                 <tt class="literal">\X</tt>
0328                                             </td><td>       non exadecimal digits       </td></tr><tr><td>
0329                                                 <tt class="literal">\c</tt>
0330                                             </td><td>       control charactrs           </td></tr><tr><td>
0331                                                 <tt class="literal">\C</tt>
0332                                             </td><td>       non control charactrs       </td></tr><tr><td>
0333                                                 <tt class="literal">\p</tt>
0334                                             </td><td>       punctation                  </td></tr><tr><td>
0335                                                 <tt class="literal">\P</tt>
0336                                             </td><td>       non punctation              </td></tr><tr><td>
0337                                                 <tt class="literal">\b</tt>
0338                                             </td><td>       word boundary               </td></tr><tr><td>
0339                                                 <tt class="literal">\B</tt>
0340                                             </td><td>       non word boundary           </td></tr></table><p>
0341                                     </p><p>
0342                 </p><p>
0343                         </p><p><a class="indexterm" name="d0e2534"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">rstrip</b>(</code><var class="pdparam">str</var><code>)</code>;</p></div><p>
0344             Strips white-space-only characters that might appear at the end of the given string 
0345             and returns the new stripped string.
0346           </p><p><a class="indexterm" name="d0e2549"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">split</b>(</code><var class="pdparam">str</var>, <var class="pdparam">separators</var><code>)</code>;</p></div><p>
0347             returns an array of strings split at each point where a separator character occurs in <tt class="literal">str</tt>. The separator is not returned as part of any array element.
0348             the parameter <tt class="literal">separators</tt> is a string that specifies the characters as to be used for the splitting.
0349           </p><p>
0350             </p><pre class="programlisting">
0351               
0352 eg.
0353 local a = split("1.2-3;4/5",".-/;");
0354 // the result will be  [1,2,3,4,5]
0355 
0356                     
0357             </pre><p>
0358           </p><p><a class="indexterm" name="d0e2577"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">strip</b>(</code><var class="pdparam">str</var><code>)</code>;</p></div><p>
0359               Strips white-space-only characters that might appear at the beginning or end of the given string
0360               and returns the new stripped string.
0361             </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2591"></a>Regexp class</h3></div></div><div></div></div><p>
0362                     The regexp object rapresent a precompiled regular experssion pattern. The object is created
0363                     trough the function <tt class="function">regexp()</tt>.
0364                 </p><p><a class="indexterm" name="d0e2600"></a><a class="indexterm" name="d0e2603"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">capture</b>(</code><var class="pdparam">str</var>, <var class="pdparam">[start]</var><code>)</code>;</p></div><p>
0365                         </p><p>
0366                     returns an array of tables containing two indexs("begin" and "end")of 
0367                     the first match of the regular expression in the string <i class="parameter"><tt>str</tt></i>.
0368                     An array entry is created for each captured sub expressions. If no match occurs returns null.
0369                     The search starts from the index <i class="parameter"><tt>start</tt></i>
0370                     of the string, if <i class="parameter"><tt>start</tt></i> is omitted the search starts from the beginning of the string.
0371                     </p><p>
0372                     </p><p>
0373                         the first element of the returned array(index 0) always contains the complete match.
0374                     </p><p>
0375                 </p><pre class="programlisting"> 
0376 local ex = regexp(@"(\d+) ([a-zA-Z]+)(\p)");
0377 local string = "stuff 123 Test;";
0378 local res = ex.capture(string);
0379 foreach(i,val in res)
0380 {
0381     print(format("match number[%02d] %s\n",
0382             i,string.slice(val.begin,val.end))); //prints "Test"
0383 }
0384 
0385 ...
0386 will print
0387 match number[00] 123 Test;
0388 match number[01] 123
0389 match number[02] Test
0390 match number[03] ;
0391                 
0392                 </pre><p>
0393                     </p><p><a class="indexterm" name="d0e2640"></a><a class="indexterm" name="d0e2643"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">match</b>(</code><var class="pdparam">str</var><code>)</code>;</p></div><p>
0394                         returns a true if the regular expression matches the string
0395                         <i class="parameter"><tt>str</tt></i>, otherwise returns false.
0396                     </p><p><a class="indexterm" name="d0e2663"></a><a class="indexterm" name="d0e2666"></a></p><div class="funcsynopsis"><p><code class="funcdef"><b class="fsfunc">search</b>(</code><var class="pdparam">str</var>, <var class="pdparam">[start]</var><code>)</code>;</p></div><p>
0397                         </p><p>
0398                     returns a table containing two indexs("begin" and "end") of the first match of the regular expression in
0399                     the string <i class="parameter"><tt>str</tt></i>, otherwise if no match occurs returns null. The search starts from the index <i class="parameter"><tt>start</tt></i>
0400                     of the string, if <i class="parameter"><tt>start</tt></i> is omitted the search starts from the beginning of the string.
0401                 </p><p>
0402                         </p><pre class="programlisting"> 
0403 local ex = regexp("[a-zA-Z]+");
0404 local string = "123 Test;";
0405 local res = ex.search(string);
0406 print(string.slice(res.begin,res.end)); //prints "Test"
0407                 
0408                 </pre><p>
0409                     </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e2699"></a>C API</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2702"></a>Initialization</h3></div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_register_stringlib<a class="indexterm" name="d0e2712"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">psstd_register_stringlib</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
0410                     initialize and register the string library in the given VM.
0411                 </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>
0412                     the target VM
0413                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0414                     an PSRESULT
0415                 <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
0416                     The function aspects a table on top of the stack where to register the global
0417                     library functions.
0418                 </p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2752"></a>Formatting</h3></div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_format<a class="indexterm" name="d0e2762"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRESULT&nbsp;<b class="fsfunc">psstd_format</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var>, <var class="pdparam">PSInteger&nbsp;nformatstringidx</var>, <var class="pdparam">PSInteger *&nbsp;outlen</var>, <var class="pdparam">PSChar **&nbsp;output</var><code>)</code>;</p></div><p>
0419           
0420             creates a new string formatted according to the object at positionnformatstringidx and the optional parameters following it.
0421             The format string follows the same rules as the printf family of
0422             standard C&nbsp;functions( the "*" is not supported).
0423           
0424         </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>
0425           the target VM
0426         </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;nformatstringidx</tt></i></span></dt><dd><p>
0427           index in the stack of the format string
0428         </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger *&nbsp;outlen</tt></i></span></dt><dd><p>
0429           a pointer to an integer that will be filled with the length of the newly created string
0430         </p></dd><dt><span class="term"><i class="parameter"><tt>PSChar **&nbsp;output</tt></i></span></dt><dd><p>
0431           a pointer to a string pointer that will receive the newly created string
0432         </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0433           an PSRESULT
0434         <br></p></dd><dt><span class="term">remarks:</span></dt><dd><p>
0435           the newly created string is allocated in the scratchpad memory.
0436         </p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e2829"></a>Regular Expessions</h3></div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_rex_compile<a class="indexterm" name="d0e2839"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSRex *&nbsp;<b class="fsfunc">psstd_rex_compile</b>(</code><var class="pdparam">const PSChar *&nbsp;pattern</var>, <var class="pdparam">const PSChar **&nbsp;error</var><code>)</code>;</p></div><p>
0437                     compiles an expression and returns a pointer to the compiled version.
0438                     in case of failure returns NULL.The returned object has to be deleted
0439                     through the function psstd_rex_free().
0440                 </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>const PSChar *&nbsp;pattern</tt></i></span></dt><dd><p>
0441                     a pointer to a zero terminated string containing the pattern that 
0442                     has to be compiled.
0443                 </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar **&nbsp;error</tt></i></span></dt><dd><p>
0444                     a pointer to a string pointer that will be set with an error string
0445                     in case of failure.
0446                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0447                     a pointer to the compiled pattern
0448                 <br></p></dd></dl></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_rex_free<a class="indexterm" name="d0e2889"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">psstd_rex_free</b>(</code><var class="pdparam">PSRex *&nbsp;exp</var><code>)</code>;</p></div><p>
0449                     deletes a expression structure created with psstd_rex_compile()
0450                 </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>PSRex *&nbsp;exp</tt></i></span></dt><dd><p>
0451                     the expression structure that has to be deleted
0452                 </p></dd></dl></div></dd></dl></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_rex_match<a class="indexterm" name="d0e2923"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSBool&nbsp;<b class="fsfunc">psstd_rex_match</b>(</code><var class="pdparam">PSRex *&nbsp;exp</var>, <var class="pdparam">const PSChar *&nbsp;text</var><code>)</code>;</p></div><p>
0453                     returns PSTrue if the string specified in the parameter text is an
0454                     exact match of the expression, otherwise returns PSFalse.
0455 
0456                 </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>PSRex *&nbsp;exp</tt></i></span></dt><dd><p>
0457                     the compiled expression
0458                 </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar *&nbsp;text</tt></i></span></dt><dd><p>
0459                     the string that has to be tested
0460                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0461                     PSTrue if successful otherwise PSFalse
0462                 <br></p></dd></dl></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_rex_search<a class="indexterm" name="d0e2973"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSBool&nbsp;<b class="fsfunc">psstd_rex_search</b>(</code><var class="pdparam">PSRex *&nbsp;exp</var>, <var class="pdparam">const PSChar *&nbsp;text</var>, <var class="pdparam">const PSChar **&nbsp;out_begin</var>, <var class="pdparam">const PSChar **&nbsp;out_end</var><code>)</code>;</p></div><p>
0463                     searches the first match of the expressin in the string specified in the parameter text.
0464                     if the match is found returns PSTrue and the sets out_begin to the beginning of the
0465                     match and out_end at the end of the match; otherwise returns PSFalse.
0466  
0467                 </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>PSRex *&nbsp;exp</tt></i></span></dt><dd><p>
0468                     the compiled expression
0469                 </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar *&nbsp;text</tt></i></span></dt><dd><p>
0470                     the string that has to be tested
0471                 </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar **&nbsp;out_begin</tt></i></span></dt><dd><p>
0472                     a pointer to a string pointer that will be set with the beginning of the match
0473                 </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar **&nbsp;out_end</tt></i></span></dt><dd><p>
0474                     a pointer to a string pointer that will be set with the end of the match
0475                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0476                     PSTrue if successful otherwise PSFalse
0477                 <br></p></dd></dl></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_rex_searchrange<a class="indexterm" name="d0e3041"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSBool&nbsp;<b class="fsfunc">psstd_rex_searchrange</b>(</code><var class="pdparam">PSRex *&nbsp;exp</var>, <var class="pdparam">const PSChar *&nbsp;text_begin</var>, <var class="pdparam">const PSChar *&nbsp;text_end</var>, <var class="pdparam">const PSChar **&nbsp;out_begin</var>, <var class="pdparam">const PSChar **&nbsp;out_end</var><code>)</code>;</p></div><p>
0478                     searches the first match of the expressin in the string delimited 
0479                     by the parameter text_begin and text_end.
0480                     if the match is found returns PSTrue and the sets out_begin to the beginning of the
0481                     match and out_end at the end of the match; otherwise returns PSFalse.
0482                 </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>PSRex *&nbsp;exp</tt></i></span></dt><dd><p>
0483                     the compiled expression
0484                 </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar *&nbsp;text_begin</tt></i></span></dt><dd><p>
0485                     a pointer to the beginnning of the string that has to be tested
0486                 </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar *&nbsp;text_end</tt></i></span></dt><dd><p>
0487                     a pointer to the end of the string that has to be tested
0488                 </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar **&nbsp;out_begin</tt></i></span></dt><dd><p>
0489                     a pointer to a string pointer that will be set with the beginning of the match
0490                 </p></dd><dt><span class="term"><i class="parameter"><tt>const PSChar **&nbsp;out_end</tt></i></span></dt><dd><p>
0491                     a pointer to a string pointer that will be set with the end of the match
0492                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0493                     an PSRESULT
0494                 <br></p></dd></dl></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_rex_getsubexpcount<a class="indexterm" name="d0e3118"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSInteger&nbsp;<b class="fsfunc">psstd_rex_getsubexpcount</b>(</code><var class="pdparam">PSRex *&nbsp;exp</var><code>)</code>;</p></div><p>
0495                     returns the number of sub expressions matched by the expression
0496                 </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>PSRex *&nbsp;exp</tt></i></span></dt><dd><p>
0497                     the compiled expression
0498                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0499                     the number of sub expressions matched by the expression
0500                 <br></p></dd></dl></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_rex_getsubexp<a class="indexterm" name="d0e3159"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">PSInteger&nbsp;<b class="fsfunc">psstd_rex_getsubexp</b>(</code><var class="pdparam">PSRex *&nbsp;exp</var>, <var class="pdparam">PSInteger&nbsp;n</var>, <var class="pdparam">PSRexMatch *&nbsp;subexp</var><code>)</code>;</p></div><p>
0501                     retrieve the begin and and pointer to the length of the sub expression indexed
0502                     by n. The result is passed trhough the struct PSRexMatch.
0503                     
0504                 </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>PSRex *&nbsp;exp</tt></i></span></dt><dd><p>
0505                     the compiled expression
0506                 </p></dd><dt><span class="term"><i class="parameter"><tt>PSInteger&nbsp;n</tt></i></span></dt><dd><p>
0507                     the index of the submatch(0 is the complete match)
0508                 </p></dd><dt><span class="term"><i class="parameter"><tt>PSRexMatch *&nbsp;subexp</tt></i></span></dt><dd><p>
0509                     a pointer to structure that will store the result
0510                 </p></dd></dl></div></dd><dt><span class="term">return:</span></dt><dd><p>
0511                     the function returns PSTrue if n is valid index otherwise PSFalse.
0512                 <br></p></dd></dl></div></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="d0e3212"></a>Chapter&nbsp;7.&nbsp;The Aux library</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#d0e3219">C API</a></span></dt><dd><dl><dt><span class="sect2"><a href="#d0e3222">Error handling</a></span></dt></dl></dd></dl></div><a class="indexterm" name="d0e3213"></a><p>
0513             The aux library implements default handlers for compiler and runtime errors and a stack dumping.
0514         </p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e3219"></a>C API</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e3222"></a>Error handling</h3></div></div><div></div></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_seterrorhandlers<a class="indexterm" name="d0e3232"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">psstd_seterrorhandlers</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
0515                     initialize compiler and runtime error handlers, the handlers
0516                     use the print function set through(ps_setprintfunc) to output
0517                     the error.
0518                 </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>
0519                     the target VM
0520                 </p></dd></dl></div></dd></dl></div><div class="informaltable"><table border="1"><colgroup><col></colgroup><tbody><tr><td><tt class="function">psstd_printcallstack<a class="indexterm" name="d0e3266"></a></tt></td></tr></tbody></table></div><div class="funcsynopsis"><p><code class="funcdef">void&nbsp;<b class="fsfunc">psstd_printcallstack</b>(</code><var class="pdparam">HPSCRIPTVM&nbsp;v</var><code>)</code>;</p></div><p>
0521                     print the call stack and stack contents.the function
0522                     uses the print function set through(ps_setprintfunc) to output
0523                     the stack dump.
0524                 </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>
0525                     the target VM
0526                 </p></dd></dl></div></dd></dl></div></div></div></div><div class="index"><div class="titlepage"><div><div><h2 class="title"><a name="d0e3293"></a>Index</h2></div></div><div></div></div><div class="index"><div class="indexdiv"><h3></h3><dl><dt>, <a href="#d0e49">The Input/Output library</a>, <a href="#d0e841">The Blob library</a>, <a href="#d0e1530">The Math library</a>, <a href="#d0e1931">The System library</a>, <a href="#d0e2173">The String library</a>, <a href="#d0e3212">The Aux library</a></dt></dl></div><div class="indexdiv"><h3>A</h3><dl><dt>abs, <a href="#d0e1540">Global symbols</a></dt><dt>acos, <a href="#d0e1540">Global symbols</a></dt><dt>asin, <a href="#d0e1540">Global symbols</a></dt><dt>atan, <a href="#d0e1540">Global symbols</a></dt><dt>atan2, <a href="#d0e1540">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>B</h3><dl><dt>blob, <a href="#d0e854">Global symbols</a></dt><dd><dl><dt>eos, <a href="#d0e947">The blob class</a></dt><dt>flush, <a href="#d0e947">The blob class</a></dt><dt>len, <a href="#d0e947">The blob class</a></dt><dt>readblob, <a href="#d0e947">The blob class</a></dt><dt>readn, <a href="#d0e947">The blob class</a></dt><dt>resize, <a href="#d0e947">The blob class</a></dt><dt>seek, <a href="#d0e947">The blob class</a></dt><dt>swap2, <a href="#d0e947">The blob class</a></dt><dt>swap4, <a href="#d0e947">The blob class</a></dt><dt>tell, <a href="#d0e947">The blob class</a></dt><dt>writeblob, <a href="#d0e947">The blob class</a></dt><dt>writen, <a href="#d0e947">The blob class</a></dt></dl></dd></dl></div><div class="indexdiv"><h3>C</h3><dl><dt>capture, <a href="#d0e2591">Regexp class</a></dt><dt>castf2i, <a href="#d0e854">Global symbols</a></dt><dt>casti2f, <a href="#d0e854">Global symbols</a></dt><dt>ceil, <a href="#d0e1540">Global symbols</a></dt><dt>clock, <a href="#d0e1941">Global symbols</a></dt><dt>close, <a href="#d0e152">File class</a></dt><dt>cos, <a href="#d0e1540">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>D</h3><dl><dt>date, <a href="#d0e1941">Global symbols</a></dt><dt>dofile, <a href="#d0e59">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>E</h3><dl><dt>eos, <a href="#d0e152">File class</a>, <a href="#d0e947">The blob class</a></dt><dt>exp, <a href="#d0e1540">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>F</h3><dl><dt>fabs, <a href="#d0e1540">Global symbols</a></dt><dt>file</dt><dd><dl><dt>close, <a href="#d0e152">File class</a></dt><dt>eos, <a href="#d0e152">File class</a></dt><dt>flush, <a href="#d0e152">File class</a></dt><dt>len, <a href="#d0e152">File class</a></dt><dt>readblob, <a href="#d0e152">File class</a></dt><dt>readn, <a href="#d0e152">File class</a></dt><dt>seek, <a href="#d0e152">File class</a></dt><dt>tell, <a href="#d0e152">File class</a></dt><dt>writeblob, <a href="#d0e152">File class</a></dt><dt>writen, <a href="#d0e152">File class</a></dt></dl></dd><dt>floor, <a href="#d0e1540">Global symbols</a></dt><dt>flush, <a href="#d0e152">File class</a>, <a href="#d0e947">The blob class</a></dt><dt>format, <a href="#d0e2183">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>G</h3><dl><dt>getenv, <a href="#d0e1941">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>L</h3><dl><dt>len, <a href="#d0e152">File class</a>, <a href="#d0e947">The blob class</a></dt><dt>loadfile, <a href="#d0e59">Global symbols</a></dt><dt>log, <a href="#d0e1540">Global symbols</a></dt><dt>log10, <a href="#d0e1540">Global symbols</a></dt><dt>lstrip, <a href="#d0e2183">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>M</h3><dl><dt>match, <a href="#d0e2591">Regexp class</a></dt></dl></div><div class="indexdiv"><h3>P</h3><dl><dt>PI, <a href="#d0e1540">Global symbols</a></dt><dt>pow, <a href="#d0e1540">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>R</h3><dl><dt>rand, <a href="#d0e1540">Global symbols</a></dt><dt>RAND_MAX, <a href="#d0e1540">Global symbols</a></dt><dt>readblob, <a href="#d0e152">File class</a>, <a href="#d0e947">The blob class</a></dt><dt>readn, <a href="#d0e152">File class</a>, <a href="#d0e947">The blob class</a></dt><dt>regexp, <a href="#d0e2183">Global symbols</a></dt><dd><dl><dt>capture, <a href="#d0e2591">Regexp class</a></dt><dt>match, <a href="#d0e2591">Regexp class</a></dt><dt>search, <a href="#d0e2591">Regexp class</a></dt></dl></dd><dt>remove, <a href="#d0e1941">Global symbols</a></dt><dt>rename, <a href="#d0e1941">Global symbols</a></dt><dt>resize, <a href="#d0e947">The blob class</a></dt><dt>rstrip, <a href="#d0e2183">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>S</h3><dl><dt>search, <a href="#d0e2591">Regexp class</a></dt><dt>seek, <a href="#d0e152">File class</a>, <a href="#d0e947">The blob class</a></dt><dt>sin, <a href="#d0e1540">Global symbols</a></dt><dt>split, <a href="#d0e2183">Global symbols</a></dt><dt>psrt, <a href="#d0e1540">Global symbols</a></dt><dt>psstd_createblob, <a href="#d0e1367">Blob object</a></dt><dt>psstd_createfile, <a href="#d0e526">File object</a></dt><dt>psstd_dofile, <a href="#d0e647">Script loading and serialization</a></dt><dt>psstd_format, <a href="#d0e2752">Formatting</a></dt><dt>psstd_getblob, <a href="#d0e1367">Blob object</a></dt><dt>psstd_getblobsize, <a href="#d0e1367">Blob object</a></dt><dt>psstd_getfile, <a href="#d0e526">File object</a></dt><dt>psstd_loadfile, <a href="#d0e647">Script loading and serialization</a></dt><dt>psstd_printcallstack, <a href="#d0e3222">Error handling</a></dt><dt>psstd_register_bloblib, <a href="#d0e1317">Initialization</a></dt><dt>psstd_register_iolib, <a href="#d0e476">Initialization</a></dt><dt>psstd_register_mathlib, <a href="#d0e1880">Initialization</a></dt><dt>psstd_register_stringlib, <a href="#d0e2702">Initialization</a></dt><dt>psstd_register_systemlib, <a href="#d0e2122">Initialization</a></dt><dt>psstd_rex_compile, <a href="#d0e2829">Regular Expessions</a></dt><dt>psstd_rex_free, <a href="#d0e2829">Regular Expessions</a></dt><dt>psstd_rex_getsubexp, <a href="#d0e2829">Regular Expessions</a></dt><dt>psstd_rex_getsubexpcount, <a href="#d0e2829">Regular Expessions</a></dt><dt>psstd_rex_match, <a href="#d0e2829">Regular Expessions</a></dt><dt>psstd_rex_search, <a href="#d0e2829">Regular Expessions</a></dt><dt>psstd_rex_searchrange, <a href="#d0e2829">Regular Expessions</a></dt><dt>psstd_seterrorhandlers, <a href="#d0e3222">Error handling</a></dt><dt>psstd_writeclosuretofile, <a href="#d0e647">Script loading and serialization</a></dt><dt>srand, <a href="#d0e1540">Global symbols</a></dt><dt>stderr, <a href="#d0e59">Global symbols</a></dt><dt>stdin, <a href="#d0e59">Global symbols</a></dt><dt>stdout, <a href="#d0e59">Global symbols</a></dt><dt>strip, <a href="#d0e2183">Global symbols</a></dt><dt>swap2, <a href="#d0e854">Global symbols</a>, <a href="#d0e947">The blob class</a></dt><dt>swap4, <a href="#d0e854">Global symbols</a>, <a href="#d0e947">The blob class</a></dt><dt>swapfloat, <a href="#d0e854">Global symbols</a></dt><dt>system, <a href="#d0e1941">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>T</h3><dl><dt>tan, <a href="#d0e1540">Global symbols</a></dt><dt>tell, <a href="#d0e152">File class</a>, <a href="#d0e947">The blob class</a></dt><dt>time, <a href="#d0e1941">Global symbols</a></dt></dl></div><div class="indexdiv"><h3>W</h3><dl><dt>writeblob, <a href="#d0e152">File class</a>, <a href="#d0e947">The blob class</a></dt><dt>writeclosuretofile, <a href="#d0e59">Global symbols</a></dt><dt>writen, <a href="#d0e152">File class</a>, <a href="#d0e947">The blob class</a></dt></dl></div></div></div></div></body></html>