r3_tree_dump can now optionally dump to a string. Fixes #15

Sorry for the mess.
Just cherry pick what you need.