LuaSandbox::loadString
(PECL luasandbox >= 1.0.0)
LuaSandbox::loadString — Load Lua code into the Lua environment
説明
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.
戻り値
Returns a LuaSandboxFunction which, when executed, will execute the passed $code.
例
例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() );
?>
上の例の出力は以下となります。
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
+add a note
User Contributed Notes
There are no user contributed notes for this page.
↑ and ↓ to navigate •
Enter to select •
Esc to close
Press Enter without
selection to search using Google