teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.03k stars 101 forks source link

tl removes shebang in scripts #646

Closed nagolove closed 8 months ago

nagolove commented 1 year ago

Hello! I use some Lua files as system scripts with executable bits and shebang at first line.

#!/usr/bin/env lua
some_code

But tl compiler remove this first line. Could this behavior be fixed to leave this line alone in generated file?

hishamhm commented 8 months ago

You can use

#!/usr/bin/env -S tl run

as your shebang line and keep the script code in Teal. Does that solve your problem?

I'm a bit torn about automatically preserving the shebang line upon compilation because if a Teal script contains a hashbang pointing to tl as indicated above, compiling it to Lua would render the shebang incorrect (and it's not feasible to automatically guess what the correct Lua incantation should be). Maybe the right answer would be to just cop out and add a compiler flag...

lenscas commented 8 months ago

maybe check if the shebang contains lua (or perhaps do it the other way and check if it doesn't include tl) and preserve it if it does. Then you can also emit a warning if it contains tl instead?

It won't be perfect (not by a long shot) but might be correct for enough cases to be worth it?

nagolove commented 7 months ago

Thanks all contributors for satisfying feature request!