You go to your embassy/consulate in that country (or whichever other embassy has an agreement to help if your country doesn't have one) and ask for an "emergency passport" which will allow you to take a specified route back to your own country, passing through intermediate countries and spending a while there if part of your itinerary.
Normally this takes a couple of days to arrive: if you have a flight you're probably screwed, and if you have longer to wait you might be able to wait for a full passport to arrive. The country you're in might want you to go and visit their immigration office to get letters/stamps explaining your original visa went missing too (India's is particularly painful)
Having a scan of your original passport is going to help a lot (especially if hotels/guesthouses need to see your passport), but your own passport office will have your original passport details on file somewhere, so amongst other things they can confirm your application for a replacement passport is likely to be genuine.
If you need cash, there's Western Union. A good travel insurer's phone line might be able to advise on stuff like this as well as process your claim.
I know this from the experience of losing passports twice...