moonsharp-devs / moonsharp

An interpreter for the Lua language, written entirely in C# for the .NET, Mono, Xamarin and Unity3D platforms, including handy remote debugger facilities.

Home Page:http://www.moonsharp.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lua code can set table[0], but С# can't read it

Killfrra opened this issue · comments

Setup:

T = {}
T[0] = "something"
Callback(T)
static void Callback(Table table)
{
    foreach(var pair in table.Pairs)
    {
        Console.WriteLine($"{pair.Key} {pair.Value.UserData.Object}");
    }
    DynValue dynObj = table.Get(0);
    Console.WriteLine(dynObj);
}

Result:

0 something
nil

The problem is somewhere here in Table.cs

if (key.Type == DataType.Number)
{
    int idx = GetIntegralKey(key.Number);

    if (idx > 0)
    {
        Set(idx, value);
        return;
    }
}

Set is not called

commented

Set is not called
You can even see in the code, that idx must be bigger than 0 to be called, since indexes in Lua start at 1, NOT at 0 (as it's a general convention and you are recommended to use 1, not 0)