MediaWiki  1.34.0
Scribunto_LuaEngine Class Reference
Inheritance diagram for Scribunto_LuaEngine:
Collaboration diagram for Scribunto_LuaEngine:

Public Member Functions

 addWarning ( $text)
 Adds a warning to be displayed upon preview. More...
 
 callParserFunction ( $frameId, $function, $args)
 Handler for callParserFunction() More...
 
 checkNumber ( $funcName, $args, $index0)
 Workalike for luaL_checknumber() More...
 
 checkString ( $funcName, $args, $index0)
 Workalike for luaL_checkstring() More...
 
 checkType ( $funcName, $args, $index0, $type, $msgType)
 Workalike for luaL_checktype() More...
 
 destroy ()
 
 executeFunctionChunk ( $chunk, $frame)
 Execute a module function chunk. More...
 
 executeModule ( $chunk, $functionName, $frame)
 Execute a module chunk in a new isolated environment, and return the specified function. More...
 
 expandTemplate ( $frameId, $titleText, $args)
 Handler for expandTemplate() More...
 
 frameExists ( $frameId)
 Handler for frameExists() More...
 
 getAllExpandedArguments ( $frameId)
 Handler for getAllExpandedArguments() More...
 
 getCodeEditorLanguage ()
 Get the language for Ace code editor. More...
 
 getExpandedArgument ( $frameId, $name)
 Handler for getExpandedArgument() More...
 
 getFrameTitle ( $frameId)
 Handler for getTitle() More...
 
 getGeSHiLanguage ()
 Get the language for GeSHi syntax highlighter. More...
 
 getInterpreter ()
 Get the current interpreter object. More...
 
 getLuaLibDir ()
 Return the base path for Lua modules. More...
 
 getPerformanceCharacteristics ()
 Get performance characteristics of the Lua engine/interpreter. More...
 
 incrementExpensiveFunctionCount ()
 Increment the expensive function count, and throw if limit exceeded. More...
 
 isSubsting ()
 Return whether the parser is currently substing. More...
 
 load ()
 Initialise the interpreter and the base environment. More...
 
 loadPackage ( $name)
 Handler for the loadPackage() callback. More...
 
 loadPHPLibrary ( $name)
 Handler for the loadPHPLibrary() callback. More...
 
 newChildFrame ( $frameId, $title, array $args)
 Handler for newChildFrame() More...
 
 newLuaError ( $message, $params=[])
 
 preprocess ( $frameId, $text)
 Handler for preprocess() More...
 
 registerInterface ( $moduleFileName, $interfaceFuncs, $setupOptions=[])
 Register a Lua Library. More...
 
 runConsole (array $params)
 Run an interactive console request. More...
 
 setTTL ( $ttl)
 Handler for setTTL() More...
 
- Public Member Functions inherited from ScribuntoEngineBase
 __construct (array $options)
 
 __destruct ()
 
 fetchModuleFromParser (Title $title)
 Load a module from some parser-defined template loading mechanism and register a parser output dependency. More...
 
 formatLimitData ( $key, &$value, &$report, $isHTML, $localize)
 Format limit report data. More...
 
 getDefaultExceptionParams ()
 
 getOption ( $optionName)
 Get an element from the configuration array. More...
 
 getParser ()
 
 getResourceUsage ( $resource)
 Get CPU and memory usage information, if the script engine provides it. More...
 
 getSoftwareInfo (array &$software)
 Get software information for Special:Version. More...
 
 getTitle ()
 
 newException ( $message, array $params=[])
 
 reportLimitData (ParserOutput $output)
 Add limit report data to a ParserOutput object. More...
 
 setTitle ( $title)
 
 validate ( $text, $chunkName=false)
 Validates the script and returns a Status object containing the syntax errors for the given code. More...
 

Static Public Member Functions

static newAutodetectEngine (array $options)
 If luasandbox is installed and usable then use it, otherwise. More...
 

Public Attributes

const MAX_EXPAND_CACHE_SIZE = 100
 
- Public Attributes inherited from ScribuntoEngineBase
const CPU_SECONDS = 1
 
const MEM_PEAK_BYTES = 2
 

