Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fs = require("filesystem")
- file = "test"
- args = {...}
- function loadFile(filename)
- code = ""
- for line in io.lines(filename) do
- code = code..line.."\n"
- end
- end
- function translate(filename)
- i = 0
- last = 1
- while i<=#code do
- i = i+1
- p1,p2 = string.find(code,"}.-else.-if.-{",i)
- if p1 ~= nil and p2 ~= nil then
- i = p2
- t = string.sub(code,p1,p2)
- stat = string.match(t,"}.-else.-if(.-){")
- t = "elseif "..stat.." then"
- code = string.sub(code,1,p1-1)..t..string.sub(code,p2+1,#code)
- end
- end
- code = string.gsub(code,"}.-else.-{","else")
- i = 0
- while i<=#code do
- i = i+1
- p1,p2 = string.find(code,"if.-{",i)
- if p1 ~= nil and p2 ~= nil then
- pp1,pp2 = string.find(code,"if.-else.-{",i)
- if pp2 ~= p2 then
- t = string.sub(code,p1,p2)
- t = string.gsub(t,"&&","and")
- t = string.gsub(t,"||","or")
- t = string.gsub(t,"!=","~=")
- t = string.gsub(t,"{"," then ")
- code = string.sub(code,1,p1-1)..t..string.sub(code,p2+1,#code)
- end
- end
- p1,p2 = string.find(code,"while.-{",i)
- if p1 ~= nil and p2 ~= nil then
- t = string.sub(code,p1,p2)
- t = string.gsub(t,"{"," do ")
- code = string.sub(code,1,p1-1)..t..string.sub(code,p2+1,#code)
- end
- p1,p2 = string.find(code,"for.-{",i)
- if p1 ~= nil and p2 ~= nil then
- t = string.sub(code,p1,p2)
- t = string.gsub(t,"{"," do ")
- code = string.sub(code,1,p1-1)..t..string.sub(code,p2+1,#code)
- end
- p1,p2 = string.find(code,"[a-zA-Z1-9]+%+%+",i)
- if p1 ~= nil and p2 ~= nil then
- t = string.sub(code,p1,p2)
- var = string.match(t,"(.+)%+%+")
- t = "(function()"..var.."="..var.."+1".." return "..var.." end)()"
- code = string.sub(code,1,p1-1)..t..string.sub(code,p2+1,#code)
- end
- p1,p2 = string.find(code,"[a-zA-Z1-9]+%-%-",i)
- if p1 ~= nil and p2 ~= nil then
- t = string.sub(code,p1,p2)
- var = string.match(t,"(.+)%-%-")
- t = "(function()"..var.."="..var.."-1".." return "..var.." end)()"
- code = string.sub(code,1,p1-1)..t..string.sub(code,p2+1,#code)
- end
- p1,p2 = string.find(code,"%-%-[a-zA-Z1-9]+",i)
- if p1 ~= nil and p2 ~= nil then
- t = string.sub(code,p1,p2)
- var = string.match(t,"%-%-(.+)")
- t = "(function()"..var.."="..var.."-1".." return "..var.." end)()"
- code = string.sub(code,1,p1-1)..t..string.sub(code,p2+1,#code)
- end
- p1,p2 = string.find(code,"%+%+[a-zA-Z1-9]+",i)
- if p1 ~= nil and p2 ~= nil then
- t = string.sub(code,p1,p2)
- var = string.match(t,"%+%+(.+)")
- t = "(function()"..var.."="..var.."+1".." return "..var.." end)()"
- code = string.sub(code,1,p1-1)..t..string.sub(code,p2+1,#code)
- end
- p1,p2 = string.find(code,"%S+%+=%S+",i)
- if p1 ~= nil and p2 ~= nil then
- t = string.sub(code,p1,p2)
- var,st = string.match(t,"(.+)%+=(.+)")
- t = var.."="..var.."+"..st
- code = string.sub(code,1,p1-1)..t..string.sub(code,p2+1,#code)
- end
- p1,p2 = string.find(code,"%S+%-=%S+",i)
- if p1 ~= nil and p2 ~= nil then
- t = string.sub(code,p1,p2)
- var,st = string.match(t,"(.+)%-=(.+)")
- t = var.."="..var.."-"..st
- code = string.sub(code,1,p1-1)..t..string.sub(code,p2+1,#code)
- end
- p1,p2 = string.find(code,"%S+%*=%S+",i)
- if p1 ~= nil and p2 ~= nil then
- t = string.sub(code,p1,p2)
- var,st = string.match(t,"(.+)%*=(.+)")
- t = var.."="..var.."*"..st
- code = string.sub(code,1,p1-1)..t..string.sub(code,p2+1,#code)
- end
- p1,p2 = string.find(code,"%S+%/=%S+",i)
- if p1 ~= nil and p2 ~= nil then
- t = string.sub(code,p1,p2)
- var,st = string.match(t,"(.+)%/=(.+)")
- t = var.."="..var.."/"..st
- code = string.sub(code,1,p1-1)..t..string.sub(code,p2+1,#code)
- end
- p1,p2 = string.find(code,"function .-{",i)
- if p1 ~= nil and p2 ~= nil then
- t = string.sub(code,p1,p2)
- func = string.match(t,"function (.+){")
- t = "function "..func
- code = string.sub(code,1,p1-1)..t..string.sub(code,p2+1,#code)
- end
- p1,p2 = string.find(code,"}",i)
- if p1 ~= nil and p2 ~= nil then
- pp1,pp2 = string.find(code,"[a-zA-Z1-9]-=.-{.-}",lastT)
- if pp2 ~= nil then
- if i >= pp2 then lastT = i end
- end
- if pp2 ~= p2 then
- code = string.sub(code,1,p1-1).." end "..string.sub(code,p2+1,#code)
- end
- end
- p1,p2 = string.find(code,"export.-[a-zA-Z1-9]+",i)
- if p1 ~= nil and p2 ~= nil then
- t = string.sub(code,p1,p2)
- lib = string.match(t,"export.-([a-zA-Z1-9]+)")
- code = string.sub(code,1,p1-1).."local "..lib.." = require('"..lib.."')"..string.sub(code,p2+1,#code)
- end
- end
- f = io.open(filename,"w")
- f:write(code)
- f:close()
- end
- if #args == 2 and fs.exists(args[1]) then
- loadFile(args[1])
- translate(args[2])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement