Snusmumriken

Love2d project-runner windows

Jul 25th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. --[[Works on windows,
  2.     Running using cmd:
  3.         start /d "path\to\lua5X\folder" lua5X.exe path\to\love2d\folder ./
  4.     Running using notepad++:
  5.     Insert into shortcuts.xml (Key "112" = alt, running as alt + f1):
  6.       <Command name="Run as LOVE2d" Ctrl="no" Alt="yes" Shift="no" Key="112">
  7.          path\to\lua5X.exe path\to\thisScript.lua path\to\LOVE2d\folder $(CURRENT_DIRECTORY)
  8.       </Command>
  9.     example:
  10.     <Command...>C:\lua5.3\lua53.exe C:\script\runner.lua C:\LOVE\LOVE_0.10 $(CURRENT_DIRECTORY)</Command>
  11.     ]]
  12.  
  13. function fileExists(path)
  14.     local success, f = pcall(io.open, path,"r")
  15.     return f and io.close(f) and true
  16. end
  17. -- Checking interpreter
  18. interprepath = arg[1] or os.exit()
  19. -- Init path
  20. projpath = arg[2] and arg[2]:gsub('\\', '/') or os.exit()
  21. projpath = projpath:sub(-1) == '/' and projpath:sub(1, -2) or projpath
  22. -- Run debug when any additional flags
  23. dbg = arg[3] and true or false
  24.  
  25. -- Finding folder with 'main.lua'-file
  26. while projpath:find('/') do
  27.     if fileExists(projpath..'/main.lua') then
  28.         os.execute('start /d "'..interprepath..'" love.exe '..projpath)
  29.         break
  30.     end
  31.     -- Up to the Folder Tree!
  32.     projpath = projpath:match('(.*)%/')
  33. end
  34.  
  35. if dbg then
  36.     for k, v in pairs(arg) do
  37.         print(k..':  '..v)
  38.     end
  39. end
  40. os.exit()
Add Comment
Please, Sign In to add comment