Re: A way to associate a Lua value with a FFI pointer?

  • From: Richard Hundt <richardhundt@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 09 Apr 2014 11:17:24 +0200

On 4/9/14 11:14 AM, Richard Hundt wrote:
> On 4/9/14 11:09 AM, Daniel Kolesa wrote:
>> 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].
> 
> LuaJIT 2.0.3 -- Copyright (C) 2005-2014 Mike Pall. http://luajit.org/
> JIT: ON CMOV SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse
>> ffi = require('ffi')
>> p1 = ffi.new('char[1]')
>> i1 = ffi.cast('intptr_t', p1)
>> = i1
> 310296LL
>> i2 = ffi.cast('intptr_t', p1)
>> = i2
> 310296LL
>> = string.format('%p %p', i1, i2)
> 0x0004be20 0x0004c210
>>
> 
> They i1 and i2 have the same value, but different address.
> 

Sorry, that wasn't very articulate... what I mean is that i1 and i2 have
different addresses, and so hash to different values.


Other related posts: