lua-users home
lua-l archive

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


On Tue, Jun 9, 2015 at 9:55 PM, Mike <lua-l@inbox.ru> wrote:
> Hello, everybody.
>
> Is there a way to run a piece of code from the currently executing lua script
> (I mean a lua chunk or a function) in a "subprocess" and establish a pipe
> to/from its stdin/stdout something like io.popen() does?
>
> This is somewhat different from the launching a subprocess for an external
> program or for the lua script itself that may be done with io.popen()
> as the launched chunk is to be able to access the current values of the
> currently executing lua script global variables and/or upvalues
> (at least their copies in the forked process's image).
> More simply, I mean the feature like "process substitution" in bash,
> for example:
> -----
> #! /bin/bash
>
> greeting="Hello world!"
>
> do-greeting()
> {
>   echo "$greeting"
> }
>
> cat < <(do-greeting)
> -----
>
> Thanks.
>
> --
> Mike
>

Maybe coroutines are what you are looking for.


-- 


Best regards,
Boris Nagaev