MediaWiki  1.34.0
Scribunto_LuaLibraryBase Class Reference

This class provides some basic services that Lua libraries will probably need. More...

Inheritance diagram for Scribunto_LuaLibraryBase:
Collaboration diagram for Scribunto_LuaLibraryBase:

Public Member Functions

 __construct (Scribunto_LuaEngine $engine)
 
 incrementExpensiveFunctionCount ()
 Increment the expensive function count, and throw if limit exceeded. More...
 
 register ()
 Called to register the library. More...
 

Protected Member Functions

 checkType ( $name, $argIdx, $arg, $expectType)
 Check the type of a variable. More...
 
 checkTypeOptional ( $name, $argIdx, &$arg, $expectType, $default)
 Check the type of a variable, with default if null. More...
 
 getEngine ()
 Get the engine. More...
 
 getInterpreter ()
 Get the interpreter. More...
 
 getLuaType ( $var)
 Get the Lua type corresponding to the type of the variable. More...
 
 getParser ()
 Get the parser. More...
 
 getParserOptions ()
 Get the parser options. More...
 
 getTitle ()
 Get the title. More...
 

Private Attributes

Scribunto_LuaEngine $engine
 

Detailed Description

This class provides some basic services that Lua libraries will probably need.

Definition at line 27 of file LibraryBase.php.

Constructor & Destructor Documentation

◆ __construct()

Scribunto_LuaLibraryBase::__construct ( Scribunto_LuaEngine  $engine)
Parameters
Scribunto_LuaEngine$engine

Definition at line 36 of file LibraryBase.php.

References $engine.

Member Function Documentation

◆ checkType()

Scribunto_LuaLibraryBase::checkType (   $name,
  $argIdx,
  $arg,
  $expectType 
)
protected

Check the type of a variable.

If the type of the variable does not match the expected type, a Scribunto_LuaError will be thrown.

Parameters
string$nameName of the calling function (as seen from Lua)
int$argIdxIndex of the argument being tested (1-based)
mixed$argVariable to test
string$expectTypeLua type expected
Returns
void

Definition at line 141 of file LibraryBase.php.

References $type, and getLuaType().

Referenced by Scribunto_LuaTitleLibrary\cascadingProtection(), Scribunto_LuaTitleLibrary\checkNamespace(), checkTypeOptional(), Scribunto_LuaLanguageLibrary\convertGrammar(), Scribunto_LuaLanguageLibrary\convertPlural(), MediaWiki\Extensions\ParserFunctions\LuaLibrary\expr(), Scribunto_LuaLanguageLibrary\fetchLanguageName(), Scribunto_LuaLanguageLibrary\formatDate(), Scribunto_LuaLanguageLibrary\formatDuration(), Scribunto_LuaLanguageLibrary\formatNum(), Scribunto_LuaLanguageLibrary\gender(), Scribunto_LuaTitleLibrary\getContent(), Scribunto_LuaLanguageLibrary\getDurationIntervals(), Scribunto_LuaTitleLibrary\getExpensiveData(), Scribunto_LuaLanguageLibrary\getFallbacksFor(), Scribunto_LuaTitleLibrary\getFileInfo(), Scribunto_LuaSiteLibrary\getNsIndex(), Scribunto_LuaTitleLibrary\getUrl(), Scribunto_LuaLanguageLibrary\isKnownLanguageTag(), Scribunto_LuaLanguageLibrary\isSupportedLanguage(), Scribunto_LuaLanguageLibrary\isValidBuiltInCode(), Scribunto_LuaLanguageLibrary\isValidCode(), Scribunto_LuaTextLibrary\jsonDecode(), Scribunto_LuaTextLibrary\killMarkers(), Scribunto_LuaLanguageLibrary\languageMethod(), Scribunto_LuaTitleLibrary\makeTitle(), Scribunto_LuaTitleLibrary\newTitle(), Scribunto_LuaSiteLibrary\pagesInCategory(), Scribunto_LuaSiteLibrary\pagesInNamespace(), Scribunto_LuaTitleLibrary\protectionLevels(), Scribunto_LuaTitleLibrary\redirectTarget(), Scribunto_LuaTitleBlacklistLibrary\test(), Scribunto_LuaTextLibrary\textUnstrip(), Scribunto_LuaTextLibrary\textUnstripNoWiki(), and Scribunto_LuaSiteLibrary\usersInGroup().

