[textadept] experimental spawn

From: mitchell <c....at.caladbolg.net>
Date: Fri, 22 Oct 2010 18:42:10 -0400 (EDT)


I've come up with a strange beast: asynchronous spawning from ta using
glib. I'm actually somewhat afraid of it because I don't know how it can
interfere with ta. For those of you curious, I've attached a patch to
current hg tip (667) as well as lspawn.c. Put lspawn.c in src/lua/src/ and

Anyone with a better understanding of this stuff please comment :)

lspawn has one lua function: spawn(). It takes up to 6 arguments:
   * current_dir (string) - the directory to run the command in
   * argv (string or table) - single commands can be passed as strings
(e.g. 'ls', but anything else needs to be a table of strings like {
'echo', 'foo' })
   * envp (table) - environment variable pairs in addition to the current
ones. (e.g. { 'foo=bar', 'baz=barfoo' })
   * stdout_callback (function that takes a string param) - callback
function when something is printed to stdout.
   * stderr_callback (function that takes a string param)
   * exit_callback (function that takes an integer param) - callback
function when the spawned process exits returning status code.

spawn() returns a function that can act as stdin for the spawned process.
Calling that function with any string parameter passes it as stdin.
Calling the function with nil kills the process (SIGKILL).


local spawn = require 'spawn'

-- Lists contents of /tmp and prints exit code
spawn.spawn('/tmp', 'ls', nil, gui.print, gui.print, gui.print)

-- Prints 'hi' from being passed as stdin
input = spawn.spawn(nil,
                     { 'lua', '-e', 'print(io.read())' },
                     nil, gui.print)

-- Kills a process before any input
input = spawn.spawn(nil,
                     { 'lua', '-e', 'print(io.read())' },
                     nil, gui.print)

Ultimately I'd like to have compile/run commands asynchronously print to
ta buffers without the blocking caused by popen.


Received on Fri 22 Oct 2010 - 18:42:10 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:52:16 EST