moonsharp icon indicating copy to clipboard operation
moonsharp copied to clipboard

Bug in Varargs when no parameters is passed to a function

Open fgretief opened this issue 8 years ago • 1 comments

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
>

fgretief avatar Jul 26 '17 13:07 fgretief

Fix in #324

Joy-less avatar Aug 12 '23 22:08 Joy-less