To complete my comments in response:
According to Lua docs on lua_pcall , pcall returns either success (end of fragment) or the first error. Thus, in the latter case, it will push only one message onto the stack. It will never continue execution after the first error.
What you are trying to achieve is checking for possible errors in the file. In statically typed languages ββsuch as C, each variable must be defined at compile time, so the compiler can determine when a function that does not exist is called.
Lua, however, is a dynamically typed language in which variables have no types, but rather are placeholders for values ββ(which have types). This means that Lua cannot tell in advance whether printMessage function, string, value, or if it does not exist (nil). It is only at runtime when a variable needs to be called that Lua checks its type.
Therefore, it is impossible to achieve what you want. Executing code outside the first unhandled error is also meaningless, since an error can make assumptions in subsequent fragments invalid (for example, about global variables that a non-existent function should have set) - this will be a mess.
As for syntax errors, they usually happen when compiling the source file, i.e. at boot time. However, the Lua parser stops at the first syntax error. This is due to the fact that in many cases, syntax errors in one place invalidate everything that follows it. As Ethan noted in his comment, many parsers report subsequent errors that disappear or change after fixing errors that precede them. This is true for even strong weight parsers such as MSVS.
source share