lua_runner.lua (2121B)
1 local platform = vim.uv.os_uname() 2 local deps_install_dir = table.remove(_G.arg, 1) 3 _G.c_include_path = {} 4 while vim.startswith(_G.arg[1], '-I') do 5 table.insert(_G.c_include_path, string.sub(table.remove(_G.arg, 1), 3)) 6 end 7 local subcommand = table.remove(_G.arg, 1) 8 local suffix = (platform and platform.sysname:lower():find 'windows') and '.dll' or '.so' 9 package.path = (deps_install_dir .. '/?.lua;') 10 .. (deps_install_dir .. '/?/init.lua;') 11 .. package.path 12 package.cpath = deps_install_dir .. '/?' .. suffix .. ';' .. package.cpath 13 14 local uv = vim.uv 15 16 -- we use busted and luacheck and their lua dependencies 17 -- But installing their binary dependencies with luarocks is very 18 -- slow, replace them with vim.uv wrappers 19 20 local system = {} 21 package.loaded['system.core'] = system 22 function system.monotime() 23 uv.update_time() 24 return uv.now() * 1e-3 25 end 26 function system.gettime() 27 local sec, usec = uv.gettimeofday() 28 return sec + usec * 1e-6 29 end 30 function system.sleep(sec) 31 uv.sleep(sec * 1e3) 32 end 33 34 local term = {} 35 package.loaded['term.core'] = term 36 function term.isatty(_) 37 return uv.guess_handle(1) == 'tty' 38 end 39 40 local lfs = { _VERSION = 'fake' } 41 package.loaded['lfs'] = lfs 42 43 function lfs.attributes(path, attr) 44 local stat = uv.fs_stat(path) 45 if attr == 'mode' then 46 return stat and stat.type or '' 47 elseif attr == 'modification' then 48 if not stat then 49 return nil 50 end 51 local mtime = stat.mtime 52 return mtime.sec + mtime.nsec * 1e-9 53 else 54 error('not implemented') 55 end 56 end 57 58 function lfs.currentdir() 59 return uv.cwd() 60 end 61 62 function lfs.chdir(dir) 63 local status, err = pcall(uv.chdir, dir) 64 if status then 65 return true 66 else 67 return nil, err 68 end 69 end 70 71 function lfs.dir(path) 72 local fs = uv.fs_scandir(path) 73 return function() 74 if not fs then 75 return 76 end 77 return uv.fs_scandir_next(fs) 78 end 79 end 80 81 function lfs.mkdir(dir) 82 return uv.fs_mkdir(dir, 493) -- octal 755 83 end 84 85 if subcommand == 'busted' then 86 require 'busted.runner'({ standalone = false }) 87 elseif subcommand == 'luacheck' then 88 require 'luacheck.main' 89 else 90 error 'unknown subcommand' 91 end