Debian Codegraph @

extensions/ParserFunctions/includes/LuaLibrary.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\ParserFunctions;
4
5 use MediaWiki\Extension\Scribunto\Engines\LuaCommon\LibraryBase;
6 use MediaWiki\Extension\Scribunto\Engines\LuaCommon\LuaError;
7
8 class LuaLibrary extends LibraryBase {
9 public function register() {
10 $lib = [
11 'expr' => [ $this, 'expr' ],
12 ];
13
14 return $this->getEngine()->registerInterface(
15 __DIR__ . '/mw.ext.ParserFunctions.lua', $lib, []
16 );
17 }
18
19 public function expr( $expression = null ) {
20 $this->checkType( 'mw.ext.ParserFunctions.expr', 1, $expression, 'string' );
21 try {
22 $exprParser = new ExprParser();
23 return [ $exprParser->doExpression( $expression ) ];
24 } catch ( ExprError $e ) {
25 throw new LuaError( $e->getMessage() );
26 }
27 }
28
29 }