Getting an error code back when a Lua script dies is actually pretty straightforward. Use lua_pcall() or one of its relatives to call the script and the return value will tell if there's been a run time error.
This little snippet will load up a script and run it. If something goes wrong you'll get a message, not just a blank stare. This sort of stuff, detailed error-handling, is often left for the end but I believe it's very useful to developers and while the project is being built. The earlier you build-in explicit, clear error codes the more robust the application will be. I've seen many cases where a program is designed and built then error-checking is bolted on at the end. What ends up happening is that there's no communication channel for the error information to reach the right end-point. Instead message boxes start popping up for the user and the program can't cope with problems that could have been handled internally.
But I digress. The first switch in the above code checks for errors that occur while running the script. The second switch is concerned with diagnosing an error that happened while loading the script from a file. The information provided isn't very detailed. This might be sufficient for some cases, depending how large and involved your codebase is. There are debuggers that will help you through Lua code which may reduce the need in some cases for more detailed information. Still, we usually like to at least see a stack trace. This can be achieved by supplying an error-handler function to pcall.
While the documentation for lua_pcall() mentions the idea of dumping a stack trace for a runtime error, there don't seem to be many accessible examples of doing this. I found a thread about lua_pcall() error functions on a mailing list that seems to have some clues about a function that's part of the Lua source which may do what I want. I'll do a little more digging and elaborate if I find anything good.