Advertisement
Bolodefchoco_LUAXML

[Biblioteca] Execute

Mar 28th, 2016
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 28/03/2016
  3. --Last update: 26/05/2016
  4. --[[ Notes:
  5.     Nenhuma das funções poderão ser usadas no Transformice
  6.     execute.getFile
  7.         Does:
  8.             Retorna as coisas do arquivo
  9.         Args:
  10.             file --> Nome do arquivo (String)
  11.             format --> Formato de coleta
  12.                 *n --> Retorna o primeiro número do arquivo
  13.                 *a --> Lê o arquivo por completo
  14.                 *l/*L --> A primeira linha
  15.                 number --> Lê de 0 até número (Deve ser int)
  16.     execute.editFile
  17.         Does:
  18.             Edita algo no arquivo
  19.         Args:
  20.             file --> Nome do arquivo (String)
  21.             format --> Formato de edição
  22.                 w --> Modo escrita
  23.                 a --> Modo de adição
  24.                 r+ --> Modo de atualização (Não apaga tudo)
  25.                 w+ --> Modo de atualização (Apaga tudo)
  26.                 a+ --> Modo de adição no fim do arquivo
  27.             edition --> Uma string com todas as informações para a edição
  28. ]]--
  29.  
  30. execute={}
  31.  
  32. execute.getFile=function(file,format)
  33.     file = assert(io.open(file,"r"),"The file "..file.." does not exist or you have not access")
  34.     local formatModes = [[ Formats
  35.         "*n" -> Returns the first number;
  36.         "*a" -> Reads all the file;
  37.         "*l/*L" -> First line;
  38.         number -> Reads from 0 'till number (Must be int)
  39.     ]]
  40.     if format~="*n" and format~="*a" and format~="*l" and format~="*L" and type(format)~="number" then error(formatModes) end
  41.     format = format or "*a"
  42.     local _file = file:read(format)
  43.     file:close()
  44.     return _file
  45. end
  46.  
  47. execute.editFile=function(file,format,edition)
  48.     if edition == nil then error("Edition needs a value") end
  49.     if format == "r" then error("Format must be a edition mode") end
  50.     local formatModes = [[ Formats
  51.         "r" -> Read; --You cant use this one here.
  52.         "w" -> Write mode;
  53.         "a" -> Add mode;
  54.         "r+" -> Att mode (Do not erase everything);
  55.         "w+" -> Att mode (Erase everything);
  56.         "a+" -> Add mode in the end of the file
  57.     ]]
  58.     if format ~= "w" and format ~= "a" and format ~= "r+" and format ~= "w+" and format ~= "a+" then error(formatModes) end
  59.     file = assert(io.open(file,format),"The file "..file.." does not exist or you have not access")
  60.     file:write(edition);file:flush();file:close()
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement