LuaSandbox::getProfilerFunctionReport()
* to return timings in samples.
*/
public const SAMPLES = 0;
/**
* Used with LuaSandbox::getProfilerFunctionReport()
* to return timings in seconds.
*/
public const SECONDS = 1;
/**
* Used with LuaSandbox::getProfilerFunctionReport()
* to return timings in percentages of the total.
*/
public const PERCENT = 2;
/**
* Call a function in a Lua global variable.
*
* If the name contains "." characters, the function is located via recursive table accesses, * as if the name were a Lua expression.
* *If the variable does not exist, or is not a function, * false will be returned and a warning issued.
* *For more information about calling Lua functions and the return values,
* see LuaSandboxFunction::call()
.
Lua variable name.
* @param mixed[] $argumentsArguments to the function.
* @return array|boolReturns an array of values returned by the Lua function, * which may be empty, or false in case of failure.
* @see LuaSandboxFunction::call() * @since luasandbox >= 1.0.0 */ public function callFunction($name, array $arguments) {} /** * Disable the profiler. * * @link https://www.php.net/manual/en/luasandbox.disableProfiler.php * @since luasandbox >= 1.1.0 * @see LuaSandbox::enableProfiler() * @see LuaSandbox::getProfilerFunctionReport() */ public function disableProfiler() {} /** * Enable the profiler. * *The profiler periodically samples the Lua environment * to record the running function. Testing indicates that * at least on Linux, setting a period less than 1ms will * lead to a high overrun count but no performance problems.
* * @link https://www.php.net/manual/en/luasandbox.enableprofiler.php * @param float $period [optional]Sampling period in seconds.
* @return boolReturns a boolean indicating whether the profiler is enabled.
* @since luasandbox >= 1.1.0 * @see LuaSandbox::disableProfiler() * @see LuaSandbox::getProfilerFunctionReport() */ public function enableProfiler($period = 0.02) {} /** * Fetch the current CPU time usage of the Lua environment. * *This includes time spent in PHP callbacks.
* *Note: On Windows, this function always returns zero. * On operating systems that do not support CLOCK_THREAD_CPUTIME_ID, * such as FreeBSD and Mac OS X, this function will return the * elapsed wall-clock time, not CPU time.
* * @link https://www.php.net/manual/en/luasandbox.getcpuusage.php * @return floatReturns the current CPU time usage in seconds.
* @since luasandbox >= 1.0.0 * @see LuaSandbox::getMemoryUsage() * @see LuaSandbox::getPeakMemoryUsage() * @see LuaSandbox::setCPULimit() */ public function getCPUUsage() {} /** * Fetch the current memory usage of the Lua environment. * * @link https://www.php.net/manual/en/luasandbox.getmemoryusage.php * @return int * @since luasandbox >= 1.0.0 * @see LuaSandbox::getMemoryUsage() * @see LuaSandbox::getCPUUsage() * @see LuaSandbox::setMemoryLimit() */ public function getMemoryUsage() {} /** * Fetch the peak memory usage of the Lua environment. * * @link https://www.php.net/manual/en/luasandbox.getpeakmemoryusage.php * @return intReturns the current memory usage in bytes.
* @since luasandbox >= 1.0.0 * @see LuaSandbox::getMemoryUsage() * @see LuaSandbox::getCPUUsage() * @see LuaSandbox::setMemoryLimit() */ public function getPeakMemoryUsage() {} /** * Fetch profiler data. * *For a profiling instance previously started by LuaSandbox::enableProfiler()
,
* get a report of the cost of each function.
The measurement unit used for the cost is determined by the $units parameter:
*LuaSandbox::SAMPLES
Measure in number of samples.LuaSandbox::SECONDS
Measure in seconds of CPU time.LuaSandbox::PERCENT
Measure percentage of CPU time.Note: On Windows, this function always returns an empty array. * On operating systems that do not support CLOCK_THREAD_CPUTIME_ID, * such as FreeBSD and Mac OS X, this function will report the * elapsed wall-clock time, not CPU time.
* * @link https://www.php.net/manual/en/luasandbox.getprofilerfunctionreport.php * @param int $units Measurement unit constant. * @return arrayReturns profiler measurements, sorted in descending order, as an associative array. * Keys are the Lua function names (with source file and line defined in angle brackets), values are the * measurements as integer or float.
* @since luasandbox >= 1.1.0 * @see LuaSandbox::SAMPLES * @see LuaSandbox::SECONDS * @see LuaSandbox::PERCENT */ public function getProfilerFunctionReport($units = LuaSandbox::SECONDS) {} /** * Return the versions of LuaSandbox and Lua. * * @link https://www.php.net/manual/en/luasandbox.getversioninfo.php * @return arrayReturns an array with two keys:
*Loads data generated by LuaSandboxFunction::dump()
.
Data from LuaSandboxFunction::dump()
.
Name for the loaded function.
* @return LuaSandboxFunction * @since luasandbox >= 1.0.0 * @see LuaSandbox::loadString() */ public function loadBinary($code, $chunkName = '') {} /** * Load Lua code into the Lua environment. * *This is the equivalent of standard Lua's loadstring()
function.
Lua code.
* @param string $chunkName [optional]Name for the loaded chunk, for use in error traces.
* @return LuaSandboxFunctionReturns a LuaSandboxFunction
which, when executed,
* will execute the passed $code
.
This only has effect when called from within a callback from Lua. * When execution returns to Lua, the timer will be automatically unpaused. * If a new call into Lua is made, the timer will be unpaused * for the duration of that call.
* *If a PHP callback calls into Lua again with timer not paused, * and then that Lua function calls into PHP again, * the second PHP call will not be able to pause the timer. * The logic is that even though the second PHP call would * avoid counting the CPU usage against the limit, * the first call still counts it.
* * @link https://www.php.net/manual/en/luasandbox.pauseusagetimer.php * @return boolReturns a boolean indicating whether the timer is now paused.
* @since luasandbox >= 1.4.0 * @see LuaSandbox::setCPULimit() * @see LuaSandbox::unpauseUsageTimer() */ public function pauseUsageTimer() {} /** * 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()
.
The name of the library. * In the Lua state, the global variable of this name will be set to the table of functions. * If the table already exists, the new functions will be added to it.
* @param array $functionsReturns an array, where each key is a function name, * and each value is a corresponding PHP callable.
* @since luasandbox >= 1.0.0 * @see LuaSandbox::loadString() * @see LuaSandbox::wrapPhpFunction() */ public function registerLibrary($libname, $functions) {} /** * Set the CPU time limit for the Lua environment. * *If the total user and system time used by the environment after the call
* to this method exceeds this limit, a LuaSandboxTimeoutError
exception is thrown.
Time used in PHP callbacks is included in the limit.
* *Setting the time limit from a callback while Lua is running causes the timer to be reset, * or started if it was not already running.
* *Note: On Windows, the CPU limit will be ignored. On operating systems * that do not support CLOCK_THREAD_CPUTIME_ID, such as FreeBSD and * Mac OS X, wall-clock time rather than CPU time will be limited.
* * @link https://www.php.net/manual/en/luasandbox.setcpulimit.php * @param bool|float $limitLimit as a float in seconds, or false for no limit.
* @since luasandbox >= 1.0.0 * @see LuaSandbox::getCPUUsage() * @see LuaSandbox::setMemoryLimit() */ public function setCPULimit($limit) {} /** * Set the memory limit for the Lua environment. * * @link https://www.php.net/manual/en/luasandbox.setmemorylimit.php * @param int $limitMemory limit in bytes.
* @throws LuaSandboxMemoryErrorException is thrown if this limit is exceeded.
* @since luasandbox >= 1.0.0 * @see LuaSandbox::getMemoryUsage() * @see LuaSandbox::getPeakMemoryUsage() * @see LuaSandbox::setCPULimit() */ public function setMemoryLimit($limit) {} /** * Unpause the timer paused byLuaSandbox::pauseUsageTimer()
.
*
* @link https://www.php.net/manual/en/luasandbox.unpauseusagetimer.php
* @since luasandbox >= 1.0.0
* @see LuaSandbox::setCPULimit()
* @see LuaSandbox::unpauseUsageTimer()
*/
public function unpauseUsageTimer() {}
/**
* Wrap a PHP callable in a LuaSandboxFunction.
*
* Wraps a PHP callable in a LuaSandboxFunction
,
* so it can be passed into Lua as an anonymous function.
The function must return either an array of values (which may be empty), * or NULL which is equivalent to returning the empty array.
* *Exceptions will be raised as errors in Lua, however only LuaSandboxRuntimeError
* exceptions may be caught inside Lua with
pcall()
or
xpcall()
.
For more information about calling Lua functions and the return values,
* see LuaSandboxFunction::call()
.
Callable to wrap.
* @return LuaSandboxFunction * @since luasandbox >= 1.2.0 * @see LuaSandbox::loadString() * @see LuaSandbox::registerLibrary() */ public function wrapPhpFunction($function) {} } /** * Represents a Lua function, allowing it to be called from PHP. * *A LuaSandboxFunction may be obtained as a return value from Lua,
* as a parameter passed to a callback from Lua,
* or by using LuaSandbox::wrapPhpFunction()
, LuaSandbox::loadString()
,
* or LuaSandbox::loadBinary()
.
Errors considered to be the fault of the PHP code will result in the * function returning false and E_WARNING being raised, for example, * a resource type being used as an argument. Lua errors will result * in a LuaSandboxRuntimeError exception being thrown.
* *PHP and Lua types are converted as follows:
*$a[0]
and $a["0"]
as being equivalent).Lua functions inherently return a list of results. So on success, * this method returns an array containing all of the values returned by Lua, * with integer keys starting from zero. * Lua may return no results, in which case an empty array is returned.
* * @link https://www.php.net/manual/en/luasandboxfunction.call.php * @param string[] $argumentsArguments passed to the function.
* @return array|boolReturns an array of values returned by the function, * which may be empty, or false on error.
* @since luasandbox >= 1.0.0 */ public function call($arguments) {} /** * Dump the function as a binary blob. * * @link https://www.php.net/manual/en/luasandboxfunction.dump.php * @return stringReturns a string that may be passed to LuaSandbox::loadBinary()
.
These may be caught inside Lua using pcall()
or xpcall()
.
These may not be caught inside Lua using pcall()
or xpcall()
.