Simple HTTPS loader in pure Lua

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
groverburger
Prole
Posts: 49
Joined: Tue Oct 30, 2018 9:27 pm

Simple HTTPS loader in pure Lua

Post by groverburger »

Hello everyone!

I found a hack using io.popen to load HTTPS files that might be useful. It's a very short code snippet, no external dependencies required!

Code: Select all

return function (address)
    local query = nil

    -- check if windows or not windows
    if package.config:sub(1,1) == "\\" then
        -- TODO fix the annoying cmd window that pops up here
        query = io.popen("powershell (wget " .. address .. ").Content", "r")
    else
        -- not windows, assuming posix
        query = io.popen("curl -s '" .. address .. "'", "r")
    end

    local httpsResult = query:read("*all")
    query:close()
    return httpsResult
end
I've tested this on Windows 8.1 and MacOS 10.14.6, and I'm relatively confident that this should work on newer OS versions too. This might work on Linux as it uses curl for all non-Windows OSs, but I haven't tested this.

I still don't know of a way to prevent the annoying CMD box that appears in Windows without forking Love itself. Maybe a DLL can be added that adds a workaround? I also don't know of a way to send HTTPS data either. Any info on improving this is appreciated.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Simple HTTPS loader in pure Lua

Post by pgimeno »

I've checked in the Vista computer of my mother-in-law, and PowerShell doesn't exist. Löve is supported in Vista, so it looks like Windows 8 is a requirement that any application that uses this trick should specify.

Some Linux users would need to install curl explicitly, not all systems come with it pre-installed. wget is probably more common, but still a separate package in most distributions.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Simple HTTPS loader in pure Lua

Post by zorg »

Yep, me being on Win7 also precludes using the snippet since it also lacks powershell. Not sure if wget depends on curl that a relatively new Win10 build included natively (or so i heard) or not, because then the compatibility is even worse.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 42 guests