◆ checkTypeOptional()

Scribunto_LuaLibraryBase::checkTypeOptional (   $name,
  $argIdx,
$arg,
  $expectType,
  $default 
)
protected

Check the type of a variable, with default if null.

If the variable is null, $default will be assigned. Otherwise, if the type of the variable does not match the expected type, a Scribunto_LuaError will be thrown.

Parameters
string$nameName of the calling function (as seen from Lua)
int$argIdxIndex of the argument being tested (1-based)
mixed&$argVariable to test/set
string$expectTypeLua type expected
mixed$defaultDefault value
Returns
void

Definition at line 164 of file LibraryBase.php.

References checkType().

Referenced by Scribunto_LuaLanguageLibrary\fetchLanguageName(), Scribunto_LuaLanguageLibrary\fetchLanguageNames(), Scribunto_LuaLanguageLibrary\formatDate(), Scribunto_LuaLanguageLibrary\formatDuration(), Scribunto_LuaLanguageLibrary\getDurationIntervals(), Scribunto_LuaTitleLibrary\getUrl(), Scribunto_LuaSiteLibrary\interwikiMap(), Scribunto_LuaTextLibrary\jsonDecode(), Scribunto_LuaTextLibrary\jsonEncode(), Scribunto_LuaTitleLibrary\makeTitle(), Scribunto_LuaSiteLibrary\pagesInCategory(), and Scribunto_LuaTitleBlacklistLibrary\test().

◆ getEngine()

◆ getInterpreter()

Scribunto_LuaLibraryBase::getInterpreter ( )
protected

Get the interpreter.

Returns
Scribunto_LuaInterpreter interpreter

Definition at line 65 of file LibraryBase.php.

Referenced by getLuaType().

◆ getLuaType()

Scribunto_LuaLibraryBase::getLuaType (   $var)
protected

Get the Lua type corresponding to the type of the variable.

If the variable does not correspond to any type, the PHP type will be returned (prefixed with "PHP"). For example, "PHP resource" or "PHP object of class Foo".

Parameters
mixed$varVariable to test
Returns
string Type

Definition at line 106 of file LibraryBase.php.

References $type, and getInterpreter().

Referenced by checkType(), Scribunto_LuaLanguageLibrary\languageMethod(), and Scribunto_LuaTitleLibrary\newTitle().

◆ getParser()

◆ getParserOptions()

Scribunto_LuaLibraryBase::getParserOptions ( )
protected

Get the parser options.

Returns
ParserOptions parser options

Definition at line 92 of file LibraryBase.php.

Referenced by Scribunto_LuaLanguageLibrary\formatDate(), and Scribunto_LuaLanguageLibrary\gender().

◆ getTitle()

Scribunto_LuaLibraryBase::getTitle ( )
protected

Get the title.

Returns
Title title

Definition at line 83 of file LibraryBase.php.

References getEngine().

Referenced by Scribunto_LuaUriLibrary\register(), and Scribunto_LuaTitleLibrary\register().

◆ incrementExpensiveFunctionCount()

Scribunto_LuaLibraryBase::incrementExpensiveFunctionCount ( )

◆ register()

Scribunto_LuaLibraryBase::register ( )
abstract

Called to register the library.

This should do any necessary setup and then call $this->getEngine()->registerInterface(). The value returned by that call should be returned from this function, and must be for 'deferLoad' libraries to work right.

Returns
array Lua package

Reimplemented in Scribunto_LuaCommonTestsFailLibrary, Scribunto_LuaCommonTestsLibrary, Scribunto_LuaSiteLibrary, Scribunto_LuaTitleLibrary, Scribunto_LuaLanguageLibrary, MediaWiki\Extensions\ParserFunctions\LuaLibrary, Scribunto_LuaTextLibrary, Scribunto_LuaHashLibrary, Scribunto_LuaHtmlLibrary, Scribunto_LuaMessageLibrary, Scribunto_LuaUriLibrary, and Scribunto_LuaTitleBlacklistLibrary.

Member Data Documentation

◆ $engine

Scribunto_LuaEngine Scribunto_LuaLibraryBase::$engine
private

Definition at line 31 of file LibraryBase.php.

Referenced by __construct(), and getEngine().


The documentation for this class was generated from the following file: