This article, by Claudio Valderrama, one of the Firebird core developers, shows the possibilities available in Firebird to write general purpose external functions, a.k.a. User Defined Functions (UDFs):
Writing External Functions — A General Guide (pdf)