How can I redirect the output of the print function ?

script.Options.DebugPrint = s => { Console.WriteLine(s); }

How can I redirect the input to the Lua program ?

script.Options.DebugInput = () => { return Console.ReadLine(); }

How can I redirect the IO streams of a Lua program ?

IoModule.SetDefaultFile(script, Platforms.StandardFileType.StdIn, myInputStream);
IoModule.SetDefaultFile(script, Platforms.StandardFileType.StdOut, myOutputStream);
IoModule.SetDefaultFile(script, Platforms.StandardFileType.StdErr, myErrorStream);

How can I limit the number of instructions a script will execute without losing state ?

See Preemptive coroutines.