Yes, a mapping table is always a possibility, I was hoping for some way to do it without this though. Also, I don't think you really need the tonumber() here. Indexing tables with cdata is fine here, as we want the key to be the address, the problem with cdata table indexes is just when doing something like, tbl[5LL] == tbl[5]. 2014-04-09 10:02 GMT+01:00 Richard Hundt <richardhundt@xxxxxxxxx>: > On 4/9/14 10:54 AM, Daniel Kolesa wrote: > > Hello, > > > > I would like to know if there is any way to associate a generic Lua > > value with a FFI pointer. > > I'm not sure if I have the full context, but I do this sort of thing: > > ``` > local reg = { } > function setptrvalue(ptr, val) > local key = tonumber(ffi.cast('intptr_t', ptr)) > reg[key] = val > end > function getptrvalue(ptr) > local key = tonumber(ffi.cast('intptr_t', ptr)) > return reg[key] > end > ``` > > You can always get your pointer back from `intptr_t` with a cast. > >