void * _get_stderr(void * arg) { luaServer_t * s; if ( arg == NULL ) return stderr; s = luaL_getprivate(arg); if ( (s == NULL) || (s->err == NULL) ) return stderr; return s->err; }
void * _get_stdin(void * arg) { luaServer_t * s; if ( arg == NULL ) return stdin; s = luaL_getprivate(arg); if ( (s == NULL) || (s->in == NULL) ) return stdin; return s->in; }
void * _get_stdout(void * arg) { luaServer_t * s; if ( arg == NULL ) return stdout; s = luaL_getprivate(arg); if ( (s == NULL) || (s->out == NULL) ) return stdout; return s->out; }
int lua_init_socket(lua_State * L, pthread_t * pthread, char * hostname, int port) { luaServer_t * p; p = luaL_getprivate(L); if ( p == NULL ) return -1; p->client_socket = -1; p->server_socket = -1; p->socket_port = port; p->hostname = strdup( (hostname) ? hostname : "localhost" ); assert( pthread_create(pthread, NULL, lua_server, p) == 0 ); return 0; }
static int pmain(lua_State *L) { /* open standard libraries */ luaL_checkversion(L); lua_newlibs_init(L); if (handle_luainit(L) != LUA_OK) return 0; /* error running LUA_INIT */ _set_stdfiles(L, luaL_getprivate(L)); dotty(L); _reset_stdfiles(L); lua_pushboolean(L, 1); /* signal no errors */ return 1; }
int lua_init_socket(lua_State * L, pthread_t * pthread, char * hostname, int port) { luaServer_t * p; int r; p = luaL_getprivate(L); if ( p == NULL ) return -1; p->client_socket = -1; p->server_socket = -1; p->socket_port = port; p->hostname = strdup( (hostname) ? hostname : "localhost" ); /* Split assert and function because using NDEBUG define will remove function */ r = pthread_create(pthread, NULL, lua_server, p); assert( r == 0 ); return 0; }