Buffer.prototype.write encoding fixes

Fixes #690 and some other write method parameter handling.
The `tonumber(length)` on was leftover from the old code. I've gotten rid of it. If no arguments past the original string are not passed, the length variable will not be used.