lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 11/7/06, Simon Wittber <simonwittber@gmail.com> wrote:
Hello Lua people,

I'm examining lua for the purposes of using it in small casual game projects.

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
pre-emptive threading.

Sorry to burst your bubble... but Lua does not have pre-emptive
threading built in...  However in a game engine, use of Lua's
co-routines can make game logic very simple (each entity gets its own
coroutine and you cycle through it for operations).
Threading in a game engine can be tricky, you'll want to setup some
specific threads to queue operations.  Ex:  One thread doing game
logic (looping over the co-routines and handling events), one thread
doing graphics, one thread for sound, one thread for networking
code...
Collapsing some items might be good for contention issues.  Whenever
you start a rendering phase, you'd probably have to lock the game
logic thread.  For the sound thread, you probably would want to have a
function exposed to the game logic to queue up a sound to be processed
(though many sound libraries handle all this for you).
Note about network programming.. using asynchronous socket events is
much better than the thread-per-client model.  Examples of methods
are: Window's IO Completion Ports,  linux event, BSD kqueues..
A good library to look into for that would be libevent.  It abstracts
asynchronous socket events away such that you can use it on many
platforms w/ it using the best methods for it.

Is there a good, simple example of writing and building a C module for
use in Lua?
The lua-users wiki should have some pointers on that...

Is there a facility which lets Lua programs dynamically load arbitrary
shared C modules?
There was one somewhere for loading arbitrary libraries/functions, but
I can't remember.  This method is probably something to avoid in a
game engine due to speed requirements... it'd  probably be better to
create a wrapper library for Lua to load in to access external library
functionality.
What is the purpose of using the local keyword in the global scope?
Ex:
local x = 1
require("lib") -- lib doesn't know about the local x
It also makes accesses to that variable faster because lua can compile
it to be a direct reference rather than a global table lookup (IIRR).
Would I still be considered sane if I implemented a scene graph
library in Lua? :-)

A scene graph would likely involve lots of matrix algebra... however
if you pull that out into C/C++ and just have lua tell it what sort of
operations to do... then it could work out reasonably fast.


--
Thomas Harning Jr.