Compare commits
No commits in common. "128798cf221a1ae2f2675dce4ed46c248576e46c" and "b316ced86248d65fec62abcd7c64be34b94e5bc4" have entirely different histories.
128798cf22
...
b316ced862
@ -1,93 +0,0 @@
|
|||||||
local repo = "https://buduf.ddns.net/git/Buduf/ComputerCraft/raw/branch/master/"
|
|
||||||
local function printUsage()
|
|
||||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
|
||||||
print("This program downloads a file from my git repository. Usage:")
|
|
||||||
print(programName .. " <programname> [filename]")
|
|
||||||
print(programName .. " run <programname>")
|
|
||||||
end
|
|
||||||
|
|
||||||
local tArgs = { ... }
|
|
||||||
|
|
||||||
local run = false
|
|
||||||
if tArgs[1] == "run" then
|
|
||||||
table.remove(tArgs, 1)
|
|
||||||
run = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if #tArgs < 1 then
|
|
||||||
printUsage()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local url = repo .. table.remove(tArgs, 1) .. ".lua"
|
|
||||||
|
|
||||||
if not http then
|
|
||||||
printError("getscript requires the http API")
|
|
||||||
printError("Set http.enabled to true in CC: Tweaked's config")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local function getFilename(sUrl)
|
|
||||||
sUrl = sUrl:gsub("[#?].*", ""):gsub("/+$", "")
|
|
||||||
return sUrl:match("/([^/]+)$")
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get(sUrl)
|
|
||||||
-- Check if the URL is valid
|
|
||||||
local ok, err = http.checkURL(url)
|
|
||||||
if not ok then
|
|
||||||
printError(err or "Invalid URL.")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
write("Connecting to " .. sUrl .. "... ")
|
|
||||||
|
|
||||||
local response = http.get(sUrl, nil, true)
|
|
||||||
if not response then
|
|
||||||
print("Failed.")
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
print("Success.")
|
|
||||||
|
|
||||||
local sResponse = response.readAll()
|
|
||||||
response.close()
|
|
||||||
return sResponse or ""
|
|
||||||
end
|
|
||||||
|
|
||||||
if run then
|
|
||||||
local res = get(url)
|
|
||||||
if not res then return end
|
|
||||||
|
|
||||||
local func, err = load(res, getFilename(url), "t", _ENV)
|
|
||||||
if not func then
|
|
||||||
printError(err)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local ok, err = pcall(func, table.unpack(tArgs))
|
|
||||||
if not ok then
|
|
||||||
printError(err)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local sFile = tArgs[1] or getFilename(url) or url
|
|
||||||
local sPath = shell.resolve(sFile)
|
|
||||||
if fs.exists(sPath) then
|
|
||||||
print("File already exists")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local res = get(url)
|
|
||||||
if not res then return end
|
|
||||||
|
|
||||||
local file, err = fs.open(sPath, "wb")
|
|
||||||
if not file then
|
|
||||||
printError("Cannot save file: " .. err)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
file.write(res)
|
|
||||||
file.close()
|
|
||||||
|
|
||||||
print("Downloaded as " .. sFile)
|
|
||||||
end
|
|
||||||
@ -4,7 +4,8 @@ for key, monitor in pairs(monitors) do
|
|||||||
monitor.setTextScale(0.5)
|
monitor.setTextScale(0.5)
|
||||||
monitor.clear()
|
monitor.clear()
|
||||||
monitor.setCursorPos(1, 1)
|
monitor.setCursorPos(1, 1)
|
||||||
|
--monitor.write("Hello World!")
|
||||||
end
|
end
|
||||||
local wo = colony.getWorkOrders()
|
local wo = colony.getWorkOrders()
|
||||||
local s = printTable(wo)
|
local pr = textutils.serialise(wo)
|
||||||
monitors[1].write(s)
|
printTable(wo, 0)
|
||||||
|
|||||||
@ -1,16 +1,14 @@
|
|||||||
local result = ""
|
local function _printTable(table, s, tabs)
|
||||||
|
|
||||||
local function _printTable(table, tabs)
|
|
||||||
for key, value in pairs(table) do
|
for key, value in pairs(table) do
|
||||||
if type(value) == "table" then
|
if type(value) == "table" then
|
||||||
_printTable(value, tabs + 1)
|
_printTable(table, "", tabs + 1)
|
||||||
else
|
else
|
||||||
result = result .. "\n" .. string.rep(" ", tabs) .. key .. ": " .. value
|
print(string.rep(' ', tabs), key, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
function printTable(table)
|
function printTable(table)
|
||||||
_printTable(table, 0)
|
return _printTable(table, "", 0)
|
||||||
return result
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user