Re: [textadept] experimental spawn

From: mitchell <c....at.caladbolg.net>
Date: Sun, 24 Oct 2010 23:57:20 -0400 (EDT)

> Looks useful. What do you think about a feature for executing lua code
> at an interval? My use case is to update code auto-completion based on
> the current buffer every 5 seconds or so. Something like a lua interface
> to g_timout_add or g_timeout_add_seconds that allows a lua function to
> be called at an interval. Since it's integrated with GTK's main loop, it
> shouldn't cause any threading problems.

This has been added to hg as _G.timeout(interval, lua function, args).
LuaDoc is in core/._G.luadoc

mitchell

>
> http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#g-timeout-add
> http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#g-timeout-add-seconds
>
> On 10/22/2010 03:42 PM, mitchell wrote:
>> Hi,
>>
>> 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 recompile.
>>
>> 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).
>>
>> Usage:
>>
>> 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)
>> input('hi\n')
>>
>> -- Kills a process before any input
>> input = spawn.spawn(nil,
>> { 'lua', '-e', 'print(io.read())' },
>> nil, gui.print)
>> input(nil)
>>
>> Ultimately I'd like to have compile/run commands asynchronously print
>> to ta buffers without the blocking caused by popen.
>>
>> mitchell
>>
>
> --
> You received this message because you are subscribed to the Google Groups "textadept" group.
> To post to this group, send email to textadept.at.googlegroups.com.
> To unsubscribe from this group, send email to textadept+unsubscribe.at.googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/textadept?hl=en.
>
>

mitchell
Received on Sun 24 Oct 2010 - 23:57:20 EDT

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