lua-users home
lua-l archive

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


On Fri, Nov 17, 2017 at 2:46 AM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> Late night thought. I want to implement a way to tell Lua to wrap a
>> segment of text and run it as the arguments of os.execute(). Could you
>> give me a hint on how I would do that with ltokenp?
>
> ltokenp does not see whitespace. This could be a problem for this application.
> If you don't mind putting the text inside quotes, then something like this
> works with ltokenp:
>
>         `"ls *.lua"
>
> Here is the filter:
>
> -- replace ` with os.execute
> function FILTER(line,token,text,value)
>         local t=text
>         if t=="<file>" or t=="<eof>" then return end
>         if t=="<string>" then value=string.format("%q",value) end
>         if t=="`" then value="os.execute" end
>         io.write(value," ")
> end

Thank you, I look forward to the rabbit hole I just fell down.

>> A safe table navigator symbol would be a fun thing to implement too.
>
> What do you mean?
>