[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Strange string.format result
- From: bil til <biltil52@...>
- Date: Sat, 26 Nov 2022 00:03:58 +0100
PPS: Maybe one (hopefully last - sorry...) further test result:
> print( string.format( "%d %d %d", select( 1, 3, 4, 5)))
3 4 5
> print( string.format( "%d %d %d", select( 1, 3, 4, 5), 6, 7))
3 6 7
... here the same happens somehow, as soon as I add further parameters
after the select function, the select function result is shortened to
only one return...
Am Fr., 25. Nov. 2022 um 23:56 Uhr schrieb bil til <biltil52@gmail.com>:
>
> PS: The following also might be interesting:
> > do
> >> function Test() return 3, 5 end
> >> s= string.format( "%d %d", Test(), 4)
> >> end
> > s
> 3 4
>
> ... so it looks like the '...' of string.format somehow keeps only the
> first return value of Test, except if Test function is the last
> parameter... . Is this normal?
>
> (I thought, that for such "further parameter stripping" it would be
> required to specify this explicitely by brackets like in s=
> string.format( "%d %d", (Test()), 4)? (this gives the same as above,
> in this case it is clear to me...).
>
> Am Fr., 25. Nov. 2022 um 23:46 Uhr schrieb bil til <biltil52@gmail.com>:
> >
> > If I do the following in Lua 5.4:
> > > do
> > >> function Test() return 3, 5 end
> > >> s= string.format( "%d %d %d", 4, Test())
> > >> end
> > > s
> > 4 3 5
> > ... this is as expected...
> >
> > > do
> > >> function Test() return 3, 5 end
> > >> s= string.format( "%d %d %d", Test(), 4)
> > >> end
> > stdin:3: bad argument #4 to 'format' (no value)
> > stack traceback:
> > [C]: in function 'string.format'
> > stdin:3: in main chunk
> > [C]: in ?
> > ... this somehow does NOT work as I would expect... (I would expect
> > that s now is '3 5 4')
> >
> > (if I debug with breakpoint in str_format, then the top of stack ( int
> > top = lua_gettop(L);) is only 3 in this last case... in first case it
> > is 4 as expected.... .
> >
> > Is this some error of Lua, or do I miss here something?