lua-users home
lua-l archive

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


Hi John,

	I guess the simpler thing to do is just to remove the couroutine
	functions from the lua interpreter used by the script writer.

	Why the script writer should need to use couroutines?

	In the lua interpreter, the couroutine functions are in the table
	"couroutine", so just set that table to "nil" in the lua state
	and the script writer will not more able to use them.

	You will still able to implement your "Wait" function using
	the lua_resume and lua_yeld 'C' functins.

	This is my way to go:

		1) I create a lua state
		2) I remove all the unwanted functions from setting them to 'nil'
		3) I add my own function to the lua state

	I hope this can help you.

	bye.


> -----Message d'origine-----
> De : lua-bounces@bazar2.conectiva.com.br
> [mailto:lua-bounces@bazar2.conectiva.com.br]De la part de John Haggerty
> Envoyé : mardi 8 mars 2005 03:45
> À : lua@bazar2.conectiva.com.br
> Objet : Threads vs Coroutines and Wait()
>
>
> Hi, I'm a new user of Lua and, as usual, I'm trying to use it as
> a scripting
> language for my game.
>
> I want to have a Wait() function which takes a length of time and "pauses"
> for that time. Of course, during this time, gameplay must
> continue, so what
> really needs to happen is the script has to stop executing, and be resumed
> later.
>
> I figured I'd use coroutines to do this. Wait() could tell the game engine
> to resume the current coroutine in X seconds, and then yield.
> Gameplay would
> continue, and the game engine would later resume the coroutine.
>
> But a problem occurs when the script writer starts using
> coroutines on their
> own. If they create a coroutine and run it, and then *that*
> coroutine calls
> Wait(), then it will yield back to their own original coroutine
> rather than
> all the way back to the game engine.
>
> I was hoping that using "Threads" as described in 3.20 in the
> documentation
> might avoid this problem, and that lua_resume/lua_yield doesn't take Lua's
> coroutine.resume() and coroutine.yield() into account. But after reading
> some messages in this group I'm worried that lua_resume and lua_yield are
> essentially identical to coroutine.resume() and coroutine.yield(), so my
> problem remains.
>
> Is there any way to achieve what I want? Is there any sort of tricky usage
> of coroutines that avoids the problem, or is there a solution that doesn't
> involve coroutines at all? Or will I have to require that the
> user not call
> Wait() from within a coroutine (and can this be automatically enforced)?
>
> Thanks for any help or explanation you can offer. Sorry if I've
> unknowingly
> violated any unwritten community rules, as this is my first post here. =)
>
> (As a side note, why does 3.20 talk about "Threads" while 2.10 talks about
> "Coroutines?" Is there a difference or is it just a different
> name depending
> on whether you're calling the functions from C code or from Lua?)
>
>  - Slime
>  [ http://www.slimeland.com/ ]
>
>