lua-users home
lua-l archive

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


Hello,

my .02EUR, just to be sure :-)

I might want man_talk() to block until a certain condition is met (say, the
sample is played). Do I have to
man_talk("some words")
until man_done_talking() do
	yield()
end

or is there (will there be) the possibility for C extensions to yield by
themselves, and write:
man_talk("some words")
and internally have the C implementation man_talk(L) call the sound
subsystem, and yield until the subsystem says the resource is played ? Of
course, the lua state could not resume the C extension at the exact point
where it yielded, but the function could check whether it was called
normally or because of a yield() being resumed ?

>From what I have understood so far, when a lua coroutine calls yield(), the
execution is to resume right after the yield point. resuming just before the
yield call (thus causing yield() to be the next statement being executed),
and having yield() continue execution when called because of a resume should
not change the current behaviour specification ?

This would produce much simpler and elegant scripts when a sequence of
lengthy actions is to be described, for example if several samples and/or
animations are to be played one after the other.
Oh well, thinking about it, I suppose one can always do

function Yielder(cfunction)
	local f = function (...)
		local yielded = 0
		until %cfunction(yielded,unpak(arg)) do
			yield()
			yielded=1
		end
	end
	return coroutine.create(f)
end

man_talk = Yielder(man_talk)

man_talk("some_words")


(or the syntactically correct equivalent, I haven't tested :-)

Cheers,

Benoit.



> -----Original Message-----
> From: Thatcher Ulrich [mailto:tu@tulrich.com]
> Sent: lundi 8 juillet 2002 15:47
> To: Multiple recipients of list
> Subject: Re: some questions about lua
> 
> 
> On Jul 07, 2002 at 02:57 +0800, jason zhang wrote:
> > 
> > 4. Could I execute the lua script step by step? For example, I have
> > the following script:
> >   man_go_forward( 100, 100, 100 );
> >   while( !button_pressed ){ man_wait() };
> >   man_talk( "some words" );
> >   man_fight();
> > I need some control or some delay between lines of script. I need to
> > execuate the script to some line, then engine code , then 
> the script from
> > the last position .....
> >     Is it possible?
> 
> This sounds like a job for the new coroutine features in 5.0-work0 --
> you can put a "yield()" call in your scripts where you want to return
> back to the engine, and the engine can call "lua_resume()" when it
> wants to continue running the script from the spot where it yeild()ed.
> 
> In the example above, you could replace "man_wait()" with "yield()".
> 
> -- 
> Thatcher Ulrich
> http://tulrich.com
>