LuaSandbox::loadString
PHP function
Edit on GitHub ✎
(PECL luasandbox >= 1.0.0)
Load Lua code into the Lua environment
Description
LuaSandbox::loadString(string $code, string $chunkName = ''): LuaSandboxFunction
Loads Lua code into the Lua environment.
This is the equivalent of standard Lua's loadstring() function.
Parameters
codeLua code.
chunkNameName for the loaded chunk, for use in error traces.
Return Values
Returns a LuaSandboxFunction which, when executed, will execute the passed $code.
Examples
Loading code into Lua
php
<?php
// create a new LuaSandbox
$sandbox = new LuaSandbox();
// Load the code
$function = $sandbox->loadString(
<<<CODE
return "Hello, world"
CODE
);
// Execute the loaded code
var_dump( $function->call() );
?>The above example will output:
output
array(1) {
[0]=>
string(12) "Hello, world"
}See Also
LuaSandbox::registerLibraryLuaSandbox::wrapPhpFunction