My computer game is powered using Love2d in Lua, there is dead space in the menu of my game and I'd like to fill it up with something. So I'll like to put a twitter feed there, how can I receive all the twitter posts created by AND mentioned from @stickydestroyer; how can I make it look good and code the actual thing.

I know I have to use some sort of cURL module, but how can I get the feed AND make it looking nicely?


You'll probably want to use the REST API to recover a user timeline and/or a mentions timeline.

To make requests you'll probably want a socket and JSON API for Lua. You find a specific example involving the use of both of those APIs to talk to a different REST API (not Twitter's) here, which you can probably adapt to use for Twitter based on their documentation.

What you'll get from the Twitter endpoint is JSON data, which you can then format as appropriate to make it look nice within the context of your game.

| improve this answer | |
  • \$\begingroup\$ Some pitfalls from having done similar things with the Facebook API: luasocket.http does not block, so you'll need to love.thread. LuaJSON is buggy with unicode characters, so you may have to fudge the results a bit. \$\endgroup\$ – Anko Dec 6 '12 at 20:11
  • \$\begingroup\$ What do you mean it doesn't block? \$\endgroup\$ – qaisjp Dec 7 '12 at 8:02
  • 1
    \$\begingroup\$ It means the function will return to your code immediately but (in this case) the actual HTTP request may not be complete yet, because it's being carried out by another thread or something. By contrast a blocking call would involve waiting within the function until the request completed fully and the response was available to you. \$\endgroup\$ – user1430 Dec 7 '12 at 15:52
  • \$\begingroup\$ Oops, I typoed! luasocket.http does block! (So you'll need a thread.) The explanation from Josh is correct though. Sorry! \$\endgroup\$ – Anko Dec 7 '12 at 16:53
  • \$\begingroup\$ Aha, so it "sleeps" until the value is returned. \$\endgroup\$ – qaisjp Dec 7 '12 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.