Protected Member Functions

 formatHtmlLogs ( $logs, $localize)
 Format the logged data for HTML output. More...
 
 getFrameById ( $frameId)
 Helper function for the implementation of frame methods. More...
 
 getLogBuffer ()
 Get data logged by modules. More...
 
 loadLibraryFromFile ( $fileName)
 Load a library from the given file and execute it in the base environment. More...
 
 newInterpreter ()
 Create a new interpreter object. More...
 
 newModule ( $text, $chunkName)
 
 normalizeModuleFileName ( $fileName)
 Normalize a lua module to its full path. More...
 
- Protected Member Functions inherited from ScribuntoEngineBase
 getLibraries ( $engine, array $coreLibraries=[])
 Load a list of all libraries supported by this engine. More...
 
 getLibraryPaths ( $engine, array $coreLibraryPaths=[])
 Load a list of all paths libraries can be in for this engine. More...
 

Protected Attributes

 $availableLibraries = []
 
array $currentFrames = []
 
 $expandCache = []
 
Scribunto_LuaInterpreter $interpreter
 
 $loaded = false
 
array $mw
 
- Protected Attributes inherited from ScribuntoEngineBase
ScribuntoModuleBase[] $modules = []
 
array $options
 
Parser $parser
 
Title $title
 

Static Protected Attributes

static array $libraryClasses
 Libraries to load. More...
 
static array $libraryPaths
 Paths for modules that may be loaded from Lua. More...
 

Private Member Functions

 doCachedExpansion ( $frame, $input, $cacheKey)
 
 instantiatePHPLibrary ( $name, $def, $loadDeferred)
 Instantiate and register a library. More...
 
 setupCurrentFrames (PPFrame $frame=null)
 Replaces the list of current frames, and return a ScopedCallback that will reset them when it goes out of scope. More...
 

Detailed Description

Definition at line 6 of file LuaCommon.php.

Member Function Documentation

◆ addWarning()

Scribunto_LuaEngine::addWarning (   $text)

Adds a warning to be displayed upon preview.

Definition at line 877 of file LuaCommon.php.

References ScribuntoEngineBase\getParser().

◆ callParserFunction()

Scribunto_LuaEngine::callParserFunction (   $frameId,
  $function,
  $args 
)

◆ checkNumber()

Scribunto_LuaEngine::checkNumber (   $funcName,
  $args,
  $index0 
)

Workalike for luaL_checknumber()

Parameters
string$funcNameThe Lua function name, for use in error messages
array$argsThe argument array
int$index0The zero-based argument index

Definition at line 487 of file LuaCommon.php.

References $args, and checkType().

Referenced by setTTL().

◆ checkString()

Scribunto_LuaEngine::checkString (   $funcName,
  $args,
  $index0 
)

Workalike for luaL_checkstring()

Parameters
string$funcNameThe Lua function name, for use in error messages
array$argsThe argument array
int$index0The zero-based argument index

Definition at line 476 of file LuaCommon.php.

References $args, and checkType().

Referenced by getExpandedArgument(), loadPackage(), loadPHPLibrary(), and preprocess().

◆ checkType()

Scribunto_LuaEngine::checkType (   $funcName,
  $args,
  $index0,
  $type,
  $msgType 
)

Workalike for luaL_checktype()

Parameters
string$funcNameThe Lua function name, for use in error messages
array$argsThe argument array
int$index0The zero-based argument index
string | array$typeThe allowed type names as given by gettype()
string$msgTypeThe type name used in the error message
Exceptions
Scribunto_LuaError

Definition at line 459 of file LuaCommon.php.

References $args, and $type.

Referenced by checkNumber(), and checkString().

◆ destroy()

Scribunto_LuaEngine::destroy ( )

Reimplemented from ScribuntoEngineBase.

Definition at line 103 of file LuaCommon.php.

◆ doCachedExpansion()

Scribunto_LuaEngine::doCachedExpansion (   $frame,
  $input,
  $cacheKey 
)
private

Definition at line 892 of file LuaCommon.php.

References MAX_EXPAND_CACHE_SIZE, and serialize().

Referenced by expandTemplate(), and preprocess().

◆ executeFunctionChunk()

Scribunto_LuaEngine::executeFunctionChunk (   $chunk,
  $frame 
)

Execute a module function chunk.

Parameters
mixed$chunkAs accepted by Scribunto_LuaInterpreter::callFunction()
PPFrame | null$frame
Returns
array

Definition at line 290 of file LuaCommon.php.

References getInterpreter(), and setupCurrentFrames().

◆ executeModule()

Scribunto_LuaEngine::executeModule (   $chunk,
  $functionName,
  $frame 
)

Execute a module chunk in a new isolated environment, and return the specified function.

