lua-users home
lua-l archive

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


On Wed, Aug 27, 2014 at 3:55 PM, Milind Gupta <milind.gupta@gmail.com> wrote:
> Hi,
>       I was trying to use the ltn12 base64 encoding filter but I think I
> don't understand it clearly. If I do the following:
>
> Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
>> mime = require("mime")
>> print(ltn12)
> table: 00B6D1F0
>> enc = mime.encode("base64")
>> print(enc("Test Text"))
> VGVzdCBUZXh0
>> print(enc())
> nil
>> print(enc())
> nil
>> print(enc("Test Text"))
> nil
>>
>
>
> For the last one I was expecting to give me the encoding again. Why did it
> give me nil? Is it not the right way to reuse the filter? Any help would be
> appreciated.
>
> Thanks,
> Milind

The filter operates on a stream. Once you pass in nil (or no value),
that signals that the stream has ended. To pass more data afterward
violates the API. (However, you should keep calling it with nil as the
input again until the output is also nil, as filters can generate
additional data.)

-- 
Sent from my Game Boy.