Php/docs/luasandbox.loadstring
来自菜鸟教程
LuaSandbox::loadString
(PECL luasandbox >= 1.0.0)
LuaSandbox::loadString — Load Lua code into the Lua environment
说明
public LuaSandbox::loadString
( string $code
[, string $chunkName
=
] ) : LuaSandboxFunction
Loads Lua code into the Lua environment.
This is the equivalent of standard Lua's loadstring()
function.
参数
code
- Lua code.
chunkName
- Name for the loaded chunk, for use in error traces.
范例
Example #1 Loading code into Lua
<?php// create a new LuaSandbox$sandbox = new LuaSandbox();// Load the code$function = $sandbox->loadString(<<<CODE return "Hello, world"CODE);// Execute the loaded codevar_dump( $function->call() );?>
以上例程会输出:
array(1) { [0]=> string(12) "Hello, world" }
参见
- LuaSandbox::registerLibrary() - Register a set of PHP functions as a Lua library
- LuaSandbox::wrapPhpFunction() - Wrap a PHP callable in a LuaSandboxFunction