lua-users home
lua-l archive

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

Thomas Lauer wrote:
> However, this means that once a filter function is installed, it
> expects to be called only as a filter and *not* to set a filter for
> another file.  
> The following version of the token filter file is completely off the
> top of my head (and it's getting late anyway...), so it will
> certainly need much more polishing. But it seems to work and it shows
> the basic idea:   
> local _get
> function FILTER(get,source)
> 	if get==nil then -- we are being called as a filter
> 		local line,token,value=_get()
> 		print("FILTER",line,token,value)
> 		return line,token,value
> 	else
> 	  _get=get -- we are being called to set a new filter function
> 		print("FILTER",source)
>   end
> end
> As I am relatively new to this token filter business, others
> (especially lhf, I would think) will certainly find a much more
> elegant solution.  

I don't know if it's a more elegant solition, but you can also make your
filter reset itself when it receives a eof token. Since the compilation
and execution of a chunk are done in seperate steps, you should always
receive the eof of a chunk before the compilation of another one starts.