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.

65 lines
1.3 KiB

local shell = require("shell")
local internet = require("internet")
local fs = require("filesystem")
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
args[1] = "http://mc.bashed.rocks:13699/"..args[1]
-- Get local filename
local fileName = ""
if args[2] == nil then
local t = split(args[1], "/")
fileName = t[#t]
else
fileName = args[2]
end
local newArgs = slice(args, 3, #args-2)
-- 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)