lua-users home
lua-l archive

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


On 05/05/2011 21:28, Peter Cawley wrote:
This is not surprising, as IIRC, there is no guarantee that the
default allocator doesn't use the opaque UD value, and you go and
change the opaque UD value.

Well, I must have overlooked that. Time to fix my codes.

Then, if one still wants to use the default Lua/LuaJIT allocator and at the same time his own UD, what are the options?

lua_Alloc default_alloc;
void *default_ud;
int my_ud = 123;

void * MyAlloc (void *ud, void *ptr, size_t osize, size_t nsize)
{
  return default_alloc(default_ud, ptr, osize, nsize);
}

void ChangeAlloc (lua_State *L)
{
  default_alloc = lua_getallocf(L, &default_ud);
  lua_setallocf(L, MyAlloc, &my_ud);
}

Is it guaranteed that the default allocator and/or default UD pointer will never change? (It seems a silly question but I doubt such a guarantee exists).

--
Shmuel