mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-27 17:50:06 +00:00
Namespace LuaStandalone engine
Change-Id: I7d3f77a56c8b74e0481197224006f19ff4c9d108
This commit is contained in:
parent
dc97acc945
commit
c479ad6f86
|
@ -40,8 +40,6 @@
|
|||
"Scribunto_LuaEngine": "includes/engines/LuaCommon/LuaEngine.php",
|
||||
"Scribunto_LuaModule": "includes/engines/LuaCommon/LuaModule.php",
|
||||
"Scribunto_LuaInterpreter": "includes/engines/LuaCommon/LuaInterpreter.php",
|
||||
"Scribunto_LuaStandaloneEngine": "includes/engines/LuaStandalone/LuaStandaloneEngine.php",
|
||||
"Scribunto_LuaStandaloneInterpreter": "includes/engines/LuaStandalone/LuaStandaloneInterpreter.php",
|
||||
"Scribunto_LuaLibraryBase": "includes/engines/LuaCommon/LibraryBase.php",
|
||||
"Scribunto_LuaSiteLibrary": "includes/engines/LuaCommon/SiteLibrary.php",
|
||||
"Scribunto_LuaUriLibrary": "includes/engines/LuaCommon/UriLibrary.php",
|
||||
|
@ -51,7 +49,8 @@
|
|||
"Scribunto_LuaTitleLibrary": "includes/engines/LuaCommon/TitleLibrary.php",
|
||||
"Scribunto_LuaTextLibrary": "includes/engines/LuaCommon/TextLibrary.php",
|
||||
"Scribunto_LuaHtmlLibrary": "includes/engines/LuaCommon/HtmlLibrary.php",
|
||||
"Scribunto_LuaHashLibrary": "includes/engines/LuaCommon/HashLibrary.php"
|
||||
"Scribunto_LuaHashLibrary": "includes/engines/LuaCommon/HashLibrary.php",
|
||||
"MediaWiki\\Extension\\Scribunto\\Engines\\LuaStandalone\\LuaStandaloneInterpreterFunction": "includes/engines/LuaStandalone/LuaStandaloneInterpreterFunction.php"
|
||||
},
|
||||
"AutoloadNamespaces": {
|
||||
"MediaWiki\\Extension\\Scribunto\\": "includes/",
|
||||
|
@ -155,7 +154,7 @@
|
|||
"maxLangCacheSize": 30
|
||||
},
|
||||
"luastandalone": {
|
||||
"class": "Scribunto_LuaStandaloneEngine",
|
||||
"class": "MediaWiki\\Extension\\Scribunto\\Engines\\LuaStandalone\\LuaStandaloneEngine",
|
||||
"errorFile": null,
|
||||
"luaPath": null,
|
||||
"memoryLimit": 52428800,
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Scribunto\Engines\LuaStandalone;
|
||||
|
||||
use Exception;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use ParserOutput;
|
||||
use Scribunto_LuaEngine;
|
||||
use Wikimedia\AtEase\AtEase;
|
||||
|
||||
class Scribunto_LuaStandaloneEngine extends Scribunto_LuaEngine {
|
||||
class LuaStandaloneEngine extends Scribunto_LuaEngine {
|
||||
/** @var int|null */
|
||||
protected static $clockTick;
|
||||
/** @var array|false */
|
||||
public $initialStatus;
|
||||
|
||||
/**
|
||||
* @var Scribunto_LuaStandaloneInterpreter
|
||||
* @var LuaStandaloneInterpreter
|
||||
*/
|
||||
protected $interpreter;
|
||||
|
||||
|
@ -91,17 +96,17 @@ class Scribunto_LuaStandaloneEngine extends Scribunto_LuaEngine {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return Scribunto_LuaStandaloneInterpreter
|
||||
* @return LuaStandaloneInterpreter
|
||||
*/
|
||||
protected function newInterpreter() {
|
||||
return new Scribunto_LuaStandaloneInterpreter( $this, $this->options + [
|
||||
return new LuaStandaloneInterpreter( $this, $this->options + [
|
||||
'logger' => LoggerFactory::getInstance( 'Scribunto' )
|
||||
] );
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function getSoftwareInfo( array &$software ) {
|
||||
$ver = Scribunto_LuaStandaloneInterpreter::getLuaVersion( $this->options );
|
||||
$ver = LuaStandaloneInterpreter::getLuaVersion( $this->options );
|
||||
if ( $ver !== null ) {
|
||||
if ( substr( $ver, 0, 6 ) === 'LuaJIT' ) {
|
||||
$software['[http://luajit.org/ LuaJIT]'] = str_replace( 'LuaJIT ', '', $ver );
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Scribunto\Engines\LuaStandalone;
|
||||
|
||||
use MediaWiki\Extension\Scribunto\ScribuntoException;
|
||||
use MWException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use Scribunto_LuaError;
|
||||
use Scribunto_LuaInterpreter;
|
||||
use Scribunto_LuaInterpreterNotFoundError;
|
||||
use UtfNormal\Validator;
|
||||
|
||||
class Scribunto_LuaStandaloneInterpreter extends Scribunto_LuaInterpreter {
|
||||
class LuaStandaloneInterpreter extends Scribunto_LuaInterpreter {
|
||||
/** @var int */
|
||||
protected static $nextInterpreterId = 0;
|
||||
|
||||
/**
|
||||
* @var Scribunto_LuaStandaloneEngine
|
||||
* @var LuaStandaloneEngine
|
||||
*/
|
||||
public $engine;
|
||||
|
||||
|
@ -55,7 +61,7 @@ class Scribunto_LuaStandaloneInterpreter extends Scribunto_LuaInterpreter {
|
|||
protected $callbacks;
|
||||
|
||||
/**
|
||||
* @param Scribunto_LuaStandaloneEngine $engine
|
||||
* @param LuaStandaloneEngine $engine
|
||||
* @param array $options
|
||||
* @throws MWException
|
||||
* @throws Scribunto_LuaInterpreterNotFoundError
|
||||
|
@ -237,7 +243,7 @@ class Scribunto_LuaStandaloneInterpreter extends Scribunto_LuaInterpreter {
|
|||
/**
|
||||
* @param string $text
|
||||
* @param string $chunkName
|
||||
* @return Scribunto_LuaStandaloneInterpreterFunction
|
||||
* @return LuaStandaloneInterpreterFunction
|
||||
*/
|
||||
public function loadString( $text, $chunkName ) {
|
||||
$this->cleanupLuaChunks();
|
||||
|
@ -247,12 +253,12 @@ class Scribunto_LuaStandaloneInterpreter extends Scribunto_LuaInterpreter {
|
|||
'text' => $text,
|
||||
'chunkName' => $chunkName
|
||||
] );
|
||||
return new Scribunto_LuaStandaloneInterpreterFunction( $this->id, $result[1] );
|
||||
return new LuaStandaloneInterpreterFunction( $this->id, $result[1] );
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function callFunction( $func, ...$args ) {
|
||||
if ( !( $func instanceof Scribunto_LuaStandaloneInterpreterFunction ) ) {
|
||||
if ( !( $func instanceof LuaStandaloneInterpreterFunction ) ) {
|
||||
throw new MWException( __METHOD__ . ': invalid function type' );
|
||||
}
|
||||
if ( $func->interpreterId !== $this->id ) {
|
||||
|
@ -287,18 +293,18 @@ class Scribunto_LuaStandaloneInterpreter extends Scribunto_LuaInterpreter {
|
|||
}
|
||||
|
||||
public function cleanupLuaChunks() {
|
||||
if ( isset( Scribunto_LuaStandaloneInterpreterFunction::$anyChunksDestroyed[$this->id] ) ) {
|
||||
unset( Scribunto_LuaStandaloneInterpreterFunction::$anyChunksDestroyed[$this->id] );
|
||||
if ( isset( LuaStandaloneInterpreterFunction::$anyChunksDestroyed[$this->id] ) ) {
|
||||
unset( LuaStandaloneInterpreterFunction::$anyChunksDestroyed[$this->id] );
|
||||
$this->dispatch( [
|
||||
'op' => 'cleanupChunks',
|
||||
'ids' => Scribunto_LuaStandaloneInterpreterFunction::$activeChunkIds[$this->id]
|
||||
'ids' => LuaStandaloneInterpreterFunction::$activeChunkIds[$this->id]
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function isLuaFunction( $object ) {
|
||||
return $object instanceof Scribunto_LuaStandaloneInterpreterFunction;
|
||||
return $object instanceof LuaStandaloneInterpreterFunction;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
|
@ -567,7 +573,7 @@ class Scribunto_LuaStandaloneInterpreter extends Scribunto_LuaInterpreter {
|
|||
$s .= '}';
|
||||
return $s;
|
||||
case 'object':
|
||||
if ( !( $var instanceof Scribunto_LuaStandaloneInterpreterFunction ) ) {
|
||||
if ( !( $var instanceof LuaStandaloneInterpreterFunction ) ) {
|
||||
throw new MWException( __METHOD__ . ': unable to convert object of type ' .
|
||||
get_class( $var ) );
|
||||
} elseif ( $var->interpreterId !== $this->id ) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
class Scribunto_LuaStandaloneInterpreterFunction {
|
||||
namespace MediaWiki\Extension\Scribunto\Engines\LuaStandalone;
|
||||
|
||||
class LuaStandaloneInterpreterFunction {
|
||||
/** @var bool[] */
|
||||
public static $anyChunksDestroyed = [];
|
||||
/** @var int[][] */
|
||||
|
@ -59,3 +61,6 @@ class Scribunto_LuaStandaloneInterpreterFunction {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Alias exists due to serialization of class name into MWServer.lua
|
||||
class_alias( LuaStandaloneInterpreterFunction::class, 'Scribunto_LuaStandaloneInterpreterFunction' );
|
||||
|
|
|
@ -559,6 +559,7 @@ function MWServer:serialize( var )
|
|||
else
|
||||
id = self:addChunk(var)
|
||||
end
|
||||
-- Serialization of a PHP class name is fun when it is namespaced...
|
||||
return 'O:42:"Scribunto_LuaStandaloneInterpreterFunction":2:{s:13:"interpreterId";i:' ..
|
||||
self.interpreterId .. ';s:2:"id";i:' .. id .. ';}'
|
||||
elseif t == 'thread' then
|
||||
|
|
|
@ -5,10 +5,10 @@ use MediaWiki\Extension\Scribunto\ScribuntoException;
|
|||
/**
|
||||
* @covers \MediaWiki\Extension\Scribunto\ScribuntoEngineBase
|
||||
* @covers Scribunto_LuaEngine
|
||||
* @covers Scribunto_LuaStandaloneEngine
|
||||
* @covers \MediaWiki\Extension\Scribunto\Engines\LuaStandalone\LuaStandaloneEngine
|
||||
* @covers \MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxEngine
|
||||
* @covers Scribunto_LuaInterpreter
|
||||
* @covers Scribunto_LuaStandaloneInterpreter
|
||||
* @covers \MediaWiki\Extension\Scribunto\Engines\LuaStandalone\LuaStandaloneInterpreter
|
||||
* @covers \MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxInterpreter
|
||||
*/
|
||||
class Scribunto_LuaCommonTest extends Scribunto_LuaEngineTestBase {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxEngine;
|
||||
use MediaWiki\Extension\Scribunto\Engines\LuaStandalone\LuaStandaloneEngine;
|
||||
use MediaWiki\Extension\Scribunto\ScribuntoEngineBase;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use PHPUnit\Framework\DataProviderTestSuite;
|
||||
use PHPUnit\Framework\TestSuite;
|
||||
|
@ -21,7 +23,7 @@ trait Scribunto_LuaEngineTestHelper {
|
|||
'maxLangCacheSize' => 30,
|
||||
],
|
||||
'LuaStandalone' => [
|
||||
'class' => Scribunto_LuaStandaloneEngine::class,
|
||||
'class' => LuaStandaloneEngine::class,
|
||||
'errorFile' => null,
|
||||
'luaPath' => null,
|
||||
'memoryLimit' => 50000000,
|
||||
|
@ -136,7 +138,14 @@ trait Scribunto_LuaEngineTestHelper {
|
|||
$options = ParserOptions::newFromAnon();
|
||||
$options->setTemplateCallback( [ $this, 'templateCallback' ] );
|
||||
$parser->startExternalParse( $this->getTestTitle(), $options, Parser::OT_HTML, true );
|
||||
$class = "Scribunto_{$this->engineName}Engine";
|
||||
|
||||
// HACK
|
||||
if ( $this->engineName === 'LuaSandbox' ) {
|
||||
$class = LuaSandboxEngine::class;
|
||||
} elseif ( $this->engineName === 'LuaStandalone' ) {
|
||||
$class = LuaStandaloneEngine::class;
|
||||
}
|
||||
|
||||
$this->engine = new $class(
|
||||
self::$engineConfigurations[$this->engineName] + [ 'parser' => $parser ]
|
||||
);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxEngine;
|
||||
use MediaWiki\Extension\Scribunto\Engines\LuaStandalone\LuaStandaloneEngine;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
|
@ -55,7 +56,7 @@ class Scribunto_LuaEnvironmentComparisonTest extends PHPUnit\Framework\TestCase
|
|||
|
||||
try {
|
||||
$this->engines['LuaStandalone'] = $this->makeEngine(
|
||||
Scribunto_LuaStandaloneEngine::class, $this->standaloneOpts
|
||||
LuaStandaloneEngine::class, $this->standaloneOpts
|
||||
);
|
||||
} catch ( Scribunto_LuaInterpreterNotFoundError $e ) {
|
||||
$this->markTestSkipped( "LuaStandalone interpreter not available" );
|
||||
|
|
|
@ -6,6 +6,9 @@ if ( !wfIsCLI() ) {
|
|||
|
||||
require_once __DIR__ . '/../LuaCommon/LuaInterpreterTest.php';
|
||||
|
||||
use MediaWiki\Extension\Scribunto\Engines\LuaStandalone\LuaStandaloneEngine;
|
||||
use MediaWiki\Extension\Scribunto\Engines\LuaStandalone\LuaStandaloneInterpreter;
|
||||
use MediaWiki\Extension\Scribunto\Engines\LuaStandalone\LuaStandaloneInterpreterFunction;
|
||||
use MediaWiki\Extension\Scribunto\ScribuntoException;
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
|
@ -13,9 +16,9 @@ use Wikimedia\TestingAccessWrapper;
|
|||
* @group Lua
|
||||
* @group LuaStandalone
|
||||
* @group Standalone
|
||||
* @covers Scribunto_LuaStandaloneInterpreter
|
||||
* @covers \MediaWiki\Extension\Scribunto\Engines\LuaStandalone\LuaStandaloneInterpreter
|
||||
*/
|
||||
class Scribunto_LuaStandaloneInterpreterTest extends Scribunto_LuaInterpreterTest {
|
||||
class LuaStandaloneInterpreterTest extends Scribunto_LuaInterpreterTest {
|
||||
/** @var array */
|
||||
public $stdOpts = [
|
||||
'errorFile' => null,
|
||||
|
@ -31,8 +34,8 @@ class Scribunto_LuaStandaloneInterpreterTest extends Scribunto_LuaInterpreterTes
|
|||
|
||||
protected function newInterpreter( $opts = [] ) {
|
||||
$opts += $this->stdOpts;
|
||||
$engine = new Scribunto_LuaStandaloneEngine( $this->stdOpts );
|
||||
return new Scribunto_LuaStandaloneInterpreter( $engine, $opts );
|
||||
$engine = new LuaStandaloneEngine( $this->stdOpts );
|
||||
return new LuaStandaloneInterpreter( $engine, $opts );
|
||||
}
|
||||
|
||||
public function testIOErrorExit() {
|
||||
|
@ -202,7 +205,7 @@ class Scribunto_LuaStandaloneInterpreterTest extends Scribunto_LuaInterpreterTes
|
|||
);
|
||||
$ret = null;
|
||||
$interpreter->cleanupLuaChunks();
|
||||
$testfunc = new Scribunto_LuaStandaloneInterpreterFunction( $interpreter->id, $id );
|
||||
$testfunc = new LuaStandaloneInterpreterFunction( $interpreter->id, $id );
|
||||
try {
|
||||
$interpreter->callFunction( $testfunc );
|
||||
$this->fail( "Expected exception because function #1 should have been freed" );
|
||||
|
@ -218,7 +221,7 @@ class Scribunto_LuaStandaloneInterpreterTest extends Scribunto_LuaInterpreterTes
|
|||
$interpreter->loadString( 'return function() return "testFreeFunction #2" end', 'test' )
|
||||
);
|
||||
$id = $ret[0]->id;
|
||||
$func = new Scribunto_LuaStandaloneInterpreterFunction( $interpreter->id, $id );
|
||||
$func = new LuaStandaloneInterpreterFunction( $interpreter->id, $id );
|
||||
$ret = null;
|
||||
$interpreter->cleanupLuaChunks();
|
||||
$this->assertEquals(
|
||||
|
@ -227,7 +230,7 @@ class Scribunto_LuaStandaloneInterpreterTest extends Scribunto_LuaInterpreterTes
|
|||
);
|
||||
$func = null;
|
||||
$interpreter->cleanupLuaChunks();
|
||||
$testfunc = new Scribunto_LuaStandaloneInterpreterFunction( $interpreter->id, $id );
|
||||
$testfunc = new LuaStandaloneInterpreterFunction( $interpreter->id, $id );
|
||||
try {
|
||||
$interpreter->callFunction( $testfunc );
|
||||
$this->fail( "Expected exception because function #2 should have been freed" );
|
||||
|
@ -252,7 +255,7 @@ class Scribunto_LuaStandaloneInterpreterTest extends Scribunto_LuaInterpreterTes
|
|||
);
|
||||
$func = null;
|
||||
$interpreter->cleanupLuaChunks();
|
||||
$testfunc = new Scribunto_LuaStandaloneInterpreterFunction( $interpreter->id, $id );
|
||||
$testfunc = new LuaStandaloneInterpreterFunction( $interpreter->id, $id );
|
||||
try {
|
||||
$interpreter->callFunction( $testfunc );
|
||||
$this->fail( "Expected exception because function #3 should have been freed" );
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class Scribunto_LuaStandaloneTest extends Scribunto_LuaEngineUnitTestBase {
|
||||
class LuaStandaloneTest extends Scribunto_LuaEngineUnitTestBase {
|
||||
/** @inheritDoc */
|
||||
protected static $moduleName = 'StandaloneTests';
|
||||
|
||||
|
|
Loading…
Reference in a new issue