Advertisement
ZNZNCOOP

translator.lua

Oct 12th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.89 KB | None | 0 0
  1. args = {...}
  2.  
  3. if #args > 0 then
  4.    print("Converting files...")
  5.    for i = 1, #args do
  6.       t = ''
  7.       f = io.open(args[i],'r')
  8.       if(f ~= nil) then
  9.          for l in io.lines(args[i]) do
  10.             t = t..l..'\n'
  11.          end
  12.  
  13.          len = 1
  14.          while len > 0 do
  15.             t, len = string.gsub(t,'while(.+){(.+)}', 'while %1 do %2 end')
  16.          end
  17.          len = 1
  18.          while len > 0 do
  19.             t, len = string.gsub(t,'for(.+){(.+)}', 'for %1 do %2 end')
  20.          end
  21.          len = 1
  22.          while len > 0 do
  23.             t, len = string.gsub(t,'if(.+){(.+)}','if %1 then %2 end')
  24.          end
  25.          len = 1
  26.          while len > 0 do
  27.             t, len = string.gsub(t,'function(.+){(.+)}', 'function %1 %2 end')
  28.          end
  29.          f:close()
  30.          f = io.open(args[i]..'.out', 'w')
  31.          f:write(t)
  32.          f:close()
  33.       end
  34.    end
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement