lua-users home
lua-l archive

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


> Well, let's say I have an ImageMagic library and an ndarray library.  How do
> I use your memoryview module to convert the ImageMagic image to an ndarray?
>
> -- load an image using ImageMagick library
> img = Image()
> img:open("lena.jpg")
>
> -- allocate an array
> a = ndarray(img.height,img.width)
>
> -- efficiently copy the pixels of img into a
>>>> put some FFI _expression_ here <<<

Using LuaJIT or luaffi, it's probably going to be something along the lines of:

ffi.C.memcpy(img.data, a.pointer, img.bytes)

but I don't know the APIs of either of those objects you're describing.

OK, so let's say I am a library writer and want people to be able to do that.  What data types should img.data and a.pointer be?  You're basically declaring ffi to be the standard for 1D typed arrays, and it's a standard that is very complex and totally unsafe.  Putting simple 1D typed arrays into the core would provide a simple type that img.data and a.pointer could return, plus the ability to write safe native code for copying the data around.

Anyway, the discussion has made it clear that there is no current effort and no significant interest in adding such a type to Lua.  Thanks to everybody for the feedback.

Tom