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
|
|
|
|
2024-10-13 12:48:58 +00:00
|
|
|
use MediaWiki\Extension\Scribunto\Engines\LuaCommon\LibraryBase;
|
|
|
|
use MediaWiki\Extension\Scribunto\Engines\LuaCommon\LuaError;
|
2019-03-28 03:52:55 +00:00
|
|
|
|
2024-10-13 12:48:58 +00:00
|
|
|
class LuaLibrary extends LibraryBase {
|
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 ) {
|
2024-10-13 12:48:58 +00:00
|
|
|
throw new LuaError( $e->getMessage() );
|
2014-04-08 16:04:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|