lua-users home
lua-l archive

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


David Given wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

kathrin_69@gmx.de wrote:
[...]
If I would overwrite it in a way so that all memory used by  my
lua_State* is inside my own (pre-allocated) buffer, I could just save
and re-load that buffer to/from disc and resume execution. What do you
think, will this work? It sounds pretty easy so far.

This will only work if you new buffer is loaded at the same address as
the old one, as there'll be pointers embedded all throughout the data.
Yes. But how can this be achieved? Is there any windows API to get a fixed address? Or do I have to use a DLL with an "shared" part and load that DLL on a fixed address into process space?

And if there happen to be pointers anywhere else --- such as on the
stack --- then you will be in for what is technically known as A World
Of Pain!
I'm not the most experienced C-programmer, but if I save the lua_State* between two calls to lua_Resume(), there shouldn't be any process stack memory in use by Lua functions, because all Lua-functions are already returned and therefore all stack is un-winded. Am I wrong with this?

Personally I'd go for something like Pluto, which
saves/restores the state at a much higher level.
I have not tried it yet, but I fear serialization will be to slow for my needs, because I'll have to save the lua_State on every cycle of a simulation loop to allow precise/granular rollback.