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
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:
- "gspawn-win32-helper.exe" from the
bin
directory of this file - "lua52.dll" from the Lua Binaries project: http://luabinaries.sourceforge.net/
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.
Download the glib source
Copy all of the
glib/*.h
files into a new directory somewhere.Run
CC=i586-mingw32msvc-gcc ./configure --host=i586-mingw32msvc
. You'll get an error about "gettext" go intoconfigure
, search around for "gettext", and replace the "=no" option with "=yes". Then go intoconfigure.ac
, search around for "gettext", and delete the check for it. Now run the command again and you should get a top-levelconfig.h
generated. Put that in the new directory with the*.h
files in the previous step.Run the following command (obviously replace "/home/mitchell/textadept/" with the path to Textadept's home and make sure the "src/win32gtk" directory exists):
i586-mingw32msvc-gcc -mms-bitfields -mwindows -o gspawn-win32-helper.exe gspawn-win32-helper.c `PKG_CONFIG_PATH=/home/mitchell/textadept/src/win32gtk/lib/pkgconfig pkg-config --define-variable=prefix=/home/mitchell/textadept/src/win32gtk --cflags glib-2.0` -Iglib `PKG_CONFIG_PATH=/home/mitchell/textadept/src/win32gtk/lib/pkgconfig pkg-config --define-variable=prefix=/home/mitchell/textadept/src/win32gtk --libs glib-2.0`
Now you can use the generated "gspawn-win32-helper.exe".
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”.