Concentrate and refine Lua error reporting:

Add a single function that reports errors.

Check global Lua state pointer before using it, just in case Lua wasn't initialized.

Use wrapper lua_dofile instead of luaL_dofile, as it reports errors.
Add wrapper to pass strings for format specifiers from Lua to C++

Lua might send strings containing "%s" or similar, which would be interpreted by popup and add_msg, and both functions would expect further parameters, which Lua does not provide.
Add compatibility for Lua 5.2

Lua 5.1 is still supported.