mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ParserFunctions
synced 2024-11-24 00:06:21 +00:00
4bcd4ac8cb
This change depends on the Scribunto change I74fd43f7920c8772e9078f745ac6062d5461a7f1 included in REL1_40. Depends-On: I74fd43f7920c8772e9078f745ac6062d5461a7f1 Change-Id: Id4156a8934583971df6b449d13f3d8eb6cee6368
30 lines
717 B
PHP
30 lines
717 B
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\ParserFunctions;
|
|
|
|
use MediaWiki\Extension\Scribunto\Engines\LuaCommon\LibraryBase;
|
|
use MediaWiki\Extension\Scribunto\Engines\LuaCommon\LuaError;
|
|
|
|
class LuaLibrary extends LibraryBase {
|
|
public function register() {
|
|
$lib = [
|
|
'expr' => [ $this, 'expr' ],
|
|
];
|
|
|
|
return $this->getEngine()->registerInterface(
|
|
__DIR__ . '/mw.ext.ParserFunctions.lua', $lib, []
|
|
);
|
|
}
|
|
|
|
public function expr( $expression = null ) {
|
|
$this->checkType( 'mw.ext.ParserFunctions.expr', 1, $expression, 'string' );
|
|
try {
|
|
$exprParser = new ExprParser();
|
|
return [ $exprParser->doExpression( $expression ) ];
|
|
} catch ( ExprError $e ) {
|
|
throw new LuaError( $e->getMessage() );
|
|
}
|
|
}
|
|
|
|
}
|