lua-users home
lua-l archive

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


On Thu, Feb 2, 2012 at 04:30, <StephenSimpson@eaton.com> wrote:

The Lua 5.2 reference for lua_Reader talks about the reader's behaviour in terms of 'chunks'
I've been talking in this thread about a reader that streams data to the parser
... it's not aware of a 'chunk'.  In other words I'm not doing the reader correctly.

My context and restrictions are:
 - The lua_Reader is serialising discontiguous data for the parser
 - The discontiguities are block-ish, 1-byte to say the size of a TCP segment
 - reallocations and mem copies should be avoided if at all possible
 - single OS thread (Integrity RTOS)

Thanks


Honestly, patching the parser appears to be the easiest solution. The only way to tell where a statement starts and where it ends is to parse the source. At the moment, the only existing Lua 5.2 parser that I know of is lparser.c, in the Lua sources.

Don't be afraid, the source is very clean, and easy to read and modify. 

A first step would be to replace the `statlist(*L)` call in `luaY_parser(...)` with a call to `statement(*L)`, so that the parser returns after one statement instead of one chunk. 

http://www.lua.org/source/5.2/lparser.c.html#luaY_parser

I'm not familiar with the reader side of things, nor how to detect where the parser stopped reading the stream, but it should be easier to figure it out (or to add the functionality) than to re-implement a full parser in the reader...

Kind regards,
-- Pierre-Yves