private void RunBlock(List<String> block)
{
foreach (String rawLine in block)
{
String line = stripComment(rawLine);
commandBuffer += line + "\n";
}
string cmd;
int lineNumber = 0;
int commandLineStart = 0;
while (parseNext(ref commandBuffer, out cmd, ref lineNumber, out commandLineStart))
{
try
{
Line = commandLineStart;
Command cmdObj = Command.Get(cmd, this, commandLineStart);
commands.Add(cmdObj);
}
catch (kOSException e)
{
if (ParentContext.FindClosestParentOfType<ContextRunProgram>() != null)
{
// Error occurs in a child of another running program
StdOut("Error in '" + e.Program.Filename + "' on line " + e.LineNumber + ": " + e.Message);
State = ExecutionState.DONE;
return;
}
else
{
// Error occurs in the top level program
StdOut("Error on line " + e.LineNumber + ": " + e.Message);
State = ExecutionState.DONE;
return;
}
}
catch (Exception e)
{
// Non-kos exception! This is a bug, but no reason to kill the OS
StdOut("Flagrant error on line " + lineNumber);
UnityEngine.Debug.Log("Program error");
UnityEngine.Debug.Log(e);
State = ExecutionState.DONE;
return;
}
}
if (commandBuffer.Trim() != "")
{
StdOut("End of file reached inside unterminated statement");
State = ExecutionState.DONE;
}
}