Simple HTTPS loader in pure Lua
Posted: Mon Dec 28, 2020 4:23 am
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!
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.
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 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.