Neo.IronLua.LuaRuntimeException: Property/field 'WriteLine' must be unique.

Mar 29, 2014 at 8:28 AM
Edited Mar 29, 2014 at 8:28 AM
I got LuaRuntimeException with this C# Code
        using (Lua lTest = new Lua())
        {
            LuaGlobal lgTest = lTest.CreateEnvironment();
            lgTest.RegisterPackage("console", typeof(System.Console));
            dynamic gTest = lgTest;

            try { object[] r = gTest.dochunk("console.WriteLine(\"Test execution LUA script by NeoLua\");", "Test.lua"); }
            catch (TargetInvocationException e)
            {
                Console.WriteLine("Expception: {0}", e.InnerException.Message);
                Console.WriteLine("StackTrace: {0}", e.StackTrace);
            }
        }
InnerException.Message: Property/field 'WriteLine' must be unique.

Can you explain me why I get this error?
Coordinator
Mar 29, 2014 at 12:08 PM
Edited Mar 29, 2014 at 12:13 PM
console.WriteLine is translated to get member "WriteLine" and call the result:
Delegate dlg = getMember(console, "WriteLine");
dlg.DynamicInvoke("a");
For members there is no concept of overloading. To call overloaded methods you must use the colon (console:WriteLine).
callMember(console, "WriteLine", "a");
NeoLua takes care of self parameter, that might be existing. In this example it is set to null.

There are to ways to call WriteLine:
1.
local console = clr.System.Console;
console:WriteLine('Test');
2.
g.RegisterPackage("console", typeof(System.Console));
g.DoChunk("console:WriteLine('a');");
BECAREFUL: The secound way works in NeoLua 0.8.3. I found a little error on Static-Calls on static classes :).
Mar 29, 2014 at 12:57 PM
Edited Mar 29, 2014 at 12:58 PM
OK, Where can I download NeoLua 0.8.3?
Current version version on Codeplex & Nuget is 0.8.2.

Rem : I wonder if there is not a problem with the lib on Nuget. Look at response of Mud on StackOverflow. I do not to worry because I have not used the installation via Nuget.
Coordinator
Mar 29, 2014 at 1:02 PM
I will upload this version on sunday. Because, I just fixed it.

I am thinking to allow to select the overloaded function:
console.WriteLine[clr.System.String]('Hallo Welt');
Is this confusing?
Coordinator
Mar 29, 2014 at 1:41 PM
Edited Mar 29, 2014 at 1:43 PM
PapyRef wrote:
Rem : I wonder if there is not a problem with the lib on Nuget. Look at response of Mud on StackOverflow. I do not to worry because I have not used the installation via Nuget.
Would be nice to know the exception?
And thanks for the response to the comment. May be he will show up?
Mar 29, 2014 at 1:49 PM
First way, It's OK.
I'll wait for the update 0.8.3 to testing secound way.
Coordinator
Mar 30, 2014 at 3:42 PM
Edited Mar 30, 2014 at 6:16 PM
It is now possible to write.
using(Lua l = new Lua())
{
  dynamic g = l.CreateEnvironment();
  g.console = LuaType.GetType(typeof(Console));
  g.dochunk("console.WriteLine('test');");

  g.console.WriteLine('Test'); // should also work

  g.dochunk("c = console.WriteLine[clr.System.String];"); // access a special overload
  g.c('Hallo');
Hopefully, I did not break other things.

Becareful with the get-member syntax, it creates a new object for the overloaded members:
console.WriteLine('test');
will be translated to:
c = getMember console,"WriteLine";
Invoke(c, 'Test');
Marked as answer by PapyRef on 4/3/2014 at 8:44 AM