| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\Scribunto\Engines\LuaCommon; |
| 4 | |
| 5 | use LuaSandboxFunction; |
| 6 | |
| 7 | abstract class LuaInterpreter { |
| 8 | /** |
| 9 | * Load a string. Return an object which can later be passed to callFunction. |
| 10 | * If there is a pass error, a LuaError will be thrown. |
| 11 | * |
| 12 | * @param string $text The Lua source code |
| 13 | * @param string $chunkName |
| 14 | * @return mixed |
| 15 | */ |
| 16 | abstract public function loadString( $text, $chunkName ); |
| 17 | |
| 18 | /** |
| 19 | * Call a Lua function. Return an array of results, with indices starting |
| 20 | * at zero. If an error occurs, a LuaError will be thrown. |
| 21 | * |
| 22 | * @param mixed $func The function object |
| 23 | * @param mixed ...$args Arguments to the function |
| 24 | * @return array |
| 25 | */ |
| 26 | abstract public function callFunction( $func, ...$args ); |
| 27 | |
| 28 | /** |
| 29 | * Wrap a PHP callable as a Lua function, which can be passed back into |
| 30 | * Lua. If an error occurs, a LuaError will be thrown. |
| 31 | * |
| 32 | * @param callable $callable The PHP callable |
| 33 | * @return LuaSandboxFunction a Lua function |
| 34 | */ |
| 35 | abstract public function wrapPhpFunction( $callable ); |
| 36 | |
| 37 | /** |
| 38 | * Test whether an object is a Lua function. |
| 39 | * |
| 40 | * @param mixed|LuaSandboxFunction $object |
| 41 | * @return bool |
| 42 | */ |
| 43 | abstract public function isLuaFunction( $object ); |
| 44 | |
| 45 | /** |
| 46 | * Register a library of functions. |
| 47 | * |
| 48 | * @param string $name The global variable name to be created or added to. |
| 49 | * @param array<string,callable> $functions An associative array mapping the function name to the |
| 50 | * callback. The callback may throw a LuaError, which will be |
| 51 | * caught and raised in the Lua code as a Lua error, catchable with |
| 52 | * pcall(). |
| 53 | */ |
| 54 | abstract public function registerLibrary( $name, array $functions ); |
| 55 | |
| 56 | /** |
| 57 | * Pause CPU usage and limits |
| 58 | * @return void |
| 59 | */ |
| 60 | abstract public function pauseUsageTimer(); |
| 61 | |
| 62 | /** |
| 63 | * Unpause CPU usage and limits |
| 64 | * @return void |
| 65 | */ |
| 66 | abstract public function unpauseUsageTimer(); |
| 67 | } |