Parameters
mixed$chunkAs accepted by Scribunto_LuaInterpreter::callFunction()
string$functionName
PPFrame | null$frame
Returns
mixed
Exceptions
ScribuntoException

Definition at line 262 of file LuaCommon.php.

References getInterpreter(), ScribuntoEngineBase\newException(), and setupCurrentFrames().

◆ expandTemplate()

Scribunto_LuaEngine::expandTemplate (   $frameId,
  $titleText,
  $args 
)

◆ formatHtmlLogs()

Scribunto_LuaEngine::formatHtmlLogs (   $logs,
  $localize 
)
protected

Format the logged data for HTML output.

Parameters
string$logsLogged data
bool$localizeWhether to localize the message key
Returns
string HTML

Definition at line 322 of file LuaCommon.php.

References wfMessage().

Referenced by Scribunto_LuaStandaloneEngine\formatLimitData(), and Scribunto_LuaSandboxEngine\formatLimitData().

◆ frameExists()

Scribunto_LuaEngine::frameExists (   $frameId)

Handler for frameExists()

Definition at line 602 of file LuaCommon.php.

◆ getAllExpandedArguments()

Scribunto_LuaEngine::getAllExpandedArguments (   $frameId)

Handler for getAllExpandedArguments()

Definition at line 690 of file LuaCommon.php.

References getFrameById(), and getInterpreter().

◆ getCodeEditorLanguage()

Scribunto_LuaEngine::getCodeEditorLanguage ( )

Get the language for Ace code editor.

Returns
string|false

Reimplemented from ScribuntoEngineBase.

Definition at line 384 of file LuaCommon.php.

◆ getExpandedArgument()

Scribunto_LuaEngine::getExpandedArgument (   $frameId,
  $name 
)

Handler for getExpandedArgument()

Definition at line 670 of file LuaCommon.php.

References $args, checkString(), getFrameById(), and getInterpreter().

◆ getFrameById()

Scribunto_LuaEngine::getFrameById (   $frameId)
protected

Helper function for the implementation of frame methods.

Parameters
string$frameId
Returns
PPFrame
Exceptions
Scribunto_LuaError

Definition at line 585 of file LuaCommon.php.

References ScribuntoEngineBase\getParser().

Referenced by callParserFunction(), expandTemplate(), getAllExpandedArguments(), getExpandedArgument(), getFrameTitle(), newChildFrame(), preprocess(), and setTTL().

◆ getFrameTitle()

Scribunto_LuaEngine::getFrameTitle (   $frameId)

Handler for getTitle()

Definition at line 645 of file LuaCommon.php.

References getFrameById().

◆ getGeSHiLanguage()

Scribunto_LuaEngine::getGeSHiLanguage ( )

Get the language for GeSHi syntax highlighter.

Returns
string|false

Reimplemented from ScribuntoEngineBase.

Definition at line 380 of file LuaCommon.php.

◆ getInterpreter()

Scribunto_LuaEngine::getInterpreter ( )

◆ getLogBuffer()

Scribunto_LuaEngine::getLogBuffer ( )
protected

Get data logged by modules.

Returns
string Logged data

Definition at line 303 of file LuaCommon.php.

References getInterpreter().

Referenced by Scribunto_LuaSandboxEngine\getLimitReportData(), and Scribunto_LuaStandaloneEngine\reportLimitData().

◆ getLuaLibDir()

Scribunto_LuaEngine::getLuaLibDir ( )

Return the base path for Lua modules.

Returns
string

Definition at line 189 of file LuaCommon.php.

Referenced by Scribunto_LuaSandboxEngine\getMwLuaLine().

◆ getPerformanceCharacteristics()

Scribunto_LuaEngine::getPerformanceCharacteristics ( )
abstract

Get performance characteristics of the Lua engine/interpreter.

phpCallsRequireSerialization: boolean whether calls between PHP and Lua functions require (slow) serialization of parameters and return values

Returns
array

Reimplemented in Scribunto_LuaStandaloneEngine, and Scribunto_LuaSandboxEngine.

◆ incrementExpensiveFunctionCount()

Scribunto_LuaEngine::incrementExpensiveFunctionCount ( )

Increment the expensive function count, and throw if limit exceeded.

Definition at line 864 of file LuaCommon.php.

References ScribuntoEngineBase\getParser().

◆ instantiatePHPLibrary()

