ForeverDev

Untitled

Sep 26th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.66 KB | None | 0 0
  1. function translate(language, code)
  2.     local translations;
  3.     if language == "javascript" or language == "js" then
  4.         translations = {
  5.             ["var"] = "local",
  6.             ["(%a+)%s*%+%+"] = "%1 = %1 + 1",
  7.             ["(%a+)%s*%+%=%s*(" .. patterns.number .. ")"] = "%1 = %1 + %2",
  8.             ["(%a+)%s*%-%-"] = "%1 = %1 - 1",
  9.             ["function%s+(%a+)%s*%((.+)%)%s*{"] = "function %1(%2)",   
  10.             ["while%s*%((.+)%)%s*{"] = "while %1 do",  
  11.             ["(function%s+%a+%s*%(.+%).+)}"] = "%1 end",
  12.             ["([while]?[if]?)(.+)([do]?[then]?)(.+)}"] = "%1 %2 %3 %4 end",
  13.             ["console%.log"] = "print"
  14.         }
  15.     end
  16.     for pattern, replace in pairs(translations) do
  17.         code = code:gsub(pattern, replace)
  18.     end
  19.     return code
  20. end
Advertisement
Add Comment
Please, Sign In to add comment