void * lua_create_instance(void) { luaServer_t * p; lua_State * L; p = (luaServer_t *)calloc(1, sizeof(luaServer_t)); if (p == NULL) return NULL; L = luaL_newstate(); if ( L == NULL ) { free(p); return NULL; } p->client_socket = -1; p->server_socket = -1; p->in = NULL; p->out = NULL; p->err = NULL; luaL_setprivate(L, p); // Make sure we display the copyright string for Lua. luai_writestring(L, LUA_COPYRIGHT, strlen(LUA_COPYRIGHT)); luai_writeline(L); _lua_openlib(L); return L; }
int lua_shell(void * pServer) { int status, result; lua_State *L; L = luaL_newstate(); /* create state */ if (L == NULL ) { l_message(L, "Lua-Shell", "cannot create state: not enough memory"); return EXIT_FAILURE; } luaL_setprivate(L, pServer); /* call 'pmain' in protected mode */ lua_pushcfunction(L, &pmain); status = lua_pcall(L, 0, 1, 0); result = lua_toboolean(L, -1); /* get result */ finalreport(L, status); lua_close(L); return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE; }