Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print function stops printing if there is a nil present in the input array. #78

Closed
alekso56 opened this issue Dec 24, 2015 · 7 comments
Closed

Comments

@alekso56
Copy link

Originally Kubuxu came up with this bug/feature request linked here:
Kubuxu/ComputercraftLua@17dd0e4

VERSION:
1.41 to 1.76 (probably earlier too)
DESCRIPTION:
i typed print(1,2,nil,3) and it printed 1 2
EXPECTED RESULT:
1 2 nil 3
REPRODUCTION STEPS:
lua -> print(1,2,nil,3)

@KnightMiner
Copy link

This is intended, as any function that takes an unlimited number of parameters stops after the first nil. In fact, lua tables don't even keep nil values (converting any values after a nil to key indexed values rather than keeping the array), which makes taking all parameters after the nil next to impossible to do efficiently.

Find an alternate way to print the values, such as removing the value from the table entirely, or checking for nil before adding it.

@BombBloke
Copy link
Contributor

Kubuxu says spec is to print the whole list, you say it's spec not to. Where do you guys get these specs from?

FWIW, I'd run a basic "for n = 1, whatever do" loop that manually indexes into the arg table on each iteration. Either use #arg or arg.n in place of "whatever", depending on the desired behaviour. As far as I'm aware, this'd be more efficient than calling an iterator function every time the loop repeats, wouldn't it be?

@KnightMiner
Copy link

My assumption is based on how the Lua manual seems to advise using ipairs for the illiterator for ... parameters, combined with the fact that stopping upon reaching a nil value is expected behavior in most other ComputerCraft functions

@dan200
Copy link
Owner

dan200 commented Dec 25, 2015

Standalone lua is the reference implementation. Somebody test it in that?
On 25 Dec 2015 17:01, "KnightMiner" notifications@github.com wrote:

My assumption is based on how the Lua manual seems to advise using ipairs
for the illiterator for ... parameters, combined with the fact that
stopping upon reaching a nil value is expected behavior in most other
ComputerCraft functions


Reply to this email directly or view it on GitHub
#78 (comment)
.

@Wojbie
Copy link
Contributor

Wojbie commented Dec 25, 2015

According to http://www.lua.org/cgi-bin/demo
It prints word nil.
input

print(1,2,"ala",3,nil,a,v,c,d,1)

output

1   2   ala 3   nil nil nil nil nil 1

@dan200
Copy link
Owner

dan200 commented Dec 25, 2015

Sounds like a worthwhile change then. Will fix

@dan200
Copy link
Owner

dan200 commented Dec 25, 2015

Fixed for 1.77

@dan200 dan200 closed this as completed Dec 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants