FunctionInternal::generateCode now writes to a stream, not a file

Function::generateCode is overloaded to keep the old functionality, but it can now return a string directly