lua-users home
lua-l archive

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

I'm not an expert, but it looks fairly straightforward. Lua strings
can contain embedded "\0"s so I use them to transmit binary data
between C and Lua, and also Lua’s pattern matching can be quite
powerful for processing binary strings. Once you understand using the
"stack" to communicate different types of value between C and Lua,
what you want to do (jumping between C and Lua) should be easy. Start


PS 'Lua' is Portuguese for 'moon', so is not all caps...

2009/12/26 Alexey Mikhailov <>:
> Excuse me, I forgot to put Subject line. My bad.
> Alexey Mikhailov wrote:
>> Hello, LUA fondlers!
>> I'm working on some application, and I want to embed LUA for flexible
>> data processing. Let me describe my application briefly.
>> There is some binary information passed through network. My application
>> receives it and stores in archive in binary form and in segment of
>> shared memory. So basically, there are two posibilities for processing
>> information: off-line (through filesystem archive, for custom time slice),
>> on-line (real-time with shared memory segment). I have few static C
>> libraries: two libraries for accessing information: binary infomation in
>> archive and binary information in shared memory segment, and another one
>> parses binary information.
>> So basically, it can work like this:
>> archive_query (time_t time1, time_t time2, void (*cb) (u_int8_t *buf,
>> size_t siz);
>> online_process (void (*cb) (u_int8_t 8buf, size_t siz);
>> Then for each given slice of information callback `cb' function is
>> called. Then this function can use parse binary information and process
>> data.
>> And now I want to embed LUA here. Basically, there are two operations
>> I want to perform on data 'filter' (to get only needed bits of
>> information)
>> and 'map' (perform some lua actions on each portion of data).
>> So basically I want to call something like this in LUA. (code in
>> pseudolanguage)
>> foreach packet that (satisfies)CONDITION in [time1, time2]
>>  summary_param += packet.size done
>> (receive query in LUA -> call C function to query -> C callback will
>> be called and information will be parsed -> call LUA code to process
>> data)
>> Hopefully, I described my problem clear enough, but feel free to ask
>> any questions!
>> So, my questions are: is it hard to implement this scheme? are there
>> some examples using similiar approach? any general advices?