Hello Ben and every buddy else,
I investigated a bit and it seems much simpler: If I call lua_Newstate
instead of luaL_Newstate as I did until now, I am able to pass an
allocator function which is used exclusively for memory management by
Lua regarding the lua_State* it is assigned to.
The default allocator function used by luaL_Newstate() is this:
-----------------------------
static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
(void)ud;
(void)osize;
if (nsize == 0) {
free(ptr);
return NULL;
}
else
return realloc(ptr, nsize);
}
-----------------------------
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.
Two questions to the l_alloc function shown above:
1. What is void* ud for? The src code says something about "auxiliary
data to the allocation function". Why is it not used by that function?