Created
September 19, 2023 07:45
-
-
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*.
This file contains hidden or 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
| --[[ | |
| 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