2014-04-08 16:04:32 +00:00
|
|
|
<?php
|
|
|
|
|
2022-03-05 15:06:59 +00:00
|
|
|
namespace MediaWiki\Extension\ParserFunctions;
|
2019-03-28 03:52:55 +00:00
|
|
|
|
|
|
|
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-04-13 03:45:24 +00:00
|
|
|
$exprParser = new ExprParser();
|
|
|
|
return [ $exprParser->doExpression( $expression ) ];
|
2014-04-08 16:04:32 +00:00
|
|
|
} catch ( ExprError $e ) {
|
|
|
|
throw new Scribunto_LuaError( $e->getMessage() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|