LuaSandbox::loadString
(PECL luasandbox >= 1.0.0)
LuaSandbox::loadString — Load Lua code into the Lua environment
Beschreibung
Loads Lua code into the Lua environment.
This is the equivalent of standard Lua's loadstring()
function.
Parameter-Liste
-
code
-
Lua code.
-
chunkName
-
Name for the loaded chunk, for use in error traces.
Rückgabewerte
Returns a LuaSandboxFunction which, when executed, will execute the passed $code.
Beispiele
Beispiel #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 code
var_dump( $function->call() );
?>
Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
array(1) { [0]=> string(12) "Hello, world" }
Siehe auch
- LuaSandbox::registerLibrary() - Register a set of PHP functions as a Lua library
- LuaSandbox::wrapPhpFunction() - Wrap a PHP callable in a LuaSandboxFunction