The correct answer is: C. I was having dinner with some friends last night when you came.

The other options are incorrect because they use the past perfect tense, which is used to talk about an action that was completed before another action in the past. In this case, the action of "coming" happened after the action of "having dinner," so the past perfect tense is not appropriate.

The past progressive tense is used to talk about an action that was in progress at a specific time in the past. In this case, the action of "having dinner" was in progress at the time when "you came." Therefore, the past progressive tense is the correct tense to use.

The other options are also incorrect because they use the wrong words. Option A uses the past tense form of "have," which is incorrect because the action of "having dinner" was in progress at the time when "you came." Option B uses the present perfect tense form of "be," which is incorrect because the action of "having dinner" was in progress at a specific time in the past. Option D uses the simple present tense form of "come," which is incorrect because the action of "coming" happened after the action of "having dinner."