This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
eleure's profile picture

add shebang line to beginning of all included lua programs

Started by eleure, 15 March 2013 - 10:26 AM
eleure #1
Posted 15 March 2013 - 11:26 AM
#!/usr/bin/env lua
as these lines are comments, they would have no effect on the workings of the programs.
the benefit of doing this is so that editors can automatically determine that the programs are lua, and highlight them as such.

edit: # is not a comment marker in lua, but shebang lines are standard so the lua interpreter should ignore them.

edit 2:
confirmed. from pil:
When the interpreter loads a file, it ignores its first line if that line starts with a number sign (`#´). That feature allows the use of Lua as a script interpreter in Unix systems. If you start your program with something like

#!/usr/local/bin/lua
Dlcruz129 #2
Posted 15 March 2013 - 11:34 AM
What point would this serve? This isn't UNIX.
eleure #3
Posted 15 March 2013 - 11:35 AM
What point would this serve? This isn't UNIX.
syntax highlighting is the point. when opening CC programs in any (good) editor, the files will be automatically highlighted as lua, saving me, and everyone else, the trouble of setting highlighting each time we open a file.

edit:
it should also be noted that OS X is UNIX at its core, and bash (the linux shell) supports executing files based on their shebang lines. as we're not concerned with executing the files via the lua interpreter, that's a moot point, however.
Cloudy #4
Posted 15 March 2013 - 11:38 AM
No. This would require alterations on our side, as I doubt it would work out of the box.

Plus I just don't see the point.
eleure #5
Posted 15 March 2013 - 11:39 AM
No. This would require alterations on our side, as I doubt it would work out of the box.

Plus I just don't see the point.
my first post clearly illustrates that it does work outside the box. it requires a copy/paste to the beginning of each file. nothing more.

the point is so that syntax highlighting is automatically enabled. if the editor you use to edit the actual lua programs is worth its salt, it'll automatically detect the programs as lua because of this line, thus making your programming experience, and everyone else who edits or reads them, much more tolerable.
Cloudy #6
Posted 15 March 2013 - 11:42 AM
Your first post says that the Lua interpreter (e.g. The compiled Lua binary) acts that way. Not CC. Not anything using it as a scripting library.
eleure #7
Posted 15 March 2013 - 11:43 AM
Your first post says that the Lua interpreter (e.g. The compiled Lua binary) acts that way. Not CC. Not anything using it as a scripting library.
my first post says that the first line is ignored, if it's a shebang line, for any files loaded by the interpreter. i just tested this with the alias program. it still works as intended.

edit: tried with bios.lua. no issue.
Cloudy #8
Posted 15 March 2013 - 12:09 PM
Try with others.

This is pointless anyway though. CC programs can't be ran in a standard Lua interpreter stand alone, so I'm not going to add one line to cater for you being too lazy to change the language your editor highlights as.
Cranium #9
Posted 15 March 2013 - 12:21 PM
Plus, you do know you can edit all of the lua files yourself, right? Even the ones in ROM…..
This suggestion is pretty pointless IMO.
eleure #10
Posted 15 March 2013 - 12:28 PM
i don't understand the hostility. i'm far from lazy. it's a matter of convenience, not laziness.

i'm not talking about using the shebang line to run programs through the interpreter. i'm only talking about syntax highlighting.

i threw together a quick script to add the shebang line to the beginning of a file.
#!/usr/bin/env ruby

content = File.read(ARGV[0])

File.open(ARGV[0], 'w') do | f |
  f << "#!/usr/bin/env lua\n" << content
end

i ran it on every CC program, so mine all have this line. i have no issues running CC at all. again, this is for everyone else. if it were about me, i'd have simply used this script, or a similar one, from the start.

Plus, you do know you can edit all of the lua files yourself, right? Even the ones in ROM…..
This suggestion is pretty pointless IMO.

yes, that's why i'm suggesting this. for syntax highlighting when editing those files. it's generally beneficial for everyone who edits those files. i don't understand the objection. this is a clearly useful and easy change, with no drawback whatsoever.
Cloudy #11
Posted 15 March 2013 - 12:35 PM
I'm sorry but I think it is just unnecessary cruft, more likely to confuse than help.

Suggestion denied.
eleure #12
Posted 15 March 2013 - 12:41 PM
you expect your users to learn a programming language, but you don't think they can wrap their heads around a shebang line?

it isn't necessary, but it takes little effort and is clearly useful.

again, i've applied this to my own files, so i'm arguing for the benefit of others, including the developers who actually write the default scripts.
SuicidalSTDz #13
Posted 15 March 2013 - 12:49 PM
I don't find this useful at all, more of a pain than a help. Most people here don't even know what you are talking about, nor want to know about it.

EDIT: You say you have applied it to your files, correct? Well, then I see no need for this to thread to continue.
Cloudy #14
Posted 15 March 2013 - 12:54 PM
I'm really not willing to discuss this further as it has no point.