Scribunto_LuaEngine::instantiatePHPLibrary (   $name,
  $def,
  $loadDeferred 
)
private

Instantiate and register a library.

Parameters
string$name
array | string$def
bool$loadDeferred
Exceptions
MWException
Returns
array|null

Definition at line 499 of file LuaCommon.php.

Referenced by load(), and loadPHPLibrary().

◆ isSubsting()

Scribunto_LuaEngine::isSubsting ( )

Return whether the parser is currently substing.

Definition at line 887 of file LuaCommon.php.

References ScribuntoEngineBase\getParser(), and OT_WIKI.

◆ load()

Scribunto_LuaEngine::load ( )

◆ loadLibraryFromFile()

Scribunto_LuaEngine::loadLibraryFromFile (   $fileName)
protected

Load a library from the given file and execute it in the base environment.

Parameters
string$fileNameFile name/path to load
Returns
array|null the export list, or null if there isn't one.

Definition at line 344 of file LuaCommon.php.

References $cache, getInterpreter(), and ObjectCache\getLocalServerInstance().

Referenced by registerInterface().

◆ loadPackage()

Scribunto_LuaEngine::loadPackage (   $name)

Handler for the loadPackage() callback.

Load the specified module and return its chunk. It's not necessary to cache the resulting chunk in the object instance, since there is caching in a wrapper on the Lua side.

Definition at line 546 of file LuaCommon.php.

References $args, $path, ScribuntoEngineBase\$title, checkString(), ScribuntoEngineBase\fetchModuleFromParser(), ScribuntoEngineBase\getLibraryPaths(), Title\hasContentModel(), Title\newFromText(), and normalizeModuleFileName().

◆ loadPHPLibrary()

Scribunto_LuaEngine::loadPHPLibrary (   $name)

Handler for the loadPHPLibrary() callback.

Register the specified library and return its function table. It's not necessary to cache the function table in the object instance, since there is caching in a wrapper on the Lua side.

Definition at line 525 of file LuaCommon.php.

References $args, checkString(), and instantiatePHPLibrary().

◆ newAutodetectEngine()

static Scribunto_LuaEngine::newAutodetectEngine ( array  $options)
static

If luasandbox is installed and usable then use it, otherwise.

Parameters
array$options
Returns
Scribunto_LuaEngine

Definition at line 62 of file LuaCommon.php.

References ScribuntoEngineBase\$options, Scribunto_LuaSandboxInterpreter\checkLuaSandboxVersion(), and Scribunto\newEngine().

◆ newChildFrame()

Scribunto_LuaEngine::newChildFrame (   $frameId,
  $title,
array  $args 
)

◆ newInterpreter()

Scribunto_LuaEngine::newInterpreter ( )
abstractprotected

Create a new interpreter object.

Returns
Scribunto_LuaInterpreter

Reimplemented in Scribunto_LuaSandboxEngine, and Scribunto_LuaStandaloneEngine.

Referenced by load().

◆ newLuaError()

Scribunto_LuaEngine::newLuaError (   $message,
  $params = [] 
)
Parameters
string$message
array$params
Returns
Scribunto_LuaError

Definition at line 99 of file LuaCommon.php.

References ScribuntoEngineBase\getDefaultExceptionParams().

◆ newModule()

Scribunto_LuaEngine::newModule (   $text,
  $chunkName 
)
protected
Parameters
string$text
string | bool$chunkName
Returns
Scribunto_LuaModule

Reimplemented from ScribuntoEngineBase.

Definition at line 90 of file LuaCommon.php.

Referenced by runConsole().

◆ normalizeModuleFileName()

Scribunto_LuaEngine::normalizeModuleFileName (   $fileName)
protected

Normalize a lua module to its full path.

If path does not look like an absolute path (i.e. begins with DIRECTORY_SEPARATOR or "X:"), prepend getLuaLibDir()

Parameters
string$fileNamename of the lua module file
Returns
string

Definition at line 201 of file LuaCommon.php.

Referenced by loadPackage(), and registerInterface().

◆ preprocess()

Scribunto_LuaEngine::preprocess (   $frameId,
  $text 
)

Handler for preprocess()

Definition at line 833 of file LuaCommon.php.

References $args, checkString(), doCachedExpansion(), getFrameById(), and getInterpreter().

◆ registerInterface()

Scribunto_LuaEngine::registerInterface (   $moduleFileName,
  $interfaceFuncs,
  $setupOptions = [] 
)

Register a Lua Library.

