[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Saving (part of) the lua state
- From: "Markus Heukelom" <Markus.Heukelom@...>
- Date: Mon, 22 Oct 2007 13:36:15 +0200
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