multithreading - How to catch a Lua exception in C# -


i using assembly named luainterface run lua-code inside c# application. during lua execution create winforms & map event handlers (lua-methods) them.

the problem dostring (aka runluacode) method runs init routine , constructors. fine , intended, dostring function acts non blocking function returns while lua-created-forms still there. means exception (null-ref , alike) not raised during constructor not handled lua error handling crashes way wndproc of editor - kills editor , make error handling virtually impossible.

is there way create new thread / process / appdomain handles it's own wndproc sub-task needs handle exceptions?

should block editor @ dostring while loop in lua until forms closed?

what other options have?

any advice on matter appreciated!

another lua enthusiast!! finally! :) toying idea use lua macro scripting in .net apps.

i not sure it. wrote sample code , seems working ok. simple try catch around dostring gets luaexceptions. dostring block main thread unless explicitly create new thread. in case of new thread normal .net multithreaded exception handling rules apply.

example:

public const string scripttxt = @" luanet.load_assembly ""system.windows.forms"" luanet.load_assembly ""system.drawing""  form = luanet.import_type ""system.windows.forms.form"" button = luanet.import_type ""system.windows.forms.button"" point = luanet.import_type ""system.drawing.point"" messagebox = luanet.import_type ""system.windows.forms.messagebox"" messageboxbuttons = luanet.import_type ""system.windows.forms.messageboxbuttons""  form = form() form.text = ""hello, world!"" button = button() button.text = ""click me!"" button.location = point(20,20) button.click:add(function()         messagebox:show(""clicked!"", """", messageboxbuttons.ok) -- throw ex     end)    form.controls:add(button) form:showdialog()";          private static void main(string[] args)         {             try             {                 var lua = new lua();                 lua.dostring(scripttxt);             }             catch(luaexception ex)             {                 console.writeline(ex.message);             }             catch(exception ex)             {                 if (ex.source == "luainterface")                 {                     console.writeline(ex.message);                 }                 else                 {                     throw;                 }             }              console.readline();         }  

luainterface has pretty documentation tricky error handling explained.

http://penlight.luaforge.net/packages/luainterface/#t6

i hope helps. :)


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -