MediaWiki REL1_34
LuaDataProvider.php
Go to the documentation of this file.
1<?php
2
3class 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}
const NS_MODULE
__construct( $engine, $moduleName)