lua-users home
lua-l archive

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

2012/2/2  <>:
> 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.
> So to make my application work I'd either have to make the reader chunk-aware (which seems to be implied by the Lua reference) or do a major extension to the parsing framework, eg. lua_Streamer or something like that
> I reckon the major extension is the wrong move at the moment.
> So I'd like ideas for making a reader chunk-aware.

I think you may be mistaken here, and that your initial understanding
of the reader is the right one. The reader function must provide only
one chunk, but that can be in multiple calls. The manual states that
the function must return "a piece of the chunk". The important words
are "piece", and "the". A piece is not a chunk in itself (it just a
"piece"), and all the pieces are concatenated and considered to be a
single chunk ("the" chunk). In other words, the lua_load function
won't complain before the reader has returned the very last piece of
the chunk (by returning NULL or setting size to 0). And after that you
have to reset to reader to return another independently complete chunk
(ie. not reffering to locals in the previous chunk for example), but
that occurs in a second call to lua_load.

Another important point is that cutting a chunk in multiple smaller
chunks may change its behavior. For example "local a = 42; print(a)"
does not give the same result as "local a = 42" followed by