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:
Tim Starling 2012-09-06 14:54:26 +10:00
parent 9859591271
commit aacca08815

View file

@ -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