[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Calling functions in other states
- From: David Olofson <david@...>
- Date: Thu, 15 Nov 2007 18:59:07 +0100
On Thursday 15 November 2007, Tom Miles wrote:
> I apologise if this is either a stupid question, or has been asked
> before, but I was wondering if there was a way that I haven't found
> of calling functions of one state from within a lua script of
Well, my first thought is "you don't." No matter how you implement it,
you're going to end up with a caller->callie->caller roundtrip, and
no matter how you implement it, there is going to be some latency and
overhead. It's a simple way of dealing with multithreading, but it's
inherently very inefficient in most applications.
> I have several states all started with lua_newthread() all
> of which run their own scripts. I have a very convoluted method at
> the moment for each thread to "talk to each other" which is
> hideously slow and has been a nightmare to maintain as new
> situations arise, and was wondering what the "industry standard" way
> of doing it was (if there was one)?
For an effective and (relatively speaking) simple solution, try some
form of message passing. Basically the same low level functionality
as RPC (Remote Procedure Calls), but you just send a message and get
on with your work, without waiting for a response. The receiver will
eventually process the message and, if appropriate, send back a
You can implement RPC over a system like this, but RPC is a
fundamentally broken design unless you really don't have anything
useful to do while waiting for the "return".
//David Olofson - Programmer, Composer, Open Source Advocate
.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
'-- http://www.reologica.se - Rheology instrumentation --'