Loading images remotely for example code

Hi. I wrote this function to load images remotely without needing to rewrite the code to handle callbacks.

You specify width, height, url for your resources and the loader will return an image that will be updated with the correct data when loaded. You could save the image as well when downloaded.

local imageMap = {
    ["Documents:GreyButton"] = {128,128,
        "https://dl.dropbox.com/s/97ru3ti7zvwa9eu/Photo%202013-02-23%2021%2031%2037.png"
    },
    ["Documents:Earth"] = {300,200,
        "https://dl.dropbox.com/s/fzrsg4mzzchm325/earth.jpg"
    }
}
function readRemoteImage(name)
    if type(name) == "string" then
        local img = readImage(name)
        if img == nil then
            local w,h,url = unpack(imageMap[name] or {1,1})
            img = image(w,h)
            if url then
                http.request(url, function (data)
                    pushStyle()
                    setContext(img)
                    spriteMode(CORNER)
                    sprite(data,0,0,w,h)
                    setContext()
                    popStyle()
                end)
            end
        end
        return img
    else
        return name
    end
end