Operating a separate terminal under Lua control

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Operating a separate terminal under Lua control

Dirk Laurie-2
I thought this would work:

$ lua
Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
> term = io.popen('xterm -e "lua"',"w")
> term:write"Some Lua input\n"
file (0x1ef95f0)
> term:close()

After the first line, the new terminal appears. Encouraging.
After the second line, nothing changes on the terminal,
I thought it would pass my Lua input to it and run it.
After the third line, MY terminal dies. Ctrl-C brings it back,
killing the other terminal.

What I want to do is to make the other terminal execute
some Lua commands, as if I had been typing them in
there.

Am I trying the impossible or missing the obvious?

Reply | Threaded
Open this post in threaded view
|

Re: Operating a separate terminal under Lua control

Daurnimator
On 1 March 2017 at 01:52, Dirk Laurie <[hidden email]> wrote:

> I thought this would work:
>
> $ lua
> Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
>> term = io.popen('xterm -e "lua"',"w")
>> term:write"Some Lua input\n"
> file (0x1ef95f0)
>> term:close()
>
> After the first line, the new terminal appears. Encouraging.
> After the second line, nothing changes on the terminal,
> I thought it would pass my Lua input to it and run it.
> After the third line, MY terminal dies. Ctrl-C brings it back,
> killing the other terminal.
>
> What I want to do is to make the other terminal execute
> some Lua commands, as if I had been typing them in
> there.
>
> Am I trying the impossible or missing the obvious?
>

You need a pty library.
Try http://tset.de/lpty/index.html

Reply | Threaded
Open this post in threaded view
|

Re: Operating a separate terminal under Lua control

Nagaev Boris
In reply to this post by Dirk Laurie-2
On Tue, Feb 28, 2017 at 2:52 PM, Dirk Laurie <[hidden email]> wrote:

> I thought this would work:
>
> $ lua
> Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
>> term = io.popen('xterm -e "lua"',"w")
>> term:write"Some Lua input\n"
> file (0x1ef95f0)
>> term:close()
>
> After the first line, the new terminal appears. Encouraging.
> After the second line, nothing changes on the terminal,
> I thought it would pass my Lua input to it and run it.
> After the third line, MY terminal dies. Ctrl-C brings it back,
> killing the other terminal.
>
> What I want to do is to make the other terminal execute
> some Lua commands, as if I had been typing them in
> there.
>
> Am I trying the impossible or missing the obvious?
>

BTW I wrote a library to emulate terminal from Lua:
http://lua-users.org/lists/lua-l/2015-03/msg00325.html

--
Best regards,
Boris Nagaev