Module:Sandbox

-- Module:Sandbox > Testing area for all your Lua functions > Don't declare global variables, keep everything within local scope

local p = {}

-- Switch function for nested data structures (Thread:5225) > >> > baz >>  > foo1

function p.switch(frame) -- Sample data -- To be placed in Module:Name/data, then called via mw.loadData local data = { foo = { bar = 'baz', bar1 = 'baz1' },       bar = { baz = 'foo', baz1 = 'foo1' }   }    local text = frame.args[1] local textkey = frame.args[2] if data[text] ~= nil and data[text][textkey] ~= nil then text = data[text][textkey] else text = nil -- Modify invalid key output here end return text end return p