lua-users home
lua-l archive

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


Hi all,

Michal's method to create a food for ffi.cdef()'s consumption toggled
me to try to play more with this idea. As a result I can now do:

-- just import whatever is defined if you do #include <somefile.h>  in C
ffi.include "stdio.h"
ffi.include "time.h"
ffi.include "unistd.h"

-- import the library and get the definitions from the following list
of header files
avutil = ffi.loadlib { "avutil", "libavutil/avstring.h" }
avcodec = ffi.loadlib { "avcodec", "libavcodec/avcodec.h" }
avformat = ffi.loadlib { "avformat", "libavformat/avformat.h" }

The "include" part assumes the headers are in their places, and uses
the popen of "echo '#include <filename.h>' | gcc -E -" with some
filtering to get the data.

This is all fine and dandy. The problem with this method is that it
produces duplicate definitions (since each include is treated
separately). This makes luajit unhappy.

I've made a small patch that does the "collision avoidance" (i.e.
basically renames the redefinitions) - but it's probably not the best
way to do it. Maybe have the "collision avoidance" code reference the
"original" type and then after the cdef run go over the list of
"collided types" and verify that their definitions are the same as
those they collided with ?

Wonder what everyone's thoughts on this are.

The code to see what I mean (and a diff to luajit) is here:
https://github.com/ayourtch/luajit-fun/tree/master/ffmpeg

cheers,
andrew