Re: Small helper FFI cdef generator script (in perl)

  • From: Justin Cormack <justin@xxxxxxxxxxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 29 May 2013 00:20:49 +0100

On 28 May 2013 16:57, "Wesley Smith" <wesley.hoke@xxxxxxxxx> wrote:
>
> Has anyone use the luaclang-parser to scrape header files?
> https://github.com/mkottman/luaclang-parser
> I had a look at it when it was first released.  It has a pretty nice
> interface for generating databases of functions and type definitions.

Yes. See https://github.com/justincormack/luacparse-example for an example
(and presentation). That is one way of using it or you can do the db thing
with the data.

Justin

> wes
>
> On Tue, May 28, 2013 at 8:51 AM, William Adams <william_a_adams@xxxxxxx>
wrote:
> > Yah, you're right.  I'm getting ahead of myself.
> >
> > Right now I use the reflect.lua that your pointed out to do the second
half of what I described here.
> >
> > Using your lcpp to front end the header parsing, at least the pre
parsing portion, I can just compile, and then use reflect to grab stuff and
stick it in database.
> >
> > Using an lpeg based parser, I can parse the headers that are 'clean'
from your preprocessor and achieve what I'm truly after, or even just rely
on what luajit/reflect does and call it a day.
> >
> > So, my observation boils down to this.  lcpp is a great addition to the
language processing tools that are part of the Lua(JIT) universe.
> >
> > -- William
> > ===============================
> > - Shaping clay is easier than digging it out of the ground.
> >
> >
> > ----------------------------------------
> >> Date: Tue, 28 May 2013 15:20:36 +0000
> >> Subject: RE: Small helper FFI cdef generator script (in perl)
> >> From: michael@xxxxxxxxxxxx
> >> To: luajit@xxxxxxxxxxxxx
> >>
> > . But it seems to me that you want a reflect library for
> >> LuaJIT. Good thing they exist:
> >>
> >> -- get code from http://www.corsix.org/lua/reflect/reflect.lua
> >> reflect = require("reflect")
> >> reflect.typeof(ffi.C.GetProcessHeaps)
> >>
> >> This returns a table describing the function signature of
GetProcessHeaps
> >> (if already known to LiaJIT ffi). Am Im right?
> >>
> >> regrads,
> >> Michael
> >>
> >>
> >> On Tue, May 28, 2013 1:50 pm, William Adams wrote:
> >>> Upon inspection:
> >>>
> >>>
> >>> function lcpp.compile(code, predefines) local state = lcpp.init(code,
> >>> predefines) local buf = {} for output in state:doWork() do
> >> table.insert(buf,
> >>> output) end return table.concat(buf, NEWL), state end
> >>>
> >>> I see what I'm after is there internally. The 'state' does almost
> >>> exactly what I would want. So, just exposing that as part of the
public
> >>> interface?
> >>>
> >>> -- William
> >>> ===============================
> >>> - Shaping clay is easier than digging it out of the ground.
> >>>
> >>>
> >>>
> >>> ----------------------------------------
> >>>
> >>>> From: william_a_adams@xxxxxxx
> >>>> To: luajit@xxxxxxxxxxxxx
> >>>> CC: michael@xxxxxxxxxxxx
> >>>> Subject: RE: Small helper FFI cdef generator script (in perl)
> >>>> Date: Tue, 28 May 2013 13:42:52 +0000
> >>>>
> >>>>
> >>>> I think the cool thing about lcpp, and various other tools, is that
you
> >>>> can quickly go from a header file to a type reflection interface
> >>>> (reflect.lua) without much trouble. I think that's pretty darned
> >>>> useful.
> >>>>
> >>>> You could parse a ton of header files, and then have a function:
> >>>> whatis(something) which would go through an internal database of all
> >>>> known things (types, function prototypes, constants) and feed you
back
> >>>> the signature for that thing. For example:
> >>>>
> >>>> whatis("GetProcessHeaps");
> >>>>
> >>>>> function => int_32_t GetProcessHeaps(int32_t NumberOfHeaps, void
> >>>>> **ProcessHeaps);
> >>>>>
> >>>>
> >>>> That's pretty useful when you're spelunking APIs, and does not
require
> >>>> the fullness of a compiler runtime.
> >>>>
> >>>> One suggestion for lcpp... Could it be possible to implement another
> >>>> "compile" which was an iterator? Basically:
> >>>>
> >>>>
> >>>> lcpp.items(someheader)
> >>>>
> >>>> Then I could do some filtering on the stream of items as they come
out.
> >>>> They could be strings, or a well known data structure, like what the
> >>>> reflect.lua creates. That way, I could either generate a massive
> >>>> string, or I could do "other stuff".
> >>>>
> >>>> -- William
> >>>>
> >>>>
> >>>> ===============================
> >>>> - Shaping clay is easier than digging it out of the ground.
> >>>>
> >>>>
> >>>>
> >>>> ----------------------------------------
> >>>>
> >>>>> Date: Tue, 28 May 2013 15:18:22 +0300
> >>>>> From: alex@xxxxxxxxxxx
> >>>>> To: luajit@xxxxxxxxxxxxx
> >>>>> CC: michael@xxxxxxxxxxxx
> >>>>> Subject: Re: Small helper FFI cdef generator script (in perl)
> >>>>>
> >>>>>
> >>>>> On 28.05.2013 14:56, Michael Willigens wrote:
> >>>>>
> >>>>>> Did you check lcpp? Its an C PreProcessor written in Lua5.1
> >>>>>> (wihtout any
> >>>>>> depencies). It still has some flaws but I can use it to include
tons
> >>>>>> of headers and defines.
> >>>>>>
> >>>>>> https://github.com/willsteel/lcpp
> >>>>>>
> >>>>>>
> >>>>>
> >>>>> Yes, I bookmarked (starred) lcpp for future use immediately after
> >>>>> your announce ;-)
> >>>>>
> >>>>>
> >>>
> >>
> >>
>

Other related posts: