mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-09-23 18:30:32 +00:00
Add mw.getCurrentFrame()
Provide a convenient means to access the current frame so that the parameter passed to module functions won't need to be conventionally stored in a global variable. Change-Id: I0254d86a1094866a3ce4899e4021d0b33367bb35
This commit is contained in:
parent
9859591271
commit
aacca08815
|
@ -6,6 +6,7 @@ local php
|
||||||
local setupDone
|
local setupDone
|
||||||
local allowEnvFuncs = false
|
local allowEnvFuncs = false
|
||||||
local logBuffer = ''
|
local logBuffer = ''
|
||||||
|
local currentFrame
|
||||||
|
|
||||||
--- Put an isolation-friendly package module into the specified environment
|
--- Put an isolation-friendly package module into the specified environment
|
||||||
-- table. The package module will have an empty cache, because caching of
|
-- table. The package module will have an empty cache, because caching of
|
||||||
|
@ -374,8 +375,12 @@ end
|
||||||
|
|
||||||
function mw.executeFunction( chunk )
|
function mw.executeFunction( chunk )
|
||||||
local frame = newFrame( 'current' )
|
local frame = newFrame( 'current' )
|
||||||
|
local oldFrame = currentFrame
|
||||||
|
|
||||||
|
currentFrame = frame
|
||||||
local results = { chunk( frame ) }
|
local results = { chunk( frame ) }
|
||||||
|
currentFrame = oldFrame
|
||||||
|
|
||||||
local stringResults = {}
|
local stringResults = {}
|
||||||
for i, result in ipairs( results ) do
|
for i, result in ipairs( results ) do
|
||||||
stringResults[i] = tostring( result )
|
stringResults[i] = tostring( result )
|
||||||
|
@ -395,5 +400,8 @@ function mw.getLogBuffer()
|
||||||
return logBuffer
|
return logBuffer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mw.getCurrentFrame()
|
||||||
|
return currentFrame
|
||||||
|
end
|
||||||
|
|
||||||
return mw
|
return mw
|
||||||
|
|
Loading…
Reference in a new issue