mediawiki-extensions-Scribunto/includes/engines/LuaSandbox/LuaSandboxCallback.php
Reedy 1628cfa367 Namespace LuaSandbox engine
Change-Id: I485401c202057ae0fea7226ab21e68ce1c7d40c8
2022-07-30 22:51:42 +01:00

37 lines
742 B
PHP

<?php
namespace MediaWiki\Extension\Scribunto\Engines\LuaSandbox;
use LuaSandboxRuntimeError;
use Scribunto_LuaError;
class LuaSandboxCallback {
/**
* @var callable
*/
protected $callback;
/**
* @param callable $callback
*/
public function __construct( $callback ) {
$this->callback = $callback;
}
/**
* We use __call with a variable function name so that LuaSandbox will be
* able to return a meaningful function name in profiling data.
* @param string $funcName
* @param array $args
* @return mixed
*/
public function __call( $funcName, $args ) {
try {
return ( $this->callback )( ...$args );
} catch ( Scribunto_LuaError $e ) {
throw new LuaSandboxRuntimeError( $e->getLuaMessage() );
}
}
}