Lua/Love order of exection with callbacks

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
manyshotsshort
Prole
Posts: 4
Joined: Mon May 27, 2013 10:20 pm

Lua/Love order of exection with callbacks

Post by manyshotsshort »

First off, totally enjoying Love and Lua, picked it up about 2 weeks ago and been busy trying soo many things.

So this is probably just a Lua question mainly unless something like love.graphics does some kinda threading I don't know about yet. When my process runs, is it single threaded? I keep finding myself trying to code defensively against ConcurrentAccessException type stuff (yes java guy by trade), and it occurs to me that I don't think I have to. Is this true? When a callback happens and its accessing a global var, that method is the only thing executing at that time yes?

Thanks!
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Lua/Love order of exection with callbacks

Post by Boolsheet »

By default you only have one thread that executes the Lua code. The LÖVE code you call with Lua functions also runs in that thread. No need to worry about multithreading issues. Take a look at love.run to see the main loop.

You only have to think about concurrent access if you start another thread with the love.thread module. The Lua state for the new thread is completely separate and you can safely pass messages with the Thread API, but other parts are not safe and may cause issues. For example, the ImageData object got some mutex locks, but SoundData doesn't have it (yet?).

The love.audio module also starts a thread, but this is not visible to the lover as it's only to manage decoding and buffer queues.
Shallow indentations.
manyshotsshort
Prole
Posts: 4
Joined: Mon May 27, 2013 10:20 pm

Re: Lua/Love order of exection with callbacks

Post by manyshotsshort »

That's exactly what I was hoping to hear. Ty for the link to love.run, makes much more sense now.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests