Skip to content

Instantly share code, notes, and snippets.

@Ale32bit
Created September 19, 2023 07:45
Show Gist options
  • Select an option

  • Save Ale32bit/b8eed2a4a6ff00eb5f9334d8d8fb3940 to your computer and use it in GitHub Desktop.

Select an option

Save Ale32bit/b8eed2a4a6ff00eb5f9334d8d8fb3940 to your computer and use it in GitHub Desktop.
Load packages from the web without downloading to files. Science isn't about *why* - it's about *why not*.
--[[
WebPackage by AlexDevs
Load packages from the web without downloading to files.
(Requires HTTP to be enabled ofc)
Usage:
require("webpackage")
local myPackage = require("https://pastebin.com/raw/pe3mgfdi")
]]
local function from_http(name)
if not http.checkURL(name) then
return nil, "package path is not an URL"
end
local h, hErr = http.get(name)
if not h then
return nil, hErr
end
local content = h.readAll()
h.close()
local fn, err = load(content, name, nil, _ENV)
if fn then
return fn, name
else
return nil, err
end
end
table.insert(package.loaders, from_http)
return true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment