Page 1 of 1

Lua/Love order of exection with callbacks

Posted: Fri Jun 14, 2013 12:45 am
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!

Re: Lua/Love order of exection with callbacks

Posted: Fri Jun 14, 2013 1:46 am
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.

Re: Lua/Love order of exection with callbacks

Posted: Fri Jun 14, 2013 2:21 am
by manyshotsshort
That's exactly what I was hoping to hear. Ty for the link to love.run, makes much more sense now.