Implement scalarfunc macro.

Wraps an arbitrary function such that it can be passed to the registerfunc
function.
Handle functions which throw errors in scalarfunc.
Export correct funcs and rename sqlerror.