To wrap up my comments into an answer:
According to Lua docs on lua_pcall
, pcall returns on either success (end of chunk) or first error thrown. So in the latter case, it will push only one message to the stack. It will never continue execution after the first error.
What you're trying to achieve is checking for possible errors in the file. In statically typed languages like C, every variable has to be defined at compile time, so the compiler can spot instances of calling non existing function.
Lua, however, is a dynamically typed language, in which variables have no types but rather are placeholders for values (which do have types). This means, that Lua cannot tell in advance whether printMessage
is a function, a string, a value or if it doesn't exist (nil). It is only at run time when the variable is about to be called that Lua checks its type.
It is therefore not possible to achieve what you want that way. Running the code beyond the first unhandled error is pointless as well, as the error may render assumptions in subsequent fragments invalid (for instance about global variables that the non existing function should have set) - it would be a mess.
As to syntax errors, these are generally caught when compiling the source file, that is while loading. However, Lua parser stops at first encountered syntax error. This is due to the fact that many times syntax errors in one place invalidate everything that follows it. As Etan pointed out in his comment, many parsers report subsequent errors that disappear or change once you've fixed errors that precede them. It is also true for even heavy weight parsers like those in MSVS.