Skip to content

Bug in Varargs when no parameters is passed to a function #198

@fgretief

Description

@fgretief

I found an issue with varargs under MoonSharp.

In Lua v5.2 when you do a select('#', ...) in a function that has no inputs, the count returns 0 as expected, but in MoonSharp it returns 1. The print confirms that the input is actually nil instead of being empty.

Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> function x(...) print(select('#', ...), ...) end
> x()
0                    <-- correct
> x('a')
1       a
> x('a','b')
2       a       b
> x(nil)
1       nil          <-- correct
> x(nil, 'b')
2       nil     b
>
MoonSharp Console 2.0.0.0 [std.dotnet.clr4]
Copyright (C) 2014-2016 Marco Mastropaolo
http://www.moonsharp.org


Type Lua code to execute it or type !help to see help on commands.

Welcome.

> function x(...) print(select('#', ...), ...) end
> x()
1       nil          <-- wrong
> x('a')
1       a
> x('a', 'b')
2       a       b
> x(nil)
1       nil          <-- correct
> x(nil, 'a')
2       nil     a
>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions