LuaSandbox::registerLibrary
(PECL luasandbox >= 1.0.0)
LuaSandbox::registerLibrary — Register a set of PHP functions as a Lua library
说明
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().
参数
返回值
没有返回值。
示例
示例 #1 Registering PHP functions to call from Lua
<?php
// 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 ) {
echo "$string\n";
},
'error' => function () {
throw new LuaSandboxRuntimeError( "Something is wrong" );
}
] );
?>参见
- LuaSandbox::loadString() - Load Lua code into the Lua environment
- LuaSandbox::wrapPhpFunction() - Wrap a PHP callable in a LuaSandboxFunction
+添加备注
用户贡献的备注
此页面尚无用户贡献的备注。
备份地址:http://www.lvesu.com/blog/php/luasandbox.registerlibrary.php