Skip to content

Commit

Permalink
Wrap uv_(get|set)_process_title
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Jul 1, 2012
1 parent 417f36f commit ee604fd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/luv.c
Expand Up @@ -156,6 +156,8 @@ static const luaL_reg luv_f[] = {
{"cpuInfo", luv_cpu_info},
{"interfaceAddresses", luv_interface_addresses},
{"execpath", luv_execpath},
{"getProcessTitle", luv_get_process_title},
{"setProcessTitle", luv_set_process_title},
{"handleType", luv_handle_type},
{"activateSignalHandler", luv_activate_signal_handler},
{NULL, NULL}
Expand Down
24 changes: 24 additions & 0 deletions src/luv_misc.c
Expand Up @@ -26,6 +26,10 @@
#define PATH_MAX (8096)
#endif

#ifndef MAX_TITLE_LENGTH
#define MAX_TITLE_LENGTH (8192)
#endif

#ifndef _WIN32

const char *luv_signo_string(int signo) {
Expand Down Expand Up @@ -362,6 +366,26 @@ int luv_execpath(lua_State* L) {
return 1;
}

int luv_get_process_title(lua_State* L) {
char title[8192];
uv_err_t err = uv_get_process_title(title, 8192);
if (err.code) {
return luaL_error(L, "uv_get_process_title: %s: %s", uv_err_name(err), uv_strerror(err));
}
lua_pushstring(L, title);
return 1;
}

int luv_set_process_title(lua_State* L) {
const char* title = luaL_checkstring(L, 1);
uv_err_t err = uv_set_process_title(title);
if (err.code) {
return luaL_error(L, "uv_set_process_title: %s: %s", uv_err_name(err), uv_strerror(err));
}
return 0;
}


int luv_handle_type(lua_State* L) {
uv_file file = luaL_checkint(L, 1);
uv_handle_type type = uv_guess_handle(file);
Expand Down
2 changes: 2 additions & 0 deletions src/luv_misc.h
Expand Up @@ -37,6 +37,8 @@ int luv_uptime(lua_State* L);
int luv_cpu_info(lua_State* L);
int luv_interface_addresses(lua_State* L);
int luv_execpath(lua_State* L);
int luv_get_process_title(lua_State* L);
int luv_set_process_title(lua_State* L);
int luv_handle_type(lua_State* L);

#endif

0 comments on commit ee604fd

Please sign in to comment.