(PECL luasandbox >= 1.0.0)

LuaSandbox::registerLibraryRegister a set of PHP functions as a Lua library


public LuaSandbox::registerLibrary ( string $libname , array $functions ) : void

Registers a set of PHP functions as a Lua library, so that Lua can call the relevant PHP code.

For more information about calling Lua functions and the return values, see LuaSandboxFunction::call().



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.


An array, where each key is a function name, and each value is a corresponding PHP callable.

Zwracane wartości

Nie jest zwracana żadna wartość.


Przykład #1 Registering PHP functions to call from Lua


// create a new LuaSandbox
$sandbox = new LuaSandbox();

// Register some functions in the Lua environment

function frobnosticate$v ) {
    return [ 
$v 42 ];

$sandbox->registerLibrary'php', [
'frobnosticate' => 'frobnosticate',
'output' => function ( $string ) {
'error' => function () {
        throw new 
LuaSandboxRuntimeError"Something is wrong" );
] );


Zobacz też:

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top