This should be called from the library's PHP module's register() method.

The value for $interfaceFuncs is used to populate the mw_interface global that is defined when the library's Lua module is loaded. Values must be PHP callables, which will be seen in Lua as functions.

Parameters
string$moduleFileNameThe path to the Lua portion of the library (absolute, or relative to $this->getLuaLibDir())
array$interfaceFuncsPopulates mw_interface
array$setupOptionsPassed to the modules setupInterface() method.
Returns
array Lua package

Definition at line 175 of file LuaCommon.php.

References loadLibraryFromFile(), and normalizeModuleFileName().

Referenced by load().

◆ runConsole()

Scribunto_LuaEngine::runConsole ( array  $params)

Run an interactive console request.

Parameters
array$paramsAssociative array. Options are:
  • title: The title object for the module being debugged
  • content: The text content of the module
  • prevQuestions: An array of previous "questions" used to establish the state
  • question: The current "question", a string script
Returns
array containing:
  • print: The resulting print buffer
  • return: The resulting return value

Reimplemented from ScribuntoEngineBase.

Definition at line 388 of file LuaCommon.php.

References getInterpreter(), newModule(), setupCurrentFrames(), and wfMessage().

◆ setTTL()

Scribunto_LuaEngine::setTTL (   $ttl)

Handler for setTTL()

Definition at line 655 of file LuaCommon.php.

References $args, checkNumber(), and getFrameById().

◆ setupCurrentFrames()

Scribunto_LuaEngine::setupCurrentFrames ( PPFrame  $frame = null)
private

Replaces the list of current frames, and return a ScopedCallback that will reset them when it goes out of scope.

Parameters
PPFrame | null$frameIf null, an empty frame with no parent will be used
Returns
ScopedCallback

Definition at line 235 of file LuaCommon.php.

References $currentFrames, $expandCache, and ScribuntoEngineBase\getParser().

Referenced by executeFunctionChunk(), executeModule(), and runConsole().

Member Data Documentation

◆ $availableLibraries

Scribunto_LuaEngine::$availableLibraries = []
protected

Definition at line 51 of file LuaCommon.php.

◆ $currentFrames

array Scribunto_LuaEngine::$currentFrames = []
protected

Definition at line 49 of file LuaCommon.php.

Referenced by setupCurrentFrames().

◆ $expandCache

Scribunto_LuaEngine::$expandCache = []
protected

Definition at line 50 of file LuaCommon.php.

Referenced by setupCurrentFrames().

◆ $interpreter

Scribunto_LuaInterpreter Scribunto_LuaEngine::$interpreter
protected

Definition at line 39 of file LuaCommon.php.

Referenced by getInterpreter().

◆ $libraryClasses

array Scribunto_LuaEngine::$libraryClasses
staticprotected
Initial value:
= [
'mw.site' => 'Scribunto_LuaSiteLibrary',
'mw.uri' => 'Scribunto_LuaUriLibrary',
'mw.ustring' => 'Scribunto_LuaUstringLibrary',
'mw.language' => 'Scribunto_LuaLanguageLibrary',
'mw.message' => 'Scribunto_LuaMessageLibrary',
'mw.title' => 'Scribunto_LuaTitleLibrary',
'mw.text' => 'Scribunto_LuaTextLibrary',
'mw.html' => 'Scribunto_LuaHtmlLibrary',
'mw.hash' => 'Scribunto_LuaHashLibrary',
]

Libraries to load.

See also the 'ScribuntoExternalLibraries' hook. Maps module names to PHP classes or definition arrays

Definition at line 11 of file LuaCommon.php.

◆ $libraryPaths

array Scribunto_LuaEngine::$libraryPaths
staticprotected
Initial value:
= [
'.',
'luabit',
'ustring',
]

Paths for modules that may be loaded from Lua.

See also the 'ScribuntoExternalLibraryPaths' hook. Paths

Definition at line 28 of file LuaCommon.php.

◆ $loaded

Scribunto_LuaEngine::$loaded = false
protected

Definition at line 34 of file LuaCommon.php.

◆ $mw

array Scribunto_LuaEngine::$mw
protected

Definition at line 44 of file LuaCommon.php.

◆ MAX_EXPAND_CACHE_SIZE

const Scribunto_LuaEngine::MAX_EXPAND_CACHE_SIZE = 100

Definition at line 53 of file LuaCommon.php.

Referenced by doCachedExpansion().


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