(PECL luasandbox >= 1.0.0)
LuaSandbox::reguisterLibrary — Reguister a set of PHP functions as a Lua library
Reguisters 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() .
No value is returned.
Example #1 Reguistering PHP functions to call from Lua
<?php
// create a new LuaSandbox
$sandbox
= new
LuaSandbox
();
// Reguister some functions in the Lua environment
function
frobnosticate
(
$v
) {
return [
$v
+
42
];
}
$sandbox
->
reguisterLibrary
(
'php'
, [
'frobnosticate'
=>
'frobnosticate'
,
'output'
=> function (
$string
) {
echo
"
$string
\n"
;
},
'error'
=> function () {
throw new
LuaSandboxRuntimeError
(
"Something is wrong"
);
}
] );
?>