Make lang:parseFormattedNumber more like tonumber

Users seem to expect that mw.language's parseFormattedNumber will act
like tonumber when given nil or other non-string values, returning nil
instead of raising an error. There's no reason not to, so we may as
well.

Change-Id: Ie0ff19efc84ca738e115bbd524bfd92fccf26127
This commit is contained in:
Brad Jorsch 2013-07-03 12:01:41 -04:00 committed by Anomie
parent ad3e5a7c48
commit 25cbfd776d

View file

@ -113,7 +113,10 @@ class Scribunto_LuaLanguageLibrary extends Scribunto_LuaLibraryBase {
if ( is_numeric( $args[0] ) ) {
$args[0] = strval( $args[0] );
}
$this->checkType( $name, 1, $args[0], 'string' );
if ( $this->getLuaType( $args[0] ) !== 'string' ) {
// Be like tonumber(), return nil instead of erroring out
return array( null );
}
return array( $lang->$name( $args[0] ) );
// Custom handling