* Judge says parliament lacked quorum to enact law
* State free to appeal ruling nullifying legislation
* Activists say law violates constitutional rights
* Western donors have cut aid in protest (Adds White House comment)
By Elias Biryabarema
KAMPALA, Aug 1 (Reuters) - Uganda's constitutional court on Friday overturned an anti-homosexuality law that punished gay sex with long prison sentences and was condemned by Western and other donors, some of whom withheld aid in protest.
The new ruling, which can be appealed, voids a statute signed into law by the president in February and which had broad support in the religiously conservative east African nation.
Under the Anti-Homosexuality Act, those convicted of "aggravated homosexuality" - defined as someone with HIV having gay sex or gay sex with anyone vulnerable, such as a disabled person - would be put in prison for life.
Homosexuality is a taboo issue in much of Africa and is illegal in 37 countries on the continent. But the punishments laid out in Uganda were among the harshest.
Citing irregularities in the way the law was passed, Judge Steven Kavuma said the speaker of parliament had acted illegally by not accepting objections pointing to the fact that there was no quorum for a vote.
"The Act itself so enacted by this reason alone is unconstitutional," he said.
Lawyers said the constitutional court ruling could be challenged through an appeals process.
Fear of violence, imprisonment and loss of jobs mean few gays in Africa are open about their sexuality.
The United States, Uganda's biggest donor, called the legislation "atrocious", likening it to anti-Semitic laws in Nazi Germany and apartheid in South Africa. When it was passed, Washington said it would review relations with Kampala.
Ugandan President Yoweri Museveni is scheduled to travel to the United States next week for a summit of African leaders hosted by U.S. President Barack Obama.
Museveni is to hold a press conference on Saturday and is likely to comment on the court's ruling.
The White House welcomed the court's decision.
"This is an important step in the right direction for human rights, not just of the LGBT (lesbian, gay, bisexual and transgender) community, but of all Ugandans," said Ned Price, a spokesman for the White House National Security Council.
Ethics and Integrity Minister Simon Lokodo, who has in the past said that aid should not be tied to Uganda's stand on homosexuality, declined to comment on the ruling.
The World Bank and some European donors - Norway, Denmark and the Netherlands - withheld aid or loans worth more than $118 million. Sweden resumed financial support to Uganda this week.
Uganda relies on aid to fund about 20 percent of its budget.
The Ugandan shilling came under pressure when the law was passed. On Friday, it rose, with banks cutting long dollar positions on expectations of a resumption in aid.
The government had resisted Western pressure to rescind the law but in July Kampala said that donors had "misinterpreted" the measure, saying it was to prevent the promotion of gay sex to children, not to punish or ostracise homosexuals.
Ugandans opposed to the law had brought a petition to the constitutional court, saying that the law violated fundamental rights. This aspect was not addressed by the judge.
"I welcome the ruling although I would have loved the judge to go into the substance of our petition," said Frank Mugisha, executive director of Sexual Minorities Uganda.
"That's where he would have realised that the law violates the Constitution of Uganda and (I) am sure he would have gone ahead to declare homosexuality legal in Uganda."
The law also criminalised lesbianism for the first time and made it a crime to help individuals engage in homosexual acts.
"This decision is a bright spot in a dark record on human rights," Asia Russell, Uganda-based director of international policy at Health GAP, an HIV advocacy group.
During the bill signing, Museveni had said homosexuality was emblematic of the West's "social imperialism" in Africa. Powerful Christian groups with links to U.S. evangelical groups have labelled homosexuality an imported Western social evil.
"We're wondering whether the ruling is in any way related to the president's travel to America because Obama has made it clear his No. 1 policy agenda is advancing homosexualism," said Pastor Martin Ssempa, one of the evangelical pastors who were most instrumental in pushing for the law. (Additional reporting by Roberta Rampton in Washington; Writing by James Macharia; Editing by Edmund Blair/Mark Heinrich)