lspawn

Note: Textadept 7.2 beta 3 includes this functionality by default. This module is deprecated.

Introduction

lspawn is a Textadept module for spawning asynchronous processes using GTK. (Therefore, it cannot be used with the ncurses version of Textadept). This is useful for interacting with external programs in a separate thread via stdin, stdout, and stderr. Textadept will not block while external programs are running.

Download

v0.3

hg repository

Install

Create a ~/.textadept/modules/os/ directory and place the unzipped contents of lspawn_x.x/ there.

On Linux, depending on your architecture (run uname -i to determine it), run:

# x86_64 ONLY
ln -s spawn.so.x86_64 spawn.so
# i386 ONLY
ln -s spawn.so.i386 spawn.so

On Mac OSX, run:

ln -s spawn.so.osx spawn.so

In your ~/.textadept/init.lua, load the module:

os.spawn = require 'os.spawn'

Documentation

Documentation is in spawn.luadoc. You can also load the tags and api adeptsense files in your Lua module's post_init.lua file:

_M.lua.sense:load_ctags(_USERHOME..'/modules/os/tags')
_M.lua.sense.api_files[#_M.lua.sense.api_files + 1] =
  _USERHOME..'/modules/os/api'

Usage

Spawn the program program with /tmp/ as the current working directory and prints stdout and stderr to Textadept's message buffer:

os.spawn('/tmp/', 'program', nil, nil, print, print)

Spawn a Lua program that asks for user input:

p = os.spawn(nil, { 'lua', '-e', 'io.read()' })
p('my input\n') -- do not forget the newline

After spawning a process that does not exit right away, kill it:

p = os.spawn(nil, 'program')
p(nil)

Please see the spawn.luadoc for parameter documentation.

Notes on Win32

There are some hoops to jump through. You need 2 external files:

Both of these files need to go into Textadept's home directory.

The spawned process will create the "black box" console window. There is no way around this. GLib's spawn code uses process.h's _wspawnvp() and _wspawnv() functions, which I think are responsible. I don't think it's possible to swap CreateProcess() for _wspawn*() because GLib uses more low-level functions for pipes and such.

Compiling against Glib

If someone wants to try and use CreateProcess() instead, you'll have to recompile the "gspawn-win32-helper.c" file from Glib source. You can link against Textadept's win32gtk/ glib, but you'll have to jump through more hoops to get some necessary "*.h" files.

Added the file “lspawn-0-1.zip”.
Deleted the file “lspawn-0-1.zip”.
Added the file “lspawn-0-2.zip”.
Deleted the file “lspawn-0-2.zip”.
Added the file “lspawn-0-3.zip”.


Edited on Tuesday, April 15th 2014 at 3:33 PM.