Advertisement
Guest User

Untitled

a guest
Nov 30th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. --LUA fileFuncs
  2. function writeDataToFile(file, data)
  3.  
  4. --Open/Create file------------
  5. local wFd = io.open(file,"w")
  6.  
  7. --Modify ---------------------
  8. local writeSucess = false --Determin sucess of
  9. if wFd:write(data) then --Write to file
  10. writeSucess = true
  11. end
  12.  
  13. --Close ----------------------
  14. wFd:close()
  15. return writeSucess
  16. end
  17.  
  18.  
  19.  
  20.  
  21. -- see if the file exists
  22. function file_exists(file)
  23. local f = io.open(file, "rb")
  24. if f then f:close() end
  25. return f ~= nil
  26. end
  27.  
  28. -- get all lines from a file, returns an empty
  29. -- list/table if the file does not exist
  30. function lines_from(file)
  31. if not file_exists(file) then
  32. return {}
  33. else
  34. lines = {}
  35. for line in io.lines(file) do
  36. lines[#lines + 1] = line
  37. end
  38. return lines
  39. end
  40. end
  41.  
  42.  
  43. function lines_from_dropbox(file)
  44. local dropboxPath = os.getenv("HOME").."/Documents/Dropbox.spritepack/"
  45. return lines_from(dropboxPath..file)
  46. end
  47.  
  48.  
  49. function txt_from_dropbox(file)
  50. local dropboxPath = os.getenv("HOME").."/Documents/Dropbox.spritepack/"
  51. return join(lines_from(dropboxPath..file), "\n")
  52. end
  53.  
  54. function join(array, sep)
  55. string = ""
  56. for i,v in pairs(array) do
  57. string = string..v..sep
  58. end
  59. return string
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement