Sha256: fb89026e3a74d265476b07373403d1f90fb4d11c68f608b2737b21f65449116b

Contents?: true

Size: 711 Bytes

Versions: 5

Compression:

Stored size: 711 Bytes

Contents

local http = require("socket.http")
local ltn12 = require("ltn12")

local M = {}

require "json"
local parseJson = function( filename )
  local file = io.open( filename, "r" )
  if file then
    local contents = file:read( "*a" )
    result = json.decode( contents )
    io.close( file )
    return result
  else
    return {}
  end
end
M.parseJson = parseJson

local parseRemoteJson = function( remoteUrl )
  local tempFilename = system.pathForFile( "temp.json", system.TemporaryDirectory )
  local tempFile = io.open( tempFilename, "w+b" )

  http.request {
    url = remoteUrl,
    sink = ltn12.sink.file( tempFile )
  }

  return parseJson( tempFilename )
end
M.parseRemoteJson = parseRemoteJson

return M

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nakor-0.0.9 lib/nakor/generators/corona-game-template/scripts/lib/io_ext.lua
nakor-0.0.8 lib/nakor/generators/corona-game-template/io_ext.lua
nakor-0.0.7 lib/nakor/generators/corona-game-template/io_ext.lua
nakor-0.0.6 lib/nakor/generators/corona-game-template/io_ext.lua
nakor-0.0.5 lib/nakor/generators/corona-game-template/io_ext.lua