neolithos / neolua

A Lua implementation for the Dynamic Language Runtime (DLR).
https://neolua.codeplex.com/
Apache License 2.0
466 stars 76 forks source link

NeoLua fails to get the correct overload of System.Type.GetMethod #158

Closed Meigyoku-Thmn closed 1 year ago

Meigyoku-Thmn commented 1 year ago

NeoLua Version: 1.3.14 (Nuget)

Example to reproduce:

namespace Target
{
    public class Program
    {
        [MethodImpl(MethodImplOptions.NoInlining)]
        static public string GetMessage()
        {
            return "Try to change this message.";
        }
        static void Main()
        {
            using (var l = new Lua())
            {
                LuaType.RegisterTypeExtension(typeof(RuntimeReflectionExtensions));
                var g = l.CreateEnvironment();
                try
                {
                    var chunk = l.CompileChunk(TestContent, "test.lua", new LuaCompileOptions() {
                        DebugEngine = LuaStackTraceDebugger.Default
                    });

                    g.DoChunk(chunk);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Expception: {0}", e.Message);
                    var d = LuaExceptionData.GetData(e);
                    Console.WriteLine("StackTrace: {0}", d.FormatStackTrace(0, false));
                }
            }
        }
        const string TestContent = @"
            const Assembly          typeof System.Reflection.Assembly
            local getMessageMethod = Assembly:GetEntryAssembly():GetType('Target.Program'):GetMethod('GetMessage')
            print(getMessageMethod)
        ";
    }
}

Error message:

Expception: Value cannot be null.
Parameter name: types

If I try to force the correct overload:

const string TestContent = @"
    const Assembly          typeof System.Reflection.Assembly
    local getMessageMethod = Assembly:GetEntryAssembly():GetType('Target.Program'):GetMethod[string]('GetMessage')
    print(getMessageMethod)
";

Then I get this error:

Expception: Value cannot be null.
Parameter name: name
neolithos commented 1 year ago

The [string] does only work, if use the normal ., not the member call. Btw. the result of string is nil => clr.System.String.

EDIT: I need to add a test case!