How do I do simple http requests with love/lua?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
cazura
Prole
Posts: 14
Joined: Fri Jan 03, 2020 4:17 pm
Location: Brazil

How do I do simple http requests with love/lua?

Post by cazura »

Hello! First, I know Love is not meant for web, so I am sorry if my question should not be asked here.

Here is my issue: I want to get time from http://worldtimeapi.org/

By running

Code: Select all

http = require("socket.http")
tempVar = http.request("http://worldtimeapi.org/api/timezone/Europe/London.txt")
I succefully get the response in love. Now I am also porting to web through love.js, and after the port this same code doesn't work and gives me the error: WebSocket is closed before the connection is established.

Image

I found this love.js git issue which may be relevant, but I'm not sure: https://github.com/TannerRogalsky/love.js/issues/26

So... There is a way to fix it or do it in some other way?

EXTRA: I can get the time with javascript in my index just fine. I also found this cute thing: https://fengari.io/ that allows me run lua/javascript very easily. BUT I couldn't figure a way of making the gate between my game and the index page scripts, making them interact and trigger events from my game. I don't even know if this is possible, but would be cool because I could then use https://docs.kongregate.com/docs/javascript-api as well!
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How do I do simple http requests with love/lua?

Post by zorg »

Yeah, this seems more of a lovejs issue than löve, especially since you yourself said that it worked in löve proper.
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: Google [Bot] and 226 guests