file.lua 668 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. -- No need to explain
  2. Toml=require("toml")
  3. local File={}
  4. function File.reqsubdir(dir)
  5. return love.filesystem.getDirectoryItems(dir)
  6. end
  7. function File.reqlua(dir)
  8. return love.filesystem.load(dir)
  9. end
  10. function File.tostr(file)
  11. return love.filesystem.read(file)
  12. end
  13. function File.fromstr(data,file)
  14. local lfile=io.open(file,"w")
  15. lfile:write(data)
  16. lfile:close()
  17. end
  18. function File.dcfromtoml(file)
  19. return Toml.parse(File.tostr(file),{strict=false})
  20. end
  21. function File.ectotoml(data,file)
  22. -- Can lead to issues, io handle path differently
  23. local lfile=io.open(file,"w")
  24. lfile:write(Toml.encode(data))
  25. lfile:close()
  26. end
  27. return File