[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Lua callinfo
- From: "Dino Patti" <dino@...>
- Date: Mon, 21 Feb 2005 15:17:44 +0100
Hey, thanks that really helped, my main problem was that I didn't use
threads, but was resuming and yielding on my main thread.
I now run the script in a corutine. I put the thread-object on the global
index and it is now saved when I'm persisting.
I have one more question though, when I have unpersisted, the old
GLOBALINDEX table is at stack index 2. Now I just replace that into the new
GLOBALINDEX table. But what is the "cleanest" way to do it?
Because after I've done the replacing the GLOBALINDEX table for the main
thread is not the same as the GLOBALINDEX table for my thread.
[mailto:email@example.com] On Behalf Of Ben Sunshine-Hill
Sent: 21. februar 2005 08:26
To: Lua list
Subject: Re: Lua callinfo
On Fri, 18 Feb 2005 12:32:22 +0100, Dino Patti <firstname.lastname@example.org>
> I'm trying to serialize(persist) and deserialize(unpersist) a lua
> state using the Pluto lib. It seems to work fine (got good help from the
> But now I face a difficult task. I have to start(resume) the same
> place where I left(yielded) the original script I serialized.
> The script contains many yields and resumes, and I want to start the
> script again as if it wasn't persisted/unpersisted but it just resumed.
The key here is that in order to save a thread including its execution
position, that thread _must_ be yielded. There's a lot of different ways to
accomplish this, based on how your control flows, but if you're not really
making use of coroutines otherwise, probably the simplest way is to run the
main script _as_ a coroutine with lua_newthread. Then, in a loop, resume the
thread, and when it returns from the resume (by yielding from the script)
check what value is returned by the yield. For instance (this code is purely
SIGNAL_CONTINUE = 0,
SIGNAL_SAVEANDCONTINUE = 1,
SIGNAL_EXIT = 2
lua_State *L2 = lua_createthread(...);
int signal = lua_tonumber(L2, -1);
// do pluto persistence
// clean up and exit
In the script, you can call yield(0) to simply do nothing (it's unclear why
you'd want to do this), yield(1) to save the state and continue execution,
or yield(2) to exit.