On 16 Oct 2013 15:41, "Lourival Vieira Neto" <lourival.n...@gmail.com> wrote: > > Hi Justin, > > On Tue, Oct 15, 2013 at 7:38 PM, Justin Cormack > <jus...@specialbusservice.com> wrote: > > On Thu, Oct 10, 2013 at 7:15 PM, Lourival Vieira Neto > > <lourival.n...@gmail.com> wrote: > >> Hi folks, > >> > >> It has been a long time since my GSoC project and though I have tried > >> to come back, I've experienced some personal issues. However, now I'm > >> coding again. > >> > >> I'm developing a library to handle buffers in Lua, named lbuf. It is > >> been developed as part of my efforts to perform experimentation in > >> kernel network stack using Lua. Initially, I intended to bind mbuf to > >> allow, for example, to write protocols dissectors in Lua. For example, > >> calling a Lua function to inspect network packets: > >> > >> function filter(packet) > >> if packet.field == value then return DROP end > >> return PASS > >> end > >> > >> Thus, I started to design a Lua binding to mbuf inspired by '#pragma > >> pack' and bitfields of C lang. Then, I realized that this Lua library > >> could be useful to other kernel (and user-space) areas, such as device > >> drivers and user-level protocols. So, I started to develop this > >> binding generically as a independent library to give random access to > >> bits in a buffer. It is just in the early beginning, but I want to > >> share some thoughts. > > > > I have been using the luajit ffi and luaffi, which let you directly > > use C structs (with bitfields) in Lua to do this. It makes it easier > > to reuse stuff that is already defined in C. (luaffi is not in its > > current state portable but my plan is to strip out the non portable > > bits, which are the function call support). > > > > Justin > > I never used luaffi. It sounds very interesting and I think it could > be very useful to bind already defined C structs, but my purpose is to > dynamically define data layouts using Lua syntax (without parsing C > code). >
Yes absolutely it makes more sense if already defined in C. For parsing binary stuff I would look at Erlang for inspiration too, it is one of the nicer designs. Justin