lua-users home
lua-l archive

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


A simple API might have four functions (using Lua syntax to describe both Lua and C APIs):

a = typed_vector(size,tcode) -- allocs 1D array of the given size and type
a:size() -- returns the size of the 1D typed array
a:type_code() -- returns the type of the 1D typed array

a[index] -- needed only in Lua, for simple element access
a:address_of() -- needed only in C, pointer access to elements

Type codes would exist for common standard C types ("char", "uint", "float", ...), and common sized types ("uint8", "float32", "float64"), ...).

Although such a simple API may mean that getting two libraries to talk to each other may involve extra copying, even with that, it's a lot faster and easier than having nothing at all. A more complex interface would be a Lua adaptation of a subset of the Python buffer and memory view APIs (http://docs.python.org/c-api/buffer.html); they allow data to be exposed without copying, but at the cost of higher complexity.

Tom

On Thu, Sep 27, 2012 at 6:30 PM, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
> Therefore, I think it would be good if there were a STANDARD for typed
> arrays [..] It doesn't need to have many (or even any) operations on
> it, but it does need a C API that is available and acceptable to all
> extension writers.

What kind of API do you have in mind?