[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: local keyword in the global scope, and other things.
- From: "Thomas Lefort" <thomas.lefort@...>
- Date: Wed, 8 Nov 2006 21:28:31 +0100
I've been using python+pygame for a long time, but it's lack of real
multithreading has made me consider alternatives, esp. as multi-core
machines are becoming more common. This is what brings me to Lua. From
what I can see, Lua is one of the few languages to provide real
Well, Lua does not natively support preemptive threading, but there
are patches and libraries. It's worth noting however that Lua offers
cooperative threading (coroutines).
Do you really need threads ? Or can you solve concurrency issues by
softer means ?
Indeed preemptive threading incurs a large engineering overhead:
complex design, tricky code, subtle bugs that are difficult to
I for one use a combination of Lua coroutines and C++ threads for soft
real time graphics rendering. The coroutines drive the many concurrent
behaviours that contribute a frame. The threads handle heavier,
blocking operations such as video decoding, and could run on a
Using the power of Lua, one can make such threads appear as
non-blocking coroutines. Thus the high-level logic can be expressed at
the coroutine level or above, abstracting the preemptive backend,
limiting the engineering overhead. This approach is implemented by
HelperThreads ( http://helper-threads.luaforge.net/ ) for instance.
If you really want explicit preemptive threads, you can use solutions
such as Lua 5.1 pthread ( http://lua51pthread.luaforge.net/ ) or
LuaThread ( http://www.cs.princeton.edu/~diego/professional/luathread/
Is there a good, simple example of writing and building a C module for
use in Lua?
Yes (see below).
Is there a facility which lets Lua programs dynamically load arbitrary
shared C modules?
What is the purpose of using the local keyword in the global scope?
Same as in any scope, why ?
For complete answers and examples see Programming in Lua (
http://www.lua.org/pil/ ) and the wiki.
Would I still be considered sane if I implemented a scene graph
library in Lua? :-)
Of course ! And I bet you can find a few existing ones already.