lua-users home
lua-l archive

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


I'm not an expert, but i think your assertion is right - "block" in
this context means a certain amount of text that is processed at a
time.

The lua_Reader will be called once for each block, i think the default
is a line of input. I have used a reader from lua to turn a CSV file
into a lua table:

function load_csv_file(fname)
   local state=1
   local file = io.open(fname)
   local f = function()
		if state==1 then
		   state=2
		   return "return {"
		end
		if state==2 then
		   local line = file:read()
		   if line then
		      return "{"..line.."},"
		   else
		      state=3
		      return "}"
		   end
		end
		if state==3 then
		   return nil
		end
	     end
	return assert(load(f))()
end


But i'm not sure that this would really help improving your error
messages, perhaps you could catch compile errors, but not run time.

On Jan 24, 2008 5:22 PM, Wesley Smith <wesley.hoke@gmail.com> wrote:
> Sorry for the quick follow up:
>
> lua_Reader:
> "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. The reader function may
> return pieces of any size greater than zero."
>
> What is tripping me up is the the use of the word "block".  I
> typically understand block to mean a piece of code like:
>
> do
> --stuff
> end
>
> Does block here mean something else?  I'm thinking it does, but am
> having mental discombobulations right now.
> thanks,
> wes
>