Navigation Menu

Skip to content

Commit

Permalink
luvit.lua: map process.pid to native.getpid()
Browse files Browse the repository at this point in the history
Allows for PID to be extracted from Lua process.

./src/luv.c: Mapped getpid() to lua_getpid()

Translates C function for getting Process ID to Lua function.

./src/luv_process.c: Defined function for retrieving PID

Calls for PID from System.

./src/luv_process.h: Added lua_getpid() function

Allows function to be called in luv.c.
  • Loading branch information
mkandrashoff authored and philips committed May 26, 2012
1 parent 153fefa commit d8bc9b9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/luvit/luvit.lua
Expand Up @@ -133,6 +133,10 @@ process.env = setmetatable({}, {
end
})
--Retrieve PID
process.getpid = native.getpid
process.pid = process.getpid()
-- Copy date and time over from lua os module into luvit os module
local OLD_OS = require('os')
local OS_BINDING = require('os_binding')
Expand Down
3 changes: 2 additions & 1 deletion src/luv.c
Expand Up @@ -66,7 +66,8 @@ static const luaL_reg luv_f[] = {
/* Process functions */
{"spawn", luv_spawn},
{"processKill", luv_process_kill},

{"getpid", luv_getpid},

/* Stream functions */
{"shutdown", luv_shutdown},
{"listen", luv_listen},
Expand Down
6 changes: 6 additions & 0 deletions src/luv_process.c
Expand Up @@ -32,6 +32,12 @@ void luv_process_on_exit(uv_process_t* handle, int exit_status, int term_signal)

}

/* Retrieves Process ID */
int luv_getpid(lua_State* L){
int pid = getpid();
lua_pushinteger(L, pid);
return 1;
}

/* Initializes uv_process_t and starts the process. */
int luv_spawn(lua_State* L) {
Expand Down
1 change: 1 addition & 0 deletions src/luv_process.h
Expand Up @@ -26,5 +26,6 @@

int luv_spawn(lua_State* L);
int luv_process_kill(lua_State* L);
int luv_getpid(lua_State* L);

#endif

0 comments on commit d8bc9b9

Please sign in to comment.