ForeverDev

LUA -> JAVASCRIPT

Sep 26th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.03 KB | None | 0 0
  1. local sp = require(game.ServerScriptService.StudioPlus)
  2.  
  3. sp([[
  4.    
  5.     var x = 5
  6.    
  7.     function example(parameter) {
  8.         if (parameter < 10) {
  9.             var loops = 0
  10.             while (loops < 10) {
  11.                 console.log(loops)
  12.                 loops++
  13.             }
  14.         }
  15.     }
  16.    
  17.     example(5)
  18.    
  19. ]]).executeLanguage("javascript")
  20.  
  21.  
  22.  
  23. --inside the module script where the translation takes place
  24.  
  25. function translate(language, code)
  26.     local translations;
  27.     if language == "javascript" or language == "js" then
  28.         translations = {
  29.             ["var"] = "local", 
  30.             ["function%s+(%a+)%s*%((.+)%)%s*{"] = "function %1(%2)",                   
  31.             ["if%s*%((.+)%)%s*{"] = "if %1 then",
  32.             ["while%s*%((.+)%)%s*{"] = "while %1 do",
  33.             ["(%a+)%+%+"] = "%1 = %1 + 1",
  34.             ["}"] = "end",
  35.             ["console%.log"] = "print"
  36.         }
  37.     end
  38.     for pattern, replace in pairs(translations) do
  39.         code = code:gsub(pattern, replace)
  40.     end
  41.     return code
  42. end
  43.  
  44. {
  45.     executeLanguage = function(language)
  46.         --note, object is the passed string in sp(); in this case, the javascript code
  47.         loadstring(translate(language, object))()
  48.     end
  49. }
Advertisement
Add Comment
Please, Sign In to add comment