2019-12-18 20:12:45 +00:00
|
|
|
<?php
|
|
|
|
|
2022-07-30 18:22:25 +00:00
|
|
|
namespace MediaWiki\Extension\Scribunto\Engines\LuaSandbox;
|
|
|
|
|
|
|
|
use LuaSandboxRuntimeError;
|
2022-08-03 12:31:15 +00:00
|
|
|
use MediaWiki\Extension\Scribunto\Engines\LuaCommon\LuaError;
|
2022-07-30 18:22:25 +00:00
|
|
|
|
|
|
|
class LuaSandboxCallback {
|
2019-12-18 20:12:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var callable
|
|
|
|
*/
|
|
|
|
protected $callback;
|
|
|
|
|
2020-01-14 18:50:34 +00:00
|
|
|
/**
|
|
|
|
* @param callable $callback
|
|
|
|
*/
|
2019-12-18 20:12:45 +00:00
|
|
|
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 );
|
2022-08-03 12:31:15 +00:00
|
|
|
} catch ( LuaError $e ) {
|
2019-12-18 20:12:45 +00:00
|
|
|
throw new LuaSandboxRuntimeError( $e->getLuaMessage() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|