lua-users home
lua-l archive

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


> > lua_Readers? (*shudder*), fortunately I've avoided the need to use
> those
> > so far - the docs confused me no end! :)
> 
> Please help us improve the docs: what points are confusing?
> 
> Anyway, read the source to see how they're used:
> 	http://www.lua.org/source/5.1/lauxlib.c.html#luaL_loadfile
> 	http://www.lua.org/source/5.1/lauxlib.c.html#getF


I couldn't really find anything in PIL, so I went to the online manual
and got this (which I'm sure you are familiar with anyway).

lua_Reader
typedef const char * (*lua_Reader) (lua_State *L,
                                    void *data,
                                    size_t *size);

The reader function used by lua_load. Every time it needs another piece
of the chunk, lua_load calls the reader, passing along its data
parameter. The reader must return a pointer to a block of memory with a
new piece of the chunk and set size to the block size. The block must
exist until the reader function is called again. To signal the end of
the chunk, the reader must return NULL or set size to zero. The reader
function may return pieces of any size greater than zero.


What is meant by a chunk in this case? What use is the data parameter
used for?  What point is the state in this case for that matter, and is
it valid to manipulate it?  The fact that you have directed me to the
source to see how it is used would be a simple enough example of why the
documentation is confusing (unless I have missed something in PIL.)
Also, this says nothing about how it would help with my original
question!

So I've been using Lua for 2-3 years or so, and I've avoided Readers as
I haven't really understand how they can help me (actually on 2nd look,
I think it might solve 1 problem we had a while ago that I solved with a
new loader - but that's not my point!).  I'm sure that when I understand
the useage correctly I will find a million and one uses for them, but
until then...

Tom