lua-users home
lua-l archive

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


I'm not sure which LuaJIT API you are referring to; do you have a URL?  Does that API require any support from LuaJIT?  

Tom

On Thu, Sep 27, 2012 at 8:13 PM, Coda Highland <chighland@gmail.com> wrote:
On Thu, Sep 27, 2012 at 7:53 PM, Tom <tmbdev@gmail.com> wrote:
> 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

It seems to me that the best API would be the one that's native to
LuaJIT, as that would provide the best performance there and work with
no further adaptation. Imitating that (e.g. luaffi) would allow
non-LuaJIT projects to use the same API.

/s/ Adam