Oh, I can relate...spent a lot of time at school feeling like that, and it sometimes happens in halls at uni as well if my flatmates ask people round. It got to the point in high school that I'd try and avoid being round people completely as far as possible - I'd spend breaks in the library (or toilets if the library was shut), go home for lunch, arrive just in time so I wouldn't have to wait before the bell...

Like you say, if you're actually alone, it's fine. Feeling alone while surrounded by people is horrible, though.
Anyway, this was something I brought up in therapy - my therapist suggested that I might have social anxiety, and we did exposure therapy for it. One of the hardest ones for me was spending my free periods in the dining room instead of the library - I was in S6 (final year at high school in Scotland), and by that point I didn't really have anyone I could call a friend at school. I was sure that if I went in people would either ignore me or tell me I couldn't sit with them.
But I managed to work up the courage to go in anyway...at first I sat at a table by myself, but the next time, my therapist persuaded me to sit at a table with others. And they didn't turn me away! I was amazed...ok, they didn't really talk to me much, but for once I actually felt included.
So I think the trick, although it's hard to do, is to ask directly if it'd be ok if you sat down with them to eat. If you cook your own food then you don't need to worry about asking to eat theirs (I'd be worried about being rude

), but if you're at the same table then you're more likely to feel included. You don't even have to talk much, just listen and contribute when you can.
Hope I helped a little!