MCPcopy Create free account
hub / github.com/Tencent/UnLua / global_create

Function global_create

Plugins/UnLuaExtensions/LuaSocket/Source/src/serial.cpp:146–173  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * Creates a serial object \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

144* Creates a serial object
145\*-------------------------------------------------------------------------*/
146static 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

Callers

nothing calls this directly

Calls 10

openFunction · 0.85
lua_pushnilFunction · 0.85
lua_pushstringFunction · 0.85
lua_pushnumberFunction · 0.85
auxiliar_setclassFunction · 0.85
io_initFunction · 0.85
timeout_initFunction · 0.85
buffer_initFunction · 0.85
socket_strerrorFunction · 0.70
socket_setnonblockingFunction · 0.70

Tested by

no test coverage detected