Advertisement
1lann

compiler

Oct 29th, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. -- http://lua-users.org/wiki/LuaCompilerInLua
  2. tArgs = {...}
  3. -- compile the input file(s)
  4. local chunk = {}
  5. for _, file in ipairs(tArgs) do
  6. chunk[#chunk + 1] = assert(loadfile(file))
  7. end
  8.  
  9. if #chunk == 1 then
  10. chunk = chunk[1]
  11. else
  12. -- combine multiple input files into a single chunk
  13. for i, func in ipairs(chunk) do
  14. chunk[i] = ("%sloadstring%q(...);"):format(
  15. i==#chunk and "return " or " ",
  16. string.dump(func))
  17. end
  18. chunk = assert(loadstring(table.concat(chunk)))
  19. end
  20.  
  21. local out = assert(io.open("luac.lua.out", "w"))
  22. out:write(string.dump(chunk))
  23. out:close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement