File: native.c

package info (click to toggle)
lua-nvim 0.2.4-1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 168 kB
  • sloc: makefile: 67; ansic: 32
file content (39 lines) | stat: -rw-r--r-- 767 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>

#define UNUSED(x) ((void)x)

#ifdef _WIN32
static int pid_wait(lua_State *L) {
  (void)(L);
  return 0;
}
#else
#include <sys/wait.h>
#include <signal.h>

static int pid_wait(lua_State *L) {
  int status;
  pid_t pid = (pid_t)luaL_checkinteger(L, 1);
  /* Work around libuv bug that leaves defunct children:
   * https://github.com/libuv/libuv/issues/154 */
  while (!kill(pid, 0)) waitpid(pid, &status, WNOHANG);
  return 0;
}
#endif

static const luaL_Reg native_lib_f[] = {
  {"pid_wait", pid_wait},
  {NULL, NULL}
};

int luaopen_nvim_native(lua_State *L) {
  lua_newtable(L);
#if LUA_VERSION_NUM >= 502
  luaL_setfuncs(L, native_lib_f, 0);
#else
  luaL_register(L, NULL, native_lib_f);
#endif
  return 1;
}