More splicing stuff
[project/luci.git] / libs / nixio / src / nixio.c
index 327f650..ae1af7a 100644 (file)
 
 /* pushes nil, error number and errstring on the stack */
 int nixio__perror(lua_State *L) {
-    lua_pushnil(L);
+       if (errno == EAGAIN) {
+               lua_pushboolean(L, 0);
+       } else {
+               lua_pushnil(L);
+       }
     lua_pushinteger(L, errno);
     lua_pushstring(L, strerror(errno));
     return 3;
@@ -84,8 +88,14 @@ int nixio__tofd(lua_State *L, int ud) {
        return fd;
 }
 
+static int nixio_strerror(lua_State *L) {
+       lua_pushstring(L, strerror(luaL_checkinteger(L, 1)));
+       return 1;
+}
+
 /* object table */
 static const luaL_reg R[] = {
+       {"strerror",    nixio_strerror},
        {NULL,                  NULL}
 };
 
@@ -103,7 +113,7 @@ LUALIB_API int luaopen_nixio(lua_State *L) {
 
        /* register metatable as socket_meta */
        lua_pushvalue(L, -2);
-       lua_setfield(L, -2, "socket_meta");
+       lua_setfield(L, -2, "meta_socket");
 
        /* register methods */
        nixio_open_file(L);
@@ -114,11 +124,26 @@ LUALIB_API int luaopen_nixio(lua_State *L) {
        nixio_open_poll(L);
        nixio_open_io(L);
        nixio_open_splice(L);
+       nixio_open_tls_context(L);
+       nixio_open_tls_socket(L);
 
        /* module version */
        lua_pushnumber(L, VERSION);
        lua_setfield(L, -2, "version");
 
+       /* some constants */
+       lua_createtable(L, 0, 7);
+
+       NIXIO_PUSH_CONSTANT(EACCES);
+       NIXIO_PUSH_CONSTANT(ENOSYS);
+       NIXIO_PUSH_CONSTANT(EINVAL);
+       NIXIO_PUSH_CONSTANT(EWOULDBLOCK);
+       NIXIO_PUSH_CONSTANT(EAGAIN);
+       NIXIO_PUSH_CONSTANT(ENOMEM);
+       NIXIO_PUSH_CONSTANT(ENOENT);
+
+       lua_setfield(L, -2, "const");
+
        /* remove meta table */
        lua_remove(L, -2);