0

I am trying to get a list of all the syntax errors in a Lua script, using MoonSharp. I have the following code, where the variable code is the Lua script:

try
{
   Script.RunString(code);
   return "";
}
catch (SyntaxErrorException ex)
{
   return Convert.ToString(ex);
}

But it only gives me the first syntax error. Is there a way to get a list of all errors? Would a different library to MoonSharp be a good idea?

EchoDevG
  • 3
  • 3
  • 1
    It's usually not possible for an interpreter to detect more than one syntax error at a time. The first syntax error is just where the code becomes invalid. Since the interpreter can't guess what you were really trying to do, it can't figure out where the code becomes "valid" again and start looking for the next syntax error. – luther Feb 01 '23 at 03:53
  • Your script depends on `code` halting. If `code = "while 1 do end"`, your program won't halt. You should at most *load* the code, but not *run* it if you're only interested in finding the first syntax error (because as luther explained, you can't get a "list of" syntax errors). – Luatic Feb 01 '23 at 11:14

0 Answers0