Improve robustness of lua function calling

-   Output of lua_tostring() must not be freed
-   Catch malloc() failure
-   Don't run subsequent code on errors
-   Use lua_pcall() in order to handle lua errors
-   Check type of value returned on the lua stack
-   Fix evbuffer shuffling in error cases