Just a quick suggestion.

Using things like $nul=SetOption("WrapAtEOL","on") do you need this for your function to work? Or is this just a best coding practice?

Either way, may I suggest that the black box method of UDF's is a good idea. Basically this means any UDF should take into consideration the status of SetOptions from the parent script. For example, I just wrote a UDF a few days ago where I needed novarinstrings turned on, i was using Execute with code stings put together based off of UDF options.

Since i needed novarinstrings, when i turned that option on, i also captured the current status, and the last thing i did before exiting the UDF was return novarinstrings back to it's original value.

This way, i can code my UDF that way i wanted to with out forcing someone else to convert to my coding preferences/needs.

Everything else looks good!