<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.luasandbox.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'luasandbox.registerlibrary.php',
    1 => 'LuaSandbox::registerLibrary',
    2 => 'Register a set of PHP functions as a Lua library',
  ),
  'up' => 
  array (
    0 => 'class.luasandbox.php',
    1 => 'LuaSandbox',
  ),
  'prev' => 
  array (
    0 => 'luasandbox.pauseusagetimer.php',
    1 => 'LuaSandbox::pauseUsageTimer',
  ),
  'next' => 
  array (
    0 => 'luasandbox.setcpulimit.php',
    1 => 'LuaSandbox::setCPULimit',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/luasandbox/luasandbox/registerlibrary.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="luasandbox.registerlibrary" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">LuaSandbox::registerLibrary</h1>
  <p class="verinfo">(PECL luasandbox &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">LuaSandbox::registerLibrary</span> &mdash; <span class="dc-title">Register a set of PHP functions as a Lua library</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-luasandbox.registerlibrary-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>LuaSandbox::registerLibrary</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$libname</code></span>, <span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$functions</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <p class="simpara">
   Registers a set of PHP functions as a Lua library, so that Lua can call
   the relevant PHP code.
  </p>
  <p class="simpara">
   For more information about calling Lua functions and the return values,
   see <span class="methodname"><a href="luasandboxfunction.call.php" class="methodname">LuaSandboxFunction::call()</a></span>.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-luasandbox.registerlibrary-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <dl>
   
    <dt><code class="parameter">libname</code></dt>
    <dd>
     <span class="simpara">
      The name of the library. In the Lua state, the global variable of this
      name will be set to the table of functions. If the table already exists,
      the new functions will be added to it.
     </span>
    </dd>
   
   
    <dt><code class="parameter">functions</code></dt>
    <dd>
     <span class="simpara">
      An <span class="type"><a href="language.types.array.php" class="type array">array</a></span>, where each key is a function name, and each value is a
      corresponding PHP <span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span>.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-luasandbox.registerlibrary-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="simpara">
   Es wird kein Wert zurückgegeben.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-luasandbox.registerlibrary-examples">
  <h3 class="title">Beispiele</h3>
  <div class="example" id="example-1">
   <p><strong>Beispiel #1 Registering PHP functions to call from Lua</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// create a new LuaSandbox<br /></span><span style="color: #0000BB">$sandbox </span><span style="color: #007700">= new </span><span style="color: #0000BB">LuaSandbox</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Register some functions in the Lua environment<br /><br /></span><span style="color: #007700">function </span><span style="color: #0000BB">frobnosticate</span><span style="color: #007700">( </span><span style="color: #0000BB">$v </span><span style="color: #007700">) {<br />    return [ </span><span style="color: #0000BB">$v </span><span style="color: #007700">+ </span><span style="color: #0000BB">42 </span><span style="color: #007700">];<br />}<br /><br /></span><span style="color: #0000BB">$sandbox</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">registerLibrary</span><span style="color: #007700">( </span><span style="color: #DD0000">'php'</span><span style="color: #007700">, [<br />    </span><span style="color: #DD0000">'frobnosticate' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'frobnosticate'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'output' </span><span style="color: #007700">=&gt; function ( </span><span style="color: #0000BB">$string </span><span style="color: #007700">) {<br />        echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$string</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />    },<br />    </span><span style="color: #DD0000">'error' </span><span style="color: #007700">=&gt; function () {<br />        throw new </span><span style="color: #0000BB">LuaSandboxRuntimeError</span><span style="color: #007700">( </span><span style="color: #DD0000">"Something is wrong" </span><span style="color: #007700">);<br />    }<br />] );<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-luasandbox.registerlibrary-seealso">
  <h3 class="title">Siehe auch</h3>
  <ul class="simplelist">
   <li><span class="methodname"><a href="luasandbox.loadstring.php" class="methodname" rel="rdfs-seeAlso">LuaSandbox::loadString()</a> - Load Lua code into the Lua environment</span></li>
   <li><span class="methodname"><a href="luasandbox.wrapphpfunction.php" class="methodname" rel="rdfs-seeAlso">LuaSandbox::wrapPhpFunction()</a> - Wrap a PHP callable in a LuaSandboxFunction</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>