dnGLua/API

Wrap array-returning APIs

Opened this issue · 0 comments

Currently, it is inconsistent and also confusing whether a developer should use 0-based indexing or 1-based indexing.
For example:

print(player.GetAll()[1])

The above code will actually not work, a temporary workaround is available for dealing with this issue:

print(player.GetAll().get(1))

The get method uses 1-based indexing and will therefore return the first player from the table.

Another example is that someone may be tempted to iterate players like so:

foreach (var ply in player.GetAll()) {
    print(ply.Name);
}

However that does not work currently, a temporary workaround is available for dealing with this issue:

player.GetAll().each((ply) => {
    print(ply.Name);
});

By using custom loop API, you will get the expected result.