Hi Abou,
Having a generic swap coupon class, that could take a payoff script would be useful and of course would fit in nicely. However we would need some payoff script support, which is not currently in QuantLib, so we would need to use something else (maybe like muparser?).
Then for pricing a generic script, you would normally use MonteCarlo which would be fine for T0 pricing but in an XVA context it could be quite slow.
Do you want to start working on this and submit a merge request?
Regards,
Niall.