void VerifySyntax()
{
scintillaWrapper.Enabled = false;
try
{
lua_State L = parentComponent.main_L;
int lineIndex = 0;
int lineCount = scintillaWrapper.Lines.Count;
InvokeLua.lua_Reader_RetString ScintillaReader =
delegate(lua_State _L, IntPtr _data, ref size_t sz)
{
if (lineIndex >= lineCount)
{
sz = UIntPtr.Zero;
return "";
}
string line = scintillaWrapper.Lines[lineIndex++].Text;
sz = (size_t)line.Length;
return line;
};
if (InvokeLua.LUA_OK == InvokeLua.lua_load(L, ScintillaReader, IntPtr.Zero, ""))
{
InvokeLua.lua_pop(L, 1);
MessageBox.Show("Syntax verified as correct!",
"Success",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else
{
string error = InvokeLua.lua_tostring(L, -1);
InvokeLua.lua_pop(L, 1);
Match explodedError = Regex.Match(error, @"^\[[^\]]*\]\:(\d+)\:(.*)$");
int lineNum = int.Parse(explodedError.Groups[1].Value);
string message = explodedError.Groups[2].Value;
scintilla.GotoLine(lineNum-1);
SystemSounds.Exclamation.Play();
editor.GUIController.SetStatusBarText("[Line " + lineNum + "]: " + message);
/*
MessageBox.Show("Line " + lineNum + ":\n" + message,
"Syntax Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
*/
}
}
finally
{
scintillaWrapper.Enabled = true;
scintillaWrapper.Focus();
}
}