lua-users home
lua-l archive

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


Oh! i was getting an error when I tried to do that, but I think the problem is that I've got a C call farther upstream. I'm put a wrapper around a light user data object and I'm using a c __index function in the metatable. That's the issue right there.

Thanks!

Matthew Harmon wrote:

You can call lua_yield() as the last statement of your glue routine.  Below
is one of my glue routines that let's my script yield for a given time
period.

static int LuaWaitSec(lua_State* l)
   {
   // grab a pointer to the correct manager object
   // from the GLOBAL table in this state
   s = GetScriptManagerObject();

   // signal the manager that we're waiting for x seconds
   s->waitTimestamp = s->time + lua_tonumber(1);
   s->state         = LSS_WAITTIME;

   // yield control, our eventual resume() will push one value on the stack
   return(lua_yield(l, 1));
   }

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of John Paquin
Sent: Friday, August 13, 2004 4:24 PM
To: LuaList
Subject: Yielding

I know this has been covered before, but I can't seem to find it in the archives.

Is there any way to do a yield (or something like it) from c that has been called from Lua?

In my game, I want to do something like this from lua:

 player.newpath = pathfinder.makepath(pointa,pointb)

I want the Lua code to return only when it has a path.
On the c side, however, I want to add the makepath request to the pathfinder's queue, then "yield". The pathfinder would then complete the request incrementally while the game continues to run. When the path is complete, the c code would then "resume" the Lua code.

Is there a way to do this?