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

first line in Lua script starting with # causes error "expected statement near '#'" #211

Closed
okroth opened this issue Feb 10, 2021 · 6 comments

Comments

@okroth
Copy link

okroth commented Feb 10, 2021

Lua allows at the top of a Lua script a special line starting with # to support the shebang mechanism of Unix shells.
The Lua interpreter skips such a line.
I could not find an option to let luacheck do the same

@okroth
Copy link
Author

okroth commented Feb 10, 2021

I found that in lexer.lua, line 690, there IS a test for a shebang line, but it requires the line to begin with #! , where the Lua interpreter just requires the line to begin with # .

@linuxmaniac
Copy link
Contributor

please read #198

@alerque
Copy link

alerque commented Oct 7, 2021

I think this may be a case where Lua is wrong and we can ignore what it might have allowed. As far as I know the so called hashbang / shebang must actually be both characters to valid for the use case of specifying a script interpreter. Are there really any other valid use case that shouldn't throw a warning?

In any event if you still think this is an issue we should address, please open a new issue on the new official repository. As the previous commenter noted the maintainer of this one passed away and we have no way to resolve issues here any more. It would be appreciated if you close this to help us track what is dealt with and (if applicable) open a new issue on the active repository. Thanks!

@okroth
Copy link
Author

okroth commented Oct 7, 2021

We have a different use case, where the first line contains a digital signature of the rest of the Lua script, which is hidden from the Lua interpreter by the #-character.
In the meantime we simply modified the lexer.lua in our copy to look only for the '#' and not the '!'

@okroth okroth closed this as completed Oct 7, 2021
@alerque
Copy link

alerque commented Oct 7, 2021

I think a bit more orthodox way to do this would be to use a Lua comment, somewhat like luacheck does to pass cues to itself, something like:

-- signature: <hash>
print("rest of script")

Overloading the idea of a hashbang for this seems like an edge case that probably shouldn't be allowed. That Lua handles it is probably a mistake or lazy parsing shortcut and you might not want to rely on it.

Of course it is open source and you can do what you like, but as a the current maintainer I'm not convinced this is something we should accommodate in the regular releases.

@okroth
Copy link
Author

okroth commented Oct 7, 2021

retrospectively, the comment would have been the better choice, but I can't change it any more.

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

3 participants