summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Scribunto/includes/engines/LuaCommon/LuaInterpreter.php
blob: e1840310535d1d77ba1c40f70a3b2db7b47544a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php

// @codingStandardsIgnoreLine Squiz.Classes.ValidClassName.NotCamelCaps
abstract class Scribunto_LuaInterpreter {
	/**
	 * Load a string. Return an object which can later be passed to callFunction.
	 * If there is a pass error, a Scribunto_LuaError will be thrown.
	 *
	 * @param string $text The Lua source code
	 * @param string $chunkName The chunk name
	 * @return mixed
	 */
	abstract public function loadString( $text, $chunkName );

	/**
	 * Call a Lua function. Return an array of results, with indices starting
	 * at zero. If an error occurs, a Scribunto_LuaError will be thrown.
	 *
	 * @param mixed $func The function object
	 */
	abstract public function callFunction( $func /*...*/ );

	/**
	 * Wrap a PHP callable as a Lua function, which can be passed back into
	 * Lua. If an error occurs, a Scribunto_LuaError will be thrown.
	 *
	 * @param callable $callable The PHP callable
	 * @return object a Lua function
	 */
	abstract public function wrapPhpFunction( $callable );

	/**
	 * Test whether an object is a Lua function.
	 *
	 * @param object $object
	 * @return bool
	 */
	abstract public function isLuaFunction( $object );

	/**
	 * Register a library of functions.
	 *
	 * @param string $name The global variable name to be created or added to.
	 * @param array $functions An associative array mapping the function name to the
	 *    callback. The callback may throw a Scribunto_LuaError, which will be
	 *    caught and raised in the Lua code as a Lua error, catchable with
	 *    pcall().
	 */
	abstract public function registerLibrary( $name, array $functions );

	/**
	 * Pause CPU usage and limits
	 * @return void
	 */
	abstract public function pauseUsageTimer();

	/**
	 * Unpause CPU usage and limits
	 * @return void
	 */
	abstract public function unpauseUsageTimer();
}

// @codingStandardsIgnoreLine Squiz.Classes.ValidClassName.NotCamelCaps
class Scribunto_LuaInterpreterNotFoundError extends MWException {}

// @codingStandardsIgnoreLine Squiz.Classes.ValidClassName.NotCamelCaps
class Scribunto_LuaInterpreterBadVersionError extends MWException {}