lua-users home
lua-l archive

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


> is there an easy way to convert from malloc and free to using the Lua allocator? Some macros perhaps? Any example code?

#define LUA_ALLOC(p,size)	lua_getallocf(L,NULL)(NULL,p,0,size)
#define malloc(size)		LUA_ALLOC(NULL,size)
#define free(p)			LUA_ALLOC(p,0)
#define realloc(p)		LUA_ALLOC(p,size)

This code assumes a Lua state named L in the scope. If that is not the case,
fix LUA_ALLOC.