It is a rare thing, but very occasionally, the theatrical stars align. You find yourself looking at a beautifully designed stage, with a cast who knows exactly what they’re doing, surrounded by an audience who is having a great time. Every joke is funny. At the interval, you beat the queue for the ice cream. Quite clearly, the gods of theatre want you to be happy.

Nell Gwynn is the story of one of the seventeenth century’s biggest theatrical stars and a strong contender for best historical rags-to-riches story: Gwynn herself started out as an orange seller in a London theatre, and rose to become a dramatic and comic legend in her own right, as well as Charles II’s mistress. After a decade of Oliver Cromwell’s protectorate, the Restoration was an explosion of colour and light and laughter for the London theatre scene. Here, that’s obvious even before any actor appears onstage – Hugh Durrant’s gorgeous set design is worth coming for on its own, combining the decadence of the Caroline court with the spectacle and variety of Nell’s home territory of the theatre.

Music in a play so inspired by Restoration drama could go one of two ways, as could the jokes – fortunately there’s nothing here that seems overly worthy, or like it has an axe to grind. Emily Baines’s band lurks on its balcony and contributes apparently seamlessly to the atmosphere; and I don’t spot a single joke that fails to hit – more than once there’s an audible “OOOH” from the audience when something dramatic happens. Part of that is down to Jessica Swale’s script, which masterfully treads the line between topical and timeless, between bawdy humour, quick wit, self-awareness and levity. You can see how Nell Gwynn won an Olivier for best new comedy in 2016, and director Christopher Luscombe certainly does it justice.

Luscombe also has a jewel of a cast: Laura Pitt-Pulford is impressive as Nell, standing out in a very strong ensemble. I come away feeling like I understand Gwynn, which is no mean feat. Other highlights include Esh Alladi as grandiose actor Edward Kynaston; Sam Marks as leading man and Nell’s first cheerleader Charles Hart; and Mossie Smith as the well-meaning but often-eavesdropping Nancy. Ben Righton as King Charles is surprisingly sympathetic, and the whole cast is obviously having a lot of fun. That’s great – the audience is right there with them.

If there’s anything that seems a bit out of place, it’s the brief appearance of Nell’s mother in the second half – it’s hard to tell if it’s unnecessary, or just a bit underdeveloped. But now I’m nitpicking: Nell Gwynn combines just enough history and drama to be really good fun. If you get a chance, you should definitely see it.

Nell Gwynn runs at King’s Theatre, Edinburgh until 22nd April.