Lua Function print - No output

Apr 2, 2014 at 7:40 AM
Edited Apr 2, 2014 at 7:41 AM
With print() lua Function there is no output.
            using (Lua lTest = new Lua())
            {
                dynamic gTest = lTest.CreateEnvironment();
                try { object[] r = gTest.dochunk(@"
                                                   print('print: Test execution of LUA script with NeoLua');
                                                  ", 
                                                  "Test.lua"); }
                catch (TargetInvocationException e)
                {
                    Console.WriteLine("Expception: {0}", e.InnerException.Message);
                    Console.WriteLine("StackTrace: {0}", e.StackTrace);
                }
            }
NeoLua print function use OnPrint(....)
OnPrint function do Debug.WriteLine(...)
I think it should be: Console.WriteLine(...)
Coordinator
Apr 2, 2014 at 7:43 AM
I decided to use Debug.WriteLine, because I use the script language normally in UI-Applications. And there Console.WriteLine will raise a exception.

Override just OnPrint with Console.WriteLine for Console-Applications.
Apr 2, 2014 at 8:13 AM
To determine if a .NET application is running in GUI mode:
bool is_console_app = Console.OpenStandardInput(1) != Stream.Null;
Source: How can a C# Windows Console application tell if it is run interactively
Alternative : Determine if an executable is a Console Application in C#

Otherwise I proceeded in the following manner:
    public class TestLuaGlobal : LuaGlobal
    {
        public TestLuaGlobal(Lua lua) : base(lua) { }

        protected override void OnPrint(string sText) { Console.WriteLine(sText); }
    }

            using (Lua lTest = new Lua())
            {
                dynamic gTest = new TestLuaGlobal(lTest);
                try { object[] r = gTest.dochunk(@"
                                                   print('print: Test execution of LUA script with NeoLua');
                                                  ", 
                                                  "Test.lua"); }
                catch (TargetInvocationException e)
                {
                    Console.WriteLine("Expception: {0}", e.InnerException.Message);
                    Console.WriteLine("StackTrace: {0}", e.StackTrace);
                }
            }
Coordinator
Apr 2, 2014 at 9:13 AM
I created a Issue, I will add this to the next release.

Thx, for testing.
Marked as answer by PapyRef on 4/3/2014 at 8:43 AM