Skip to content

Instantly share code, notes, and snippets.

@mpeterv
Created December 4, 2015 15:19
Show Gist options
  • Select an option

  • Save mpeterv/cbbd90ab99a8715da488 to your computer and use it in GitHub Desktop.

Select an option

Save mpeterv/cbbd90ab99a8715da488 to your computer and use it in GitHub Desktop.
#!/usr/bin/env lua
local remote_prog = [[
local name = [=[%s]=]
local fh = assert(io.open(name))
local src = assert(fh:read("*a"))
fh:close()
local f = assert((loadstring or load)(src))
local activelines = assert(debug.getinfo(f, "L").activelines)
local lines = {}
for line in pairs(activelines) do table.insert(lines, line) end
table.sort(lines)
for _, line in ipairs(lines) do print(line) end
]]
if not arg[1] or arg[1] == "-h" or arg[1] == "--help" then
print("Pass a file name as the first argument.")
print("Optionally, pass path to Lua interpreter as the second argument.")
else
os.execute((arg[2] or "lua") .. " -e '" .. remote_prog:format(arg[1]) .. "'")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment