もう一人のLuaマニア!! ついに!:) また、Lua を使用して .NET アプリのマクロ スクリプトを作成するというアイデアも考えています。
よくわかりません。サンプルコードを書きましたが、問題なく動作しているようです。DoString を単純に try catch すると、LuaExceptions が取得されます。新しいスレッドを明示的に作成しない限り、DoString はメイン スレッドをブロックします。新しいスレッドの場合、通常の .NET マルチスレッド例外処理規則が適用されます。
例:
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) -- this will throw an 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 には、トリッキーなエラー処理が説明されている非常に優れたドキュメントがあります。
http://penlight.luaforge.net/packages/LuaInterface/#T6
お役に立てば幸いです。:)