I think it would be pretty possible, have you tried looking at monkey.lua and mermanthin.lua in the scripts file? You might learn something from them.
After a big of skimming through however, it seems that the function you just said makes an object walk in 1 direction with 1 speed, so, in that way, you would need to have some sort of control that reacts to the mouse when clicked, then alter its direction, I don't know if that's so easy.