I am using the an assembly named LuaInterface to run lua-code inside my C# application. During the lua execution I create some WinForms & map event handlers (lua-methods) to them.
The problem is that the doString
(aka runLuaCode
) method only runs the init routine and the constructors. This is fine and intended, however the doString
function acts non blocking so the function returns while the Lua-created-Forms are still there. This means that any exception (null-ref and alike) which is not raised during the constructor is not handled by the lua error handling an crashes all the way up to my wndProc of my Editor - which most likely kills my editor and make error handling virtually impossible.
Is there any way to create a new Thread / Process / AppDomain that handles it's own WndProc so that only this sub-task needs to handle the exceptions?
Should I block my Editor at the doString with a while loop in lua until the forms are closed?
What other options do I have?
Any advice on this matter is greatly appreciated!
Another Lua enthusiast!! Finally! :) I am also toying with the idea to use Lua for macro scripting in my .NET apps.
I am not sure I get it. I wrote some sample code and it seems to be working ok. Simple try catch around DoString gets the LuaExceptions. DoString does block the main thread unless you explicitly create a new thread. In case of a new thread normal .NET multithreaded exception handling rules apply.
Example:
LuaInterface has a pretty good documentation where tricky error handling is explained.
http://penlight.luaforge.net/packages/LuaInterface/#T6
I hope it helps. :)