0

I am trying to integrate a Lua Scripting interface into my C# project by using LuaInterface.

It works as expected if I execute syntactically correct code, but as soon as a syntax error (or any other error as it seems) is introduced to the script an SEHException gets thrown without any information regarding the error.

A simple example to trigger the behavior: new LuaInterface.Lua().DoString("die");

That of course completely nullifies Lua's error handling mechanisms and is a show-stopper for me.

Apparently this is a known bug which is open since 2011.

Are there any workarounds, a version of LuaInterface without this bug or is there an alternative lua wrapper which correctly handles errors?

M.Stramm
  • 1,289
  • 15
  • 29

1 Answers1

2

Lua errors (syntax or runtime errors) encountered by DoString should result in a LuaException being thrown. Its message will contain the error string generated by Lua. For instance, given your example:

try
{
    new LuaInterface.Lua().DoString("die");
}
catch (LuaException ex)
{
    Console.WriteLine(ex.Message);
}

You should get the following error:

[string "chunk"]:1: '=' expected near '<eof>'

You don't show any context for your one liner. Is it wrapped in a try-catch block?

If so, perhaps it's a bug?

Mud
  • 28,277
  • 11
  • 59
  • 92
  • My one-liner is not wrapped in a try-catch block. Even if I do wrap it, the exception is still an SEHException, not a LuaException, so it doesn't get thrown. Apparently it is a bug. Now the question remains: How to work around it? – M.Stramm Nov 30 '12 at 00:06
  • Alright, I disabled Debugging-Break when Exceptions cross AppDomain or managed/native boundary and that made it work. It is not pretty, but whatever. – M.Stramm Nov 30 '12 at 02:10