Spawn callback #9

Closed
wants to merge 21 commits into
from

Conversation

Projects
None yet
2 participants
@jerojasro
Contributor

jerojasro commented Feb 21, 2011

Hi,

I modified the luaH_luakit_spawn (luah.c) to allow defining Lua callbacks for async-spawned processes, which get called once the spawned process finishes.

the Lua callback function receives 4 arguments: kind of process termination, code of process termination, stdout for the process, stderr for the process.

An example of how to use it is available in lib/async_call_example.lua

I think the functions I added could use some better names, but I'm not so familiar with the naming scheme used.

Can you look at the code, propose corrections/modifications if neccessary, and eventually merge this? Thanks

jerojasro and others added some commits Jan 14, 2011

changed function used for spawning processes
changed from g_spawn_command_line_async to g_spawn_async, so we can get
the PID of the child process
added docs for lua callback handling
Added a bunch of TODOs...
add callback handling infrastructure
  * create a table in the registry to store the Lua callback handler
    functions
  * add an entry in that callbacks table for each spawned process
made definition of callback optional - check func. type
  * made the lua callback function argument to luaH_luakit_spawn
    optional
  * ensure that the type of the element received as second argument is a
    function
pass termination status to Lua callback function
now the function defined as callback receives 2 arguments:

  * the termination type: one of either: normal exit (NORMAL_EXIT),
    termination by a signal (TERM_SIGNAL), or unknown reason
    (TERM_UNKNOWN)
  * the termination number. When the process terminated normally, it
    contains the return code of the process. When terminated by a
    signal, it contains the signal number.
expose codes for types of process finalization to lua side
3 new items added to the `luakit` namespace:

  luakit.PROC_TERM_EXIT
  luakit.PROC_TERM_SIGNAL
  luakit.PROC_TERM_UNKNOWN
Javier Rojas
changed callback data to pass std{out,err} file descriptors
those descriptors will be used to pass the std{out,err} to the Lua
callback function as text.
@jerojasro

This comment has been minimized.

Show comment Hide comment
@jerojasro

jerojasro Mar 15, 2011

Contributor

I made two changes to the code:

  • Removed the reading of stdout and stderr, since it seems they are destroyed/closed when the spawned process dies
  • Changed the way the lua callback is invoked; now the code uses lua_pcall
Contributor

jerojasro commented Mar 15, 2011

I made two changes to the code:

  • Removed the reading of stdout and stderr, since it seems they are destroyed/closed when the spawned process dies
  • Changed the way the lua callback is invoked; now the code uses lua_pcall
@mason-larobina

This comment has been minimized.

Show comment Hide comment
@mason-larobina

mason-larobina Mar 15, 2011

Owner

Thanks, from what I've seen these patches look nice. I'll merge them when I get time tomorrow.

Owner

mason-larobina commented Mar 15, 2011

Thanks, from what I've seen these patches look nice. I'll merge them when I get time tomorrow.

@mason-larobina

This comment has been minimized.

Show comment Hide comment
@mason-larobina

mason-larobina Mar 27, 2011

Owner

Merged in with some modifications (namely to use the existing luaH_object_ref and luaH_object_unref system instead of setting up and managing a custom callback registry). You can see my changes here:

a776ad7...ea7223d

Thanks again,

Mason.

Owner

mason-larobina commented Mar 27, 2011

Merged in with some modifications (namely to use the existing luaH_object_ref and luaH_object_unref system instead of setting up and managing a custom callback registry). You can see my changes here:

a776ad7...ea7223d

Thanks again,

Mason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment