As others have said if there are items that you must, or wish to, avoid then politely stating so as soon as possible, possibly including giving the host a chance to withdraw the invitation if the restrictions are severe or contrary to point of the invitation, e.g. Shellfish allergy at a clam bake or pork at a hog roast.
Do be prepared to need to clarify the level or degree of restriction - for example I have heard that some strictly kosher practices insist that food cannot be prepared, nor consumed with, equipment and tableware that has been in contact with non-kosher material and some people not only do not consume alcohol they are uncomfortable with others doing so in their presence.
If your restrictions extend to others it is probably better to use the form of "I would love to come but I cannot because...." as in many of the places that I have been placing restrictions on yourself and asking others if they can accommodate them is considered fine, with the proviso of politely stated restrictions and plenty of notice, but attempting to force your restrictions on others is not considered acceptable.
Also it is sometimes necessary to ask for clarification - I had one friend ask what a stew being served at a mass catering even was and on being told it was pork he explained that he had dietary restrictions that forbade pork and said he would go and find something else. The caterer asked if he was OK with beef and offered to see if the beef stew was ready. On checking she stated that it was not ready and offered a ham salad as a "suitable" alternative.
Many people are not aware of what is in the food that we eat ourselves, I am remided of a well known brand of Vegitarian foods that it was revealed the "secret ingredient" that made them taste so good was pork fat, and this can lead to confusion.
Do be aware that you may encounter a certain amount of wry humour if your restrictions seem contradictory, e.g.: I know a number of claimed "vegetarians" who do eat sea food, poultry and bacon - I accommodate them but I may also tease them about it.