lua-users home
lua-l archive

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


> Well, I guess it's probably confusing. And inconsistent with e.g.
> arrays or structs, where the actual start address of the data is
> shown. 64 bit integers or complex numbers already show their value
> and not the (irrelevant) cdata object address, too.
>
> I've just changed it so tostring(pointer) shows the address the
> pointer points to. Much easier to spot NULL pointers, too.
>
> --Mike

> ffi = require("ffi")
> x = ffi.new("const char *","hello there")
> =x
cdata<const char *>: 0x41ce25d8
> =x
cdata<const char *>: 0x41ce25d8
> x = x + 1
> =x
cdata<const char *>: 0x41ce25d9
> x = x + 1
> =x
cdata<const char *>: 0x41ce25da
>
> str = ffi.string(x)
> =str
llo there
>

Thanks Mike, now i can believe in my eyes :)


On Tue, Jun 7, 2011 at 4:26 PM, Fabio Kaminski <fabiokaminski@gmail.com> wrote:
> On Tue, Jun 7, 2011 at 4:12 PM, Mike Pall <mikelu-1106@mike.de> wrote:
>> Duncan Cross wrote:
>>> On Tue, Jun 7, 2011 at 7:03 PM, Fabio Kaminski <fabiokaminski@gmail.com> wrote:
>>> > but cast from void * to char * give me a new address (pointing to
>>> > somewhere else) and not the same pointer:
>>>
>>> This is incorrect. What you are seeing here, when you print the
>>> pointer, is not the value of the pointer itself but of the FFI cdata
>>> object that has been allocated to house it.
>>
>> Well, I guess it's probably confusing. And inconsistent with e.g.
>> arrays or structs, where the actual start address of the data is
>> shown. 64 bit integers or complex numbers already show their value
>> and not the (irrelevant) cdata object address, too.
>>
>> I've just changed it so tostring(pointer) shows the address the
>> pointer points to. Much easier to spot NULL pointers, too.
>>
>> --Mike
>>
>>
> cool feature!
>
> also can't wait for function callbacks to arrive in a future release.. ;)
>
> thanks
>