Advertisement
Rakoonic

LUA / Corona - simple file IO with JSON support

May 19th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1. --------------------------------------------------------------
  2. -- INITIALISATION --------------------------------------------
  3.  
  4. module(..., package.seeall)
  5.  
  6. local JSON = require( "json" )
  7.  
  8. --------------------------------------------------------------
  9. -- FILE FUNCTIONS --------------------------------------------
  10.  
  11. -- Encode table to JSON string
  12. function JSONEncode( data )
  13.  
  14.     return
  15.    
  16. end
  17.  
  18. -- Decode JSON string to table
  19. function JSONDecode( data )
  20.  
  21.     return JSON.decode(data, 1, nil, {}, {})
  22.    
  23. end
  24.  
  25. -- Save data to a file
  26. function saveData(filePath, data)
  27.  
  28.     file = io.open( filePath, "w" )
  29.     file:write(data)
  30.     io.close( file )
  31.    
  32. end
  33.  
  34. -- Load data from a file, returning a table
  35. function loadData(filePath)
  36.  
  37.     local file = io.open( filePath, "r" )
  38.     if file then
  39.         local data = file:read( "*a" )
  40.         io.close( file )
  41.         return data
  42.     end
  43.    
  44.     return false
  45.    
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement