lua-users home
lua-l archive

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


On Tue, Jun 7, 2011 at 2:14 PM, Peter Cawley <lua@corsix.org> wrote:
> On Tue, Jun 7, 2011 at 6:09 PM, Fabio Kaminski <fabiokaminski@gmail.com> wrote:
>> without that.. only manipulating ptr from a C function .. :(
>
> The FFI has pointer arithmetic; you can add integers to pointers as
> you would in C, and cast them around, as you would in C.
>
> I don't yet appreciate what you're complaining about or why you need
> to convert things to strings and pass strings rather than just passing
> pointers and lengths to C.
>
>

from lua to C there 's no problem at all.. its pretty much transparent...

but suppose a buffer being filled by the kernel.. and my thoughts are
about doing the switch from C userspace to lua with less memory copy
possible..
yes..  the ideia is not passing the full string.. but the filled
buffer whenever lua app call a tostring() or bytes().. only then the
lua string would be created..

now i just wanna have the ability to slice the given C buffer.. so
sorry about the noise..

but tried pointer arith and thats fine with char[] or even char *, but
not void *.. (wich is not _very_ wrong)

but cast from void * to char * give me a new address (pointing to
somewhere else) and not the same pointer:

>  x = ffi.new("void *") -- just for testing purposes
> =x
cdata<void *>: 0x4016dc78

> x = x + 1
stdin:1: attempt to perform arithmetic on 'void *' and 'double'
stack traceback:
	stdin:1: in main chunk
	[C]: ?

> z = ffi.new("char *")
> =z
cdata<char *>: 0x4016cbb8
> z = z + 1                          --ok,  here pointer arith works.. so how about casting that void * ptr that the api gave me to char * ? lets try..
> =z
cdata<char *>: 0x40170aa8


> c = ffi.cast("uint8_t *", x)
> =x
cdata<void *>: 0x4016dc78
> =c
cdata<unsigned char *>: 0x40171300 -- oops, looks like a new pointer
somewhere else..
>

But ok, i will try to handle those problems with a wrapper or middle man api..
only passing "final" data to the lua context.. processing from C

but  this could almost be done interelly in lua code, with ffi..