lua-users home
lua-l archive

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


> I strongly recommend you try LuaJIT's FFI interface, which IMO
> implement C array in a Lua-elegant way.
>
> At least, you can see this document and get some idea:
>
> See this section: Motivating Example: Using C Data Structures
> http://luajit.org/ext_ffi.html

I have.  I did in no way mean to say that there's something wrong or
unelegant about LuaFFI, it just takes a different route.  From what I
understand the FFI library in LuaJIT depends on the JIT nature of the
compilation to emit the correct C declarations and code upon
compilation while the standalone LuaFFI module incorporates a C parser
in order to parse your declarations.  As I've said this allows you to
do a lot more than just expose multidimensional arrays to Lua but,
depending on the circumstances, it might present additional problems
too.

In the first case you need to stick to LuaJIT which might be a problem
or not, and with LuaFFI you have a lot of added complexity.  Besides
the matter of dealing with it as a programmer there's also the matter
of how you use Lua.  In my case, I need it to script an application
into which it's embedded.  The biggest virtue of Lua in this respect
(in my opinion of course) is its simplicity.  I can keep the C core
which needs to be efficient separate and hidden from the end user and
expose it via Lua in a simple and elegant way.  Now I know, I could
probably try to hide the C declarations inside module code somewhere
and present the user with a simple Lua-like interface for what I need
to do.  That's a pretty valid approach but in my experience complexity
has a way of crawling to the surface so unless I really need it, I
prefer to do without it.  I repeat that this depends entirely on what
you need to do.

Dimitris