[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Exiting lua from a C function
- From: "Thatcher Ulrich" <tu@...>
- Date: Mon, 4 Feb 2002 23:43:16 -0500
On Feb 05, 2002 at 01:36 -0000, worldpretending wrote:
> Sorry to respond to an old thread, but I thought I may as well
> link my question to the previous one on the same issue. (Besides,
> it proves I searched the archives before posting.)
>
> --- In lua-l@y..., "Peter Prade" <prade@p...> wrote:
> > > The matter is, is there any way to cancel a script execution
> > > from within a C fucntion ?
> > >
> > > It would be something like:
> > > LUA_endExecution( state )
> >
> > if you call lua_error(), script execution will stop:
> >
> > from the reference manual:
> > = void lua_error (lua_State *L, const char *message);
> > - This function never returns. If lua_error is called from a C function
> > - that has been called from Lua, then the corresponding Lua execution
> > - terminates, as if an error had occurred inside Lua code.
>
> This function would appear to terminate the whole script that is
> being executed. I would like to know if there is a mechanism that
> would let me temporarily exit - that is, pause execution of a Lua
> script while preserving all the variables so that I can resume it
> at a later stage. Basically, some simple context-switching. The idea
> is that I can have a Wait function in a script that pauses script
> execution for the specified time. Deciding when to continue the
> script would be handled by the enclosing C++ program, but obviously
> I need to know whether jumping out of the script while leaving
> everything intact is even possible (and if so, if it's practical)
> first.
Sounds like you're asking for "yield". The answer is, yes it does
exist, as a patch for Lua 4.0. See
http://www.lua-users.org/wiki/PowerPatches , under "yield patch".
--
Thatcher Ulrich <tu@tulrich.com>
http://tulrich.com