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

  • From: Daniel Kolesa <quaker66@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 9 Apr 2014 10:20:12 +0100

Right, but p1's address stays the same - what I meant is you could do
reg[ptr] = val and return reg[ptr] directly.


2014-04-09 10:14 GMT+01:00 Richard Hundt <richardhundt@xxxxxxxxx>:

> 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.
>
>

Other related posts: