mw = mw or {} function mw.clone( val ) local tableRefs = {} local function recursiveClone( val ) if type( val ) == 'table' then -- Encode circular references correctly if tableRefs[val] ~= nil then return tableRefs[val] end local retVal retVal = {} tableRefs[val] = retVal for key, elt in pairs( val ) do retVal[key] = recursiveClone( elt ) end return retVal else return val end end return recursiveClone( val ) end function mw.executeModule( chunk ) local env = mw.clone( _G ) setfenv( chunk, env ) return chunk() end return mw