mediawiki-extensions-Parser.../ParserFunctions.library.php
Jackmcbarn f7bd89e435 Allow calling #expr from Lua without the parser
Add mw.ext.ParserFunctions.expr, allowing #expr to be used without needing
to use frame:callParserFunction.

Change-Id: I64c78fafad7da503b141efb36da64c3e3d8501a5
2014-05-05 17:58:40 +00:00

22 lines
586 B
PHP

<?php
class Scribunto_LuaParserFunctionsLibrary extends Scribunto_LuaLibraryBase {
public function register() {
$lib = array(
'expr' => array( $this, 'expr' ),
);
$this->getEngine()->registerInterface( __DIR__ . '/mw.ext.ParserFunctions.lua', $lib, array() );
}
public function expr( $expression = null ) {
$this->checkType( 'mw.ext.ParserFunctions.expr', 1, $expression, 'string' );
try {
return array( ExtParserFunctions::getExprParser()->doExpression( $expression ) );
} catch ( ExprError $e ) {
throw new Scribunto_LuaError( $e->getMessage() );
}
}
}