lua-users home
lua-l archive

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


> One solution could be something like:
> 
> LUA_API void lua_userdatasize(lua_State *L, size_t size)
> 
> which would assign the given size in bytes (to the GC) to the userdata
> situated on top of the stack.


You can implement this function as follows (I gess ;-):

/* in lapi.c */
LUA_API void lua_userdatasize (lua_State *L, size_t size) {
  if (ttype(L->top-1) != LUA_TUSERDATA ||
      tsvalue(L->top-1)->len != 0)
    lua_error("...");
  tsvalue(L->top-1)->len = size;
  L->nblocks += size*sizeof(char); 
}

Maybe something similar should go into the official API for 4.1...

-- Roberto