Fix segmentation fault and attempt to call nil in callbacks

The commit messages are quite verbose, so I don't have much to say here.

Both the bugs can be reproduced from 93f3d0cc16 (the actual HEAD). For your convenience:
* 963ed75 : https://gist.github.com/FunkyAss/f1ce008accf3008886e0
* f307002 : https://gist.github.com/FunkyAss/c73715fc1acadb858899

A couple of thoughts about the actual codebase (not directly related to the patches, but working on them "inspired" me):
1) calling ```luaL_error``` as ```return luaL_error``` will not fix any error or unintended behaviour, but could make some of them easier to spot;
2) it's plenty of luaL_error. A lua script with proper error checking will probably be full of ```pcall```s (with their overhead) and maybe string manipulation functions (for checking error messages);