lua-users home
lua-l archive

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



You might want to check Lua Lanes sources. They do exactly this among other things.

_G.state is regarded as a special table, which carries persistant state of a lane (akin thread); in order for the lane to be suspended and later revitalized. Of course, Lanes offers one a whole lot more, too.

	http://luaforge.net/projects/lanes/

	http://kotisivu.dnainternet.net/askok/bin/lanes/index.html

"Results can be read for a cancelled lane, too. This allows getting the last contents of a special state table from the lane, to be put aside for consequtive resurrection of the thread (maybe on some other machine, even!)."

-asko


Markus Heukelom kirjoitti 22.10.2007 kello 14:36:

Suppose I want to save (a part of) the lua state, in binary form. For
example, lets assume I have _G.state = {...}, and I want to save _G.state,
to load it somewhere later.

I scanned luac.c and found that it saves the lua_State in binary form using
the luaU_dump and clvalue() functions.

So, I thought of doing something like this:

// c sketch

#define toproto(L,i) (clvalue(L->top+(i))->l.p)

lua_getfield(L, LUA_GLOBALSINDEX, "state");
luaU_dump(L, toproto(L,t), mywriter("somefile"), ... );

...and somewhere later:

lua_load(L, myreader("somefile"), ... ) ;
lua_setfield(L, LUA_GLOBALINDEX, "state");

// end sketch

Would that work?

If that is the case, wouldn't it be useful if the lua_dump() function would
just do this (instead of what it does now for functions only)? (So I
wouldn't have to use internal (i.e. non-api) lua functions?)

Thanks,
________________________________

Markus Heukelom
Incontrol Enterprise Dynamics