static int hop_create(lua_State *L) { snHopLoop *src = createLoop(L); if (!src) return luaL_error(L, "Could not create snHopLoop."); snHopLoop *hloop = lua_newuserdata(L, sizeof(snHopLoop)); if (!hloop) { free(src); return luaL_error(L, "Could not create snHopLoop."); } memcpy(hloop, src, sizeof(snHopLoop)); luaL_getmetatable(L, "pl.makenika.hoploop"); lua_setmetatable(L, -2); int i = 0; for (i = 0; i < SN_SETSIZE; i++) { hloop->events[i].mask = SN_NONE; hloop->timers[i].mask = SN_NONE; } hloop->shouldStop = 0; hloop->api->addEvent = addEvent; hloop->api->removeEvent = removeEvent; hloop->api->poll = poll; hloop->api->setTimeout = setTimeout; hloop->api->setInterval = setInterval; hloop->api->clearTimer = clearTimer; free(src); return 1; }
int main() { try { List<int>* list = new List<int>(); createList(list); createLoop(list); Node<int>* loopHead = getLoopPoint(list); if( NULL != loopHead ) cout << "found loop head to be : " << *loopHead << endl; else cout << "No loop detected." << endl ; } catch( const char* msg) { cout << "Exception occured : " << msg ; } // deleting looped list will also result in segmentation fault return 0; }