MediaWiki  1.34.0
LuaDataProvider.php
Go to the documentation of this file.
1 <?php
2 
3 class Scribunto_LuaDataProvider implements Iterator {
4  protected $engine = null;
5  protected $exports = null;
6  protected $key = 1;
7 
8  public function __construct( $engine, $moduleName ) {
9  $this->engine = $engine;
10  $this->key = 1;
11  $module = $engine->fetchModuleFromParser(
12  Title::makeTitle( NS_MODULE, $moduleName )
13  );
14  if ( $module === null ) {
15  throw new Exception( "Failed to load module $moduleName" );
16  }
17  // Calling executeModule with null isn't the best idea, since it brings
18  // the whole export table into PHP and throws away metatables and such,
19  // but for this use case, we don't have anything like that to worry about
20  $this->exports = $engine->executeModule( $module->getInitChunk(), null, null );
21  }
22 
23  public function destroy() {
24  $this->engine = null;
25  $this->exports = null;
26  }
27 
28  public function rewind() {
29  $this->key = 1;
30  }
31 
32  public function valid() {
33  return $this->key <= $this->exports['count'];
34  }
35 
36  public function key() {
37  return $this->key;
38  }
39 
40  public function next() {
41  $this->key++;
42  }
43 
44  public function current() {
45  return $this->engine->getInterpreter()->callFunction( $this->exports['provide'], $this->key );
46  }
47 
48  public function run( $key ) {
49  list( $ret ) = $this->engine->getInterpreter()->callFunction( $this->exports['run'], $key );
50  return $ret;
51  }
52 }
Scribunto_LuaDataProvider\$engine
$engine
Definition: LuaDataProvider.php:4
Scribunto_LuaDataProvider\$key
$key
Definition: LuaDataProvider.php:6
Scribunto_LuaDataProvider\__construct
__construct( $engine, $moduleName)
Definition: LuaDataProvider.php:8
Scribunto_LuaDataProvider\key
key()
Definition: LuaDataProvider.php:36
Scribunto_LuaDataProvider\destroy
destroy()
Definition: LuaDataProvider.php:23
Scribunto_LuaDataProvider\valid
valid()
Definition: LuaDataProvider.php:32
Scribunto_LuaDataProvider\$exports
$exports
Definition: LuaDataProvider.php:5
NS_MODULE
const NS_MODULE
Definition: Scribunto.constants.php:5
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:586
Scribunto_LuaDataProvider
Definition: LuaDataProvider.php:3
Scribunto_LuaDataProvider\run
run( $key)
Definition: LuaDataProvider.php:48
Scribunto_LuaDataProvider\rewind
rewind()
Definition: LuaDataProvider.php:28
Scribunto_LuaDataProvider\next
next()
Definition: LuaDataProvider.php:40
Scribunto_LuaDataProvider\current
current()
Definition: LuaDataProvider.php:44