lua-users home
lua-l archive

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


ffi or syscall libraries would also work. But that's not especially portable, if that's important to you.

Rather than trying to share access to your globals with a subprocess, it might be better to use a configuration chunk, command line options, or piped input.

What are you actually trying to do, though? Does it actually need to be in another process? Using loadstring (or its cousins) would probably work just fine in most cases.

On Tue, Jun 9, 2015 at 4:10 PM, Sean Conner <sean@conman.org> wrote:
It was thus said that the Great Mike once stated:
> 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)
> -----

  Yes, but it will involve calling pipe(), fork() and dup2() at a minimum,
which means you need something like luaposix (or lposix or whatever it's
called).  Also, depending on how you process the data, you may need to call
io.setvbuf() on the resulting streams (if you are using the io.* library to
read the pipes).

  -spc





--
Brigham Toskin