2014-04-08 16:04:32 +00:00
|
|
|
<?php
|
|
|
|
|
2019-03-28 03:52:55 +00:00
|
|
|
namespace MediaWiki\Extensions\ParserFunctions;
|
|
|
|
|
|
|
|
use Scribunto_LuaError;
|
|
|
|
use Scribunto_LuaLibraryBase;
|
|
|
|
|
|
|
|
class LuaLibrary extends Scribunto_LuaLibraryBase {
|
2014-04-08 16:04:32 +00:00
|
|
|
public function register() {
|
2017-06-06 15:20:02 +00:00
|
|
|
$lib = [
|
|
|
|
'expr' => [ $this, 'expr' ],
|
|
|
|
];
|
2014-04-08 16:04:32 +00:00
|
|
|
|
2017-06-02 18:55:29 +00:00
|
|
|
return $this->getEngine()->registerInterface(
|
2017-06-06 15:20:02 +00:00
|
|
|
__DIR__ . '/mw.ext.ParserFunctions.lua', $lib, []
|
2017-06-02 18:55:29 +00:00
|
|
|
);
|
2014-04-08 16:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function expr( $expression = null ) {
|
|
|
|
$this->checkType( 'mw.ext.ParserFunctions.expr', 1, $expression, 'string' );
|
|
|
|
try {
|
2019-03-28 03:52:55 +00:00
|
|
|
return [ ParserFunctions::getExprParser()->doExpression( $expression ) ];
|
2014-04-08 16:04:32 +00:00
|
|
|
} catch ( ExprError $e ) {
|
|
|
|
throw new Scribunto_LuaError( $e->getMessage() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|