Log In  

Hi Zep! :)

0.2.5g: In non-C-style for loops, if a multi-line comment is opened/closed before the first variable declaration, without trailing whitespace before the variable name, it will throw a syntax error. All other situations seem to be okay:

--[[ok]]foo = --[[ok]]{1}

--ok
for --[[ok]]i=0,1 do
    print(foo[i])
end

for --[[ok]] v in all(foo) do
    print(v)
end

for --[[ok]] k, --[[ok]]v in pairs(foo) do
    print(v)
end

for --[[ok]] k, --[[ok]]v in ipairs(foo) do
    print(v)
end

--not ok
for --[[oops]]v in all(foo) do
    print(v)
end

for --[[oops]]k, --[[ok]]v in pairs(foo) do
    print(v)
end

for --[[oops]]k, --[[ok]]v in ipairs(foo) do
    print(v)
end
P#125822 2023-02-13 21:00 ( Edited 2023-02-13 21:02)

I wonder how vanilla lua handles these.

Edit: Well, the lua 5.3.4 that I apparently installed on this PC at some point says they're all ok.

P#125872 2023-02-15 03:44 ( Edited 2023-02-15 03:47)

@Felice Oops, thx, I forgot to mention I tried it on 5.4 and found it was legal. I would normally never shove comments in the middle of a line like this but Shrinko8 annotations require it

P#125874 2023-02-15 04:03
2

Same with:

function --[[oops]]f() end
P#130295 2023-05-29 21:19

Fileinput, it appears.Generate is what FileInput is. As a result, it can only be iterated over once until all elements are eaten and executing the next method of the object raises StopIteration.

geometry dash lite

P#134267 2023-09-13 09:59 ( Edited 2024-03-12 08:05)
2

I ran into this as well (https://www.lexaloffle.com/bbs/?tid=54395)

I have a few things to add here: the first "ok" example doesn't work for me:

for --[[oops]]i=0,1 do
    print(i)
end

(this prints "[nil]", instead of "0 1")

And here's another interestingly-broken case:

for                --[[spaaaace]]k=0,1 do
  print(k)
end
print(fork)

This prints "[nil] 0" -- it seems that the preprocessor is accidentally removing all leading spaces before the comment, leading to the equivalent of this code:

fork=0,1

do print(k) end --nil

print(fork) --0
P#135434 2023-10-05 04:30 ( Edited 2023-10-05 22:44)
1
P#135435 2023-10-05 04:59

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 00:56:50 | 0.012s | Q:21