Last active
August 13, 2023 03:55
-
-
Save ruliana/a829e1d7f83b9e964bf1dfbd2ab077c0 to your computer and use it in GitHub Desktop.
Lua script for loading and executing files from URLs in FICSIT Network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- All the scripts that should be loaded. | |
-- Put then in load order | |
local URLs = { | |
"https://gist.githubusercontent.com/ruliana/b48dcbaa1ddd92882e9a3cca36d6777f/raw/819bb7ebbd530a1d94601549fd6ae819ecea1cf4/FIN-item-flow-measurement.lua" | |
} | |
local card = computer.getPCIDevices(findClass("FINInternetCard"))[1] | |
if not card then | |
error("Internet card not found") | |
end | |
function getFromInternet(scriptURL) | |
local req = card:request(scriptURL, "GET", "") | |
print(string.format("Requesting \"%s\"", scriptURL)) | |
local status, libdata = req:await() | |
if status ~= 200 then | |
error(string.format("Error %d on GET \"%s\"", status, scriptURL)) | |
end | |
print("Done!") | |
return libdata | |
end | |
for _, scriptURL in ipairs(URLs) do | |
local libdata = getFromInternet(scriptURL) | |
filesystem.initFileSystem("/dev") | |
filesystem.makeFileSystem("tmpfs", "tmp") | |
filesystem.mount("/dev/tmp","/") | |
local file = filesystem.open("main.lua", "+a") | |
file:write(libdata) | |
file:close() | |
end | |
-- load the library from the file system and run it | |
local json = filesystem.doFile("main.lua") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment