OpenComputers Von Neumann Machine Programs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.6 KiB

local shell = require("shell")
local fs = require("filesystem")
local internet = require("internet")
local args = {...}
-- Split string based on delimiter
function split(s, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(s, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
-- Slice table
function slice(tbl, first, last, step)
local sliced = {}
for i = first or 1, last or #tbl, step or 1 do
sliced[#sliced+1] = tbl[i]
end
return sliced
end
-- Error checking
if args[1] == nil then
print("URL must exist")
return
end
local handle = internet.request(args[1])
local result = ""
for chunk in handle do result = result..chunk end
-- Print the body of the HTTP response
-- print(result)
-- Grab the metatable for the handle. This contains the
-- internal HTTPRequest object.
local mt = getmetatable(handle)
-- The response method grabs the information for
-- the HTTP response code, the response message, and the
-- response headers.
local code, message, headers = mt.__index.response()
print("code = "..tostring(code))
print("message = "..tostring(message))
-- Sandbox so we don't write to the screen
sandbox_env = {
assert = assert,
require = require,
pairs = pairs,
pcall = pcall,
tostring = tostring,
string = string,
io = {write = function(...) end, read = io.read, open = io.open, stderr = io.stderr}
}
-- pcall(fs.remove, fileName)
-- shell.execute("wget -f "..args[1].." "..fileName, sandbox_env)
-- -- Run downloaded file
-- local c = fileName
-- for _, i in ipairs(newArgs) do c = c.." "..i end
-- shell.execute(c)function split(s, sep)