lua-users home
lua-l archive

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


The only way right now is to use another buffer:

buf = alien.buffer()
buf2 = alien.buffer(4) -- for 32 bit pointers
buf2:set(0, buf:topointer(), "pointer")
buf2:get(0, "int") -- this returns the integer value of the pointer

Of course you can reuse buf2 to get the address of other buffers. But
remember that you have to keep a reference to the original buffer or
Lua may collect it.

BTW, have you thought about using a buffer instead of struct.pack?
struct.pack lets you pack a whole structure as a one-liner, but using
a buffer makes it easier to understand what the code is doing, IMHO (I
use buffers on the struct implementation that I am [slowly] working
on, at

Fabio Mascarenhas

On Sun, Jul 26, 2009 at 1:18 PM, Cosmin
Apreutesei<> wrote:
> Hi,
> Is there a way to get the address of a buffer object? I need to store
> the address of a buffer in a structure that I'll pack with
> alien.struct.pack. The only solution I have found till now involves
> creating another buffer just to store and later retrieve the address
> of the first one.
> Thanks,
> Cosmin.
> PS: Hope it's ok to ask questions related to lua libraries on this
> list (or should I go to luaforge?)