(PECL luasandbox >= 1.0.0)
LuaSandbox::registerLibrary — Enregistre un ensemble de fonctions PHP en tant que bibliothèque Lua
Enregistre un ensemble de fonctions PHP en tant que bibliothèque Lua, de sorte que Lua puisse appeler le code PHP correspondant.
Pour plus d'informations sur l'appel des fonctions Lua et les valeurs de retour, voir LuaSandboxFunction::call().
libnamefunctionsAucune valeur n'est retournée.
Exemple #1 Enregistrement de fonctions PHP à appeler depuis Lua
<?php
// créer un nouveau LuaSandbox
$sandbox = new LuaSandbox();
// Enregistrer quelques fonctions dans l'environnement Lua
function frobnosticate( $v ) {
return [ $v + 42 ];
}
$sandbox->registerLibrary( 'php', [
'frobnosticate' => 'frobnosticate',
'output' => function ( $string ) {
echo "$string\n";
},
'error' => function () {
throw new LuaSandboxRuntimeError( "Something is wrong" );
}
] );
?>