lua-users home
lua-l archive

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

From: Roberto Ierusalimschy <>

> One more question: can you be sure the __gc of a table is being called
> twice? For what I saw in your code (the first version you sent), the
> problem of destroying the same userdata twice could be caused by
> some bug in the weak table, if it returned the same userdata for
> two different tables. That is, when cleaning the weak table from a
> deleted key, it might get corrupted and then could return a wrong
> value in a future query.

I added an id field to my proxy (key)

local PROXY_COUNT = 0

  local proxy = {type = "userdata", id = PROXY_COUNT }, PROXY_COUNT)

... callback sets the id in the userdata too
then, on dispose, i pass the proxy's id

__gc = function(proxy)
  local data = cache[proxy]
  cache[proxy] = nil

In my dispose callback, when this code segfaults, the id passed matches the id of the userdata id i stored at the beginging
p->id == 274, lua_tointeger(L, 2) == 274
p->id == 740, lua_tointeger(L, 2) == 740

lua-l mailing list --
To unsubscribe send an email to