-------------------------------------------------------------------------*\ * Creates a serial object \*-------------------------------------------------------------------------*/
| 144 | * Creates a serial object |
| 145 | \*-------------------------------------------------------------------------*/ |
| 146 | static int global_create(lua_State *L) { |
| 147 | const char* path = luaL_checkstring(L, 1); |
| 148 | |
| 149 | /* allocate unix object */ |
| 150 | p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); |
| 151 | |
| 152 | /* open serial device */ |
| 153 | t_socket sock = open(path, O_NOCTTY|O_RDWR); |
| 154 | |
| 155 | /*printf("open %s on %d\n", path, sock);*/ |
| 156 | |
| 157 | if (sock < 0) { |
| 158 | lua_pushnil(L); |
| 159 | lua_pushstring(L, socket_strerror(errno)); |
| 160 | lua_pushnumber(L, errno); |
| 161 | return 3; |
| 162 | } |
| 163 | /* set its type as client object */ |
| 164 | auxiliar_setclass(L, "serial{client}", -1); |
| 165 | /* initialize remaining structure fields */ |
| 166 | socket_setnonblocking(&sock); |
| 167 | un->sock = sock; |
| 168 | io_init(&un->io, (p_send) socket_write, (p_recv) socket_read, |
| 169 | (p_error) socket_ioerror, &un->sock); |
| 170 | timeout_init(&un->tm, -1, -1); |
| 171 | buffer_init(&un->buf, &un->io, &un->tm); |
| 172 | return 1; |
| 173 | } |
| 174 | |
| 175 | #endif |
nothing calls this directly
no test coverage detected