static int forEachBarrier(lua_State* L) { RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1)); BarrierManager* barrierMgr = room->GetBarrierMgr(); //pass each barrier to the given function for (auto& it : *barrierMgr->GetContainer()) { lua_pushvalue(L, -1); lua_pushlightuserdata(L, static_cast<void*>(&it.second)); //call each iteration, throwing an exception if something happened if (lua_pcall(L, 1, 0, 0) != LUA_OK) { std::ostringstream os; os << "Lua error: "; os << lua_tostring(L, -1); throw(std::runtime_error(os.str())); } } return 0; }
static int getBarrierMgr(lua_State* L) { RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1)); lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetBarrierMgr()) ); return 1; }