2012-04-13 10:38:12 +00:00
|
|
|
<?php
|
|
|
|
|
2022-08-03 12:31:15 +00:00
|
|
|
namespace MediaWiki\Extension\Scribunto\Engines\LuaCommon;
|
|
|
|
|
|
|
|
use LuaSandboxFunction;
|
|
|
|
|
|
|
|
abstract class LuaInterpreter {
|
2012-04-13 10:38:12 +00:00
|
|
|
/**
|
|
|
|
* Load a string. Return an object which can later be passed to callFunction.
|
2022-08-03 12:31:15 +00:00
|
|
|
* If there is a pass error, a LuaError will be thrown.
|
2012-04-13 10:38:12 +00:00
|
|
|
*
|
2014-10-09 19:49:40 +00:00
|
|
|
* @param string $text The Lua source code
|
2022-01-10 09:44:08 +00:00
|
|
|
* @param string $chunkName
|
2017-09-24 17:38:14 +00:00
|
|
|
* @return mixed
|
2012-04-13 10:38:12 +00:00
|
|
|
*/
|
|
|
|
abstract public function loadString( $text, $chunkName );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call a Lua function. Return an array of results, with indices starting
|
2022-08-03 12:31:15 +00:00
|
|
|
* at zero. If an error occurs, a LuaError will be thrown.
|
2012-04-13 10:38:12 +00:00
|
|
|
*
|
2014-10-09 19:49:40 +00:00
|
|
|
* @param mixed $func The function object
|
2019-03-21 04:17:45 +00:00
|
|
|
* @param mixed ...$args Arguments to the function
|
2024-08-26 15:24:52 +00:00
|
|
|
* @return array
|
2012-04-13 10:38:12 +00:00
|
|
|
*/
|
2019-03-21 04:17:45 +00:00
|
|
|
abstract public function callFunction( $func, ...$args );
|
2012-04-13 10:38:12 +00:00
|
|
|
|
2012-12-13 20:50:44 +00:00
|
|
|
/**
|
|
|
|
* Wrap a PHP callable as a Lua function, which can be passed back into
|
2022-08-03 12:31:15 +00:00
|
|
|
* Lua. If an error occurs, a LuaError will be thrown.
|
2012-12-13 20:50:44 +00:00
|
|
|
*
|
2014-10-09 19:49:40 +00:00
|
|
|
* @param callable $callable The PHP callable
|
2020-12-18 19:04:17 +00:00
|
|
|
* @return LuaSandboxFunction a Lua function
|
2012-12-13 20:50:44 +00:00
|
|
|
*/
|
|
|
|
abstract public function wrapPhpFunction( $callable );
|
|
|
|
|
2012-12-24 14:45:16 +00:00
|
|
|
/**
|
|
|
|
* Test whether an object is a Lua function.
|
|
|
|
*
|
2020-12-18 19:04:17 +00:00
|
|
|
* @param mixed|LuaSandboxFunction $object
|
2018-04-05 11:09:10 +00:00
|
|
|
* @return bool
|
2012-12-24 14:45:16 +00:00
|
|
|
*/
|
|
|
|
abstract public function isLuaFunction( $object );
|
|
|
|
|
2012-04-13 10:38:12 +00:00
|
|
|
/**
|
|
|
|
* Register a library of functions.
|
|
|
|
*
|
2017-09-24 17:38:14 +00:00
|
|
|
* @param string $name The global variable name to be created or added to.
|
2024-08-26 15:24:52 +00:00
|
|
|
* @param array<string,callable> $functions An associative array mapping the function name to the
|
2022-08-03 12:31:15 +00:00
|
|
|
* callback. The callback may throw a LuaError, which will be
|
2014-07-07 18:46:59 +00:00
|
|
|
* caught and raised in the Lua code as a Lua error, catchable with
|
|
|
|
* pcall().
|
2012-04-13 10:38:12 +00:00
|
|
|
*/
|
2014-10-10 09:02:03 +00:00
|
|
|
abstract public function registerLibrary( $name, array $functions );
|
2013-03-06 23:28:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pause CPU usage and limits
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
abstract public function pauseUsageTimer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unpause CPU usage and limits
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
abstract public function unpauseUsageTimer();
|
2012-04-13 10:38:12 +00:00
|
|
|
}
|