LUAMOD_API int luaopen_time(lua_State *L) { /* create sentinel */ loski_TimeDriver *drv = (loski_TimeDriver *)luaL_newsentinel(L, sizeof(loski_TimeDriver), lua_sentinel); /* initialize library */ if (loski_opentime(drv) != 0) { luaL_cancelsentinel(L); return luaL_error(L, "unable to initialize library"); } /* create library table */ luaL_newlibtable(L, lib); lua_pushvalue(L, -2); /* push sentinel */ luaL_setfuncs(L, lib, 1); return 1; }
LUAMOD_API int luaopen_process(lua_State *L) { /* create sentinel */ luaL_newsentinel(L, lp_sentinel); /* create process class */ lua_pushvalue(L, -1); /* push sentinel */ luaL_newclass(L, LOSKI_PROCESSCLS, cls, 1); lua_pop(L, 1); /* remove new class */ /* create library table */ luaL_newlibtable(L, lib); lua_pushvalue(L, -2); /* push sentinel */ luaL_setfuncs(L, lib, 1); /* initialize library */ if (loski_openprocesses() != 0) { luaL_cancelsentinel(L); return luaL_error(L, "unable to initialize library"); } return 1; }
LUAMOD_API int luaopen_network (lua_State *L) { /* create sentinel */ loski_NetDriver *drv = (loski_NetDriver *)luaL_newsentinel(L, sizeof(loski_NetDriver), net_sentinel); /* initialize library */ if (loski_opennetwork(drv) != 0) { luaL_cancelsentinel(L); return luaL_error(L, "unable to initialize library"); } /* create abstract base socket class */ lua_pushvalue(L, -1); /* push sentinel */ luaL_newclass(L, loski_SocketClasses[LOSKI_BASESOCKET], NULL, sck, 1); lua_pop(L, 1); /* remove new class */ /* create TCP listening socket class */ lua_pushvalue(L, -1); /* push sentinel */ luaL_newclass(L, loski_SocketClasses[LOSKI_LSTNSOCKET], loski_SocketClasses[LOSKI_BASESOCKET], lst, 1); lua_pop(L, 1); /* remove new class */ /* create streaming socket class */ lua_pushvalue(L, -1); /* push sentinel */ luaL_newclass(L, loski_SocketClasses[LOSKI_STRMSOCKET], loski_SocketClasses[LOSKI_BASESOCKET], str, 1); lua_pop(L, 1); /* remove new class */ /* create TCP connection socket class */ lua_pushvalue(L, -1); /* push sentinel */ luaL_newclass(L, loski_SocketClasses[LOSKI_CONNSOCKET], loski_SocketClasses[LOSKI_STRMSOCKET], cnt, 1); lua_pop(L, 1); /* remove new class */ /* create UDP socket class */ lua_pushvalue(L, -1); /* push sentinel */ luaL_newclass(L, loski_SocketClasses[LOSKI_DGRMSOCKET], loski_SocketClasses[LOSKI_STRMSOCKET], dgm, 1); lua_pop(L, 1); /* remove new class */ /* create library table */ luaL_newlibtable(L, lib); lua_pushvalue(L, -2); /* push sentinel */ luaL_setfuncs(L, lib, 1); return 1; }