lua-users home
lua-l archive

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


>lua_save() would write the existing VM state to buf
>lua_restore() would regenerate the Lua VM state from the
>same buffer.

Saving VM state is not the same as saving a lua_State, or is it?
In 4.1, you wil be able to have several "threads" sharing the same global
environment, and so the two things will be different.

Perhaps you want to save VM state simply to run someting else for a while and
then switch back to the old state. If that's the case, then 4.1 is for you!

Do you really want to save the state of the VM, ie, what function is
executing and where it is and so on? Or do you simply want to save the global
environment, ie, global variables and their values? In the second case, the
easiest way would be to output Lua code that restores it when loaded. There
are examples for this in lua/test. However, even this is not sufficient because
C functions cannot be saved (perhaps saving the names of the global variables
that have C functions would be sufficient for some applications).

In summary, saving state is in principle an attractive and useful feature,
but it is ill-defined and probably too costly if done in full generality.
The solutions I'd like to see for it would use precompiled chunks because
the format is already defined and the code for loading them is already in place.
In other words, lua_restore would be simply lua_dofile.
--lhf