ref: 0ab5e19fd514edbed395c43cbe854cf43bd2a01d
parent: a5c6a7b0ba55e5a88e1e1f1f5140b1195bbfbeaf
author: telephil9 <[email protected]>
date: Tue Oct 27 16:37:25 EDT 2020
Add close function This function allows for closing file descriptors and is required to close files opened through libplumb for instance.
--- a/lib9.c
+++ b/lib9.c
@@ -1,5 +1,6 @@
#include <u.h>
#include <lib9.h>
+#include <unistd.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
@@ -26,9 +27,18 @@
return 0;
}
+static int
+lclose(lua_State *L)
+{
+ int fd;
+ fd = luaL_checkinteger(L, 1);
+ close(fd);
+ return 0;
+}
static const struct luaL_Reg lib9 [] = {
{ "fork", lfork },
+ { "close", lclose },
{ NULL, NULL }
};